summary refs log tree commit diff
path: root/nixos/modules/services/mail/opendkim.nix
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2016-01-07 01:10:56 +0300
committerNikolay Amiantov <ab@fmap.me>2016-01-13 13:07:46 +0300
commitf5efac09aaced787d9fc80c1e192367e6f93d9fb (patch)
tree2cfc089cf8fedf17b415e62990bb711d38197251 /nixos/modules/services/mail/opendkim.nix
parent1ea34520cd431277dfd97499d3fa48d42d8c7999 (diff)
downloadnixpkgs-f5efac09aaced787d9fc80c1e192367e6f93d9fb.tar
nixpkgs-f5efac09aaced787d9fc80c1e192367e6f93d9fb.tar.gz
nixpkgs-f5efac09aaced787d9fc80c1e192367e6f93d9fb.tar.bz2
nixpkgs-f5efac09aaced787d9fc80c1e192367e6f93d9fb.tar.lz
nixpkgs-f5efac09aaced787d9fc80c1e192367e6f93d9fb.tar.xz
nixpkgs-f5efac09aaced787d9fc80c1e192367e6f93d9fb.tar.zst
nixpkgs-f5efac09aaced787d9fc80c1e192367e6f93d9fb.zip
nixos/opendkim: add module
Diffstat (limited to 'nixos/modules/services/mail/opendkim.nix')
-rw-r--r--nixos/modules/services/mail/opendkim.nix109
1 files changed, 109 insertions, 0 deletions
diff --git a/nixos/modules/services/mail/opendkim.nix b/nixos/modules/services/mail/opendkim.nix
new file mode 100644
index 00000000000..1cdae9cb654
--- /dev/null
+++ b/nixos/modules/services/mail/opendkim.nix
@@ -0,0 +1,109 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+  cfg = config.services.opendkim;
+
+  defaultSock = "local:/run/opendkim/opendkim.sock";
+
+  args = [ "-f" "-l"
+           "-p" cfg.socket
+           "-d" cfg.domains
+           "-k" cfg.keyFile
+           "-s" cfg.selector
+         ] ++ optionals (cfg.configFile != null) [ "-x" cfg.configFile ];
+
+in {
+
+  ###### interface
+
+  options = {
+
+    services.opendkim = {
+
+      enable = mkOption {
+        type = types.bool;
+        default = false;
+        description = "Whether to enable the OpenDKIM sender authentication system.";
+      };
+
+      socket = mkOption {
+        type = types.str;
+        default = defaultSock;
+        description = "Socket which is used for communication with OpenDKIM.";
+      };
+
+      user = mkOption {
+        type = types.str;
+        default = "opendkim";
+        description = "User for the daemon.";
+      };
+
+      group = mkOption {
+        type = types.str;
+        default = "opendkim";
+        description = "Group for the daemon.";
+      };
+
+      domains = mkOption {
+        type = types.str;
+        description = "Local domains set; messages from them are signed, not verified.";
+      };
+
+      keyFile = mkOption {
+        type = types.path;
+        description = "Secret key file used for signing messages.";
+      };
+
+      selector = mkOption {
+        type = types.str;
+        description = "Selector to use when signing.";
+      };
+
+      configFile = mkOption {
+        type = types.nullOr types.path;
+        default = null;
+        description = "Additional opendkim configuration.";
+      };
+
+    };
+
+  };
+
+
+  ###### implementation
+
+  config = mkIf cfg.enable {
+
+    services.opendkim.domains = mkDefault "csl:${config.networking.hostName}";
+
+    users.extraUsers = optionalAttrs (cfg.user == "opendkim") (singleton
+      { name = "opendkim";
+        group = cfg.group;
+        uid = config.ids.uids.opendkim;
+      });
+
+    users.extraGroups = optionalAttrs (cfg.group == "opendkim") (singleton
+      { name = "opendkim";
+        gid = config.ids.gids.opendkim;
+      });
+
+    environment.systemPackages = [ pkgs.opendkim ];
+
+    systemd.services.opendkim = {
+      description = "OpenDKIM signing and verification daemon";
+      after = [ "network.target" ];
+      wantedBy = [ "multi-user.target" ];
+
+      serviceConfig = {
+        ExecStart = "${pkgs.opendkim}/bin/opendkim ${concatMapStringsSep " " escapeShellArg args}";
+        User = cfg.user;
+        Group = cfg.group;
+        RuntimeDirectory = optional (cfg.socket == defaultSock) "opendkim";
+      };
+    };
+
+  };
+}