1 { pkgs, lib, config, ... }:
3 inherit (builtins) attrNames listToAttrs readFile;
5 inherit (pkgs.lib) unlinesAttrs;
6 inherit (config.security) gnupg;
7 inherit (config.services) postfix rspamd dovecot2;
8 redis = config.services.redis.servers.rspamd;
9 inherit (config.users) users groups;
13 rspamd/autogeree.net.nix
14 rspamd/sourcephile.fr.nix
17 services.rspamd.dkimSelectorMap = lib.mkOption {
20 description = ''Each line maps a domain to its active DKIM selector'';
21 apply = s: pkgs.writeText "dkim_selectors.map" s;
25 users.groups.redis-rspamd.members = [ rspamd.user ];
26 users.groups.keys.members = [ rspamd.user ];
30 postfix.enable = postfix.enable;
32 "dkim_signing.conf".text = ''
33 selector_map = ${rspamd.dkimSelectorMap};
34 path = "/run/keys/gnupg/rspamd/dkim/$domain/$selector.key/file";
35 allow_username_mismatch = true;
38 selector_map = ${rspamd.dkimSelectorMap};
39 path = "/run/keys/gnupg/rspamd/dkim/$domain/$selector.key/file";
40 allow_username_mismatch = true;
42 "redis.conf".text = ''
43 servers = "${redis.unixSocket}";
46 "classifier-bayes.conf".text = ''
47 users_enabled = false;
49 servers = "${redis.unixSocket}";
68 debug_modules = [“dkim_signing”]
73 "milter_headers.conf".text = ''
74 extended_spam_headers = true;
76 "actions.conf".text = ''
77 reject = 15; # Reject when reaching this score
78 add_header = 6; # Add header when reaching this score
79 greylist = 4; # Apply greylisting when reaching this score (will emit `soft reject action`)
84 # Like controller but without a password, only the bindSockets' permissions
86 includes = [ "$CONFDIR/worker-controller.inc" ];
88 { socket = "/run/rspamd/learner.sock";
90 owner = "${rspamd.user}";
91 group = "${dovecot2.group}";
99 "$CONFDIR/worker-controller.inc"
100 gnupg.secrets."rspamd/controller/hashedPassword".path
107 #static_dir = "''${WWWDIR}";
112 security.gnupg.secrets."rspamd/controller/hashedPassword" = {
113 # Generated with: rspamadm pw
115 pipe = ''${pkgs.gnused}/bin/sed -e 's/.*/password = "\0";/' '';
116 systemdConfig.postStart = "systemctl try-restart --no-block rspamd"; # rspamd does not support reloading so far
118 systemd.services.rspamd = {
119 wants = [ gnupg.secrets."rspamd/controller/hashedPassword".service ];
120 after = [ gnupg.secrets."rspamd/controller/hashedPassword".service ];
123 fileSystems."/var/lib/redis-rspamd" = {
124 device = "rpool/var/redis-rspamd";
127 services.sanoid.datasets."rpool/var/redis-rspamd" = {
128 use_template = [ "snap" ];
133 services.redis.vmOverCommit = true;
134 services.redis.servers.rspamd = {
138 save = [ [1800 100] [300 1000] ];
139 #unixSocketPerm = "660";
142 maxmemory-policy = "volatile-ttl";
146 services.postfix.extraConfig = ''
147 smtpd_milters = unix:/run/rspamd.sock
148 milter_default_action = accept
150 # Allow users to run 'rspamc' and 'rspamadm'.
151 environment.systemPackages = [ pkgs.rspamd ];