1 { config, lib, pkgs, ... }:
3 cfg = config.services.hickory-dns;
4 toml = pkgs.formats.toml { };
6 zoneType = lib.types.submodule ({ config, ... }: {
7 freeformType = toml.type;
12 Zone name, like "example.com", "localhost", or "0.0.127.in-addr.arpa".
15 zone_type = mkOption {
16 type = types.enum [ "Primary" "Secondary" "Hint" "Forward" ];
20 - "Primary" (the master, authority for the zone).
21 - "Secondary" (the slave, replicated from the primary).
22 - "Hint" (a cached zone with recursive resolver abilities).
23 - "Forward" (a cached zone where all requests are forwarded to another resolver).
25 For more details about these zone types, consult the documentation for BIND,
26 though note that hickory-dns supports only a subset of BIND's zone types:
27 <https://bind9.readthedocs.io/en/v9_18_4/reference.html#type>
31 type = types.either types.path types.str;
32 default = "${config.zone}.zone";
33 defaultText = literalExpression ''"''${config.zone}.zone"'';
35 Path to the .zone file.
36 If not fully-qualified, this path will be interpreted relative to the `directory` option.
37 If omitted, defaults to the value of the `zone` option suffixed with ".zone".
44 meta.maintainers = with lib.maintainers; [ colinsane ];
47 (mkRenamedOptionModule [ "services" "trust-dns" "enable" ] [ "services" "hickory-dns" "enable" ])
48 (mkRenamedOptionModule [ "services" "trust-dns" "package" ] [ "services" "hickory-dns" "package" ])
49 (mkRenamedOptionModule [ "services" "trust-dns" "settings" ] [ "services" "hickory-dns" "settings" ])
50 (mkRenamedOptionModule [ "services" "trust-dns" "quiet" ] [ "services" "hickory-dns" "quiet" ])
51 (mkRenamedOptionModule [ "services" "trust-dns" "debug" ] [ "services" "hickory-dns" "debug" ])
55 services.hickory-dns = with lib; {
56 enable = mkEnableOption "hickory-dns";
57 package = mkPackageOption pkgs "hickory-dns" {
60 The package must provide `meta.mainProgram` which names the server binary; any other utilities (client, resolver) are not needed.
68 Log ERROR level messages only.
69 This option is mutually exclusive with the `debug` option.
70 If neither `quiet` nor `debug` are enabled, logging defaults to the INFO level.
77 Log DEBUG, INFO, WARN and ERROR messages.
78 This option is mutually exclusive with the `debug` option.
79 If neither `quiet` nor `debug` are enabled, logging defaults to the INFO level.
82 configFile = mkOption {
84 default = toml.generate "hickory-dns.toml" (
85 lib.filterAttrsRecursive (_: v: v != null) cfg.settings
87 defaultText = lib.literalExpression ''
88 let toml = pkgs.formats.toml { }; in toml.generate "hickory-dns.toml" cfg.settings
91 Path to an existing toml file to configure hickory-dns with.
93 This can usually be left unspecified, in which case it will be
94 generated from the values in `settings`.
95 If manually specified, then the options in `settings` are ignored.
100 Settings for hickory-dns. The options enumerated here are not exhaustive.
101 Refer to upstream documentation for all available options:
102 - [Example settings](https://github.com/hickory-dns/hickory-dns/blob/main/tests/test-data/test_configs/example.toml)
104 type = types.submodule {
105 freeformType = toml.type;
107 listen_addrs_ipv4 = mkOption {
108 type = types.listOf types.str;
109 default = [ "0.0.0.0" ];
111 List of ipv4 addresses on which to listen for DNS queries.
114 listen_addrs_ipv6 = mkOption {
115 type = types.listOf types.str;
116 default = lib.optional config.networking.enableIPv6 "::0";
117 defaultText = literalExpression ''lib.optional config.networking.enableIPv6 "::0"'';
119 List of ipv6 addresses on which to listen for DNS queries.
122 listen_port = mkOption {
126 Port to listen on (applies to all listen addresses).
129 directory = mkOption {
131 default = "/var/lib/hickory-dns";
133 The directory in which hickory-dns should look for .zone files,
134 whenever zones aren't specified by absolute path.
138 description = "List of zones to serve.";
140 type = types.listOf (types.coercedTo types.str (zone: { inherit zone; }) zoneType);
148 config = lib.mkIf cfg.enable {
149 systemd.services.hickory-dns = {
150 description = "hickory-dns Domain Name Server";
151 unitConfig.Documentation = "https://hickory-dns.org/";
155 flags = (lib.optional cfg.debug "--debug") ++ (lib.optional cfg.quiet "--quiet");
156 flagsStr = builtins.concatStringsSep " " flags;
158 ${lib.getExe cfg.package} --config ${cfg.configFile} ${flagsStr}
161 Restart = "on-failure";
165 StateDirectory = "hickory-dns";
166 ReadWritePaths = [ cfg.settings.directory ];
168 AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
169 CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
170 LockPersonality = true;
171 MemoryDenyWriteExecute = true;
172 NoNewPrivileges = true;
173 PrivateDevices = true;
174 PrivateMounts = true;
177 ProtectControlGroups = true;
179 ProtectHostname = true;
180 ProtectKernelLogs = true;
181 ProtectKernelModules = true;
182 ProtectKernelTunables = true;
183 ProtectProc = "invisible";
184 ProtectSystem = "full";
186 RestrictAddressFamilies = [ "AF_INET AF_INET6" ];
187 RestrictNamespaces = true;
188 RestrictSUIDSGID = true;
189 SystemCallArchitectures = "native";
190 SystemCallFilter = [ "@system-service" "~@privileged" "~@resources" ];
192 after = [ "network.target" ];
193 wantedBy = [ "multi-user.target" ];