From 504b1b90e809934a01357450ccdf35c4e4afc74d 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/tv') diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix index 164a6a1aa..6985baa90 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 8e41a4be471cd9bb74c8667140a70f8c05c363d4 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/tv') diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix index 6985baa90..c134745d6 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 d97be4322371f06b423e308b606824c02f1a67af 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/tv') diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix index c134745d6..ec46d8ea8 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 7a40f89e01593adff35f943aa86492ac4281d4e8 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/tv') diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix index ec46d8ea8..5eb9ac45f 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 791a7e79977de76908ab9e33eb64cbd2b02da3ed 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/tv') diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix index 5eb9ac45f..092a9626c 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