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

Flake fragments should prioritise the top-most attribute. #5651

Open
L-as opened this issue Nov 25, 2021 · 9 comments
Open

Flake fragments should prioritise the top-most attribute. #5651

L-as opened this issue Nov 25, 2021 · 9 comments
Labels

Comments

@L-as
Copy link
Member

L-as commented Nov 25, 2021

Describe the bug

Doing nix build x#y, nix eval x#y or similar, will cause Nix to evaluate packages.<system>.y before y.
This is problematic in my case, because packages uses IFD, whereas y does not.
I want to be able to evaluate y, which does not use IFD, with --no-allow-import-from-derivation.

Steps To Reproduce

  1. Have packages use IFD.
  2. Define top-level attribute y.
  3. Do nix --no-allow-import-from-derivation eval .#y. This should fail.

Expected behavior

Nix should evaluate the top-most attribute before trying the one in packages and similar.

nix-env --version output
nix (Nix) 2.5pre20211007_844dd90

@lilyball
Copy link
Member

Copying #5657 (comment) here as it really applies to the issue, not the implementation:


This is going to make nixpkgs#lib refer to the top-level lib in the flake instead of the lib in the package set. At the very least this means any overlays that update lib wouldn't apply to nixpkgs#lib after this change; I don't know if there are any other practical differences in this case besides the fact that the top-level lib has a nixosSystem function. But it's an example of a potentially surprising outcome of this change.

More generally, if nixpkgs#hello resolves to nixpkgs#legacyPackages.aarch64-darwin.hello then nixpkgs#foo should resolve to nixpkgs#legacyPackages.aarch64-darwin.foo. I shouldn't have to know the complete set of outputs of a flake to predict where arbitrary fragments resolve to. Also as a reproducibility issue, a flake adding a new top-level output shouldn't break existing flake references (e.g. nixpkgs adding a top-level hello output shouldn't break nixpkgs#hello).

I feel like perhaps a better approach is to have a separate syntax for "don't apply any prefixes to this fragment". For example, something like nixpkgs##lib.

@thufschmitt
Copy link
Member

More generally, if nixpkgs#hello resolves to nixpkgs#legacyPackages.aarch64-darwin.hello then nixpkgs#foo should resolve to nixpkgs#legacyPackages.aarch64-darwin.foo. I shouldn't have to know the complete set of outputs of a flake to predict where arbitrary fragments resolve to. Also as a reproducibility issue, a flake adding a new top-level output shouldn't break existing flake references (e.g. nixpkgs adding a top-level hello output shouldn't break nixpkgs#hello).

That’s true, but it also play the other way: if nixpkgs#foo resolves to nixpkgs#foo, then nixpkgs#hello should resolve to nixpkgs#hello. Which isn’t the case.

An “interesting” side-effect of the current behavior is that if my flake has both a toplevel foo attribute and a packages.{mySystem}.foo attribute, then there’s no way (to my knowledge) to nix eval the toplevel foo attribute

@lilyball
Copy link
Member

lilyball commented Dec 2, 2021

@regnat Despite my attempt to move the discussion here, it has continued in the PR (see #5657 (comment)).

@stale
Copy link

stale bot commented Jul 11, 2022

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

@stale stale bot added the stale label Jul 11, 2022
@tomberek
Copy link
Contributor

tomberek commented Jan 4, 2023

I feel like perhaps a better approach is to have a separate syntax for "don't apply any prefixes to this fragment". For example, something like nixpkgs##lib.

I'm looking at an approach like this: master...flox:nix:disable_attrpath_resolution

If this is preferable I can add tests/docs/etc. It's a bit odd because we're using an invalid URL, but it is also for the unique situations when one wants to express "don't perform automatic attrPath resolution".

@stale stale bot removed the stale label Jan 4, 2023
@roberth
Copy link
Member

roberth commented Jan 5, 2023

Why would eval implement any rules if it doesn't come with its own flake attribute? eval --package, sure, but this is weird.

URL

We need to stop pretending that they're universal.

@ysndr
Copy link
Member

ysndr commented Jan 6, 2023

Something perhaps more compatible might be

flake#.hello
      ^

It's not a valid nix attrpath but it allows for the attrpath to be parsed as ["", "hello"] using the existing separator.
An attrpath starting with "" could then be considered a "rooted" attrpath enforcing fully qualified access while interpreted access is still possible with the paths we know

@ysndr
Copy link
Member

ysndr commented Jan 6, 2023

In fact that already works by adding

"" = self;

to the flake output, which can be injected by nix.
I doubt that "" is commonly used as a flake output...

@tomberek
Copy link
Contributor

tomberek commented Jan 9, 2023

Edit: even newer: master...flox:nix:disable_attrpath_resolution

Supports nix eval .#. --apply builtins.attrNames

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

Successfully merging a pull request may close this issue.

6 participants