diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2022-01-10 14:02:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-10 14:02:39 +0100 |
commit | f1c69cb52d533d63a9badd4b5bcd42dfdca6c8a9 (patch) | |
tree | efd892a80e3ffa9797a70f3fe0e21cfc911cb4f0 /lib | |
parent | 325f561c68809d8dd5a001fc99d3bdcbdec1e349 (diff) | |
parent | 0de4ecff8cbeb9c3f36e58b3bdb406d676a5e118 (diff) |
Merge pull request #152046 from pennae/optimize-modules-byName
lib/modules: optimize byName
Diffstat (limited to 'lib')
-rw-r--r-- | lib/attrsets.nix | 3 | ||||
-rw-r--r-- | lib/modules.nix | 15 |
2 files changed, 9 insertions, 9 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 812521ce6d1c3..4721c833337ea 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -378,7 +378,8 @@ rec { zipAttrsWith (name: values: values) [{a = "x";} {a = "y"; b = "z";}] => { a = ["x" "y"]; b = ["z"] } */ - zipAttrsWith = f: sets: zipAttrsWithNames (concatMap attrNames sets) f sets; + zipAttrsWith = + builtins.zipAttrsWith or (f: sets: zipAttrsWithNames (concatMap attrNames sets) f sets); /* Like `zipAttrsWith' with `(name: values: values)' as the function. Example: diff --git a/lib/modules.nix b/lib/modules.nix index 573bf40e4b341..c68bbfcaa3e01 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -37,6 +37,7 @@ let toList types warnIf + zipAttrsWith ; inherit (lib.options) isOption @@ -442,10 +443,11 @@ rec { } */ byName = attr: f: modules: - foldl' (acc: module: - if !(builtins.isAttrs module.${attr}) then + zipAttrsWith (n: concatLists) + (map (module: let subtree = module.${attr}; in + if !(builtins.isAttrs subtree) then throw '' - You're trying to declare a value of type `${builtins.typeOf module.${attr}}' + You're trying to declare a value of type `${builtins.typeOf subtree}' rather than an attribute-set for the option `${builtins.concatStringsSep "." prefix}'! @@ -454,11 +456,8 @@ rec { this option by e.g. referring to `man 5 configuration.nix'! '' else - acc // (mapAttrs (n: v: - (acc.${n} or []) ++ f module v - ) module.${attr} - ) - ) {} modules; + mapAttrs (n: f module) subtree + ) modules); # an attrset 'name' => list of submodules that declare ‘name’. declsByName = byName "options" (module: option: [{ inherit (module) _file; options = option; }] |