lib/modules: add 'index' to module.args of listOf submodule#445774
lib/modules: add 'index' to module.args of listOf submodule#445774hsjobeki wants to merge 1 commit intoNixOS:masterfrom
Conversation
997b6de to
df9aeab
Compare
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/how-to-default-an-option-based-on-its-index-in-a-listof/31769/5 |
|
I always thought |
|
Yes i also fear this has performance problems; obviously due to the list concatenation. |
| # If this worked, filtering would introduces paradoxons, for example: | ||
| # [ (mkIf (index == 0) { }) { } ] | ||
| value = map (x: x.optionalValue.value or x.mergedValue) ( | ||
| filter (x: x.optionalValue ? value) evals.res |
There was a problem hiding this comment.
IIUC assuming m is sensitive to the index, a definition like [ m (lib.mkIf false n) m ] would produce indexes 0 and 2 instead of 0 and 1, because of this logic here.
Ideally that could just be fixed, but it might be ok to just fail, i.e. return [ r1 r2 r3 ] where r2 throws an error. That way at least the numbering is predictable in all cases where it produces a valid config.
| { | ||
| file = "<internal>"; | ||
| value = { | ||
| _module.args.index = acc.total + m - 1; |
There was a problem hiding this comment.
with imap0
| _module.args.index = acc.total + m - 1; | |
| _module.args.index = acc.total + m; |
|
Allow to access
indexthrough module args, equivalent toattrsOf submoduleExample:
Tested so far:
TODO:
listOf mergefilter (x: x.optionalValue ? value)Combination with operators:
The following is working because the existence of a submodule cannot be filtered by using mkIf
otherwise this would introduce paradoxons such as:
[ (mkIf (index == 0) { }) { } ]=>
[ { } { } ]The first submodule would simply not receive any definitions but cannot be removed from the list. (current behavior)
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.