authoritative-dns/authoritative-dns.nix

91 lines
2.2 KiB
Nix
Raw Normal View History

2023-10-04 09:31:17 -07:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.authoritative-dns;
zoneOpts = import ./zone-definition.nix { inherit lib; };
zoneToZonefile = import ./zone-to-zonefile.nix { inherit lib; };
2023-10-04 09:31:17 -07:00
domainOpts = { name, ... }: {
options = with types; {
domain = mkOption {
type = str;
description = "Domain name.";
default = name;
};
ksk = {
key-file = mkOption {
type = nullOr str;
description =
"Key-signing key for this zone. DNSSEC disabled when null.";
default = null;
};
};
zone = mkOption {
type = submodule zoneOpts;
description = "Definition of network zone to be served.";
};
};
};
in {
options.services.authoritative-dns = with types; {
enable = mkEnableOption "Enable authoritative DNS service.";
2023-10-05 10:53:17 -07:00
identity = mkOption {
2023-10-04 09:31:17 -07:00
type = str;
description = "The identity (CH TXT ID.SERVER) of this host.";
};
domains = mkOption {
type = attrsOf (submodule domainOpts);
default = { };
description = "A map of domain to domain options.";
};
listen-ips = mkOption {
type = listOf str;
description =
"List of IP addresses on which to listen. If empty, listen on all addresses.";
default = [ ];
};
state-directory = mkOption {
type = str;
description =
"Path on which to store nameserver state, including DNSSEC keys.";
};
timestamp = mkOption {
type = str;
description = "Timestamp to attach to zone record.";
};
};
2023-10-05 12:16:17 -07:00
imports = [ ./nsd.nix ];
2023-10-04 09:31:17 -07:00
config = mkIf cfg.enable {
2023-10-05 13:20:54 -07:00
services.fudo-nsd = {
enable = true;
identity = cfg.identity;
interfaces = cfg.listen-ips;
stateDirectory = cfg.state-directory;
2023-10-06 09:38:05 -07:00
zones = mapAttrs' (domain: domainCfg:
nameValuePair "${domain}." {
dnssec = domainCfg.ksk.key-file != null;
ksk.keyFile =
mkIf (domainCfg.ksk.key-file != null) domainCfg.ksk.key-file;
data = zoneToZonefile {
inherit domain;
inherit (cfg) timestamp;
inherit (domainCfg) zone;
};
2023-10-05 13:20:54 -07:00
}) cfg.domains;
};
2023-10-04 09:31:17 -07:00
};
}