summaryrefslogtreecommitdiffstats
path: root/lib/types.nix
diff options
context:
space:
mode:
authorlassulus <git@lassul.us>2023-02-09 09:39:02 +0100
committerlassulus <git@lassul.us>2023-02-09 09:39:02 +0100
commitc50424a6a37eee986bf4dc8f47479a56f2905a01 (patch)
tree00b673394cf383f3f47fe3d916e7d7bb3b298eb6 /lib/types.nix
parentd299a49bfea376d4d6969d00e44056363f7af0ae (diff)
parent122a46d4fced5d9b4932603b7c16f9b6d1077dd0 (diff)
Merge remote-tracking branch 'ni/master'
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix38
1 files changed, 33 insertions, 5 deletions
diff --git a/lib/types.nix b/lib/types.nix
index 32b4541..5f01ccb 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -3,11 +3,11 @@
let
inherit (lib)
all any attrNames concatMapStringsSep concatStringsSep const filter flip
- genid_uint31 hasSuffix head isInt isString length mergeOneOption mkOption
- mkOptionType optional optionalAttrs optionals range splitString
+ genid_uint31 hasSuffix head importJSON isInt isString length mergeOneOption
+ mkOption mkOptionType optional optionalAttrs optionals range splitString
stringLength substring test testString typeOf;
inherit (lib.types)
- attrsOf bool either enum int lines listOf nullOr path str submodule;
+ addCheck attrsOf bool either enum int lines listOf nullOr path str submodule;
in
rec {
@@ -287,15 +287,27 @@ rec {
};
});
+ boundedInt = min: max: mkOptionType {
+ name = "bounded integer";
+ check = x: isInt x && min <= x && x <= max;
+ 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;
};
@@ -583,6 +595,9 @@ rec {
};
};
+ flameshot.color =
+ either (addCheck str (test "#[0-9A-Fa-f]{6}")) svg.color-keyword;
+
file-mode = mkOptionType {
name = "file mode";
check = test "[0-7]{4}";
@@ -601,6 +616,19 @@ rec {
merge = mergeOneOption;
};
+ # SVG 1.1, 4.4 Recognized color keyword names
+ #
+ # svg-colors.json has been generated with:
+ # curl -sS https://www.w3.org/TR/SVG11/types.html#ColorKeywords |
+ # fq -d html '[
+ # grep_by(.["@class"]=="color-keywords") |
+ # grep_by(.["@class"]=="prop-value"and.["#text"]!="").["#text"]
+ # ] | sort'
+ #
+ svg.color-keyword = enum (importJSON ./svg-colors.json) // {
+ name = "SVG 1.1 recognized color keyword";
+ };
+
systemd.unit-name = mkOptionType {
name = "systemd unit name";
check = x: