Proposal (NixOS): snapshot configuration.nix for every nixos-rebuild and store in that system's profile

Hello, I’m new to Nix and have a suggestion. If this has been proposed and evaluated previously, please ignore. I searched and didn’t find anything, but my search-fu may not be bulletproof.

And, I know you guys are busy prepping the 21.05 release, and it has been feature-frozen, so no need to take the time to reply now. Just want to get this idea in the record for possible future consideration.

Also, thanks to everyone who has built NixOS into what it is today. It is truly an amazing game changer and is one step further out of the tarpit.


Proposal: It might be a nice QoL addition if nixos-rebuild would snapshot the configuration.nix it used, and store that somewhere out-of-the-way in the system profile it built.

If each system profile included a copy of the configuration.nix that built it, it would be easier to troubleshoot in case a new profile is broken in some way. Just diff the broken profile’s configuration.nix vs the prior working one.

I’m sure users can write some kind of hook in their configuration.nix to git commit or btrfs/zfs snapshot the configuration.nix on every nixos-rebuild, but it might be nice to have this function by default.

I suggest this because my NixOS system recently broke after I made some additions to configuration.nix. But the only changes I remember making were adding some additional packages to environment.systemPackages. That shouldn’t have caused the system to fail to boot.

It had to be due to something else. A simple diff of the broken configuration.nix vs the prior working one would help track down the error. But I didn’t expect the new system to break and so didn’t make a backup copy of the working configuration.nix. So it might be nice if nixos-rebuild did that automatically.

3 Likes

Hello!

This is actually implemented already, if you set system.copySystemConfiguration! The docs describe how to use it:

https://search.nixos.org/options?channel=20.09&show=system.copySystemConfiguration&from=0&size=50&sort=relevance&query=copysystem

This helps a lot if you have everything in one file, but it doesn’t copy any other files if you break your configuration up into multiple files, so it has limited use for more complex configurations. I don’t even think it copies hardware-configuration.nix.

8 Likes

Oh brilliant, thanks! Good enough, I don’t mind the limitations. I try not to keep anything custom in hardware-config.nix either since it’s dynamically generated per machine.