···
1
+
{ config, lib, pkgs, ... }:
5
+
cfg = config.services.dkimproxy-out;
6
+
keydir = "/var/lib/dkimproxy-out";
7
+
privkey = "${keydir}/private.key";
8
+
pubkey = "${keydir}/public.key";
13
+
services.dkimproxy-out = {
19
+
Whether to enable dkimproxy_out.
21
+
Note that a key will be auto-generated, and can be found in
28
+
example = "127.0.0.1:10027";
29
+
description = "Address:port DKIMproxy should listen on.";
34
+
example = "127.0.0.1:10028";
35
+
description = "Address:port DKIMproxy should forward mail to.";
38
+
domains = mkOption {
39
+
type = with types; listOf str;
40
+
example = [ "example.org" "example.com" ];
41
+
description = "List of domains DKIMproxy can sign for.";
44
+
selector = mkOption {
46
+
example = "selector1";
49
+
The selector to use for DKIM key identification.
51
+
For example, if 'selector1' is used here, then for each domain
52
+
'example.org' given in `domain`, 'selector1._domainkey.example.org'
53
+
should contain the TXT record indicating the public key is the one
54
+
in ${pubkey}: "v=DKIM1; t=s; p=[THE PUBLIC KEY]".
58
+
keySize = mkOption {
63
+
Size of the RSA key to use to sign outgoing emails. Note that the
64
+
maximum mandatorily verified as per RFC6376 is 2048.
68
+
# TODO: allow signature for other schemes than dkim(c=relaxed/relaxed)?
69
+
# This being the scheme used by gmail, maybe nothing more is needed for
74
+
##### implementation
76
+
configfile = pkgs.writeText "dkimproxy_out.conf"
78
+
listen ${cfg.listen}
81
+
domain ${concatStringsSep "," cfg.domains}
82
+
selector ${cfg.selector}
84
+
signature dkim(c=relaxed/relaxed)
90
+
users.groups.dkimproxy-out = {};
91
+
users.users.dkimproxy-out = {
92
+
description = "DKIMproxy_out daemon";
93
+
group = "dkimproxy-out";
94
+
isSystemUser = true;
97
+
systemd.services.dkimproxy-out = {
98
+
description = "DKIMproxy_out";
99
+
wantedBy = [ "multi-user.target" ];
101
+
if [ ! -d "${keydir}" ]; then
102
+
mkdir -p "${keydir}"
103
+
chmod 0700 "${keydir}"
104
+
${pkgs.openssl}/bin/openssl genrsa -out "${privkey}" ${toString cfg.keySize}
105
+
${pkgs.openssl}/bin/openssl rsa -in "${privkey}" -pubout -out "${pubkey}"
106
+
chown -R dkimproxy-out:dkimproxy-out "${keydir}"
110
+
exec ${pkgs.dkimproxy}/bin/dkimproxy.out --conf_file=${configfile}
113
+
User = "dkimproxy-out";
114
+
PermissionsStartOnly = true;