diff --git a/lib/modules.nix b/lib/modules.nix index 33a0d84a6d7f..d3f10944e708 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 f843d303e440..2eddeec07b1a 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