Nixos-rebuild --target-host woes

I’m investigating ways to setup and update remote server.

currently everything is tested in a VM.

for initial setup i’m using nixos-anywhere, but as far as I understand, i cannot use it the same way for updating the system like nixos-rebuild

So then to update a remote system i’m trying nixos-rebuild

specifically: nixos-rebuild switch --target-host root@127.0.0.1:6622 --flake .#server1

(also I’m not sure if I specify alternative ssh port correctly)

What I get is

copying 0 paths...
ssh: Could not resolve hostname 127.0.0.1:6622: Name or service not known
error: your NixOS configuration path seems to be missing essential files.
To avoid corrupting your current NixOS installation, the activation will abort.

This could be caused by Nix bug: https://github.com/NixOS/nix/issues/13367.
This is the evaluated NixOS configuration path: /nix/store/06gpbgc2sjlqik8y7qjan0mvkzg7d0k8-nixos-system-server1-25.11.20251226.f560cce.
Change the directory to somewhere else (e.g., `cd $HOME`) before trying again.

If you think this is a mistake, you can set the environment variable
NIXOS_REBUILD_I_UNDERSTAND_THE_CONSEQUENCES_PLEASE_BREAK_MY_SYSTEM to 1
and re-run the command to continue.
Please open an issue if this is the case.

Even though you can see ssh: Could not resolve hostname 127.0.0.1:6622: Name or service not known line in log - I do see a successful ssh connection in the VM

I have no idea how to debug what’s going on from here.

Very likely related to.

Which from my understanding should have landed in nix 2.31

hm, i’m on 25.11, and nix -–version returns 2.31.2

i guess it was fixed for nix copy, but not for nixos-rebuild ?

but the workaround from the linked issue seem to have solved my problem:

NIX_SSHOPTS=“-p 6622” nixos-rebuild switch --target-host ``root@127.0.0.1`` --flake .#server1 seem to have worked properly

nixos-rebuild uses nix copy under the hood AFAIU.

1 Like