From 033bf438bd2ae39d6a465c475500a24514cc2739 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 7 Apr 2016 20:29:07 +0200 Subject: addr4: str -> mkOptionType --- krebs/4lib/types.nix | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'krebs/4lib/types.nix') diff --git a/krebs/4lib/types.nix b/krebs/4lib/types.nix index 32d1daf9..7255dc3e 100644 --- a/krebs/4lib/types.nix +++ b/krebs/4lib/types.nix @@ -186,10 +186,16 @@ types // rec { }; }); - # TODO - addr = str; - addr4 = str; - addr6 = str; + addr = either addr4 addr6; + addr4 = mkOptionType { + name = "IPv4 address"; + check = let + IPv4address = 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); + in x: match IPv4address != null; + merge = mergeOneOption; + }; + addr6 = str; # TODO pgp-pubkey = str; -- cgit v1.2.3 From 46e818ebbc5446b4215ad9524089d9b2dc91cbd3 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 8 Apr 2016 03:53:34 +0200 Subject: retiolum: don't hardcode routing prefixes --- krebs/4lib/types.nix | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'krebs/4lib/types.nix') diff --git a/krebs/4lib/types.nix b/krebs/4lib/types.nix index 7255dc3e..24b4e14b 100644 --- a/krebs/4lib/types.nix +++ b/krebs/4lib/types.nix @@ -63,28 +63,56 @@ types // rec { net = submodule ({ config, ... }: { options = { + name = mkOption { + type = label; + default = config._module.args.name; + }; via = mkOption { type = nullOr net; default = null; }; addrs = mkOption { type = listOf addr; - default = config.addrs4 ++ config.addrs6; - # TODO only default addrs make sense - }; - addrs4 = mkOption { - type = listOf addr4; - default = []; - }; - addrs6 = mkOption { - type = listOf addr6; - default = []; + default = + optional (config.ip4 != null) config.ip4.addr ++ + optional (config.ip6 != null) config.ip6.addr; + readOnly = true; }; aliases = mkOption { # TODO nonEmptyListOf hostname type = listOf hostname; default = []; }; + ip4 = mkOption { + type = nullOr (submodule { + options = { + addr = mkOption { + type = addr4; + }; + prefix = mkOption ({ + type = str; # TODO routing prefix (CIDR) + } // optionalAttrs (config.name == "retiolum") { + default = "10.243.0.0/16"; + }); + }; + }); + default = null; + }; + ip6 = mkOption { + type = nullOr (submodule { + options = { + addr = mkOption { + type = addr6; + }; + prefix = mkOption ({ + type = str; # TODO routing prefix (CIDR) + } // optionalAttrs (config.name == "retiolum") { + default = "42::/16"; + }); + }; + }); + default = null; + }; ssh = mkOption { type = submodule { options = { -- cgit v1.2.3 From 4e99bb9d12405cf1910af3205d8668604e516f50 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 8 Apr 2016 04:38:10 +0200 Subject: krebs types.addr4: check type harder --- krebs/4lib/types.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'krebs/4lib/types.nix') diff --git a/krebs/4lib/types.nix b/krebs/4lib/types.nix index 24b4e14b..6396927d 100644 --- a/krebs/4lib/types.nix +++ b/krebs/4lib/types.nix @@ -220,7 +220,7 @@ types // rec { check = let IPv4address = 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); - in x: match IPv4address != null; + in x: match IPv4address x != null; merge = mergeOneOption; }; addr6 = str; # TODO -- cgit v1.2.3 From e74f4ddf8182067ca4f44d8d4ed91a8c5fc65147 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 8 Apr 2016 04:41:30 +0200 Subject: krebs types.addr6: str -> IPv6 address* --- krebs/4lib/types.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'krebs/4lib/types.nix') diff --git a/krebs/4lib/types.nix b/krebs/4lib/types.nix index 6396927d..f4649180 100644 --- a/krebs/4lib/types.nix +++ b/krebs/4lib/types.nix @@ -223,7 +223,14 @@ types // rec { in x: match IPv4address x != null; merge = mergeOneOption; }; - addr6 = str; # TODO + addr6 = mkOptionType { + name = "IPv6 address"; + check = let + # TODO check IPv6 address harder + IPv6address = "[0-9a-f.:]+"; + in x: match IPv6address x != null; + merge = mergeOneOption; + }; pgp-pubkey = str; -- cgit v1.2.3