Can I move /etc/nixos to my dotfiles and symlink it back to /etc/nixos?

There’s no need to symlink — /etc/nixos/configuration.nix is just the default location, and you can change it. When you run nixos-rebuild, it looks up the value of “nixos-config” in the NIX_PATH environment variable, so you can point that wherever you want.

Example (as root):

export NIX_PATH="nixos-config=/path/to/configuration.nix"
nixos-rebuild switch

See also the nix.nixPath configuration option.

7 Likes