diff options
author | Silvan Mosberger <contact@infinisil.com> | 2020-03-16 21:08:39 +0100 |
---|---|---|
committer | Silvan Mosberger <contact@infinisil.com> | 2020-03-18 04:38:50 +0100 |
commit | 15c873b486347e7861c64fb0b5a7852be9fc82e4 (patch) | |
tree | c7d2c1bab37592d399368d881c1fea9bea2c9cde | |
parent | dcdd232939232d04c1132b4cc242dd3dac44be8c (diff) |
lib/modules: Throw better error when definitions assign to an option set
-rw-r--r-- | lib/modules.nix | 4 | ||||
-rwxr-xr-x | lib/tests/modules.sh | 4 | ||||
-rw-r--r-- | lib/tests/modules/declare-option-set.nix | 3 |
3 files changed, 10 insertions, 1 deletions
diff --git a/lib/modules.nix b/lib/modules.nix index 48f4c04ed1bf..22df89f360ac 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -299,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; }; diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 8cd632a439cd..0e2fd0bf65d2 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -194,6 +194,10 @@ 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 + 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 = {}; +} |