about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2021-12-28 16:53:50 +0100
committerpennae <github@quasiparticle.net>2021-12-28 16:53:50 +0100
commit0de4ecff8cbeb9c3f36e58b3bdb406d676a5e118 (patch)
tree1bb5e3853cd33f1b6363768be88183dec1a9afed /lib
parent2dcae7d82f5ef0b373413d2fbfc1001141561c74 (diff)
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).
Diffstat (limited to 'lib')
-rw-r--r--lib/modules.nix8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 091c72e30aae3..c68bbfcaa3e01 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -444,10 +444,10 @@ rec {
       */
       byName = attr: f: modules:
         zipAttrsWith (n: concatLists)
-          (map (module:
-              if !(builtins.isAttrs module.${attr}) then
+          (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}'!
 
@@ -456,7 +456,7 @@ rec {
                   this option by e.g. referring to `man 5 configuration.nix'!
                 ''
               else
-                mapAttrs (n: f module) module.${attr}
+                mapAttrs (n: f module) subtree
               ) modules);
       # an attrset 'name' => list of submodules that declare ‘name’.
       declsByName = byName "options" (module: option: