stockholm/krebs/3modules/hosts.nix

36 lines
1.0 KiB
Nix
Raw Normal View History

2019-01-21 10:04:37 +00:00
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 {
options = {
krebs.hosts = mkOption {
default = {};
type = types.attrsOf types.host;
};
};
config = {
2019-01-21 10:51:15 +00:00
networking.hosts =
filterAttrs
(_name: value: value != [])
(zipAttrsWith
(_: concatLists)
(concatMap
(host:
concatMap
(net: let
2019-01-21 10:04:37 +00:00
aliases = longs ++ shorts;
longs = filter check net.aliases;
shorts = let s = ".${config.krebs.dns.search-domain}"; in
map (removeSuffix s) (filter (hasSuffix s) longs);
in
2019-01-21 10:51:15 +00:00
map (addr: { ${addr} = aliases; }) net.addrs)
(attrValues host.nets))
(attrValues config.krebs.hosts)));
2019-01-21 10:04:37 +00:00
};
}