The more I use NixOs the more interesting it gets. I now found out about remote builders and those are just awesome.

Under pressure

The idea is to offload build steps to a remote machine instead of using the local one. The build process might require compiling packages, so a machine with more resources can speed-up the process.

That’s handy. I can use my laptop without the fans spinning like a jet turbine, while my dev server does all the job. And in less time: laptops don’t have a cooling system as powerful as a desktop, due to the limited dimensions. When the CPU gets too hot, the thermal throttling kicks in to down-clock the CPU to prevent damage. The strategy to reduce the heat generated is to reduce it’s speed. And thermal throttling also happens in desktops, but those have room for large heatsinks and better cooling, this way desktops can sustain higher clock frequencies for longer time.

When updating my laptop using the remote machine as builder, my laptop’s CPU load was around 1.5 with a clock frequency of 1.6GHz. While my dev server was at warp speed: I saw a load of 79, 72, 45, 100% CPU usage clocked at 4.6GHz and around 35 GiB of RAM usage (!). And I didn’t hear any loud fans (desktop is far away).

When using remote builders, the local machine doesn’t build anything.

Setting up remote builders requires these steps:

  • on the remote builder:
    • Configure a trusted user: nix.config.trusted-users = ["root" "myuser"];
    • Add the public SSH key of the machine that will use that builder
  • on the laptop:
    • Add a CLI flag to nixos-reuild to use the remote builder: sudo nixos-rebuild switch --flake . --builders "ssh://myuser@builder <other builder specification>"
    • Or add nix.buildMachines to your NixOs configuration to not have to use --builders flag. Don’t forget to set nix.distributedBuilds = true, to enable using the buildMachines.

That’s all. Really.

The builder specification has eight components:

  • Host to connect to.
  • Platform architecture the builder can build to e.g. x86_64-linux, x86_64-darwin, etc.
  • Path to the private SSH key for authentication e.g. /home/me/.ssh/id_ed25519
  • Maximum number of simultaneous build jobs.
  • Relative speed of the builder.
  • List of builder supported features e.g. benchmark, big-parallel, nixos-test, kvm.
  • Public key of the builder.

More details on the builder options and configuration in the NixOs documentation and in the NixOs Wiki.

Happy building.