summaryrefslogtreecommitdiffstats
path: root/krebs/3modules/retiolum-hosts.nix
blob: 2821d62d19eee21b6b896d108e6007116e1ae8a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
with import <stockholm/lib>;
{ config, ... }: let
  # TODO dedup functions with networking.extraHosts
  check = hostname: any (domain: hasSuffix ".${domain}" hostname) domains;
  domains = attrNames (filterAttrs (_: eq "hosts") config.krebs.dns.providers);
in {
  nixpkgs.config.packageOverrides = super: {
    retiolum-hosts =
      super.writeText "retiolum-hosts" ''
        ${
          concatStringsSep
            "\n"
            (flatten
              (map
                (host: let
                  net = host.nets.retiolum;
                  aliases = longs;
                  longs = filter check net.aliases;
                in
                  optionals
                    (aliases != [])
                    (map (addr: "${addr} ${toString aliases}") net.addrs))
                (filter (host: hasAttr "retiolum" host.nets)
                        (attrValues config.krebs.hosts))))
        }
      '';
  };
}