From 89ce2f5be474b3e72b53e450054f94fd4d13e381 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 23 Jul 2015 00:37:21 +0200 Subject: * tv identity: define type harder --- 4lib/tv/default.nix | 64 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to '4lib') diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix index 164a6a1..6985baa 100644 --- a/4lib/tv/default.nix +++ b/4lib/tv/default.nix @@ -1,12 +1,10 @@ { lib, pkgs, ... }: with builtins; +with lib; -let - inherit (lib) mapAttrs stringAsChars; -in +builtins // lib // rec { -rec { git = import ./git.nix { lib = lib // { inherit addNames; @@ -59,4 +57,62 @@ rec { else if c == "\n" then "'\n'" else "\\${c}"); + types = lib.types // (with lib.types; rec { + + host = submodule { + options = { + name = mkOption { + type = label; + }; + dc = mkOption { + type = label; + }; + cores = mkOption { + type = positive; + }; + nets = mkOption { + type = attrsOf net; + apply = x: assert hasAttr "retiolum" x; x; + }; + search = mkOption { + type = hostname; + }; + }; + }; + + net = submodule ({ config, ... }: { + options = { + addrs = mkOption { + type = listOf addr; + apply = _: config.addrs4 ++ config.addrs6; + }; + addrs4 = mkOption { + type = listOf addr4; + default = []; + }; + addrs6 = mkOption { + type = listOf addr6; + default = []; + }; + aliases = mkOption { + # TODO nonEmptyListOf hostname + type = listOf hostname; + }; + }; + }); + + positive = mkOptionType { + name = "positive integer"; + check = x: isInt x && x > 0; + merge = mergeOneOption; + }; + + # TODO + addr = str; + addr4 = str; + addr6 = str; + hostname = str; + label = str; + }); + } -- cgit v1.2.3 From d4c94a768bbb22ebf859bcbaf3008f7695e5d9c9 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 23 Jul 2015 01:02:36 +0200 Subject: * tv identity: hosts.*.search -> search --- 4lib/tv/default.nix | 6 ------ 1 file changed, 6 deletions(-) (limited to '4lib') diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix index 6985baa..c134745 100644 --- a/4lib/tv/default.nix +++ b/4lib/tv/default.nix @@ -39,9 +39,6 @@ builtins // lib // rec { in xsn >= sn && substring (xsn - sn) sn xs == s ; - removeSuffix = - s : xs : substring 0 (stringLength xs - stringLength s) xs; - # setMap :: (String -> a -> b) -> Set String a -> [b] #setMap = f: xs: map (k : f k (getAttr k xs)) (attrNames xs); @@ -74,9 +71,6 @@ builtins // lib // rec { type = attrsOf net; apply = x: assert hasAttr "retiolum" x; x; }; - search = mkOption { - type = hostname; - }; }; }; -- cgit v1.2.3 From 8409890bfd7e79fcbe49a328fb79db5fa00d65cc Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 23 Jul 2015 01:25:26 +0200 Subject: * tv identity: add tinc public keys --- 4lib/tv/default.nix | 3 +++ 1 file changed, 3 insertions(+) (limited to '4lib') diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix index c134745..ec46d8e 100644 --- a/4lib/tv/default.nix +++ b/4lib/tv/default.nix @@ -92,6 +92,9 @@ builtins // lib // rec { # TODO nonEmptyListOf hostname type = listOf hostname; }; + tinc-key = mkOption { + type = str; + }; }; }); -- cgit v1.2.3 From 039f3193b75e78cc133409b69fb9784ce001ad57 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 23 Jul 2015 01:56:46 +0200 Subject: 4 tv: generate tinc config --- 4lib/tv/default.nix | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to '4lib') diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix index ec46d8e..5eb9ac4 100644 --- a/4lib/tv/default.nix +++ b/4lib/tv/default.nix @@ -76,6 +76,10 @@ builtins // lib // rec { net = submodule ({ config, ... }: { options = { + via = mkOption { + type = nullOr net; + default = null; + }; addrs = mkOption { type = listOf addr; apply = _: config.addrs4 ++ config.addrs6; @@ -92,8 +96,23 @@ builtins // lib // rec { # TODO nonEmptyListOf hostname type = listOf hostname; }; - tinc-key = mkOption { - type = str; + tinc = mkOption { + type = submodule { + options = { + config = mkOption { + type = str; + apply = _: '' + ${optionalString (config.via != null) + (concatMapStringsSep "\n" (a: "Address = ${a}") config.via.addrs)} + ${concatMapStringsSep "\n" (a: "Subnet = ${a}") config.addrs} + ${config.tinc.pubkey} + ''; + }; + pubkey = mkOption { + type = str; + }; + }; + }; }; }; }); -- cgit v1.2.3 From 27fe9055334443370a86307ed08d51b2606f509d Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 23 Jul 2015 02:00:23 +0200 Subject: 4 tv: tinc.config can access tinc.pubkey --- 4lib/tv/default.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to '4lib') diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix index 5eb9ac4..092a962 100644 --- a/4lib/tv/default.nix +++ b/4lib/tv/default.nix @@ -97,22 +97,22 @@ builtins // lib // rec { type = listOf hostname; }; tinc = mkOption { - type = submodule { + type = let net-config = config; in submodule ({ config, ... }: { options = { config = mkOption { type = str; apply = _: '' - ${optionalString (config.via != null) - (concatMapStringsSep "\n" (a: "Address = ${a}") config.via.addrs)} - ${concatMapStringsSep "\n" (a: "Subnet = ${a}") config.addrs} - ${config.tinc.pubkey} + ${optionalString (net-config.via != null) + (concatMapStringsSep "\n" (a: "Address = ${a}") net-config.via.addrs)} + ${concatMapStringsSep "\n" (a: "Subnet = ${a}") net-config.addrs} + ${config.pubkey} ''; }; pubkey = mkOption { type = str; }; }; - }; + }); }; }; }); -- cgit v1.2.3