summaryrefslogtreecommitdiffstats
path: root/3modules/tv/identity.nix
diff options
context:
space:
mode:
authorlassulus <lass@aidsballs.de>2015-07-23 02:26:42 +0200
committerlassulus <lass@aidsballs.de>2015-07-23 02:26:42 +0200
commit0db3f4ee695148b60238861384b86f0fdc880459 (patch)
tree8249b4e2713aeabdf4a9d1aeee4c38e1a527e487 /3modules/tv/identity.nix
parentb590d9e21d8c99a91fd419c3e0bea949a9ac6849 (diff)
parent791a7e79977de76908ab9e33eb64cbd2b02da3ed (diff)
Merge branch 'tv' into master
Diffstat (limited to '3modules/tv/identity.nix')
-rw-r--r--3modules/tv/identity.nix123
1 files changed, 58 insertions, 65 deletions
diff --git a/3modules/tv/identity.nix b/3modules/tv/identity.nix
index d3ac91393..584b27165 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,70 @@ 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; });
+ };
+
+ search = mkOption {
+ type = types.hostname;
};
};
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.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