This is a fairly straightforward setup for making a NixOS system configuration stateless without relying on experimental Nix features.
This means:
nix-channel
is disabled[^1]: Yes niv is a third-party tool, but it's essentially just a nice wrapper around nix-prefetch-url
and co.
We're assuming that you just installed NixOS by going through the official installation docs.
nix-shell -p git --run \
'git clone https://github.com/infinisil/sane-stable-nixos nixos'
cd nixos
sudo mv /etc/nixos/* .
nixos-generate-config --dir .
nix-shell -p niv --run \
'niv init --nixpkgs NixOS/nixpkgs --nixpkgs-branch nixos-23.11'
sudo rm -v /nix/var/nix/profiles/per-user/*/channels*
sudo ./rebuild switch
Here are some changes you can make:
./configuration.nix
niv update nixpkgs
niv update nixpkgs --branch nixos-23.11
nixpkgs/config.nix
nixpkgs/overlays.nix
nixos-generate-configuration --dir .
To apply the changes, run
sudo ./rebuild switch
All options to ./rebuild
are forwarded to nixos-rebuild
.
After rebuilding, the changes are reflected in the system. Furthermore, all Nix commands on the system will also use the the same values.