1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7
8with lib;
9
10let
11 cfg = config.services.pdnsd;
12 pdnsd = pkgs.pdnsd;
13 pdnsdUser = "pdnsd";
14 pdnsdGroup = "pdnsd";
15 pdnsdConf = pkgs.writeText "pdnsd.conf" ''
16 global {
17 run_as=${pdnsdUser};
18 cache_dir="${cfg.cacheDir}";
19 ${cfg.globalConfig}
20 }
21
22 server {
23 ${cfg.serverConfig}
24 }
25 ${cfg.extraConfig}
26 '';
27in
28
29{
30 options = {
31 services.pdnsd = {
32 enable = mkEnableOption "pdnsd";
33
34 cacheDir = mkOption {
35 type = types.str;
36 default = "/var/cache/pdnsd";
37 description = "Directory holding the pdnsd cache";
38 };
39
40 globalConfig = mkOption {
41 type = types.lines;
42 default = "";
43 description = ''
44 Global configuration that should be added to the global directory
45 of `pdnsd.conf`.
46 '';
47 };
48
49 serverConfig = mkOption {
50 type = types.lines;
51 default = "";
52 description = ''
53 Server configuration that should be added to the server directory
54 of `pdnsd.conf`.
55 '';
56 };
57
58 extraConfig = mkOption {
59 type = types.lines;
60 default = "";
61 description = ''
62 Extra configuration directives that should be added to
63 `pdnsd.conf`.
64 '';
65 };
66 };
67 };
68
69 config = mkIf cfg.enable {
70 users.users.${pdnsdUser} = {
71 uid = config.ids.uids.pdnsd;
72 group = pdnsdGroup;
73 description = "pdnsd user";
74 };
75
76 users.groups.${pdnsdGroup} = {
77 gid = config.ids.gids.pdnsd;
78 };
79
80 systemd.services.pdnsd = {
81 wantedBy = [ "multi-user.target" ];
82 after = [ "network.target" ];
83 preStart = ''
84 mkdir -p "${cfg.cacheDir}"
85 touch "${cfg.cacheDir}/pdnsd.cache"
86 chown -R ${pdnsdUser}:${pdnsdGroup} "${cfg.cacheDir}"
87 '';
88 description = "pdnsd";
89 serviceConfig = {
90 ExecStart = "${pdnsd}/bin/pdnsd -c ${pdnsdConf}";
91 };
92 };
93 };
94}