summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/modules.nix17
-rwxr-xr-xlib/tests/modules.sh8
-rw-r--r--lib/tests/modules/declare-option-set.nix3
3 files changed, 22 insertions, 6 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 6cbef5632bd7..518f4047cc60 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -93,7 +93,11 @@ rec {
res set._definedNames
else
res;
- result = { inherit options config; };
+ result = {
+ inherit options;
+ config = removeAttrs config [ "_module" ];
+ inherit (config) _module;
+ };
in result;
# collectModules :: (modulesPath: String) -> (modules: [ Module ]) -> (args: Attrs) -> [ Module ]
@@ -295,7 +299,9 @@ rec {
in
throw "The option `${showOption loc}' in `${firstOption._file}' is a prefix of options in `${firstNonOption._file}'."
else
- mergeModules' loc decls defns
+ if all (def: isAttrs def.value) defns' then mergeModules' loc decls defns
+ else let firstInvalid = findFirst (def: ! isAttrs def.value) null defns';
+ in throw "The option path `${showOption loc}' is an attribute set of options, but it is defined to not be an attribute set in `${firstInvalid.file}'. Did you define its value at the correct and complete path?"
))
// { _definedNames = map (m: { inherit (m) file; names = attrNames m.config; }) configs; };
@@ -410,10 +416,9 @@ rec {
# Type-check the remaining definitions, and merge them. Or throw if no definitions.
mergedValue =
if isDefined then
- foldl' (res: def:
- if type.check def.value then res
- else throw "The option value `${showOption loc}' in `${def.file}' is not of type `${type.description}'."
- ) (type.merge loc defsFinal) defsFinal
+ if all (def: type.check def.value) defsFinal then type.merge loc defsFinal
+ else let firstInvalid = findFirst (def: ! type.check def.value) null defsFinal;
+ in throw "The option value `${showOption loc}' in `${firstInvalid.file}' is not of type `${type.description}'."
else
# (nixos-option detects this specific error message and gives it special
# handling. If changed here, please change it there too.)
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index d87f9db0a900..1b3d01646d84 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -199,6 +199,14 @@ checkConfigOutput "true" config.conditionalWorks ./declare-attrsOf.nix ./attrsOf
checkConfigOutput "false" config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
checkConfigOutput "empty" config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
+# Check error for when an option set is defined to be a non-attribute set value
+checkConfigError 'The option path .* is an attribute set of options, but it is defined to not be an attribute set in' \
+ config.value ./declare-option-set.nix ./define-value-int-zero.nix
+
+# Even with multiple assignments, a type error should be thrown if any of them aren't valid
+checkConfigError 'The option value .* in .* is not of type .*' \
+ config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix
+
cat <<EOF
====== module tests ======
$pass Pass
diff --git a/lib/tests/modules/declare-option-set.nix b/lib/tests/modules/declare-option-set.nix
new file mode 100644
index 000000000000..fddc650ffa90
--- /dev/null
+++ b/lib/tests/modules/declare-option-set.nix
@@ -0,0 +1,3 @@
+{
+ options.value = {};
+}