nvf/lib/types/custom.nix
NotAShelf 04c8715279
lib: migrate to nixpkgs v2 merge mechanism
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: If5bf0e5f302afb9f7018b55a96109c006a6a6964
2025-11-01 20:23:41 +03:00

28 lines
788 B
Nix

{lib}: let
inherit (lib.options) mergeEqualOption;
inherit (lib.strings) isString stringLength match;
inherit (lib.types) listOf mkOptionType;
in {
mergelessListOf = elemType:
mkOptionType {
name = "mergelessListOf";
description = "mergeless list of ${elemType.description or "values"}";
check = listOf elemType.check or (x: true);
merge = mergeEqualOption;
};
char = mkOptionType {
name = "char";
description = "character";
descriptionClass = "noun";
check = value: stringLength value < 2;
merge = mergeEqualOption;
};
hexColor = mkOptionType {
name = "hex-color";
descriptionClass = "noun";
description = "RGB color in hex format";
check = v: isString v && (match "#?[0-9a-fA-F]{6}" v) != null;
};
}