Skip to content

lib.recursiveCollect: init#331375

Closed
ibizaman wants to merge 1 commit into
NixOS:masterfrom
ibizaman:lib_collect
Closed

lib.recursiveCollect: init#331375
ibizaman wants to merge 1 commit into
NixOS:masterfrom
ibizaman:lib_collect

Conversation

@ibizaman

@ibizaman ibizaman commented Jul 31, 2024

Copy link
Copy Markdown
Contributor

Description of changes

Compared to the existing 'collect' function, this one descends into lists too.

This function will be used with user-provided freeform variables - arbitrary combinations of attrset, lists and values - in the upcoming secret management feature. The PR #328472 shows how it will be used.

I purposely created a new function instead of updating the existing 'collect' one because to avoid changing the implementation of such a base function.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • 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/)
  • 24.11 Release Notes (or backporting 23.11 and 24.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
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions Bot added the 6.topic: lib The Nixpkgs function library label Jul 31, 2024
@ibizaman

Copy link
Copy Markdown
Contributor Author

@ofborg test misc

@ibizaman ibizaman marked this pull request as ready for review July 31, 2024 21:54
@ibizaman ibizaman requested a review from infinisil as a code owner July 31, 2024 21:54
@ibizaman

ibizaman commented Aug 1, 2024

Copy link
Copy Markdown
Contributor Author

Updated to instead modify the existing collect following the comment on the sibling PR #331384 (comment)

@ofborg ofborg Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Aug 1, 2024

@infinisil infinisil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See also #331384 (comment). And similarly to #331384 (review), how about recursiveCollect instead? Then we could also consider renaming collect to attrsRecursiveCollect in the future

@ibizaman ibizaman changed the title lib.collect': init lib.recursiveCollect: init Aug 15, 2024
This new 'recursiveCollect' function is like 'collect' while additionally descending into lists.

This function will be used with user-provided freeform variables - arbitrary combinations of
attrset, lists and values - in the upcoming secret management feature. The PR NixOS#328472 shows how it
will be used.
Comment thread lib/attrsets.nix
# Type

```
collect :: (AttrSet -> Bool) -> AttrSet -> [x]

@roberth roberth Aug 24, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
collect :: (AttrSet -> Bool) -> AttrSet -> [x]
collectFromData :: (Any -> Bool) -> Any -> [Any]

It'd be good to repeat the word data here, matching its use in

(regarding Any, I don't think there's anything useful that can be conveyed in this type without producing lies about its generality)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(regarding Any, ...

and if that doesn't feel right, maybe that's because a function like this would:

concatFromData :: (Any -> ListOf a) -> Any -> ListOf a

but the predicate function does not produce anything specific beyond a bool, so

:: (Any -> Bool) -> Any -> ListOf a

but that's just

:: (Any -> Bool) -> Any -> ListOf Any

@infinisil infinisil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as #331384 (review) :)

Comment thread lib/attrsets.nix


/**
Recursively collect sets that verify a given predicate named `pred` from the arbitrary nesting of

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Recursively collect sets that verify a given predicate named `pred` from the arbitrary nesting of
Recursively collect values that verify a given predicate named `pred` from the arbitrary nesting of

Comment thread lib/attrsets.nix
Comment on lines +927 to +933
attrs:
if pred attrs then
[ attrs ]
else if isAttrs attrs then
concatMap (recursiveCollect pred) (attrValues attrs)
else if isList attrs then
concatMap (recursiveCollect pred) attrs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
attrs:
if pred attrs then
[ attrs ]
else if isAttrs attrs then
concatMap (recursiveCollect pred) (attrValues attrs)
else if isList attrs then
concatMap (recursiveCollect pred) attrs
value:
if pred value then
[ value ]
else if isAttrs value then
concatMap (recursiveCollect pred) (attrValues value)
else if isList value then
concatMap (recursiveCollect pred) value

Comment thread lib/attrsets.nix
:::
*/
recursiveCollect =
pred:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@roberth Probably pred should also take the path just like #331384 (comment)

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 27, 2024
@ibizaman ibizaman closed this Mar 25, 2025
@ibizaman ibizaman deleted the lib_collect branch March 25, 2025 14:00
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 6.topic: lib The Nixpkgs function library 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants