From 3b04273d5cf816897ba6f0b1879bea259726703b Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 3 Feb 2023 18:10:50 +0100 Subject: [PATCH] lib.types.lowerBoundedInt: init --- lib/types.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index cda338130..f7c491645 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -293,15 +293,21 @@ rec { merge = mergeOneOption; }; + lowerBoundedInt = min: mkOptionType { + name = "lower bounded integer"; + check = x: isInt x && min <= x; + merge = mergeOneOption; + }; + positive = mkOptionType { + inherit (lowerBoundedInt 1) check; name = "positive integer"; - check = x: isInt x && x > 0; merge = mergeOneOption; }; uint = mkOptionType { + inherit (lowerBoundedInt 0) check; name = "unsigned integer"; - check = x: isInt x && x >= 0; merge = mergeOneOption; };