Meaning of `preferLocalBuild`?

I saw a preferLocalBuild attribute in the minecraft-server derivation. What does it do, and when should someone use it?

I couldn’t find documentation for what it does, so I thought I’d ask here for the sake of future search engine users and myself.

1 Like

only matters if you have remote builders.

preferLocalBuild

If this attribute is set to true and distributed building is enabled, then, if possible, the derivaton will be built locally instead of forwarded to a remote machine. This is appropriate for trivial builders where the cost of doing a download or remote build would exceed the cost of building locally.

1 Like

The reason why the minecraft-server does this is that the “build” process is essentially pulling down a large .jar file. There’s really no expensive build process involved with creating the build artifacts.

2 Likes

There’s no impact on whether the result is fetched from binary cache or not?

Correct, this is only concerned with the “build”. If a cache hit is available, nix will generally prefer the pre-built package.

1 Like

IIRC the attribute for that is allowSubstitutes.

1 Like

IIRC, allowSubstitutes will allow for a remote machine to download build dependencies. Generally this is the desired case if the remote machine has a faster connection, such as being located in a datacenter

I find allowSubstitutes strange as it’s not always a property of the package but a combination of the local host and proximity to caching infrastructure. For example, I always want to be able to substitute builds from our on-premises cache. But that’s not possible if allowSubstitutes=false.

I proposed to add an option to allow override via configuration, but no feedback as of yet: Allow overriding `allowSubstitutes` without modification to derivation · Issue #3686 · NixOS/nix · GitHub. I don’t know if there are other reasonable options.

Can’t agree more - in enterprise settings often only dedicated “build” machines have access “outside” and many machines only have access to the internal binary cache (or the internal build servers). Seemingly random (until I discovered allowSubstituters) ignoring of prebuilt derivations available in the cache (which is a high speed connection away) has been a head-scratcher. From now on I will be setting always-allow-substituters to true everywhere.

Is there a similar override option for preferLocalBuild? The justification “This is appropriate for trivial builders where the cost of doing a download or remote build would exceed the cost of building locally.” is not well thought-through in my opinion. How would the developer of a random derivation know what is faster (or even possible due to firewalls, etc.) in my environment?