1 {pkgs, lib, config, ...}:
2 let inherit (builtins) attrNames;
4 inherit (config.services) dkim dovecot2 rmilter;
6 createDomainDkimCert = domain:
7 let dkim_key = "${dkim.keyDir}/${domain}.${dkim.selector}.key";
8 dkim_txt = "${dkim.keyDir}/${domain}.${dkim.selector}.txt";
10 if [ ! -f "${dkim_key}" ] || [ ! -f "${dkim_txt}" ]
12 ${pkgs.opendkim}/bin/opendkim-genkey \
13 --domain "${domain}" \
14 --selector "${dkim.selector}" \
15 --directory="${dkim.keyDir}"
16 mv "${dkim.keyDir}/${dkim.selector}.private" "${dkim_key}"
17 mv "${dkim.keyDir}/${dkim.selector}.txt" "${dkim_txt}"
22 options.services.dkim = lib.mkOption {
24 type = types.submodule {
26 keyDir = lib.mkOption {
28 default = "/var/dkim";
32 selector = lib.mkOption {
53 extraConfig = "extended_spam_headers = yes;";
59 # servers = /var/run/clamav/clamd.ctl;
61 # NOTE: domain = "*"; causes rmilter to try to search key in the key path
62 # as keypath/domain.selector.key for any domain.
66 key = "${dkim.keyDir}";
67 selector = "${dkim.selector}";
73 bindSocket.type = "inet";
75 #systemd.sockets.rmilter.socketConfig.Accept = true;
76 systemd.services.rmilter = {
77 requires = [ "rmilter.socket" ];
78 after = [ "rmilter.socket" ];
80 install -D -d -o rmilter -g rmilter ${dkim.keyDir}
81 ${lib.concatStringsSep "\n" (map createDomainDkimCert (attrNames dovecot2.domains))}
82 chown -R rmilter:rmilter "${dkim.keyDir}"