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.
Source: https://github.com/NixOS/nixpkgs/issues/24374
From reading the source, I found this solution which seems to have worked, but feels really hacky:
Is there a cleaner way?