aboutsummaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-03-19 03:46:50 +0100
committerSilvan Mosberger <contact@infinisil.com>2020-03-19 03:50:47 +0100
commit742e3fc0020573deecc04029764b288fdbaed4cc (patch)
treee8c6fdbac87a8e3b7b56fb7040c8963cefc8f343 /lib/tests
parent9eecf2d05711b8e8677af8ceda17f6b9938b3eb3 (diff)
lib/tests: Check for nested option-dependent definitions
Diffstat (limited to 'lib/tests')
-rwxr-xr-xlib/tests/modules.sh3
-rw-r--r--lib/tests/modules/declare-enable-nested.nix14
-rw-r--r--lib/tests/modules/declare-int-positive-value-nested.nix9
-rw-r--r--lib/tests/modules/define-option-dependently-nested.nix16
4 files changed, 42 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index e80a3eccecd1..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
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/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;
+ };
+
+}