lib/modules: extract multiply-used value in byName

module.${attr} is used at least twice, so it must be evaluated at least
twice (and since it's a function argument, be turned into a thunk
twice).
This commit is contained in:
pennae 2021-12-28 16:53:50 +01:00
parent 2dcae7d82f
commit 0de4ecff8c

View file

@ -444,10 +444,10 @@ rec {
*/ */
byName = attr: f: modules: byName = attr: f: modules:
zipAttrsWith (n: concatLists) zipAttrsWith (n: concatLists)
(map (module: (map (module: let subtree = module.${attr}; in
if !(builtins.isAttrs module.${attr}) then if !(builtins.isAttrs subtree) then
throw '' 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 rather than an attribute-set for the option
`${builtins.concatStringsSep "." prefix}'! `${builtins.concatStringsSep "." prefix}'!
@ -456,7 +456,7 @@ rec {
this option by e.g. referring to `man 5 configuration.nix'! this option by e.g. referring to `man 5 configuration.nix'!
'' ''
else else
mapAttrs (n: f module) module.${attr} mapAttrs (n: f module) subtree
) modules); ) modules);
# an attrset 'name' => list of submodules that declare name. # an attrset 'name' => list of submodules that declare name.
declsByName = byName "options" (module: option: declsByName = byName "options" (module: option: