How to run `nixos-rebuild --target-host` from Darwin?

My solution right now is to declare this function in my .zshrc:

nixos-deploy() {
  nixos-rebuild switch --flake path:.#$1 --target-host $1 --build-host $1 --fast --use-remote-sudo      
}

On the target, you will need to set

security.sudo.wheelNeedsPassword = false;

otherwise nixos-rebuild will fail as described in this thread.

Alternatively, you can try

security.pam = {
  sshAgentAuth.enable = true;
  services.sudo.sshAgentAuth = true;
};

on the target, and adding the ForwardAgent option to ~/.ssh/config on the machine you’re deploying from:

Host <hostname>
  ForwardAgent yes

as described in this thread, though I didn’t try that.

1 Like