Make derivation to build on specific build machine

When I specify build machine in nix config like this:

  nix.buildMachines = [
    {
      hostName = "AAA";
      sshUser = "remotebuild";
      system = pkgs.stdenv.hostPlatform.system;
      supportedFeatures = ["nixos-test" "big-parallel" "kvm"];
    }
  ];

nix offloads any packages it sees to build machine but that machine is not capable for building some derivations due to memory constraints. Is there a way to force some derivations to not be offloaded to any build machines (or offloaded to one specific machine)?

Seems similar to Changing requiredSystemFeatures changes hash · Issue #2742 · NixOS/nix · GitHub, so I don’t think it’s possible in a nice flexible way.

Probably a workaround is simply to removenix.buildMachines/nix.conf directives for remote builders, nix-build the derivation you want, then re-enable remote builders. A different approach might be to start the build job on your preferred builder and serve it via a cache.

Maybe someone else has a better way to approach this.

--builders '' would achieve that on a temporary base, i.e., without touching nix.conf and sorts.

1 Like

If I were really inclined to filter on a derivation level I could also add preferLocalBuild, i.e., via overlay or override, but that can be a footgun, when I basically forget about that and circumstances change aka sounds like a design flaw.

Yeah this works. I have my own bincache so it will go across machine after I build it once, thanks!