]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/mermet/rspamd.nix
carotte: prepare switch install
[sourcephile-nix.git] / hosts / mermet / rspamd.nix
1 { pkgs, lib, config, ... }:
2 let
3 inherit (builtins) attrNames listToAttrs readFile;
4 inherit (lib) types;
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;
10 in
11 {
12 imports = [
13 rspamd/autogeree.net.nix
14 rspamd/sourcephile.fr.nix
15 ];
16 options = {
17 services.rspamd.dkimSelectorMap = lib.mkOption {
18 type = types.lines;
19 default = "";
20 description = ''Each line maps a domain to its active DKIM selector'';
21 apply = s: pkgs.writeText "dkim_selectors.map" s;
22 };
23 };
24 config = {
25 users.groups.redis-rspamd.members = [ rspamd.user ];
26 users.groups.keys.members = [ rspamd.user ];
27 services.rspamd = {
28 enable = true;
29 debug = false;
30 postfix.enable = postfix.enable;
31 locals = {
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;
36 '';
37 "arc.conf".text = ''
38 selector_map = ${rspamd.dkimSelectorMap};
39 path = "/run/keys/gnupg/rspamd/dkim/$domain/$selector.key/file";
40 allow_username_mismatch = true;
41 '';
42 "redis.conf".text = ''
43 servers = "${redis.unixSocket}";
44 db = "1";
45 '';
46 "classifier-bayes.conf".text = ''
47 users_enabled = false;
48 backend = "redis";
49 servers = "${redis.unixSocket}";
50 database = "1";
51 autolearn = true;
52 cache {
53 backend = "redis";
54 }
55 new_schema = true;
56 statfile {
57 BAYES_HAM {
58 spam = false;
59 }
60 BAYES_SPAM {
61 spam = true;
62 }
63 }
64 '';
65 /*
66 "logging.conf" = ''
67 debug_modules = [“dkim_signing”]
68 '';
69 */
70 };
71 overrides = {
72 "milter_headers.conf".text = ''
73 extended_spam_headers = true;
74 '';
75 "actions.conf".text = ''
76 reject = 15; # Reject when reaching this score
77 add_header = 6; # Add header when reaching this score
78 greylist = 4; # Apply greylisting when reaching this score (will emit `soft reject action`)
79 '';
80 };
81 workers = {
82 learner = {
83 # Like controller but without a password, only the bindSockets' permissions
84 type = "controller";
85 includes = [ "$CONFDIR/worker-controller.inc" ];
86 bindSockets = [
87 { socket = "/run/rspamd/learner.sock";
88 mode = "0660";
89 owner = "${rspamd.user}";
90 group = "${dovecot2.group}";
91 }
92 ];
93 extraConfig = ''
94 '';
95 };
96 controller = {
97 includes = [
98 "$CONFDIR/worker-controller.inc"
99 gnupg.secrets."rspamd/controller/hashedPassword".path
100 ];
101 bindSockets = [
102 "127.0.0.1:11334"
103 ];
104 extraConfig = ''
105 #count = 1;
106 #static_dir = "''${WWWDIR}";
107 '';
108 };
109 };
110 };
111 security.gnupg.secrets."rspamd/controller/hashedPassword" = {
112 # Generated with: rspamadm pw
113 user = rspamd.user;
114 pipe = ''${pkgs.gnused}/bin/sed -e 's/.*/password = "\0";/' '';
115 systemdConfig.postStart = "systemctl try-restart --no-block rspamd"; # rspamd does not support reloading so far
116 };
117 systemd.services.rspamd = {
118 wants = [ gnupg.secrets."rspamd/controller/hashedPassword".service ];
119 after = [ gnupg.secrets."rspamd/controller/hashedPassword".service ];
120 };
121
122 fileSystems."/var/lib/redis-rspamd" = {
123 device = "rpool/var/redis-rspamd";
124 fsType = "zfs";
125 };
126 services.sanoid.datasets."rpool/var/redis-rspamd" = {
127 use_template = [ "snap" ];
128 hourly = 0;
129 daily = 7;
130 monthly = 0;
131 yearly = 0;
132 };
133
134 services.redis.vmOverCommit = true;
135 services.redis.servers.rspamd = {
136 enable = true;
137 databases = 16;
138 syslog = true;
139 save = [ [1800 100] [300 1000] ];
140 #unixSocketPerm = "660";
141 settings = {
142 maxmemory = "512MB";
143 maxmemory-policy = "volatile-ttl";
144 };
145 };
146 /*
147 services.postfix.extraConfig = ''
148 smtpd_milters = unix:/run/rspamd.sock
149 milter_default_action = accept
150 '';
151 # Allow users to run 'rspamc' and 'rspamadm'.
152 environment.systemPackages = [ pkgs.rspamd ];
153 */
154 };
155 }