1 { config, lib, pkgs, ... }:
3 cfg = config.services.spamassassin;
4 spamassassin-local-cf = pkgs.writeText "local.cf" cfg.config;
11 services.spamassassin = {
12 enable = lib.mkEnableOption "the SpamAssassin daemon";
14 debug = lib.mkOption {
15 type = lib.types.bool;
17 description = "Whether to run the SpamAssassin daemon in debug mode";
20 config = lib.mkOption {
21 type = lib.types.lines;
23 The SpamAssassin local.cf config
25 If you are using this configuration:
27 add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ tests=_TESTS_ autolearn=_AUTOLEARN_ version=_VERSION_
29 Then you can Use this sieve filter:
31 require ["fileinto", "reject", "envelope"];
33 if header :contains "X-Spam-Flag" "YES" {
37 Or this procmail filter:
41 /var/vpopmail/domains/lastlog.de/js/.maildir/.spam/new
43 To filter your messages based on the additional mail headers added by spamassassin.
46 #rewrite_header Subject [***** SPAM _SCORE_ *****]
50 add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ tests=_TESTS_ autolearn=_AUTOLEARN_ version=_VERSION_
55 initPreConf = lib.mkOption {
56 type = with lib.types; either str path;
57 description = "The SpamAssassin init.pre config.";
58 apply = val: if builtins.isPath val then val else pkgs.writeText "init.pre" val;
62 # to update this list, run this command in the rules directory:
63 # grep 'loadplugin.*Mail::SpamAssassin::Plugin::.*' -o -h * | sort | uniq
66 #loadplugin Mail::SpamAssassin::Plugin::AccessDB
67 #loadplugin Mail::SpamAssassin::Plugin::AntiVirus
68 loadplugin Mail::SpamAssassin::Plugin::AskDNS
69 # loadplugin Mail::SpamAssassin::Plugin::ASN
70 loadplugin Mail::SpamAssassin::Plugin::AutoLearnThreshold
71 #loadplugin Mail::SpamAssassin::Plugin::AWL
72 loadplugin Mail::SpamAssassin::Plugin::Bayes
73 loadplugin Mail::SpamAssassin::Plugin::BodyEval
74 loadplugin Mail::SpamAssassin::Plugin::Check
75 #loadplugin Mail::SpamAssassin::Plugin::DCC
76 loadplugin Mail::SpamAssassin::Plugin::DKIM
77 loadplugin Mail::SpamAssassin::Plugin::DMARC
78 loadplugin Mail::SpamAssassin::Plugin::DNSEval
79 loadplugin Mail::SpamAssassin::Plugin::FreeMail
80 loadplugin Mail::SpamAssassin::Plugin::HeaderEval
81 loadplugin Mail::SpamAssassin::Plugin::HTMLEval
82 loadplugin Mail::SpamAssassin::Plugin::HTTPSMismatch
83 loadplugin Mail::SpamAssassin::Plugin::ImageInfo
84 loadplugin Mail::SpamAssassin::Plugin::MIMEEval
85 loadplugin Mail::SpamAssassin::Plugin::MIMEHeader
86 # loadplugin Mail::SpamAssassin::Plugin::PDFInfo
87 #loadplugin Mail::SpamAssassin::Plugin::PhishTag
88 loadplugin Mail::SpamAssassin::Plugin::Pyzor
89 loadplugin Mail::SpamAssassin::Plugin::Razor2
90 # loadplugin Mail::SpamAssassin::Plugin::RelayCountry
91 loadplugin Mail::SpamAssassin::Plugin::RelayEval
92 loadplugin Mail::SpamAssassin::Plugin::ReplaceTags
93 # loadplugin Mail::SpamAssassin::Plugin::Rule2XSBody
94 # loadplugin Mail::SpamAssassin::Plugin::Shortcircuit
95 loadplugin Mail::SpamAssassin::Plugin::SpamCop
96 loadplugin Mail::SpamAssassin::Plugin::SPF
97 #loadplugin Mail::SpamAssassin::Plugin::TextCat
98 # loadplugin Mail::SpamAssassin::Plugin::TxRep
99 loadplugin Mail::SpamAssassin::Plugin::URIDetail
100 loadplugin Mail::SpamAssassin::Plugin::URIDNSBL
101 loadplugin Mail::SpamAssassin::Plugin::URIEval
102 # loadplugin Mail::SpamAssassin::Plugin::URILocalBL
103 loadplugin Mail::SpamAssassin::Plugin::VBounce
104 loadplugin Mail::SpamAssassin::Plugin::WhiteListSubject
105 loadplugin Mail::SpamAssassin::Plugin::WLBLEval
111 config = lib.mkIf cfg.enable {
112 environment.etc."mail/spamassassin/init.pre".source = cfg.initPreConf;
113 environment.etc."mail/spamassassin/local.cf".source = spamassassin-local-cf;
115 # Allow users to run 'spamc'.
116 environment.systemPackages = [ pkgs.spamassassin ];
118 users.users.spamd = {
119 description = "Spam Assassin Daemon";
120 uid = config.ids.uids.spamd;
124 users.groups.spamd = {
125 gid = config.ids.gids.spamd;
128 systemd.services.sa-update = {
129 # Needs to be able to contact the update server.
130 wants = [ "network-online.target" ];
131 after = [ "network-online.target" ];
137 StateDirectory = "spamassassin";
138 ExecStartPost = "+${config.systemd.package}/bin/systemctl -q --no-block try-reload-or-restart spamd.service";
143 ${pkgs.spamassassin}/bin/sa-update --verbose --gpghomedir=/var/lib/spamassassin/sa-update-keys/
147 if [[ $rc -gt 1 ]]; then
152 if [[ $rc -eq 1 ]]; then
153 # No update was available, exit successfully.
157 # An update was available and installed. Compile the rules.
158 ${pkgs.spamassassin}/bin/sa-compile
162 systemd.timers.sa-update = {
163 description = "sa-update-service";
164 partOf = [ "sa-update.service" ];
165 wantedBy = [ "timers.target" ];
172 systemd.services.spamd = {
173 description = "SpamAssassin Server";
175 wantedBy = [ "multi-user.target" ];
176 wants = [ "sa-update.service" ];
185 ExecStart = "+${pkgs.spamassassin}/bin/spamd ${lib.optionalString cfg.debug "-D"} --username=spamd --groupname=spamd --virtual-config-dir=%S/spamassassin/user-%u --allow-tell --pidfile=/run/spamd.pid";
186 ExecReload = "+${pkgs.coreutils}/bin/kill -HUP $MAINPID";
187 StateDirectory = "spamassassin";