diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2020-03-19 11:22:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-19 11:22:18 +0100 |
commit | 883879e974db4082c8d50d4db9874563b3e1b117 (patch) | |
tree | e084c8928e09fab589ee4b26b59169e9a8166d87 /lib | |
parent | d57719b5b670320762ea17ad95e137b8ba98e936 (diff) | |
parent | 742e3fc0020573deecc04029764b288fdbaed4cc (diff) | |
download | nixlib-883879e974db4082c8d50d4db9874563b3e1b117.tar nixlib-883879e974db4082c8d50d4db9874563b3e1b117.tar.gz nixlib-883879e974db4082c8d50d4db9874563b3e1b117.tar.bz2 nixlib-883879e974db4082c8d50d4db9874563b3e1b117.tar.lz nixlib-883879e974db4082c8d50d4db9874563b3e1b117.tar.xz nixlib-883879e974db4082c8d50d4db9874563b3e1b117.tar.zst nixlib-883879e974db4082c8d50d4db9874563b3e1b117.zip |
Merge pull request #82915 from Infinisil/fix-infrec-dependent-option-sets
Fix dependent option sets
Diffstat (limited to 'lib')
-rw-r--r-- | lib/modules.nix | 4 | ||||
-rwxr-xr-x | lib/tests/modules.sh | 6 | ||||
-rw-r--r-- | lib/tests/modules/declare-enable-nested.nix | 14 | ||||
-rw-r--r-- | lib/tests/modules/declare-int-positive-value-nested.nix | 9 | ||||
-rw-r--r-- | lib/tests/modules/declare-option-set.nix | 3 | ||||
-rw-r--r-- | lib/tests/modules/define-option-dependently-nested.nix | 16 |
6 files changed, 43 insertions, 9 deletions
diff --git a/lib/modules.nix b/lib/modules.nix index 518f4047cc60..c18fec66c705 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -299,9 +299,7 @@ rec { in throw "The option `${showOption loc}' in `${firstOption._file}' is a prefix of options in `${firstNonOption._file}'." else - 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?" + mergeModules' loc decls defns )) // { _definedNames = map (m: { inherit (m) file; names = attrNames m.config; }) configs; }; diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 1b3d01646d84..e81cf016ee9a 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -189,6 +189,9 @@ checkConfigOutput "true" config.enable ./import-from-store.nix checkConfigOutput true config.enable ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix checkConfigOutput 360 config.value ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix checkConfigOutput 7 config.value ./define-option-dependently.nix ./declare-int-positive-value.nix +checkConfigOutput true config.set.enable ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix +checkConfigOutput 360 config.set.value ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix +checkConfigOutput 7 config.set.value ./define-option-dependently-nested.nix ./declare-int-positive-value-nested.nix # Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only # attrsOf should work with conditional definitions @@ -199,9 +202,6 @@ 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 .*' \ diff --git a/lib/tests/modules/declare-enable-nested.nix b/lib/tests/modules/declare-enable-nested.nix new file mode 100644 index 000000000000..c8da8273cba1 --- /dev/null +++ b/lib/tests/modules/declare-enable-nested.nix @@ -0,0 +1,14 @@ +{ lib, ... }: + +{ + options.set = { + enable = lib.mkOption { + default = false; + example = true; + type = lib.types.bool; + description = '' + Some descriptive text + ''; + }; + }; +} diff --git a/lib/tests/modules/declare-int-positive-value-nested.nix b/lib/tests/modules/declare-int-positive-value-nested.nix new file mode 100644 index 000000000000..72d2fb89fc3b --- /dev/null +++ b/lib/tests/modules/declare-int-positive-value-nested.nix @@ -0,0 +1,9 @@ +{ lib, ... }: + +{ + options.set = { + value = lib.mkOption { + type = lib.types.ints.positive; + }; + }; +} diff --git a/lib/tests/modules/declare-option-set.nix b/lib/tests/modules/declare-option-set.nix deleted file mode 100644 index fddc650ffa90..000000000000 --- a/lib/tests/modules/declare-option-set.nix +++ /dev/null @@ -1,3 +0,0 @@ -{ - options.value = {}; -} diff --git a/lib/tests/modules/define-option-dependently-nested.nix b/lib/tests/modules/define-option-dependently-nested.nix new file mode 100644 index 000000000000..69ee4255534a --- /dev/null +++ b/lib/tests/modules/define-option-dependently-nested.nix @@ -0,0 +1,16 @@ +{ lib, options, ... }: + +# Some modules may be distributed separately and need to adapt to other modules +# that are distributed and versioned separately. +{ + + # Always defined, but the value depends on the presence of an option. + config.set = { + value = if options ? set.enable then 360 else 7; + } + # Only define if possible. + // lib.optionalAttrs (options ? set.enable) { + enable = true; + }; + +} |