There are a few things of which I cannot get the information. Could anyone give me some hints?
In order to use remote building in nixos-rebuild, nix.buildMachines in configuration.nix should be set. However I did not find how to set the non-22 ssh port.
Is there a way to temporarily set the remote building machine in nixos-rebuild command line argument?
I have a test, and find following answer:
Put the ssh host information in /root/.ssh/config works.
But still don’t know how to turn on/off the remote building on the fly e.g., by using --option
That sounds like you’re using sudo nixos-rebuild. Consider using nixos-rebuild without sudo, then you can keep your ssh config in your non-root user, which is better if you want to use key-based auth, or even a pgp card
Might take using nixos-rebuild build && sudo nixos-rebuild switch.
Bad idea, user and root might have a different view on nixpkgs.
So that would only work properly if one also provides a fixed nixpkgs entry in the nix path.
Also, as far as I remember from my own experiments, it is not important which user actually does the build, it is important whether or not the user is building directly or through the demon.
Hm, right. It’d be tricky to make this work with the user’s ssh-agent then. I think I’d still prefer letting the user use nixos-rebuild initially if we are using flakes, because those don’t rely on the nix path.