diff --git a/lib/types.nix b/lib/types.nix index db3bd381523..e921f7f6d9f 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 7b86e518aaf..dedfc286ca3 100644 --- a/nixos/doc/manual/development/option-types.xml +++ b/nixos/doc/manual/development/option-types.xml @@ -26,6 +26,17 @@ types.int An integer. + + + types.intBetween + min + max + + An integer between min + and max (both inclusive). + Useful for e.g. port ranges. + + types.path A filesystem path, defined as anything that when coerced to