summaryrefslogtreecommitdiffstats
path: root/lib/types.nix
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2017-10-11 18:12:31 +0200
committerlassulus <lassulus@lassul.us>2017-10-11 18:12:31 +0200
commit8bf55508522f44ab7ac276da6beff51f325e6e5a (patch)
tree9c4ae8f639d185460c4ef994af74527da4b69a19 /lib/types.nix
parentbdaa1fc9bfd1381400d11d07e44991bbf4cd8eb1 (diff)
types: add cidr and use as net.address
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/types.nix b/lib/types.nix
index 70570a6b3..08dc0974e 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -92,7 +92,7 @@ rec {
default = null;
};
addrs = mkOption {
- type = listOf addr;
+ type = listOf cidr;
default =
optional (config.ip4 != null) config.ip4.addr ++
optional (config.ip6 != null) config.ip6.addr;
@@ -109,7 +109,7 @@ rec {
type = addr4;
};
prefix = mkOption ({
- type = str; # TODO routing prefix (CIDR)
+ type = cidr4;
} // optionalAttrs (config.name == "retiolum") {
default = "10.243.0.0/16";
});
@@ -125,7 +125,7 @@ rec {
apply = lib.normalize-ip6-addr;
};
prefix = mkOption ({
- type = str; # TODO routing prefix (CIDR)
+ type = cidr6;
} // optionalAttrs (config.name == "retiolum") {
default = "42::/16";
});
@@ -364,6 +364,26 @@ rec {
merge = mergeOneOption;
};
+ cidr = either cidr4 cidr6;
+ cidr4 = mkOptionType {
+ name = "CIDRv4 address";
+ check = let
+ CIDRv4address = let d = "([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"; in
+ concatMapStringsSep "." (const d) (range 1 4) + "(/([1-2]?[0-9]|3[0-2]))?";
+ in
+ test CIDRv4address;
+ merge = mergeOneOption;
+ };
+ cidr6 = mkOptionType {
+ name = "CIDRv6 address";
+ check = let
+ # TODO check IPv6 address harder
+ CIDRv6address = "[0-9a-f.:]+(/([0-9][0-9]?|1[0-2][0-8]))?";
+ in
+ test CIDRv6address;
+ merge = mergeOneOption;
+ };
+
binary-cache-pubkey = str;
pgp-pubkey = str;