I have two laptops (and maybe more hosts in the future) with a desktop all running NixOS. Both laptops will cook themselves when doing builds, so using remote building against the desktop would be nice if available. But these laptops will be in the wild and I’ll need to grab/build something at the spot sometimes, which means I won’t have a build host and I’ll have to awkwardly remove /etc/nix/machines
and modify /etc/nix/nix.conf
if I can’t nixos-rebuild
with my remote build config commented out.
I tried searching before and people alleged that it’s possible, but then not provide any resources or examples of the configuration.
Anyways, my config that works within the home network, configured for distributed build and allow my build-host to serve builds it already completed (since they share common configs):
{ config, pkgs, lib, ... }:
let
gammax = "gammax.domain.local";
in
{
nix.buildMachines = [ {
hostName = "${gammax}";
systems = [ "x86_64-linux" "i686-linux" ];
protocol = "ssh-ng";
maxJobs = 32;
speedFactor = 2;
supportedFeatures = [ "nixos-test" "big-parallel" "kvm" ];
mandatoryFeatures = [ ];
}] ;
nix.distributedBuilds = true;
nix.extraOptions = ''
builders-use-substitutes = true
'';
nix.settings = {
trusted-substituters = lib.mkBefore [ "ssh-ng://${gammax}?priority=1" "https://cache.nixos.org?priority=50"];
trusted-public-keys = lib.mkBefore [ "[gammax-public-key…]" ];
substituters = lib.mkBefore [ "ssh-ng://${gammax}" ];
};
}