How to update a NixOS machine installed via nixos-anywhere?

I was following the tutorial at https://www.youtube.com/watch?v=wr22CyoyRo4 and got confused how to update the system once it’s been installed.

The tutorial uses a host system to install NixOS on a target system via nixos-anywhere --flake. Once this is done, the target system has NixOS installed (yay) but there is nothing in /etc/nixos, so no /etc/nixos/configuration.nix on that target system. How would you go about updating it?

There is the option of running nixos-anywhere --flake from the host system again, but this seems like it is heavy-handed (it resets SSH keys I think) and probably not like the way you’re supposed to do it. My host system is also not a NixOS machine, so it lacks nixos-rebuild like he has in the tutorial.

Maybe there is some way to generate the configuration.nix file?

Since you used a flake, point nixos-rebuild switch|boot --flake at the same flake. You can update the flake with nix flake update.

If that flake is not available from the deployed system, you’ll have to make it available either by copying it over or having it accessible through the internet somehow.

1 Like

You can also add a --target-host to nixos-rebuild to deploy it from your local system.

1 Like

OK, there’s no way to switch over to being non-flake based?

nixos-anywhere doesn’t support non-flake setups afaik. I guess maybe there’s a way to recover all configured settings from a flake, but it’d be super complicated and not worth the effort.

It’d be much easier to take the modules from the nixosConfiguration and just import them from a configuration.nix, and fix the inputs from there.

You’d still need to copy the files over or use --target-host, in either case, and the latter would be a tad more awkward since you would need to change where nix reads the config from.

1 Like

Great, thank you for the information and quick reply.