about summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2023-03-22 11:23:21 +0100
committerNaïm Favier <n@monade.li>2023-03-22 12:37:28 +0100
commit8751764236e5d85cc394652288cda7a63fe78f94 (patch)
treeced6bd60b8deefd311e719be0171b96cd8cec844 /lib/modules.nix
parent435d253bd67d26c9f41ccde2d16a708dcf248c9c (diff)
lib/modules: better error for invalid option declarations
Make `byName` aware of whether it's processing options or config to give
slightly more accurate error messages.
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 051dbe2ef896a..9c3e2085e3781 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -567,15 +567,19 @@ rec {
         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 subtree}'
-                  rather than an attribute-set for the option
+                throw (if attr == "config" then ''
+                  You're trying to define a value of type `${builtins.typeOf subtree}'
+                  rather than an attribute set for the option
                   `${builtins.concatStringsSep "." prefix}'!
 
                   This usually happens if `${builtins.concatStringsSep "." prefix}' has option
                   definitions inside that are not matched. Please check how to properly define
                   this option by e.g. referring to `man 5 configuration.nix'!
-                ''
+                '' else ''
+                  An option declaration for `${builtins.concatStringsSep "." prefix}' has type
+                  `${builtins.typeOf subtree}' rather than an attribute set.
+                  Did you mean to define this outside of `options'?
+                '')
               else
                 mapAttrs (n: f module) subtree
               ) modules);