about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2023-04-04 10:42:14 +0200
committerGitHub <noreply@github.com>2023-04-04 10:42:14 +0200
commit0d5c1ac149a5c16e0b6eb415638c5f54adef7753 (patch)
tree88ca5d7030fa077832789d6e9e735fb46854bd0f /lib
parent6b53f55ddd07eca1ed9149eef5ae81d6ecf72054 (diff)
parent8751764236e5d85cc394652288cda7a63fe78f94 (diff)
Merge pull request #222516 from ncfavier/options-better-error
lib/modules: better error for invalid option declarations
Diffstat (limited to 'lib')
-rw-r--r--lib/modules.nix12
-rwxr-xr-xlib/tests/modules.sh2
2 files changed, 9 insertions, 5 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);
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 8081b186a2f9f..c1cf0a94a1b38 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -189,7 +189,7 @@ checkConfigOutput '^"foo"$' config.submodule.foo ./declare-submoduleWith-special
 ## shorthandOnlyDefines config behaves as expected
 checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-shorthand.nix
 checkConfigError 'is not of type `boolean' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-noshorthand.nix
-checkConfigError "You're trying to declare a value of type \`bool'\n\s*rather than an attribute-set for the option" config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-shorthand.nix
+checkConfigError "You're trying to define a value of type \`bool'\n\s*rather than an attribute set for the option" config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-shorthand.nix
 checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-noshorthand.nix
 
 ## submoduleWith should merge all modules in one swoop