diff --git a/docs/nix-cache.md b/docs/nix-cache.md index 63fe209..51ee44c 100644 --- a/docs/nix-cache.md +++ b/docs/nix-cache.md @@ -59,6 +59,15 @@ On `nix-cache`, install the matching public key used by `nixremote` authorized k The committed `nixremote` authorized keys are public SSH keys only. Keep the matching private keys on client hosts and out of the repository. +nix-cache's own SSH *host* key is trusted declaratively via +`programs.ssh.knownHosts` in `modules/nix-cache/remote-builder-client.nix`, +sourced from `vars.nixCacheHostKey` (`variables.nix`) — every client rebuild +picks it up automatically, so distributed builds don't fail with "Host key +verification failed" on a client that has never manually SSH'd to nix-cache +before. If nix-cache's host key is ever rotated or the host rebuilt from +scratch, update `vars.nixCacheHostKey` to match its new +`/etc/ssh/ssh_host_ed25519_key.pub`. + ## Manual verification After deployment: diff --git a/modules/nix-cache/remote-builder-client.nix b/modules/nix-cache/remote-builder-client.nix index 7c6df41..a3a641a 100644 --- a/modules/nix-cache/remote-builder-client.nix +++ b/modules/nix-cache/remote-builder-client.nix @@ -5,6 +5,14 @@ # sudo install -d -m 0700 /root/.ssh # sudo install -m 0600 ./nixremote /root/.ssh/nixremote # sudo ssh -i /root/.ssh/nixremote nixremote@nix-cache nix-store --version + # Trust nix-cache's SSH host key declaratively so the nix-daemon (root) + # can connect the first time without a manual ssh-keyscan/known_hosts + # step on every new client. + programs.ssh.knownHosts.${vars.nixCacheHost} = { + hostNames = [ vars.nixCacheHost ]; + publicKey = vars.nixCacheHostKey; + }; + nix = { distributedBuilds = true; diff --git a/variables.nix b/variables.nix index 2e5c0db..b4dc147 100644 --- a/variables.nix +++ b/variables.nix @@ -19,6 +19,15 @@ remoteBuilderUser = "nixremote"; # remote builder SSH user + # nix-cache's own SSH host public key (not a secret — the private half + # never leaves the host). Wired into every client's + # programs.ssh.knownHosts by modules/nix-cache/remote-builder-client.nix + # so distributed builds don't hit "Host key verification failed" on a + # fresh client that has never manually ssh'd to nix-cache before. Update + # this if nix-cache's host key is ever rotated or the host is rebuilt + # from scratch. + nixCacheHostKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHrMKZlIGUd3pH9G3AqbsruqUGjxIXMAZw52u9MwiBCn lxc-nix-cache"; + # Public keys authorized to SSH in as remoteBuilderUser on the nix-cache # host (modules/nix-cache/server.nix) — one per client host that's allowed # to use it as a distributed builder.