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

lib: Working with nested attrsets of packages #202517

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

roberth
Copy link
Member

@roberth roberth commented Nov 23, 2022

Description of changes

Functions for

  • extracting derivations the way nix-build does (or should)
  • flattening attribute sets
  • flattening attribute set trees of derivations (increasingly common since flakes)

TODO

  • validate in practice
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@roberth roberth changed the title Get derivations lib: Working with nested attrsets Nov 23, 2022
@roberth roberth changed the title lib: Working with nested attrsets lib: Working with nested attrsets of packages Nov 23, 2022
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Nov 23, 2022
roberth added 2 commits May 31, 2023 14:46
Why implement a bad function? Basically because the _idea_ exists
and we can't kill an idea. The best we can do is catch anyone who
tries to use it, and inform them.
lib/attrsets.nix Show resolved Hide resolved
lib/attrsets.nix Show resolved Hide resolved
Comment on lines +135 to +138
(listOf str -> str) ->
(listOf str -> attrs -> bool) ->
attrs ->
attrs
Copy link

Choose a reason for hiding this comment

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

Suggested change
(listOf str -> str) ->
(listOf str -> attrs -> bool) ->
attrs ->
attrs
(listOf str -> str) -> # joinPath
(listOf str -> attrs -> bool) -> # upTo
attrs ->
attrs

The `recurseForDerivations` attribute gets removed from the returned tree,
as it does not contain a derivation, or any information that can't be
recovered from `(attrs.type or null) == "derivation"`.
*/
Copy link

Choose a reason for hiding this comment

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

Suggested change
*/
This function probably does not interact well with splicing, so if you are using it on an attrset which is exposed in `top-level.nix`, please verify that cross-compilation still works after doing so.
*/

NOTE: This function evaluates too much and should usually be avoided.

Traverses a potentially nested attribute set of derivations and
non-derivations in approximately the way `nix-build` would.
Copy link

Choose a reason for hiding this comment

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

Suggested change
non-derivations in approximately the way `nix-build` would.
non-derivations in approximately the way `nix-build` would, removing all non-derivation leaves.

Comment on lines +144 to +145
`joinDerivationsLeafStrictSep <sep> <v>` turns the tree of derivations `<v>`
into an attribute set of derivations.
Copy link

Choose a reason for hiding this comment

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

Suggested change
`joinDerivationsLeafStrictSep <sep> <v>` turns the tree of derivations `<v>`
into an attribute set of derivations.
`joinDerivationsLeafStrictSep <sep> <v>` deletes all non-derivation leaves from the nested attrset `<v>` and flattens the result.

@roberth roberth mentioned this pull request Jun 14, 2023
13 tasks
@wegank wegank added 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 2.status: merge conflict This PR has merge conflicts with the target branch labels Mar 19, 2024
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants