trust-dns: more idiomatic way to define SOA records

This commit is contained in:
2022-12-19 04:00:27 +00:00
parent 970438be8a
commit 16cb3b83a2
2 changed files with 35 additions and 17 deletions

View File

@@ -11,22 +11,23 @@
];
sane.services.trust-dns.zones."uninsane.org".TTL = 900;
sane.services.trust-dns.zones."uninsane.org".SOA = ''
; SOA record structure: <https://en.wikipedia.org/wiki/SOA_record#Structure>
; SOA MNAME RNAME (... rest)
; MNAME = Master name server for this zone. this is where update requests should be sent.
; RNAME = admin contact (encoded email address)
; Serial = YYYYMMDDNN, where N is incremented every time this file changes, to trigger secondary NS to re-fetch it.
; Refresh = how frequently secondary NS should query master
; Retry = how long secondary NS should wait until re-querying master after a failure (must be < Refresh)
; Expire = how long secondary NS should continue to reply to queries after master fails (> Refresh + Retry)
@ IN SOA ns1.uninsane.org. admin-dns.uninsane.org. (
# SOA record structure: <https://en.wikipedia.org/wiki/SOA_record#Structure>
# SOA MNAME RNAME (... rest)
# MNAME = Master name server for this zone. this is where update requests should be sent.
# RNAME = admin contact (encoded email address)
# Serial = YYYYMMDDNN, where N is incremented every time this file changes, to trigger secondary NS to re-fetch it.
# Refresh = how frequently secondary NS should query master
# Retry = how long secondary NS should wait until re-querying master after a failure (must be < Refresh)
# Expire = how long secondary NS should continue to reply to queries after master fails (> Refresh + Retry)
sane.services.trust-dns.zones."uninsane.org".inet.SOA."@" = [''
ns1.uninsane.org. admin-dns.uninsane.org. (
2022121601 ; Serial
4h ; Refresh
30m ; Retry
7d ; Expire
5m) ; Negative response TTL
'';
''];
sane.services.trust-dns.zones."uninsane.org".extraConfig = ''
rev TXT "2022121601"

View File

@@ -4,6 +4,21 @@ with lib;
let
cfg = config.sane.services.trust-dns;
toml = pkgs.formats.toml { };
fmtRecord = proto: rrtype: name: value: "${name}\t${proto}\t${rrtype}\t${value}";
fmtRecordList = proto: rrtype: name: values: concatStringsSep
"\n"
(map (fmtRecord proto rrtype name) values)
;
fmtRecordAttrs = proto: rrtype: rrAttrs:
concatStringsSep
"\n"
(
attrValues (
mapAttrs
(name: fmtRecordList proto rrtype name)
rrAttrs
)
);
configFile = toml.generate "trust-dns.toml" {
listen_addrs_ipv4 = cfg.listenAddrsIPv4;
zones = attrValues (
@@ -12,7 +27,7 @@ let
zone_type = "Primary";
file = pkgs.writeText "${zone}.zone" (''
$TTL ${toString zcfg.TTL}
${zcfg.SOA}
${fmtRecordAttrs "IN" "SOA" zcfg.inet.SOA}
'' + zcfg.extraConfig);
}) cfg.zones
);
@@ -39,15 +54,17 @@ in
default = 3600;
description = "default TTL";
};
SOA = mkOption {
type = types.str;
description = "Start of Authority record";
};
extraConfig = mkOption {
type = types.lines;
default = "";
description = "extra lines to append to the zone file";
};
inet = {
SOA = mkOption {
type = types.attrsOf (types.listOf types.str);
description = "Start of Authority record";
};
};
};
});
default = {};