Skip to content

Commit 5a24b24

Browse files
committed
Configure nix remote / distributed build
Make srv1.local (bforsman.name) the server, and configure the clients (media, mini and whitetip (only keys tracked in git)) to use it as remote builder.
1 parent 20730e4 commit 5a24b24

File tree

7 files changed

+59
-0
lines changed

7 files changed

+59
-0
lines changed

cfg/base-small.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@
166166
passwordAuthentication = false;
167167
extraConfig = ''
168168
AllowUsers backup git bf
169+
# For nix remote / distributed builds
170+
AllowUsers nix-remote-build
169171
170172
# Doesn't work on NixOS: https://github.com/NixOS/nixpkgs/issues/18503
171173
## Allow password authentication (only) from local network

cfg/nix-remote-build-client.nix

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
nix.buildMachines = [
3+
{ hostName = "bforsman.name";
4+
systems = [ "x86_64-linux" ];
5+
# TODO: I belive maxJobs = "auto" is documented somewhere, but nix-2.2.2
6+
# and 2.3 fail with unhelpful "error: stoull".
7+
maxJobs = 4;
8+
speedFactor = 10;
9+
supportedFeatures = [
10+
"benchmark"
11+
"big-parallel"
12+
"kvm"
13+
"nixos-test"
14+
];
15+
mandatoryFeatures = [ ];
16+
# The server side user to login with
17+
sshUser = "nix-remote-build";
18+
# The client side private key for login as sshUser
19+
sshKey = "/root/.ssh/id_ed25519_nix_remote_build";
20+
}
21+
];
22+
nix.distributedBuilds = true;
23+
24+
# optional, useful when the builder has a faster internet connection than yours
25+
nix.extraOptions = ''
26+
builders-use-substitutes = true
27+
'';
28+
}

cfg/nix-remote-build-server.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# TODO: There is a nix.sshServe NixOS option, but it doesn't (yet) allow the
2+
# configuration of the nix-store --write flag.
3+
4+
let
5+
user = "nix-remote-build";
6+
in
7+
{
8+
# must be trusted to be allowed to build derivations
9+
nix.trustedUsers = [ user ];
10+
11+
users.users.nix-remote-build = {
12+
group = user;
13+
isSystemUser = true;
14+
useDefaultShell = true;
15+
openssh.authorizedKeys.keys = with import ../misc/ssh-keys.nix; [
16+
(''command="nix-store --serve --write",restrict '' + media.root.nix_remote_build)
17+
(''command="nix-store --serve --write",restrict '' + mini.root.nix_remote_build)
18+
(''command="nix-store --serve --write",restrict '' + whitetip.root.nix_remote_build)
19+
];
20+
};
21+
22+
users.groups."${user}" = { };
23+
}

machines/media/configuration.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
../../cfg/base-medium.nix
77
../../cfg/disable-suspend.nix
88
../../cfg/bcache.nix
9+
../../cfg/nix-remote-build-client.nix
910
];
1011

1112
# Use the systemd-boot EFI boot loader.

machines/mini/configuration.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
../../cfg/base-big.nix
77
../../cfg/clamav.nix
88
../../cfg/disable-suspend.nix
9+
../../cfg/nix-remote-build-client.nix
910
../../cfg/smart-daemon.nix
1011
];
1112

machines/srv1/configuration.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ in
1919
../../cfg/cgit.nix
2020
../../cfg/git-daemon.nix
2121
../../cfg/gitolite.nix
22+
../../cfg/nix-remote-build-server.nix
2223
../../cfg/postfix.nix
2324
../../cfg/smart-daemon.nix
2425
../../cfg/swraid.nix

