From 0a6cd0eb5379e985edd825f02b0f7bc4cff710a1 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 3 Dec 2026 17:03:11 +0000 Subject: ne: knot, authoritative for viljetic.de The zones come from hrm.dns.zones, a new module that writes zone files from records by owner name, checked by kzonecheck. --- modules/dns.nix | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 modules/dns.nix (limited to 'modules/dns.nix') diff --git a/modules/dns.nix b/modules/dns.nix new file mode 100644 index 00000000..276e9f81 --- /dev/null +++ b/modules/dns.nix @@ -0,0 +1,77 @@ +{ config, lib, pkgs, ... }: { + options.hrm.dns.zones = lib.mkOption { + default = {}; + description = '' + DNS zones, written as zone files for an authoritative server. + ''; + type = lib.types.attrsOf (lib.types.submodule ({ config, name, ... }: { + options = { + ttl = lib.mkOption { + type = lib.types.ints.unsigned; + default = 60; + }; + soa = { + nameserver = lib.mkOption { + type = lib.types.str; + }; + email = lib.mkOption { + type = lib.types.str; + }; + serial = lib.mkOption { + type = lib.types.ints.unsigned; + }; + refresh = lib.mkOption { + type = lib.types.ints.between 3600 86400; + default = 3600; + }; + retry = lib.mkOption { + type = lib.types.ints.unsigned; + default = 900; + }; + expire = lib.mkOption { + type = lib.types.ints.between 604800 3600000; + default = 604800; + }; + minimum = lib.mkOption { + type = lib.types.ints.between 180 86400; + default = 180; + }; + }; + records = lib.mkOption { + type = lib.types.attrsOf (lib.types.listOf lib.types.str); + default = {}; + description = '' + Records by owner name, each written after its name in the zone + file, e.g. "MX 10 ne" or "3600 NS ns2". + ''; + }; + file = lib.mkOption { + type = lib.types.package; + readOnly = true; + }; + }; + config.file = pkgs.runCommand "${name}.zone" { + nativeBuildInputs = [ pkgs.knot-dns ]; + preferLocalBuild = true; + passAsFile = [ "text" ]; + text = lib.concatLines ([ + "$TTL ${toString config.ttl}" + "@ SOA ${lib.concatStringsSep " " [ + config.soa.nameserver + (lib.replaceStrings [ "@" ] [ "." ] config.soa.email + ".") + (toString config.soa.serial) + (toString config.soa.refresh) + (toString config.soa.retry) + (toString config.soa.expire) + (toString config.soa.minimum) + ]}" + ] ++ lib.concatLists (lib.mapAttrsToList + (owner: map (record: "${owner} ${record}")) + config.records)); + } '' + kzonecheck --origin ${lib.escapeShellArg name} "$textPath" + cp "$textPath" "$out" + ''; + })); + }; +} -- cgit v1.3.1