diff options
author | Profpatsch <mail@profpatsch.de> | 2017-07-08 14:10:22 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2017-11-05 15:56:32 +0100 |
commit | c53d874277c0eaf88ec71bab9658425535a2252a (patch) | |
tree | b4943d20b57f624de9dc62e3bedc85ddaf31ca48 | |
parent | cdbe4671bef1c0ba6345c51270472998bd44e266 (diff) | |
download | nixlib-c53d874277c0eaf88ec71bab9658425535a2252a.tar nixlib-c53d874277c0eaf88ec71bab9658425535a2252a.tar.gz nixlib-c53d874277c0eaf88ec71bab9658425535a2252a.tar.bz2 nixlib-c53d874277c0eaf88ec71bab9658425535a2252a.tar.lz nixlib-c53d874277c0eaf88ec71bab9658425535a2252a.tar.xz nixlib-c53d874277c0eaf88ec71bab9658425535a2252a.tar.zst nixlib-c53d874277c0eaf88ec71bab9658425535a2252a.zip |
lib/types: add intBetween
An int type that checks the value range.
-rw-r--r-- | lib/types.nix | 6 | ||||
-rw-r--r-- | nixos/doc/manual/development/option-types.xml | 11 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/types.nix b/lib/types.nix index db3bd3815238..e921f7f6d9fc 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -114,6 +114,12 @@ rec { merge = mergeOneOption; }; + intBetween = min: max: + addCheck types.int (x: x >= min && x <= max) // { + name = "intBetween"; + description = "integer between ${toString min} and ${toString max} (both inclusively)"; + }; + str = mkOptionType { name = "str"; description = "string"; diff --git a/nixos/doc/manual/development/option-types.xml b/nixos/doc/manual/development/option-types.xml index 7b86e518aaf1..dedfc286ca30 100644 --- a/nixos/doc/manual/development/option-types.xml +++ b/nixos/doc/manual/development/option-types.xml @@ -27,6 +27,17 @@ <listitem><para>An integer.</para></listitem> </varlistentry> <varlistentry> + <term> + <varname>types.intBetween</varname> + <replaceable>min</replaceable> + <replaceable>max</replaceable> + </term> + <listitem><para>An integer between <replaceable>min</replaceable> + and <replaceable>max</replaceable> (both inclusive). + Useful for e.g. port ranges. + </para></listitem> + </varlistentry> + <varlistentry> <term><varname>types.path</varname></term> <listitem><para>A filesystem path, defined as anything that when coerced to a string starts with a slash. Even if derivations can be considered as |