1 { config, lib, pkgs, ... }:
3 cfg = config.services.dkimproxy-out;
4 keydir = "/var/lib/dkimproxy-out";
5 privkey = "${keydir}/private.key";
6 pubkey = "${keydir}/public.key";
11 services.dkimproxy-out = {
12 enable = lib.mkOption {
13 type = lib.types.bool;
16 Whether to enable dkimproxy_out.
18 Note that a key will be auto-generated, and can be found in
23 listen = lib.mkOption {
25 example = "127.0.0.1:10027";
26 description = "Address:port DKIMproxy should listen on.";
29 relay = lib.mkOption {
31 example = "127.0.0.1:10028";
32 description = "Address:port DKIMproxy should forward mail to.";
35 domains = lib.mkOption {
36 type = with lib.types; listOf str;
37 example = [ "example.org" "example.com" ];
38 description = "List of domains DKIMproxy can sign for.";
41 selector = lib.mkOption {
43 example = "selector1";
45 The selector to use for DKIM key identification.
47 For example, if 'selector1' is used here, then for each domain
48 'example.org' given in `domain`, 'selector1._domainkey.example.org'
49 should contain the TXT record indicating the public key is the one
50 in ${pubkey}: "v=DKIM1; t=s; p=[THE PUBLIC KEY]".
54 keySize = lib.mkOption {
58 Size of the RSA key to use to sign outgoing emails. Note that the
59 maximum mandatorily verified as per RFC6376 is 2048.
63 # TODO: allow signature for other schemes than dkim(c=relaxed/relaxed)?
64 # This being the scheme used by gmail, maybe nothing more is needed for
71 configfile = pkgs.writeText "dkimproxy_out.conf"
76 domain ${lib.concatStringsSep "," cfg.domains}
77 selector ${cfg.selector}
79 signature dkim(c=relaxed/relaxed)
85 users.groups.dkimproxy-out = {};
86 users.users.dkimproxy-out = {
87 description = "DKIMproxy_out daemon";
88 group = "dkimproxy-out";
92 systemd.services.dkimproxy-out = {
93 description = "DKIMproxy_out";
94 wantedBy = [ "multi-user.target" ];
96 if [ ! -d "${keydir}" ]; then
98 chmod 0700 "${keydir}"
99 ${pkgs.openssl}/bin/openssl genrsa -out "${privkey}" ${toString cfg.keySize}
100 ${pkgs.openssl}/bin/openssl rsa -in "${privkey}" -pubout -out "${pubkey}"
101 chown -R dkimproxy-out:dkimproxy-out "${keydir}"
105 exec ${pkgs.dkimproxy}/bin/dkimproxy.out --conf_file=${configfile}
108 User = "dkimproxy-out";
109 PermissionsStartOnly = true;
114 meta.maintainers = with lib.maintainers; [ ekleog ];