the_prg_server_configuratio.../nix-system-configs/modules/toolsets/remote_building.nix

50 lines
1.4 KiB
Nix

{
config,
pkgs,
lib,
...
}: {
# THE FOLLOWING CODE BLOCK IS FOR COPYING TO OTHER CONFIGURATIONS, NOT FOR THIS FILE
nix.distributedBuilds = true;
nix.buildMachines = [
{
hostName = "nixos-build-machine";
system = "x86_64-linux";
sshUser = "nixremote";
sshKey = "/root/.ssh/nixremote";
maxJobs = 4;
speedFactor = 2;
supportedFeatures = ["nixos-test" "benchmark" "big-parallel" "kvm"];
}
];
# Generate SSH key for remote building
systemd.services.generate-nixremote-key = {
description = "Generate SSH key for remote Nix builds";
wantedBy = ["multi-user.target"];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = ''
if [ ! -f /root/.ssh/nixremote ]; then
${pkgs.openssh}/bin/ssh-keygen -t ed25519 -f /root/.ssh/nixremote -N "" -C "nix-remote-builder"
fi
'';
};
programs.ssh.extraConfig = ''
Host nixos-build-machine
HostName 10.1.1.3
IdentitiesOnly yes
IdentityFile /root/.ssh/nixremote
User nixremoteStrictHostKeyChecking accept-new
'';
# Manual step required: After rebuilding the client, copy /root/.ssh/nixremote.pub
# from the client to the build machine's users.users.nixremote.openssh.authorizedKeys.keys list,
# then rebuild the build machine.
# i.e on the client: run "cat /root.ssh/nixremote.pub"
# and copy the output to the build machine's configuration.nix
}