[Nix#9605] preferLocalBuild + IFD causes Nix to prefer local builds even when the system doesn't match #86
Labels
No labels
Area/build-packaging
Area/evaluator
Area/flakes
Area/profiles
Area/remote-builds
Area/repl
Area/store
bug
Cross Compilation
devx
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
imported
Needs Langver
OS/Linux
OS/macOS
performance
regression
release-blocker
RFD
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
ux
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lix-project/lix#86
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Upstream-Issue: NixOS/nix#9605
Describe the bug
If you use import-from-derivation (IFD) to build a derivation at evaluation time and the derivation specifies
preferLocalBuild = true;
then Nix will prefer to build the derivation on the local system (instead of a remote builder) even if the derivation's system doesn't match the local system. However, if you don't use IFD (i.e. build the derivation by itself in isolation at build time) then Nix respects the derivation's specified system and won't build it locally if the local system doesn't match.The original context for this is that we have a build that used
haskell.lib.packageSourceOverrides
(which uses import-from-derivation under the hood viacallCabal2nix
) and when we ran the same build for a different system using--system
then Nix would still try to build the derivation locally despite system mismatch and then the build fails. However, if we disabled local builds (e.g. using--max-jobs 0
) then Nix correctly delegates the build to a remote builder.Steps To Reproduce
You can reproduce this by saving the following code to
flake.nix
:… then if you
nix build
that for a system other than the current one (my local system isaarch64-darwin
) then it will fail like this:This will fail regardless of whether you have configured a remote builder that supports the desired
system
(e.g.x86_64-linux
in the above example) because Nix (incorrectly) prefers to build this derivation locally (and the local system doesn't support the derivation's specified system).However, if you do any of the following then the build will succeed:
preferLocalBuild
tofalse
then it will succeed--max-jobs 0
to the command (disabling local builds) then it will succeednix-store --realise /nix/store/…-derivation-to-import.drv
then it will succeedThat last bullet point is the primary reason I consider this a bug in Nix and not, say, Nixpkgs, since I'd expect that whether or not a
.drv
successfully realizes should be independent of whether it is realized at evaluation time (i.e. import from derivation) or build time.Expected behavior
I expect the original
nix build
command to succeed. More generally, I expect any derivation to realize the same regardless of whether it is realized at evaluation time or not.nix-env --version
outputAdditional context
For reference, the Nix manual has this to say about
preferLocalBuild
:… emphasis on "if possible". Nix should only prefer building locally if the local system matches.
Priorities
Add 👍 to issues you find important.