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