1 { pkgs, lib, config, inputs, hostName, ... }:
3 inherit (builtins) attrNames listToAttrs readFile;
5 inherit (pkgs.lib) unlinesAttrs;
6 inherit (config.services) postfix rspamd dovecot2;
7 redis = config.services.redis.servers.rspamd;
8 inherit (config.users) users groups;
12 rspamd/autogeree.net.nix
13 rspamd/sourcephile.fr.nix
16 services.rspamd.dkimSelectorMap = lib.mkOption {
19 description = ''Each line maps a domain to its active DKIM selector'';
20 apply = s: pkgs.writeText "dkim_selectors.map" s;
24 users.groups.redis-rspamd.members = [ rspamd.user ];
28 postfix.enable = postfix.enable;
30 "dkim_signing.conf".text = ''
31 selector_map = ${rspamd.dkimSelectorMap};
32 path = "/run/credentials/rspamd.service/$domain.$selector.key";
33 allow_username_mismatch = true;
36 selector_map = ${rspamd.dkimSelectorMap};
37 path = "/run/credentials/rspamd.service/$domain.$selector.key";
38 allow_username_mismatch = true;
40 "redis.conf".text = ''
41 servers = "${redis.unixSocket}";
44 "classifier-bayes.conf".text = ''
45 users_enabled = false;
47 servers = "${redis.unixSocket}";
66 debug_modules = [“dkim_signing”]
71 "milter_headers.conf".text = ''
72 extended_spam_headers = true;
74 "actions.conf".text = ''
75 reject = 15; # Reject when reaching this score
76 add_header = 6; # Add header when reaching this score
77 greylist = 4; # Apply greylisting when reaching this score (will emit `soft reject action`)
82 # Like controller but without a password, only the bindSockets' permissions
84 includes = [ "$CONFDIR/worker-controller.inc" ];
86 { socket = "/run/rspamd/learner.sock";
88 owner = "${rspamd.user}";
89 group = "${dovecot2.group}";
97 "$CONFDIR/worker-controller.inc"
98 "/run/credentials/rspamd.service/controller.inc"
105 #static_dir = "''${WWWDIR}";
110 systemd.services.rspamd = {
112 LoadCredentialEncrypted = [
113 "controller.inc:${inputs.self}/hosts/${hostName}/rspamd/controller.inc.cred"
118 fileSystems."/var/lib/redis-rspamd" = {
119 device = "rpool/var/redis-rspamd";
122 services.sanoid.datasets."rpool/var/redis-rspamd" = {
123 use_template = [ "snap" ];
128 services.redis.vmOverCommit = true;
129 services.redis.servers.rspamd = {
133 save = [ [1800 100] [300 1000] ];
134 #unixSocketPerm = "660";
137 maxmemory-policy = "volatile-ttl";
141 services.postfix.extraConfig = ''
142 smtpd_milters = unix:/run/rspamd.sock
143 milter_default_action = accept
145 # Allow users to run 'rspamc' and 'rspamadm'.
146 environment.systemPackages = [ pkgs.rspamd ];