2023-06-10 10:50:53 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
with lib; {
|
2017-11-30 21:35:04 +00:00
|
|
|
|
2023-08-01 12:06:03 +00:00
|
|
|
options.krebs.zone-head-config = mkOption {
|
|
|
|
type = lib.types.attrsOf lib.types.str;
|
|
|
|
description = ''
|
|
|
|
The zone configuration head which is being used to create the
|
|
|
|
zone files. The string for each key is pre-pended to the zone file.
|
|
|
|
'';
|
|
|
|
default = {
|
|
|
|
"krebsco.de" = /* bindzone */ ''
|
2023-08-01 15:27:09 +00:00
|
|
|
$TTL 60
|
|
|
|
@ 3600 IN SOA spam.krebsco.de. spam.krebsco.de. 0 7200 3600 86400 3600
|
|
|
|
@ 3600 IN NS ns1
|
2023-08-02 09:39:33 +00:00
|
|
|
@ 3600 IN NS ni
|
2023-08-02 13:53:27 +00:00
|
|
|
@ 3600 IN NS ns2.he.net.
|
|
|
|
@ 3600 IN NS ns3.he.net.
|
2023-08-02 15:42:32 +00:00
|
|
|
@ 3600 IN NS ns2.hosting.de.
|
2023-09-13 14:28:08 +00:00
|
|
|
|
2023-10-11 17:58:47 +00:00
|
|
|
_acme-challenge IN NS ns1
|
|
|
|
|
2023-09-13 14:28:08 +00:00
|
|
|
panda NS panda
|
|
|
|
panda A 130.61.237.100
|
2024-05-22 17:27:34 +00:00
|
|
|
|
|
|
|
xkey A 217.197.83.17
|
|
|
|
xkey AAAA 2a0a:4580:5011::1
|
2023-08-01 12:06:03 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-11-30 21:35:04 +00:00
|
|
|
config = {
|
2022-08-14 23:43:57 +00:00
|
|
|
environment.etc =
|
2017-11-30 21:35:04 +00:00
|
|
|
mapAttrs'
|
2022-08-14 23:43:57 +00:00
|
|
|
(name: pkg: {
|
2017-11-30 21:35:04 +00:00
|
|
|
name = "zones/${name}";
|
2022-08-14 23:43:57 +00:00
|
|
|
value.source = pkg;
|
2017-11-30 21:35:04 +00:00
|
|
|
})
|
2022-08-14 23:43:57 +00:00
|
|
|
pkgs.krebs.zones;
|
|
|
|
|
|
|
|
nixpkgs.overlays = [
|
|
|
|
# Explicit zones generated from config.krebs.hosts.*.extraZones
|
|
|
|
(self: super: let
|
|
|
|
stripEmptyLines = s: (concatStringsSep "\n"
|
|
|
|
(remove "\n" (remove "" (splitString "\n" s)))) + "\n";
|
|
|
|
all-zones = foldAttrs (sum: current: sum + "\n" + current) ""
|
|
|
|
([config.krebs.zone-head-config] ++ combined-hosts);
|
|
|
|
combined-hosts =
|
|
|
|
mapAttrsToList (name: getAttr "extraZones") config.krebs.hosts;
|
|
|
|
in {
|
|
|
|
krebs = super.krebs or {} // {
|
|
|
|
zones = super.krebs.zones or {} //
|
|
|
|
mapAttrs'
|
|
|
|
(name: value: {
|
|
|
|
name = name;
|
|
|
|
value = self.writeText "${name}.zone" (stripEmptyLines value);
|
|
|
|
})
|
|
|
|
all-zones;
|
|
|
|
};
|
|
|
|
})
|
2022-08-14 23:44:59 +00:00
|
|
|
|
|
|
|
# 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"; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
2022-08-14 23:43:57 +00:00
|
|
|
];
|
2017-11-30 21:35:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|