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 ignores attributes with a period {"a.b" = drv} #3088

Open
roberth opened this issue Sep 11, 2019 · 14 comments
Open

nix-build ignores attributes with a period {"a.b" = drv} #3088

roberth opened this issue Sep 11, 2019 · 14 comments
Labels

Comments

@roberth
Copy link
Member

roberth commented Sep 11, 2019

To reproduce:

$ nix-build --expr '{ hi = (import <nixpkgs> {}).hello; }'
/nix/store/...-hello-2.10

$ nix-build --expr '{ "hi.there" = (import <nixpkgs> {}).hello; }'

$
@matthewbauer
Copy link
Member

matthewbauer commented Sep 13, 2019

I think this just gets rewritten as:

$ nix-build --expr '{ hi = { there = (import <nixpkgs> {}).hello; }; }'

And Nix only builds the top level derivations. This behavior can be changed with recurseForDerivations:

$ nix-build --expr '{ hi = { recurseForDerivations = true; there = (import <nixpkgs> {}).hello; }; }'

Actually this does look like a bug! hi.there is treated as top-level, but ignored later on

@zimbatm
Copy link
Member

zimbatm commented Sep 13, 2019

When the key is quoted, it should be the name of the key.

nix-repl> { "hi.there" = 4; }
{ "hi.there" = 4; }

nix-repl> { hi.there = 4; }   
{ hi = { ... }; }

@roberth
Copy link
Member Author

roberth commented Sep 13, 2019

If that were the case, I'd expect this to work, but it doesn't:

$ nix-build --expr '{ "hi.there" = (import <nixpkgs> {}).hello; hi.recurseForDerivations = true; }'

$

To be clear, I don't want this example to work. It would mess up the meaning of attribute sets.

@zimbatm
Copy link
Member

zimbatm commented Sep 13, 2019

Here is another example that doesn't work as expected:

$ nix-build --expr '{ "3des" = (import <nixpkgs> {}).hello; }'

@edolstra
Copy link
Member

This behaviour is intended: b0cb117

@zimbatm
Copy link
Member

zimbatm commented Sep 13, 2019

@edolstra is the goal to make those disallowed on the language level as well on the longer term?

@edolstra
Copy link
Member

@zimbatm No. But generally it's a good idea to avoid them.

@roberth
Copy link
Member Author

roberth commented Sep 16, 2019

@edolstra This is applying Postel's law (be conservative in what you do, be liberal in what you accept from others) to the Nixpkgs+nix-build combination. Works well for Nixpkgs.

I would like nix-build by itself to be a simple, predictable tool, by being liberal in what it accepts.

As an alternative to the filtering in nix-build, Nixpkgs may enforce its constraints by filtering out the bad attribute names as the last step in pkgs/top-level/default.nix. Is that a acceptable solution?

@zimbatm
Copy link
Member

zimbatm commented Sep 16, 2019

@edolstra if I understand it correctly, your goal was to avoid contributors from adding those attributes to nixpkgs?

I find it surprising that those attributes get filtered out on the nix level. It adds another hidden behaviour that is only discovered after looking into the nix source code, or after finding this issue.

@stale
Copy link

stale bot commented Feb 18, 2021

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

@stale stale bot added the stale label Feb 18, 2021
@roberth
Copy link
Member Author

roberth commented Feb 18, 2021

I still believe Nix can do better than this. We ought to fix root causes, not introduce more problems by adding unnecessary restrictions.

@stale stale bot removed the stale label Feb 18, 2021
@zimbatm
Copy link
Member

zimbatm commented Feb 26, 2021

I completely forgot about this issue and got bitten by it again last week

@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
@rimmington
Copy link
Contributor

Ran into this today when an attribute path containing a : mysteriously didn't build with nix-build.

If the Nix language permits attributes to be named with these characters, the tooling should work with those attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants