What is the /etc/NIXOS file? It has no content. It is some sort of marker? Does it need to be preserved or mapped?
I know /etc/nixos is where system configuration files are by default. However, I’ve got them stored in another directory, which works fine, and /etc/nixos remains empty. Does the directory still need to exist?
I don’t do anything with /etc/NIXOS (I use ZFS rollbacks and a persistent folder for /etc/nixos).
I’d assumed that it lets nix know that you are running in nixOS, and that it recreates it itself.
I’m fairly sure that /etc/nixos does not need to exist as long as the system can find the config on reboot (as it will regenerate the output from that). Having said that I have not tried it…
Yep, this is the correct answer. Whenever you switch NixOS configurations, it ensures you’re targeting an actual NixOS system. It doesn’t hold any data but its existence does tell nixos-rebuild whether or not the target rootfs is a NixOS system.
The file is created during activation. Note that switch-to-configuration is the program that bails if /etc/NIXOS doesn’t exist. So nixos-rebuild will bail without /etc/NIXOS because it calls switch-to-configuration, but activation does not bail without it. While activation is one of the steps in switch-to-configuration, it also occurs independently during boot, which causes the file to be created.