5

Is there a way to revert to the previous (or at least "current") configuration after nixos-rebuild test without rebooting?

Per the nixos-rebuild manual:

   test
       Build and activate the new configuration, but do not
       add it to the GRUB boot menu. Thus, if you reboot
       the system (or if it crashes), you will
       automatically revert to the default configuration
       (i.e. the configuration resulting from the last call
       to nixos-rebuild switch or nixos-rebuild boot).

Clearly, rebooting should get me back to a working system, but seems like it shouldn't be necessary.

The --rollback option looks promising:

   --rollback
       Instead of building a new configuration as specified
       by /etc/nixos/configuration.nix, roll back to the
       previous configuration. (The previous configuration
       is defined as the one before the “current”
       generation of the Nix profile /nix/var/nix/profiles/
       system.)

Except that I want to activate the "current" generation, not the older generation.

For example. Generation 18 is the "current" one which is slightly out of date but acceptable. Generation 17 is older. I used nixos-rebuild test --upgrade which broke Chrome, so I want to revert back to 18 without rebooting. (Until I can get the upgrade issues resolved.)

Update: I tried nixos-rebuild test --rollback, but the documentation is accurate: It reverted to 17 rather than 18.

aij
  • 183
  • 6

2 Answers2

1
# List previous generations
sudo nix-env --list-generations -p /nix/var/nix/profiles/system

# Live switch to any generation
sudo nix-env --switch-generation 12345 -p /nix/var/nix/profiles/system
sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch

Source: https://github.com/NixOS/nixpkgs/issues/24374

user206746
  • 186
  • 1
  • 3
0

From reading the source, I found this solution which seems to have worked, but feels really hacky:

# /nix/var/nix/profiles/system-18-link/bin/switch-to-configuration test
activating the configuration...
setting up /etc...
setting up tmpfiles
reloading the following units: dbus.service

Is there a cleaner way?

aij
  • 183
  • 6