{ 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" ''; })); }; }