blob: 5b0808f453ad0d63c5605002817a47f21ee48f18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
lib:
let
inherit (lib) mkOption mkOptionType mergeOneOption elem flip concatStringsSep;
inherit (lib.types) nullOr submodule bool either;
in rec {
default = v: type: mkOption { type = type; default = v; };
optional = type: mkOption { type = nullOr type; default = null; };
set = opts: mkOption { type = nullOr (submodule { options = opts; }); default = null; };
# XXX https://github.com/NixOS/nixpkgs/issues/9826
enum' = values:
let show = v: let t = builtins.typeOf v;
in if t == "string" then ''"${v}"''
else if t == "int" then builtins.toString v
else ''<${t}>'';
in mkOptionType {
name = "one of ${concatStringsSep ", " (map show values)}";
check = flip elem values;
merge = mergeOneOption;
};
boolean = either bool (enum' [ "yes" "no" ]);
boolOr = l: either bool (enum' ([ "yes" "no" ] ++ l));
}
|