Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix build vs nix develop --build inconsistency #4578

Open
tg-x opened this issue Feb 26, 2021 · 5 comments
Open

nix build vs nix develop --build inconsistency #4578

tg-x opened this issue Feb 26, 2021 · 5 comments

Comments

@tg-x
Copy link
Member

tg-x commented Feb 26, 2021

Describe the bug

nix build & nix develop --build behaves differently in case of dune packages that appears to be counter-intuitive.

With this flake.nix, nix build succeeds while nix develop --build fails due to missing dependencies.
In this example blip & urps are both the names of flake inputs, and are also package names in prevOcamlPackages, which is brought into scope on line 35.
When they are referenced on line 59-60, they mean different things in nix build & nix develop:

  • in nix build they refer to packages from prevOcamlPackages
  • in nix develop they refer to the flake inputs

Update: the issue is due to nix develop --build runs make (which in turn runs dune build, building all packages),
while nix build runs dune build -p p2p which doesn't require these inputs

Expected behavior

The same behaviour is expected in both cases.

Steps To Reproduce

Run nix build & nix develop --build

nix (Nix) 2.4pre20201205_a5d85d0

@tg-x tg-x added the bug label Feb 26, 2021
@thufschmitt
Copy link
Member

I don't think the two commands could possibly have different scoping rules because they both use the exact same function for doing the evaluation.

However, the correct scoping is that blip and urbs do come from the flake inputs, because with will never shadow an already bound variable (see in https://nixos.org/manual/nix/stable/#idm140737321917712, “The bindings introduced by with do not shadow bindings introduced by other means”). So I guess the derivation just builds fine without them − I actually tried removing them from the buildInputs list and it built without complaining.

@thufschmitt
Copy link
Member

Just digged a wee-bit deeper because I was curious, and it turns out that nix develop fails because for some reason it runs make rather than the buildPhase that buildDunePackage fails. The Makefile runs dune build which fails because p2p-poldercast depends on blip. Otoh, nix build will run the buildPhase specified by buildDunePackage, which is (essentially) dune build -p p2p. And as the p2p package doesn't depend on blip or urbs it builds fine.

@tg-x
Copy link
Member Author

tg-x commented Feb 26, 2021

Indeed, the issue is then that nix build and nix develop --build do different things.
I was expecting nix develop --build to build the default package like nix build, using buildDunePackage
and wasn't expecting it to build everything, that explains why it failed.

Is this how it's supposed to work or is this a bug?

The scoping is indeed correct and the p2p package doesn't need those inputs,
the confusion was because of the different behaviour of the two commands.

Thanks for checking!

@tg-x tg-x changed the title nix build & nix develop: variable scope inconsistency nix build vs nix develop --build inconsistency Feb 26, 2021
@stale
Copy link

stale bot commented Aug 25, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Aug 25, 2021
@roblabla
Copy link
Contributor

This is not stale, and still a problem. It seems that, in nix develop, running buildPhase will always use the stdenv/default builder's buildPhase, instead of the derivation's overridden value. Currently using nix (Nix) 2.11.0.

@stale stale bot removed the stale label Nov 19, 2022
@stale stale bot added the stale label May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants