diff options
author | jeschli <jeschli@gmail.com> | 2019-03-21 20:09:09 +0100 |
---|---|---|
committer | jeschli <jeschli@gmail.com> | 2019-03-21 20:09:09 +0100 |
commit | a045a7f054859efcb40baf8ded13bcb7fd706d01 (patch) | |
tree | df23b0d31db9fc0b0087f4d5d4c7b3dd7a88b44c /krebs/3modules/hosts.nix | |
parent | ed499a84a9fe067c80e5a4768482333863c1e9ad (diff) | |
parent | 550faa1f64434951cd3949bc96a25012349f0090 (diff) |
Merge branch 'master' of prism.r:stockholm into new-master
Diffstat (limited to 'krebs/3modules/hosts.nix')
-rw-r--r-- | krebs/3modules/hosts.nix | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/krebs/3modules/hosts.nix b/krebs/3modules/hosts.nix index 0985bb539..7fe01a769 100644 --- a/krebs/3modules/hosts.nix +++ b/krebs/3modules/hosts.nix @@ -1,6 +1,5 @@ with import <stockholm/lib>; { config, ... }: let - # TODO dedup functions with ./retiolum-hosts.nix check = hostname: any (domain: hasSuffix ".${domain}" hostname) domains; domains = attrNames (filterAttrs (_: eq "hosts") config.krebs.dns.providers); in { @@ -30,6 +29,66 @@ in { map (addr: { ${addr} = aliases; }) net.addrs) (attrValues host.nets)) (attrValues config.krebs.hosts))); + + nixpkgs.config.packageOverrides = super: let + # nameValuePair name value : { "name" : name, "value" : value } + + # addr : str + # aliase : str + # hostname : str + # netname : str + + # addrAliases : nameValuePair addr [alias] + + # hostNetAliases : host -> { ${netname} : [addrAliases] } + hostNetAliases = host: + mapAttrs (_: net: filter (x: x.name != null && x.value != []) [ + { name = net.ip4.addr or null; value = net.aliases; } + { name = net.ip6.addr or null; value = net.aliases; } + ]) host.nets; + + # netAliases : { ${netname} : [addrAliases] } + netAliases = + foldl' + (result: host: + foldl' + # λ netAliases -> [addrAliases] -> netAliases + (result: { name, value }: result // { + ${name} = result.${name} or [] ++ value; + }) + result + (mapAttrsToList nameValuePair (hostNetAliases host)) + ) + {} + (attrValues config.krebs.hosts); + + # writeHosts : str -> [addrAliases] -> package + writeHosts = name: addrAliases: super.writeText name '' + ${concatMapStringsSep + "\n" + ({ name, value }: "${name} ${toString value}") + addrAliases} + ''; + in + { + # hosts file for all krebs networks + krebs-hosts = + writeHosts "krebs-hosts" (concatLists [ + netAliases.internet + netAliases.retiolum + netAliases.wiregrill + ]); + + # combined hosts file for all networks (even custom ones) + krebs-hosts_combined = + writeHosts "krebs-hosts_combined" + (concatLists (attrValues netAliases)); + } + // + genAttrs' (attrNames netAliases) (netname: rec { + name = "krebs-hosts-${netname}"; + value = writeHosts name netAliases.${netname}; + }); }; } |