2016-01-06 22:10:56 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.opendkim;
|
|
|
|
|
|
|
|
defaultSock = "local:/run/opendkim/opendkim.sock";
|
|
|
|
|
2017-09-13 10:13:08 +00:00
|
|
|
keyFile = "${cfg.keyPath}/${cfg.selector}.private";
|
|
|
|
|
2016-01-06 22:10:56 +00:00
|
|
|
args = [ "-f" "-l"
|
|
|
|
"-p" cfg.socket
|
|
|
|
"-d" cfg.domains
|
2017-09-13 10:13:08 +00:00
|
|
|
"-k" keyFile
|
2016-01-06 22:10:56 +00:00
|
|
|
"-s" cfg.selector
|
|
|
|
] ++ optionals (cfg.configFile != null) [ "-x" cfg.configFile ];
|
|
|
|
|
|
|
|
in {
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "opendkim" "keyFile" ] [ "services" "opendkim" "keyPath" ])
|
|
|
|
];
|
2016-01-06 22:10:56 +00:00
|
|
|
|
|
|
|
###### 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;
|
2016-03-04 11:51:13 +00:00
|
|
|
default = "csl:${config.networking.hostName}";
|
|
|
|
example = "csl:example.com,mydomain.net";
|
|
|
|
description = ''
|
|
|
|
Local domains set (see <literal>opendkim(8)</literal> for more information on datasets).
|
|
|
|
Messages from them are signed, not verified.
|
|
|
|
'';
|
2016-01-06 22:10:56 +00:00
|
|
|
};
|
|
|
|
|
2017-09-13 10:13:08 +00:00
|
|
|
keyPath = mkOption {
|
2016-01-06 22:10:56 +00:00
|
|
|
type = types.path;
|
2017-09-13 10:13:08 +00:00
|
|
|
description = ''
|
|
|
|
The path that opendkim should put its generated private keys into.
|
|
|
|
The DNS settings will be found in this directory with the name selector.txt.
|
|
|
|
'';
|
|
|
|
default = "/var/lib/opendkim/keys";
|
2016-01-06 22:10:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.users = optionalAttrs (cfg.user == "opendkim") {
|
|
|
|
opendkim = {
|
2016-01-06 22:10:56 +00:00
|
|
|
group = cfg.group;
|
|
|
|
uid = config.ids.uids.opendkim;
|
2019-09-14 17:51:29 +00:00
|
|
|
};
|
|
|
|
};
|
2016-01-06 22:10:56 +00:00
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.groups = optionalAttrs (cfg.group == "opendkim") {
|
2020-01-07 05:05:49 +00:00
|
|
|
opendkim.gid = config.ids.gids.opendkim;
|
2019-09-14 17:51:29 +00:00
|
|
|
};
|
2016-01-06 22:10:56 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.opendkim ];
|
|
|
|
|
2019-02-24 14:06:38 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.keyPath}' - ${cfg.user} ${cfg.group} - -"
|
|
|
|
];
|
|
|
|
|
2016-01-06 22:10:56 +00:00
|
|
|
systemd.services.opendkim = {
|
|
|
|
description = "OpenDKIM signing and verification daemon";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
2017-09-13 10:13:08 +00:00
|
|
|
preStart = ''
|
|
|
|
cd "${cfg.keyPath}"
|
|
|
|
if ! test -f ${cfg.selector}.private; then
|
|
|
|
${pkgs.opendkim}/bin/opendkim-genkey -s ${cfg.selector} -d all-domains-generic-key
|
|
|
|
echo "Generated OpenDKIM key! Please update your DNS settings:\n"
|
|
|
|
echo "-------------------------------------------------------------"
|
|
|
|
cat ${cfg.selector}.txt
|
|
|
|
echo "-------------------------------------------------------------"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2016-01-06 22:10:56 +00:00
|
|
|
serviceConfig = {
|
2016-06-12 17:11:37 +00:00
|
|
|
ExecStart = "${pkgs.opendkim}/bin/opendkim ${escapeShellArgs args}";
|
2016-01-06 22:10:56 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
RuntimeDirectory = optional (cfg.socket == defaultSock) "opendkim";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|