Switching between `nix build` builder profiles

Remote builders can save build time, especially when they are use from multiple machines and also serve as a cache.

Remote builders can be specified in /etc/nix/nix.conf via configuration.nix, e.g. with

  nix = {
    settings = {
      max-jobs = lib.mkDefault 4; # this machine is a laptop
    };
    distributedBuilds = true;
    buildMachines = [{
      hostName = "builder.example.dk";
      system = "x86_64-linux";
      protocol = "ssh"; # ssh-ng seems slower
      speedFactor = 5; # this machine is fast
      maxJobs = 4;
      supportedFeatures = [ "nixos-test" "benchmark" "big-parallel" "kvm" ];
      mandatoryFeatures = [ ];
    }, {
      # another remote builder
    }];
  };

Fairly regularly, I’d like to not use the remote builder. When I have a bad network connection or when the remote builder is overloaded. Since the remote builders are configured in /etc/nix/nix.conf via configuration.nix changing that setting requires a cumbersome nixos-rebuild.

Is there more convenient / faster way to switch?

1 Like

Try nix build --builders "" ...

That works great!

Ideally, it’s be quick to switch between remote build servers too, but that might be handled by aliases or scripts.

You can provide the same info to the --builders option as you do in configuration.nix, see Remote Builds - Nix Reference Manual. However it is easy to forget to for example provide the maxJobs parameter when using --builders, so if you do something like --builders ssh://builder.example.dk you have, perhaps unknowingly, restricted the remote builder to only one job at a time.

It would be nice if you could add aliases for the machines together with their parameters, and then simply select which of those aliases to use with the --builders option.

Yes, selecting between profiles with --builders would be great.

1 Like

The problem is that --builders currently is used either for pointing Nix to a file containing builder machines (using the @/path/to/builders syntax), or directly define the builder machines. Perhaps a new option is needed to define the “available builders”, and then some syntax for --builders to select builders from that list.

The documentation (man nix) just says:

  · --builders value
    
    Set the builders setting.

I had no idea it can be used to point to a file with builder definitions. That is good way to switch profiles too.

1 Like