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

all-packages.nix: introduce and use dontRecurseIntoAttrs #56105

Merged
merged 1 commit into from Feb 23, 2019

Conversation

oxij
Copy link
Member

@oxij oxij commented Feb 20, 2019

What? Why?

The first non-controversial noop commit of #45841. I find this thing very useful: it provides a single place you need to override to make nix-env -qaP evaluate all packages, which is very useful for testing.

I got tired of rebasing it and fixing conflicts all the time. Can we have it in nixpkgs too, please?

git log

  • all-packages.nix: introduce and use dontRecurseIntoAttrs

nix-instantiate environment

  • Host OS: Linux 4.9, SLNOS 19.03
  • Nix: nix-env (Nix) 2.1.3
  • Multi-user: yes
  • Sandbox: yes
  • NIXPKGS_CONFIG:
{
  checkMeta = true;
  doCheckByDefault = true;
}

nix-env -qaP diffs

  • On x86_64-linux: noop
  • On aarch64-linux: noop
  • On x86_64-darwin: noop

@oxij oxij mentioned this pull request Feb 20, 2019
1 task
@oxij
Copy link
Member Author

oxij commented Feb 20, 2019

also /cc @7c6f434c, as usual

Copy link
Member

@Ma27 Ma27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea behind it, so 👍

(as a side note: unless I'm missing something, you also want to apply dontRecurseIntoAttrs on weechatScripts and roundcubePlugins. I'm "responsible" for both sub-packages and intentionally skipped the recurseIntoAttrs there).

@samueldr
Copy link
Member

Is it possible to have documentation on when one would expect to use dontRecurseIntoAttrs? What are the main use case?

Not necessarily asking the documentation in the contribution, but at least comments to the PR explaining, so it can be referenced for future documentation.

I think it's easier to grok by looking at #45841, where nodePackages has recurseIntoAttrsMaybe "nodePackages" nodePackages_8_x;, while all the version-specific attrsets have dontRecurseIntoAttrs, so they're not counted as many times as there are versioned sets, for the metrics, right? Any other uses? Does @Ma27's request makes sense here?

Thanks!

@oxij oxij force-pushed the tree/dont-recurse-into-attrs branch from cc3c0a9 to 8f86439 Compare February 21, 2019 01:29
@oxij
Copy link
Member Author

oxij commented Feb 21, 2019

@Ma27 yep, either I missed it before or it was added in-between, done.

@samueldr done? Yes, with recurseIntoAttrsMaybe the idea is exactly as you say (not to count version specific things multiple times), but this PR doesn't have that.

@samueldr
Copy link
Member

Thanks, the comment is good. (I also now fully realize what the comment meant previously.)

@7c6f434c
Copy link
Member

Hmmm. This may even be already enough to support an overlay that does the «maybe» part outside of the main codebase.

@oxij
Copy link
Member Author

oxij commented Feb 23, 2019

ping?

@7c6f434c 7c6f434c merged commit acf9a57 into NixOS:master Feb 23, 2019
@ersinakinci
Copy link
Contributor

ersinakinci commented Feb 21, 2020

In case anyone else is coming here from Google, dontRecurseIntoAttrs and its sibling recurseIntoAttrs are functions that are intended to provide metadata/semantic context for nix-env and anyone reading the code.


recurseIntoAttrs

The idea behind recurseIntoAttrs is that if you're looking for a derivation using nix-env, the search will recurse into top-level attributes that are objects. It achieves this by adding the attribute recurseForDerivations = true; to whichever set is wrapped by the function, which nix-env picks up on when running queries.

For example, nixpkgs.webos contains several sub-attributes like novacom, novacomd, etc. Thanks to the fact that webos is wrapped with recurseIntoAttrs, searching for any of those sub-attributes will yield the full attribute path:

$ nix-env -qaP novacom
nixos.webos.novacom  novacom-18

Whereas if you didn't wrap webos with recurseIntoAttrs, you would see something like this, because nix-env would only search for your derivation at the top level:

$ nix-env -qaP novacom
error: selector 'novacom' matches no derivations

dontRecurseIntoAttrs

So then what does dontRecurseIntoAttrs do?

At the moment, nothing: it's an identity function that merely returns whatever is passed into it. Since nix-env's default behavior is to not recurse into top-level attributes, it will simply, well, not recurse into an attribute when wrapped with dontRecurseIntoAttrs.

That's not to say that it's pointless. Marking an attribute with dontRecurseIntoAttrs will:

  • Lend emphasis to the fact that an attribute should not be recursed into while searching for derivations
  • More importantly, allow overriding the function so that you can recurse into all attributes wrapped in dontRecurseIntoAttrs, which can be useful during development

The second point is the main reason behind dontRecurseIntoAttrs. At the moment, its applicability is limited by the fact that the vast majority of packages aren't wrapped with dontRecurseIntoAttrs, so overriding it to act like recurseIntoAttrs won't have much effect.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/wheres-the-nodejs-apps/12064/10

@oxij oxij deleted the tree/dont-recurse-into-attrs branch August 12, 2023 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants