Nixos-rebuild remote deploy from substituter

I am on host a, and I have the derivation for a host I want to deploy locally:

$ nix path-info --derivation .#nixosConfigurations.loogle.config.system.build.toplevel
/nix/store/bwpbwbrm4sni09gwqwapvdi3z46g0711-nixos-system-loogle-23.11.20230606.af21c31.drv

I do not have the output locally:

$ nix show-derivation /nix/store/bwpbwbrm4sni09gwqwapvdi3z46g0711-nixos-system-loogle-23.11.20230606.af21c31.drv | jq -r '.[].outputs.out.path'
/nix/store/mb13r407vhf3gy4vj9b6nvizmgjm64p8-nixos-system-loogle-23.11.20230606.af21c31
# ls /nix/store/mb13r407vhf3gy4vj9b6nvizmgjm64p8-nixos-system-loogle-23.11.20230606.af21c31
ls: cannot access '/nix/store/mb13r407vhf3gy4vj9b6nvizmgjm64p8-nixos-system-loogle-23.11.20230606.af21c31': No such file or directory

But it is available in a substituter:

$ nix store ls -d --store https://cache.garnix.io  /nix/store/mb13r407vhf3gy4vj9b6nvizmgjm64p8-nixos-system-loogle-23.11.20230606.af21c31
.

How can I invoke nixos-rebuild so that

  • the derivation isn’t pushed to the other side (no need to pull in all the sources it depends upon)
  • the output path is fetched from the substituter (which is configured remotely)

It seems that

nixos-rebuild switch --use-substitutes --target-host root@loogle.nomeata.de  --flake .#loogle --fast

will pointlessly build the system locally (by fetching it from the substitutor), while

nixos-rebuild switch --use-substitutes --build-host root@loogle.nomeata.de --target-host root@loogle.nomeata.de  --flake .#loogle --fast

insists on (pointlessly) uploading the .drv to the remote host first.

I guess I can do some of the steps that nixos-rebuild does manually; once I have the output name

$ nix-env -p /nix/var/nix/profiles/system --set /nix/store/mb13r407vhf3gy4vj9b6nvizmgjm64p8-nixos-system-loogle-23.11.20230606.af21c31

will nicely fetch it (on the remote host), and then I just have to run

$ /nix/store/mb13r407vhf3gy4vj9b6nvizmgjm64p8-nixos-system-loogle-23.11.20230606.af21c31/bin/switch-to-configuration switch

it seems.

Is this too much of a corner case to be supported more directly?

See https://github.com/cachix/cachix/blob/3dd5df641801cbf7a65e810b9b8a09709d17dfb4/cachix/src/Cachix/Deploy/Activate.hs#L118

1 Like