NixOS generations

Is it possible to save the first generation where you first installed NixOS for testing/starting over without having to do a clean install? Especially if you have build several different generations on top of the first one?

Yes: I manually remove generations by removing the ‘system-xxx-link’ links from /nix/var/nix/profiles/, and AFAICS just leaving system-1-link in there should make your system keep the first generation.

ls /nix/var/nix/profiles/

let’s say i want to keep generation 199, which in this case is, system-199-link

  • get a readlink output: readlink -e /nix/var/nix/profiles/system-199-link

  • mine shows: /nix/store/j3qy0r0j79shlp18whc49vmklidznd3s-nixos-system-HP-G800-23.05.4448.5550a85a087c

  • to keep it: ln -s /nix/store/j3qy0r0j79shlp18whc49vmklidznd3s-nixos-system-HP-G800-23.05.4448.5550a85a087c /nix/var/nix/gcroots/my-virgin-generation

  • to use it again, ln -s /nix/store/j3qy0r0j79shlp18whc49vmklidznd3s-nixos-system-HP-G800-23.05.4448.5550a85a087c /nix/var/nix/profiles/system-199-link

  • nixos-rebuild boot

I’m certain theres a way to switch directly to the configuration in mind, but not exactly sure at this point.

Hope this helps

I hope this doesn’t come off as preachy, but I highly recommend versioning your NixOS configurations, partially for this reason. Even better if you use flakes, which would allow you rebuild your precise, exact config at at any historical commit point and just re-deploy it as a new generation.

In my opinion, this is conceptually simpler than trying to maintain my own gcroots. (I have tendencies to go around blasting away stray gcroots anyway, relying on my cachix cache to have my back in case I really want something back locally)

1 Like

Flakes is something I haven’t played with yet. I’m just starting to ‘kind of’ understand NixOS on channels.