summaryrefslogtreecommitdiffstats
path: root/lib/types.nix
diff options
context:
space:
mode:
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix135
1 files changed, 113 insertions, 22 deletions
diff --git a/lib/types.nix b/lib/types.nix
index 689a2c80..ad8421b1 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 listOf nullOr path str submodule;
+ addCheck attrsOf bool either enum int lines listOf nullOr path str submodule;
in
rec {
@@ -18,9 +18,6 @@ rec {
type = label;
default = config._module.args.name;
};
- cores = mkOption {
- type = uint;
- };
nets = mkOption {
type = attrsOf net;
default = {};
@@ -34,7 +31,7 @@ rec {
ci = mkOption {
description = ''
If true, then the host wants to be tested by some CI system.
- See <stockholm/krebs/2configs/buildbot-all.nix>
+ See ‹stockholm/krebs/2configs/buildbot-all.nix›
'';
type = bool;
default = false;
@@ -43,7 +40,7 @@ rec {
external = mkOption {
description = ''
Whether the host is defined externally (in contrast to being defined
- in <stockholm>). This is useful e.g. when legacy and/or adopted
+ in ‹stockholm›). This is useful e.g. when legacy and/or adopted
hosts should be part of retiolum or some other component.
'';
type = bool;
@@ -58,6 +55,14 @@ rec {
default = false;
};
+ consul = mkOption {
+ description = ''
+ Whether the host is a member of the global consul network
+ '';
+ type = bool;
+ default = false;
+ };
+
owner = mkOption {
type = user;
};
@@ -102,11 +107,18 @@ rec {
default = config._module.args.name;
};
via = mkOption {
- type = nullOr net;
+ type =
+ # XXX break infinite recursion when generating manuals
+ if config._module.args.name == "‹name›" then
+ mkOptionType {
+ name = "‹net›";
+ }
+ else
+ nullOr net;
default = null;
};
addrs = mkOption {
- type = listOf addr;
+ type = listOf (either addr str);
default =
optional (config.ip4 != null) config.ip4.addr ++
optional (config.ip6 != null) config.ip6.addr;
@@ -121,22 +133,33 @@ rec {
default = null;
};
ip4 = mkOption {
- type = nullOr (submodule {
+ type = nullOr (submodule (ip4: {
options = {
addr = mkOption {
type = addr4;
};
prefix = mkOption ({
type = cidr4;
- } // optionalAttrs (config.name == "retiolum") {
- default = "10.243.0.0/16";
+ } // {
+ retiolum.default = "10.243.0.0/16";
+ wiregrill.default = "10.244.0.0/16";
+ }.${config._module.args.name} or {
+ default = "${ip4.config.addr}/32";
+ });
+ prefixLength = mkOption ({
+ type = uint;
+ } // {
+ retiolum.default = 16;
+ wiregrill.default = 16;
+ }.${config._module.args.name} or {
+ default = 32;
});
};
- });
+ }));
default = null;
};
ip6 = mkOption {
- type = nullOr (submodule {
+ type = nullOr (submodule (ip6: {
options = {
addr = mkOption {
type = addr6;
@@ -144,11 +167,22 @@ rec {
};
prefix = mkOption ({
type = cidr6;
- } // optionalAttrs (config.name == "retiolum") {
- default = "42::/16";
+ } // {
+ retiolum.default = "42:0::/32";
+ wiregrill.default = "42:1::/32";
+ }.${config._module.args.name} or {
+ default = "${ip6.config.addr}/128";
+ });
+ prefixLength = mkOption ({
+ type = uint;
+ } // {
+ retiolum.default = 32;
+ wiregrill.default = 32;
+ }.${config._module.args.name} or {
+ default = 128;
});
};
- });
+ }));
default = null;
};
ssh = mkOption {
@@ -178,7 +212,19 @@ rec {
[config.extraConfig]
++
[config.pubkey]
+ ++
+ optional (config.pubkey_ed25519 != null) ''
+ Ed25519PublicKey = ${config.pubkey_ed25519}
+ ''
+ ++
+ optional (config.weight != null) "Weight = ${toString config.weight}"
);
+ defaultText = ''
+ Address = ‹addr› ‹port› # for each ‹net.via.addrs›
+ Subnet = ‹addr› # for each ‹net.addrs›
+ ‹extraConfig›
+ ‹pubkey›
+ '';
};
pubkey = mkOption {
type = tinc-pubkey;
@@ -190,7 +236,7 @@ rec {
extraConfig = mkOption {
description = "Extra Configuration to be appended to the hosts file";
default = "";
- type = str;
+ type = lines;
};
port = mkOption {
type = int;
@@ -202,6 +248,15 @@ rec {
description = "tinc subnets";
default = [];
};
+ weight = mkOption {
+ type = nullOr int;
+ description = ''
+ global tinc weight (latency in ms) of this particular node.
+ can be set to some high value to make it unprobable to be used as router.
+ if set to null, tinc will autogenerate the value based on latency.
+ '';
+ default = if net.via != null then null else 300;
+ };
};
}));
default = null;
@@ -227,19 +282,32 @@ rec {
};
};
}));
+ default = null;
};
};
});
+ 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;
};
@@ -252,6 +320,7 @@ rec {
path = mkOption {
type = absolute-pathname;
default = "/run/keys/${config.name}";
+ defaultText = "/run/keys/‹name›";
};
mode = mkOption {
type = file-mode;
@@ -267,10 +336,12 @@ rec {
service = mkOption {
type = systemd.unit-name;
default = "secret-${lib.systemd.encodeName config.name}.service";
+ defaultText = "secret-‹name›.service";
};
source-path = mkOption {
type = str;
- default = toString <secrets> + "/${config.name}";
+ default = config.name;
+ defaultText = "‹secrets/‹name››";
};
};
});
@@ -379,6 +450,7 @@ rec {
home = mkOption {
type = absolute-pathname;
default = "/home/${config.name}";
+ defaultText = "/home/‹name›";
};
mail = mkOption {
type = nullOr str;
@@ -406,6 +478,7 @@ rec {
uid = mkOption {
type = int;
default = genid_uint31 config.name;
+ defaultText = "genid_uint31 ‹name›";
};
};
});
@@ -414,10 +487,12 @@ rec {
name = mkOption {
type = username;
default = config._module.args.name;
+ defaultText = "genid_uint31 ‹name›";
};
gid = mkOption {
type = int;
default = genid_uint31 config.name;
+ defaultText = "genid_uint31 ‹name›";
};
};
});
@@ -520,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}";
@@ -538,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: