summaryrefslogtreecommitdiffstats
path: root/3modules
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-07-23 00:37:21 +0200
committertv <tv@shackspace.de>2015-07-23 00:37:21 +0200
commit504b1b90e809934a01357450ccdf35c4e4afc74d (patch)
tree2b6a539ad2a9f3c4d4b2cf24034cea7e239acb51 /3modules
parent14ac6d3bba12f07bd8aa79221b9c64469fe03046 (diff)
* tv identity: define type harder
Diffstat (limited to '3modules')
-rw-r--r--3modules/tv/consul.nix15
-rw-r--r--3modules/tv/identity.nix119
2 files changed, 62 insertions, 72 deletions
diff --git a/3modules/tv/consul.nix b/3modules/tv/consul.nix
index db0cd7a9e..312faa02f 100644
--- a/3modules/tv/consul.nix
+++ b/3modules/tv/consul.nix
@@ -5,8 +5,7 @@
# TODO consul-bootstrap HOST that actually does is
# TODO tools to inspect state of a cluster in outage state
-with builtins;
-with lib;
+with import ../../4lib/tv { inherit lib pkgs; };
let
cfg = config.tv.consul;
@@ -24,10 +23,10 @@ let
enable = mkEnableOption "tv.consul";
dc = mkOption {
- type = types.unspecified;
+ type = types.label;
};
hosts = mkOption {
- type = with types; listOf unspecified;
+ type = with types; listOf host;
};
encrypt-file = mkOption {
type = types.str; # TODO path (but not just into store)
@@ -38,7 +37,7 @@ let
default = "/var/lib/consul";
};
self = mkOption {
- type = types.unspecified;
+ type = types.host;
};
server = mkOption {
type = types.bool;
@@ -56,9 +55,11 @@ let
log_level = "INFO";
#node_name =
server = cfg.server;
- bind_addr = cfg.self.addr; # TODO cfg.addr
enable_syslog = true;
- retry_join = map (getAttr "addr") (filter (host: host.fqdn != cfg.self.fqdn) cfg.hosts);
+ retry_join =
+ # TODO allow consul in other nets than retiolum [maybe]
+ concatMap (host: host.nets.retiolum.addrs)
+ (filter (host: host.name != cfg.self.name) cfg.hosts);
leave_on_terminate = true;
} // optionalAttrs cfg.server {
bootstrap_expect = length cfg.hosts;
diff --git a/3modules/tv/identity.nix b/3modules/tv/identity.nix
index d3ac91393..0b94dff85 100644
--- a/3modules/tv/identity.nix
+++ b/3modules/tv/identity.nix
@@ -1,6 +1,6 @@
-{ config, lib, ... }:
+{ config, lib, pkgs, ... }:
-with lib;
+with import ../../4lib/tv { inherit lib pkgs; };
let
cfg = config.tv.identity;
@@ -13,77 +13,66 @@ let
enable = mkEnableOption "tv.identity";
self = mkOption {
- type = types.unspecified;
+ type = types.host;
};
+
+ others = mkOption {
+ type = types.host;
+ default = filterAttrs (name: _host: name != cfg.self.name) cfg.hosts;
+ };
+
hosts = mkOption {
- type = with types; attrsOf unspecified;
- default = {
- cd = {
- #dc = "cac";
- dc = "tv";
- fqdn = "cd.retiolum";
- subdomains = [
- "cgit"
- ];
- addr = "10.243.113.222";
- addr6 = "42:4522:25f8:36bb:8ccb:0150:231a:2af3";
- #internet-addr = "162.219.5.183";
- cores = 2;
- };
- mkdir = {
- #dc = "cac";
- dc = "tv";
- fqdn = "mkdir.retiolum";
- subdomains = [
- "cgit"
- ];
- addr = "10.243.113.223";
- cores = 1;
- };
- nomic = {
- #dc = "gg";
- dc = "tv";
- fqdn = "nomic.retiolum";
- subdomains = [
- "cgit"
- ];
- addr = "10.243.0.110";
- cores = 2;
- };
- rmdir = {
- #dc = "cac";
- dc = "tv";
- fqdn = "rmdir.retiolum";
- subdomains = [
- "cgit"
- ];
- addr = "10.243.113.224";
- #addr = "42:4522:25f8:36bb:8ccb:0150:231a:2af5";
- cores = 1;
- };
- wu = {
- #dc = "gg";
- dc = "tv";
- fqdn = "wu.retiolum";
- subdomains = [
- "cgit"
- ];
- addr = "10.243.13.37";
- cores = 8;
- };
- };
+ type = with types; attrsOf host;
+ apply = mapAttrs (name: value: value // { inherit name; });
};
};
imp = {
networking.extraHosts =
- let
- f = name: { addr, fqdn, subdomains, ... }: ''
- ${addr} ${toString (map (s: "${s}.${name} ${s}.${fqdn}") subdomains)}
- '';
- in
- concatStringsSep "\n" (mapAttrsToList f cfg.hosts);
+ concatStringsSep "\n" (flatten (
+ # TODO deepMap ["hosts" "nets"] (hostname: host: netname: net:
+ mapAttrsToList (hostname: host:
+ mapAttrsToList (netname: net:
+ let
+ aliases = toString (unique (longs ++ shorts));
+ longs = (splitByProvider net.aliases).hosts;
+ shorts = map (removeSuffix ".${cfg.self.search}") longs;
+ in
+ map (addr: "${addr} ${aliases}") net.addrs
+ ) host.nets
+ ) cfg.hosts
+ ));
+ };
+
+ # TODO move domain name providers to a dedicated module
+ # providers : tree label providername
+ providers = {
+ internet = "hosts";
+ retiolum = "hosts";
+ de.viljetic = "regfish";
+ de.krebsco = "ovh";
};
+ # splitByProvider : [alias] -> set providername [alias]
+ splitByProvider = foldl (acc: alias: insert (providerOf alias) alias acc) {};
+
+ # providerOf : alias -> providername
+ providerOf = alias:
+ tree-get (splitString "." alias) providers;
+
+ # insert : k -> v -> set k [v] -> set k [v]
+ insert = name: value: set:
+ set // { ${name} = set.${name} or [] ++ [value]; };
+
+ # tree k v = set k (either v (tree k v))
+
+ # tree-get : [k] -> tree k v -> v
+ tree-get = path: x:
+ let
+ y = x.${last path};
+ in
+ if typeOf y != "set"
+ then y
+ else tree-get (init path) y;
in
out