Nixos-rebuild boot but only for a single boot

I’m running NixOS on my router. Until recently I got fairly lucky and updates went without a hitch. Recently however, a simple update within the NixOS 25.05 stable tree bricked my config and I had to reset the configuration using a USB-TTL serial adapter. I’d like to avoid this in the future and I was wondering if there is any way to activate a configuration for a single boot but switch back to the previous config if the device is rebooted again. The devices is booted using U-Boot configured via boot.loader.generic-extlinux-compatible

nixos-rebuild --help and read up on the test subcommand. Does what (I think) you want. Well actually not quite. It does a switch that reverts to previous config on boot. I don’t think there is something that adds a transient boot menu item.

nixos-rebuild test immediately activates the new configuration and doesn’t install the bootloader. This is fine for testing some minor userspace changes, but not testing a new kernel or something that requires a reboot.

If you’re using systemd-boot, you can use use nixos-rebuild switch and then use bootctl to

  1. revert the default boot entry to the previous generation: bootctl set-default <gen-1>
  2. set the latest generation for the next boot only: bootctl set-oneshot <gen>.
4 Likes

That sounds cool. But I forgot to mention which bootloader I’m using and I don’t think I can enable bootctl on my board