summaryrefslogtreecommitdiffstats
path: root/krebs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2022-08-15 01:44:59 +0200
committertv <tv@krebsco.de>2022-08-15 01:45:29 +0200
commite5425253146157eb8ea251db2ad38840a4cdb255 (patch)
tree92a0b84acb9d9d48356b852d0cc008838c3e5c26 /krebs
parent31b30c5f22757da774c1cd4d409696138e6dca6b (diff)
zones: add zonefile packages for i, r, and w
Diffstat (limited to 'krebs')
-rw-r--r--krebs/3modules/zones.nix67
1 files changed, 67 insertions, 0 deletions
diff --git a/krebs/3modules/zones.nix b/krebs/3modules/zones.nix
index b9b69e993..51ced6f95 100644
--- a/krebs/3modules/zones.nix
+++ b/krebs/3modules/zones.nix
@@ -30,6 +30,73 @@ with import <stockholm/lib>;
all-zones;
};
})
+
+ # Implicit zones generated from config.krebs.hosts.*.nets.*.ip{4,6}.addr
+ (self: super: let
+ # record : { name : str, type : enum [ "A" "AAAA" ], data : str }
+
+ # toRecord : record.name -> record.type -> record.data -> record
+ toRecord = name: type: data:
+ { inherit name type data; };
+
+ # toRecords : str -> host -> [record]
+ toRecords = netname: host:
+ let
+ net = host.nets.${netname};
+ in
+ optionals
+ (hasAttr netname host.nets)
+ (filter
+ (x: x.data != null)
+ (concatLists [
+ (map
+ (name: toRecord name "A" (net.ip4.addr or null))
+ (concatMap
+ (name: [ "${name}." "4.${name}." ])
+ (net.aliases or [])))
+ (map
+ (name: toRecord name "AAAA" (net.ip6.addr or null))
+ (concatMap
+ (name: [ "${name}." "6.${name}." ])
+ (net.aliases or [])))
+ ]));
+
+ # formatRecord : record -> str
+ formatRecord = { name, type, data }: "${name} IN ${type} ${data}";
+
+ # writeZone : attrs -> package
+ writeZone =
+ { name ? "${domain}.zone"
+ , domain ? substring 0 1 netname
+ , nameservers ? [ "ni" ]
+ , netname
+ , hosts ? config.krebs.hosts
+ }:
+ self.writeText name /* bindzone */ ''
+ $TTL 60
+ @ IN SOA ns admin 1 3600 600 86400 60
+ @ IN NS ns
+ ${concatMapStringsSep "\n"
+ (name: /* bindzone */ "ns IN CNAME ${name}")
+ nameservers
+ }
+ ${concatMapStringsSep
+ "\n"
+ formatRecord
+ (concatMap
+ (toRecords netname)
+ (attrValues hosts))
+ }
+ '';
+ in {
+ krebs = super.krebs or {} // {
+ zones = super.krebs.zones or {} // {
+ i = writeZone { netname = "internet"; };
+ r = writeZone { netname = "retiolum"; };
+ w = writeZone { netname = "wiregrill"; };
+ };
+ };
+ })
];
};