mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-27 05:43:50 +03:00
lib/types: add number
For numbers that can be ints or floats.
This commit is contained in:
parent
e703a434b7
commit
eb72be8541
@ -297,6 +297,30 @@ rec {
|
||||
merge = mergeEqualOption;
|
||||
};
|
||||
|
||||
number = either int float;
|
||||
|
||||
numbers = let
|
||||
betweenDesc = lowest: highest:
|
||||
"${builtins.toJSON lowest} and ${builtins.toJSON highest} (both inclusive)";
|
||||
in {
|
||||
between = lowest: highest:
|
||||
assert lib.assertMsg (lowest <= highest)
|
||||
"numbers.between: lowest must be smaller than highest";
|
||||
addCheck number (x: x >= lowest && x <= highest) // {
|
||||
name = "numberBetween";
|
||||
description = "integer or floating point number between ${betweenDesc lowest highest}";
|
||||
};
|
||||
|
||||
nonnegative = addCheck number (x: x >= 0) // {
|
||||
name = "numberNonnegative";
|
||||
description = "nonnegative integer or floating point number, meaning >=0";
|
||||
};
|
||||
positive = addCheck number (x: x > 0) // {
|
||||
name = "numberPositive";
|
||||
description = "positive integer or floating point number, meaning >0";
|
||||
};
|
||||
};
|
||||
|
||||
str = mkOptionType {
|
||||
name = "str";
|
||||
description = "string";
|
||||
|
Loading…
Reference in New Issue
Block a user