about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2017-10-31 17:30:15 +0100
committerProfpatsch <mail@profpatsch.de>2017-11-05 15:56:32 +0100
commit462c048c77fa0aa0cb4c47d7812a57f094587f68 (patch)
tree608f72f36e786fee42167fc4d58df8888cedb5ff /lib
parent1158910676323b57ba0248a71ad0a0d8e57a960b (diff)
lib/types: add `ints.positive`.
For values that are positive, but cannot be 0.
Diffstat (limited to 'lib')
-rwxr-xr-xlib/tests/modules.sh2
-rw-r--r--lib/tests/modules/declare-int-positive-value.nix9
-rw-r--r--lib/tests/modules/define-value-int-zero.nix3
-rw-r--r--lib/types.nix4
4 files changed, 18 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index ac0372e66f8ad..96a91c0fffbc9 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -65,6 +65,8 @@ checkConfigError 'The option .* defined in .* does not exist.' config.enable ./d
 # unsigned
 checkConfigOutput "42" config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix
 checkConfigError 'The option value .* in .* is not of type.*unsigned integer.*' config.value ./declare-int-unsigned-value.nix ./define-value-int-negative.nix
+# positive
+checkConfigError 'The option value .* in .* is not of type.*positive integer.*' config.value ./declare-int-positive-value.nix ./define-value-int-zero.nix
 # between
 checkConfigOutput "42" config.value ./declare-int-between-value.nix ./define-value-int-positive.nix
 checkConfigError 'The option value .* in .* is not of type.*between.*-21 and 43.*inclusive.*' config.value ./declare-int-between-value.nix ./define-value-int-negative.nix
diff --git a/lib/tests/modules/declare-int-positive-value.nix b/lib/tests/modules/declare-int-positive-value.nix
new file mode 100644
index 0000000000000..6e48c6ac8feba
--- /dev/null
+++ b/lib/tests/modules/declare-int-positive-value.nix
@@ -0,0 +1,9 @@
+{ lib, ... }:
+
+{
+  options = {
+    value = lib.mkOption {
+      type = lib.types.ints.positive;
+    };
+  };
+}
diff --git a/lib/tests/modules/define-value-int-zero.nix b/lib/tests/modules/define-value-int-zero.nix
new file mode 100644
index 0000000000000..68bb9f415c3c9
--- /dev/null
+++ b/lib/tests/modules/define-value-int-zero.nix
@@ -0,0 +1,3 @@
+{
+  value = 0;
+}
diff --git a/lib/types.nix b/lib/types.nix
index 021641fdc229c..1675a54156df4 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -151,6 +151,10 @@ rec {
           name = "unsignedInt";
           description = "unsigned integer, meaning >=0";
         };
+        positive = addCheck types.int (x: x > 0) // {
+          name = "positiveInt";
+          description = "positive integer, meaning >0";
+        };
         u8 = unsign 8 256;
         u16 = unsign 16 65536;
         u32 = unsign 32 4294967296;