lib/types: add intBetween

An int type that checks the value range.
This commit is contained in:
Profpatsch 2017-07-08 14:10:22 +02:00
parent cdbe4671be
commit c53d874277
2 changed files with 17 additions and 0 deletions

View file

@ -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";

View file

@ -26,6 +26,17 @@
<term><varname>types.int</varname></term>
<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