-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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/attrsets: add cartesianProductOfSets function #110787
Conversation
1f82ff5
to
076440e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there's also lists.crossList
which does almost the same:
lists.crossLists (a: b: { inherit a b; }) [ [ 1 2 ] [ 10 20 ] ]
-> [ { a = 1; b = 10; } { a = 1; b = 20; } { a = 2; b = 10; } { a = 2; b = 20; } ]
Not sure if there's some unified way to implement these two
076440e
to
b99ac48
Compare
@tfc Do you think that this function could be implemented in terms of |
@blitz @infinisil i tried implementing cartesianProductOfSets = set:
let
extendSetOrFunction = setOrFunction: attrName:
if builtins.isFunction setOrFunction
then a: extendSetOrFunction (setOrFunction a) attrName
else a: setOrFunction // { ${attrName} = a; };
in
pkgs.lib.crossLists
(pkgs.lib.foldl extendSetOrFunction { } (builtins.attrNames set))
(builtins.attrValues set); not sure how much better this is. |
Tbh I think we can just deprecate |
b99ac48
to
35e3092
Compare
80f79e5
to
078667e
Compare
@infinisil i deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This came out very nicely!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please
Nice! Though the formatting makes this hard to review. Since we don't yet have a policy for auto-formatters I think we should avoid them for the time being. |
@infinisil shall i roll back the nixpkgs-fmt application to the code? |
@tfc Yes please. I really hope we can adopt a formatter for all of nixpkgs eventually though :) |
078667e
to
3b79cc1
Compare
@infinisil done |
3b79cc1
to
3f94cb2
Compare
3f94cb2
to
1dd4cb9
Compare
1dd4cb9
to
577d58a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff LGTM
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Motivation for this change
For library maintainers and other projects it is useful to build a project with multiple library and toolchain combinations.
For example, in C++ libraries it might be worthwhile to take the derivation and override it with different build profile settings and toolchains.
This might look like this:
implemented the function
cartesianProductOfSets
along with nix unit testsThings done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)