diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index ac0372e66f8a..96a91c0fffbc 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 000000000000..6e48c6ac8feb --- /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 000000000000..68bb9f415c3c --- /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 021641fdc229..1675a54156df 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; diff --git a/nixos/doc/manual/development/option-types.xml b/nixos/doc/manual/development/option-types.xml index 0b00f7077c2e..83dcf0232d9d 100644 --- a/nixos/doc/manual/development/option-types.xml +++ b/nixos/doc/manual/development/option-types.xml @@ -78,6 +78,13 @@ for 8 bits). + + + types.ints.positive + + A positive integer (that is > 0). + + String-related types: