summary refs log tree commit diff
path: root/nixos/modules/services/networking/pdnsd.nix
diff options
context:
space:
mode:
authorJinjing Wang <nfjinjing@gmail.com>2016-02-11 19:02:11 +0800
committerJinjing Wang <nfjinjing@gmail.com>2016-02-12 19:53:41 +0800
commit73b9a9662df21ad7c1a372edfda403a8f4b529aa (patch)
tree88360777830eb750c7e9ed31cc3957eaafae65c9 /nixos/modules/services/networking/pdnsd.nix
parent1d6f590844ccf95acbe6dec567b7235e195f4334 (diff)
downloadnixpkgs-73b9a9662df21ad7c1a372edfda403a8f4b529aa.tar
nixpkgs-73b9a9662df21ad7c1a372edfda403a8f4b529aa.tar.gz
nixpkgs-73b9a9662df21ad7c1a372edfda403a8f4b529aa.tar.bz2
nixpkgs-73b9a9662df21ad7c1a372edfda403a8f4b529aa.tar.lz
nixpkgs-73b9a9662df21ad7c1a372edfda403a8f4b529aa.tar.xz
nixpkgs-73b9a9662df21ad7c1a372edfda403a8f4b529aa.tar.zst
nixpkgs-73b9a9662df21ad7c1a372edfda403a8f4b529aa.zip
pdnsd service: init
Diffstat (limited to 'nixos/modules/services/networking/pdnsd.nix')
-rw-r--r--nixos/modules/services/networking/pdnsd.nix93
1 files changed, 93 insertions, 0 deletions
diff --git a/nixos/modules/services/networking/pdnsd.nix b/nixos/modules/services/networking/pdnsd.nix
new file mode 100644
index 00000000000..f4467b81895
--- /dev/null
+++ b/nixos/modules/services/networking/pdnsd.nix
@@ -0,0 +1,93 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+  cfg = config.services.pdnsd;
+  pdnsd = pkgs.pdnsd;
+  pdnsdUser = "pdnsd";
+  pdnsdGroup = "pdnsd";
+  pdnsdConf = pkgs.writeText "pdnsd.conf"
+    ''
+      global {
+        run_as=${pdnsdUser};
+        cache_dir="${cfg.cacheDir}";
+        ${cfg.globalConfig}
+      }
+
+      server {
+        ${cfg.serverConfig}
+      }
+      ${cfg.extraConfig}
+    '';
+in
+
+{ options =
+    { services.pdnsd =
+        { enable = mkEnableOption "pdnsd";
+
+          cacheDir = mkOption {
+            type = types.str;
+            default = "/var/cache/pdnsd";
+            description = "Directory holding the pdnsd cache";
+          };
+
+          globalConfig = mkOption {
+            type = types.lines;
+            default = "";
+            description = ''
+              Global configuration that should be added to the global directory
+              of <literal>pdnsd.conf</literal>.
+            '';
+          };
+
+          serverConfig = mkOption {
+            type = types.lines;
+            default = "";
+            description = ''
+              Server configuration that should be added to the server directory
+              of <literal>pdnsd.conf</literal>.
+            '';
+          };
+
+          extraConfig = mkOption {
+            type = types.lines;
+            default = "";
+            description = ''
+              Extra configuration directives that should be added to
+              <literal>pdnsd.conf</literal>.
+            '';
+          };
+        };
+    };
+
+  config = mkIf cfg.enable {
+    users.extraUsers = singleton {
+      name = pdnsdUser;
+      uid = config.ids.uids.pdnsd;
+      group = pdnsdGroup;
+      description = "pdnsd user";
+    };
+
+    users.extraGroups = singleton {
+      name = pdnsdGroup;
+      gid = config.ids.gids.pdnsd;
+    };
+
+    systemd.services.pdnsd =
+      { wantedBy = [ "multi-user.target" ];
+        after = [ "network.target" ];
+        preStart =
+          ''
+            mkdir -p "${cfg.cacheDir}"
+            touch "${cfg.cacheDir}/pdnsd.cache"
+            chown -R ${pdnsdUser}:${pdnsdGroup} "${cfg.cacheDir}"
+          '';
+        description = "pdnsd";
+        serviceConfig =
+          {
+            ExecStart = "${pdnsd}/bin/pdnsd -c ${pdnsdConf}";
+          };
+      };
+  };
+}