summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2021-03-26 00:27:35 +0100
committerGitHub <noreply@github.com>2021-03-26 00:27:35 +0100
commit3d19f1d574483491005ee9ad70b5356088db55b1 (patch)
treece57b3309540fb83b85f900ef9b4759693caa5df /lib
parent97101da6b013762a5c7661c4280bc04e86096ced (diff)
parente878fc4aac3a9cecf5f6509fd887824c52a20af3 (diff)
downloadnixpkgs-3d19f1d574483491005ee9ad70b5356088db55b1.tar
nixpkgs-3d19f1d574483491005ee9ad70b5356088db55b1.tar.gz
nixpkgs-3d19f1d574483491005ee9ad70b5356088db55b1.tar.bz2
nixpkgs-3d19f1d574483491005ee9ad70b5356088db55b1.tar.lz
nixpkgs-3d19f1d574483491005ee9ad70b5356088db55b1.tar.xz
nixpkgs-3d19f1d574483491005ee9ad70b5356088db55b1.tar.zst
nixpkgs-3d19f1d574483491005ee9ad70b5356088db55b1.zip
Merge pull request #115919 from Ma27/module-error-improvement
lib/modules: better error message if an attr-set of options is expected
Diffstat (limited to 'lib')
-rw-r--r--lib/modules.nix11
-rwxr-xr-xlib/tests/modules.sh2
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 33a0d84a6d7..d3f10944e70 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -361,6 +361,17 @@ rec {
       */
       byName = attr: f: modules:
         foldl' (acc: module:
+              if !(builtins.isAttrs module.${attr}) then
+                throw ''
+                  You're trying to declare a value of type `${builtins.typeOf module.${attr}}'
+                  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
                 acc // (mapAttrs (n: v:
                                    (acc.${n} or []) ++ f module v
                                  ) module.${attr}
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index f843d303e44..2eddeec07b1 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -169,7 +169,7 @@ checkConfigOutput "foo" config.submodule.foo ./declare-submoduleWith-special.nix
 ## 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 'value is a boolean while a set was expected' config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-shorthand.nix
+checkConfigError "You're trying to declare a value of type \`bool'\nrather 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