misc/ssh-keys.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
{
88
media.root.backup = ''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJsLLEZxPtdFQJVqG8zOuBZTUYHhhh026F2BDsHXJXPW root@media (for backup automation)'';
9+
media.root.nix_remote_build = ''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILoDrnvYjSPBWVLgwmuVaOUTnNF1ASaO7Y+oej+6WRBm root@media (nix remote build)'';
910

1011
mini.root.backup = ''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPCwtdqwE2WLolrNQmf5M/DmzaKjG29yq0lr4WgUa2z7 root@mini (for backup automation)'';
12+
mini.root.nix_remote_build = ''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE62OwZK96RYNiHbVWpQR+aD98wJn9TFmjKTnCV9pv5k root@mini (nix remote build)'';
1113

1214
mini.bf.default = ''ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTl8tsKUmHqO5eJoPvAVSu5vm7Ibml9rYxAblTUU/dl+zip7RNfl178qaX4nwUHkI3qsITJ8yQr42iIanvIPpCvM5V4rYjDmD7R4R8wSvzsrxegipG+kXfItlgsmCIuNsYZNCPtxESsLMW6tuJBfFy8L0IGmwYXLNNj7NIsrI4ElOhmWHz+VppZU1R74IghC+ZWJkkqoc9Ayt17ezLfBPYYuoan60H2/KOBtJX5qjfdxGXF5H7Oa7SBE/0zZ5Eaq8MudM/7CClc2nA787xadp8O6aQoF/ZB27dwr3mK2IugYc7w2rDlT67iQHLT27LKMU74CY//xSqkGUZOyGDAN7B bf@mini'';
1315

1416
whitetip.bf.default = ''ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCfy7XFi35G277tbjGzFeFdbtz8c3b9dQcBpE9KlcVVKMG9mMzVQeLJkehqi/NGyzV7DcJgvFW0vFJaRbQbOVuIlnC3rCwO+NUJW+48aarnna1Izv6ihHp5vprYhZT9AANfUUsaCy5ZBVljlJ34S8gJNvmq7oogh9ioi9hE3LvdZMC0M6k2WZG5+lPlDWbNjuWlYF9e9XVJlopU+xfNy98u0djyBo2urkqtNT8vXu49JarKpxgi3tMDv2pZFNNICukWsg8EEH6YIhJjsiO0RdnanzO/yQK2/SQtq0GjnzEaRilAgiUnGHC7f7iOBeNhc+hUcKltBlWmPsF9ZV5txZDT bf@whitetip'';
17+
whitetip.root.nix_remote_build = ''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBOgHOn3+Sr8WUZQiEVN3NZ6nXOL1NPUSo2Sen+63G6j root@whitetip (nix remote build)'';
1518
whitetip.root.backup = ''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAMnppoIYKUmeW09hw2nEofL3aDL12T/P8P81HMnwPpE root@whitetip (for backup automation)'';
1619

1720
my_phone.user.default = ''ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDZ63+kGCJbSI8P8LThqXJHZdiGWHpR7K/NUkimWn+3r4y22JhuRLpUHnHRfvPm16HIbrVwrHbZ6vxqvxx7hP9UGRTdRT9HjOvVoOQGIYjRtjrRiMHE/DmrBxdQ5FtQVeARKcNCWYIlubtuxg1c6ZD0fScs5yWrlumblsQxJgqS5K6csyh9yZL8rtBC0VqkroynMoYONqTTAAnx6lg9X6t2FZ3SFqCZ5VYk9DkwLZNIrwwEF87tQSuCSTX8pKw9THP0H07pafR0hWwKHuhPqbK7qlE1ZXzVtbujg/GndLbjFFV7Lpkc5h5B+fC4VBAiaKG9DQSV5LNRjrolprQkijNiFNqojnsCSJVDHSercDSTLNsN2wNPKXUlzkNyWEnefvPFrW1vPBoTF8YrPICNOi8mGLkX+ygP0ROycuKupSqkfAjXqdabAnuHNZHI1gY9j4/qlK5YhgbOu1pWVe9xVKCEfR0MG/iTi83ExiDlkzGgOcFkiDoUaKF6HMM2w6u+pgwDSsP8jmHrUuGqib3mMm3M7VMoGvxQE+T8bQ53G1/z/FI3xITpnNUs61DtUxf6uSCYJFDE5vRYSAnPW9L7/dLo5klJbDbyGyHgneFeGb5gdQEqhUZHXHXwCPyH5fn2XLA6DErMGWAvEqNVs6p2XO54UY/HuKnjr1W8eMqLVMpvVw== My phone'';

0 commit comments

Comments
 (0)