While one can rollback NixOS build generations easily, this won't give back the corresponding NixOS configuration in /etc/nixos/configuration.nix. Thus, it seems to be common to track /etc/nixos/ in a version control system (VCS) e.g. in Git.

When doing so, should the /etc/nixos/result symlink also be tracked? Why?/Why not?


I can't see any significant advantage in doing it, but maybe my use cases have been too simple in this respect.

I prefer to watch ls -l /nix/var/nix/profiles/ and/or ls -l /nix/var/nix/profiles/system-profiles, based on whether you name your system profile(s), and I typically delete by hand the symlinks that I want garbage-collected.

|improve this answer|||||

You can keep track of your configuration.nix in it's corresponding generation. You just need to create a reference to it (within itself) so that it becomes part of the closure. Here's an example:


{ config, lib, pkgs, ... }:
  # yada, yada

  environment.etc."configuration.nix".source = /etc/nixos/configuration.nix;

The environment.etc option allows you to declarative-ly create files in /etc. Nix will detect /etc/nixos/configuration.nix as a path type (paths are first-class types in Nix) and thus copy it's contents into the Nix store. The result is a symbolic link /etc/configuration.nix pointing (indirectly) to /nix/store/blah-blah-configuration.nix, which means each generation will have a /etc/configuration.nix symbolic link pointing to it's corresponding configuration. You can then do something similar with additional files, such as hardware-configuration.nix.

The catch

Although the above will store your configuration, it will not make it usable by nix-env, nix-shell, nixos-rebuild, etc, because those commands use $NIX_PATH to locate configs. While you may be able to address this (see here) I don't recommend it because when you run nixos-rebuild it will use the wrong config file (/etc/nixos/configuration.nix rather than the copy in the Nix store, which is read-only anyway). Things would get wonky real quick.

And of course the Nix store is world-readable.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.