4 ms·
Each NixOS machine has a current configuration, symlinked from /run/current-system. For example, my NixOS laptop currently has this: /run/current-system ->
by Gaelan 5y ago
Each NixOS machine has a current configuration, symlinked from /run/current-system. For example, my NixOS laptop currently has this:
/run/current-system -> /nix/store/95n5xr5n8bw6xbab8fiz6cqc6mydryg8-nixos-system-Sweetpea-21.11pre291991.ea7d4aa9b82
My $PATH contains /run/current-system/sw/bin, so all of my machine's (globally-installed) software comes from whatever the current configuration is. There's also some other stuff in there, like /run/current-system/kernel and /run/current-system/etc, which contain what you'd expect.
Let's say I want to change something. I edit /etc/nixos/configuration.nix, then run "nixos-rebuild build", which produces this:
/nix/store/0fhxjqbv20psbkjvw70wni9ww2cxfqgm-nixos-system-Sweetpea-21.11pre292748.6933d068c5d
That step does all of the downloading, etc, but it doesn't actually change anything on my system—the /run/current-system symlink hasn't changed, so I'm still running on the old configuration.
When I'm ready to change, I run "/nix/store/0fhxj.../bin/switch-to-configuration". This step actually changes the /run/current-system symlink, updates /etc, restarts any daemons that were updated, etc. Obviously, if your configuration has a new kernel, that won't be applied until you reboot.
In practice, we almost always just run "nixos-rebuild switch", which does the build and switch in one go.
This whole process is entirely idempotent and reversible; I can switch back to any configuration I've ever built (unless I've since removed them to save space, of course). GRUB also displays a list of every configuration you've ever built, so you can always boot into a stable configuration even if you've somehow made a royal mess of things.
- alias_neo 5y agoThanks for taking the time to describe that, it makes sense now. I'm impressed that it manages restarting everything on the fly without a reboot on a running system.
- pxc 5y agoOn rare occasions, there can be problems restarting a service, like if the service in the new configuration in fact relies on a newer kernel module than what you've got in your running configuration. In addition, sometimes Nix's garbage collector won't dispose of something because it can tell you've still got some processes running that use it or something like that, and so there's a bit of space you can't free up until after reboot. And of course, kernel changes still require reboots on NixOS. All in all, the service management stuff is handled very gracefully imo. I've never run into real trouble with it (and one time I had a power outage in the middle of a `nixos-rebuild switch`).