1 {pkgs, lib, config, ...}:
2 let inherit (builtins) attrNames;
3 inherit (builtins.extraBuiltins) pass;
5 inherit (pkgs.lib) unlinesAttrs;
6 inherit (config) networking;
7 inherit (config.services) rspamd-upstream dkim;
9 localConfig = pkgs.writeText "local.conf" ''
14 path = "/var/lib/rspamd/dkim/$domain.$selector.key";
16 allow_username_mismatch = true;
19 path = "/var/lib/rspamd/dkim/$domain.$selector.key";
21 allow_username_mismatch = true;
24 use = ["authentication-results", "x-spam-status"];
25 authenticated_headers = ["authentication-results"];
34 openphish_enabled = true;
35 phishtank_enabled = true;
41 options.services.dkim = lib.mkOption {
43 type = types.submodule {
45 domains = lib.mkOption {
47 type = types.attrsOf (types.submodule {
49 selector = lib.mkOption {
51 description = ''Current selector.'';
53 selectors = lib.mkOption {
55 description = ''Available selectors.'';
56 type = types.attrsOf (types.submodule {
60 description = ''Private key.'';
64 description = ''DNS record.'';
76 deployment.keys = builtins.listToAttrs (map
78 let selector = dkim.domains."${domain}".selector; in
79 { name = "dkim.${domain}.${selector}.key";
81 text = pass "${networking.domainBase}/dkim/${selector}/key" + "\n";
82 #destDir = "${redmine.stateDir}/.ssh";
83 #path = "${redmine.stateDir}/.ssh/id_ed25519";
84 user = rspamd-upstream.user;
85 group = rspamd-upstream.group;
86 permissions = "0400"; # XXX: not enforced when deployment.storeKeysOnMachine = true
89 ([ networking.domain ] ++ networking.domainAliases));
91 systemd.services.rspamd-upstream = {
95 after = [ "keys.target" ];
96 preStart = unlinesAttrs (domain: dom: ''
97 install -D -o ${rspamd-upstream.user} -g ${rspamd-upstream.group} -m 0400 \
98 /run/keys/dkim.${domain}.${dom.selector}.key \
99 /var/lib/rspamd/dkim/${domain}.${dom.selector}.key
103 services.rspamd-upstream = {
110 let selector_map_file =
111 pkgs.writeText "dkim_selectors.map"
112 (pkgs.lib.unlinesAttrs
113 (domain: dom: "${domain} ${dom.selector}")
115 "dkim_signing.conf".text = ''
116 path = "/var/lib/rspamd/dkim/$domain.$selector.key";
117 selector_map = ${selector_map_file};
118 allow_username_mismatch = true;
121 path = "/var/lib/rspamd/dkim/$domain.$selector.key";
122 selector_map = ${selector_map_file};
123 allow_username_mismatch = true;
127 debug_modules = [“dkim_signing”]
132 "milter_headers.conf".text = ''
133 extended_spam_headers = true;
135 "actions.conf".text = ''
137 reject = 15; # Reject when reaching this score
138 add_header = 6; # Add header when reaching this score
139 greylist = 4; # Apply greylisting when reaching this score (will emit `soft reject action`)
146 includes = [ "$CONFDIR/worker-normal.inc" ];
148 socket = "/run/rspamd/rspamd.sock";
150 owner = "${cfg.user}";
151 group = "${cfg.group}";
156 #includes = [ "$CONFDIR/worker-controller.inc" ];
157 bindSockets = [ "*:11334" ]; # FIXME: localhost only
160 #static_dir = "''${WWWDIR}";
162 password = "$2$fy8padyutwigfchjbye88h7i4exwx9gw$m3ohkqu9fartjkjz5oeok5xwxamwime63998awryxdt8dt431eoy";
168 services.rspamd-upstream = {
170 # FIXME: the order of sockets is messed up
171 socketActivation = false;
173 .include(priority=1,duplicate=merge) "${localConfig}"
176 workers.controller = {
179 static_dir = "''${WWWDIR}";
180 password = "$2$cifyu958qabanmtjyofmf5981posxie7$dz3taiiumir9ew5ordg8n1ia3eb73y1t55kzc9qsjdq1n8esmqqb";
181 enable_password = "$2$cifyu958qabanmtjyofmf5981posxie7$dz3taiiumir9ew5ordg8n1ia3eb73y1t55kzc9qsjdq1n8esmqqb";
185 workers.rspamd_proxy = {
188 milter = yes; # Enable milter mode
189 timeout = 120s; # Needed for Milter usually
194 count = 1; # Do not spawn too many processes of this type
197 socket = "/run/rspamd.sock";
207 services.postfix.extraConfig = ''
208 smtpd_milters = unix:/run/rspamd.sock
209 milter_default_action = accept
211 # Allow users to run 'rspamc' and 'rspamadm'.
212 environment.systemPackages = [ pkgs.rspamd ];