1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.dnsdist;
7 configFile = pkgs.writeText "dnsdist.conf" ''
8 setLocal('${cfg.listenAddress}:${toString cfg.listenPort}')
9 ${cfg.extraConfig}
10 '';
11in {
12 options = {
13 services.dnsdist = {
14 enable = mkEnableOption (lib.mdDoc "dnsdist domain name server");
15
16 listenAddress = mkOption {
17 type = types.str;
18 description = lib.mdDoc "Listen IP Address";
19 default = "0.0.0.0";
20 };
21 listenPort = mkOption {
22 type = types.int;
23 description = lib.mdDoc "Listen port";
24 default = 53;
25 };
26
27 extraConfig = mkOption {
28 type = types.lines;
29 default = "";
30 description = lib.mdDoc ''
31 Extra lines to be added verbatim to dnsdist.conf.
32 '';
33 };
34 };
35 };
36
37 config = mkIf cfg.enable {
38 systemd.packages = [ pkgs.dnsdist ];
39
40 systemd.services.dnsdist = {
41 wantedBy = [ "multi-user.target" ];
42
43 startLimitIntervalSec = 0;
44 serviceConfig = {
45 DynamicUser = true;
46
47 # upstream overrides for better nixos compatibility
48 ExecStartPre = [ "" "${pkgs.dnsdist}/bin/dnsdist --check-config --config ${configFile}" ];
49 ExecStart = [ "" "${pkgs.dnsdist}/bin/dnsdist --supervised --disable-syslog --config ${configFile}" ];
50 };
51 };
52 };
53}