1 { config, lib, pkgs, ... }:
4 cfg = config.services.dspam;
8 defaultSock = "/run/dspam/dspam.sock";
10 cfgfile = pkgs.writeText "dspam.conf" ''
12 StorageDriver ${dspam}/lib/dspam/lib${cfg.storageDriver}_drv.so
19 ${lib.optionalString (cfg.domainSocket != null) ''
20 ServerDomainSocketPath "${cfg.domainSocket}"
21 ClientHost "${cfg.domainSocket}"
35 enable = lib.mkOption {
36 type = lib.types.bool;
38 description = "Whether to enable the dspam spam filter.";
44 description = "User for the dspam daemon.";
47 group = lib.mkOption {
50 description = "Group for the dspam daemon.";
53 storageDriver = lib.mkOption {
56 description = "Storage driver backend to use for dspam.";
59 domainSocket = lib.mkOption {
60 type = lib.types.nullOr lib.types.path;
61 default = defaultSock;
62 description = "Path to local domain socket which is used for communication with the daemon. Set to null to disable UNIX socket.";
65 extraConfig = lib.mkOption {
66 type = lib.types.lines;
68 description = "Additional dspam configuration.";
71 maintenanceInterval = lib.mkOption {
72 type = lib.types.nullOr lib.types.str;
74 description = "If set, maintenance script will be run at specified (in systemd.timer format) interval";
84 config = lib.mkIf cfg.enable (lib.mkMerge [
86 users.users = lib.optionalAttrs (cfg.user == "dspam") {
89 uid = config.ids.uids.dspam;
93 users.groups = lib.optionalAttrs (cfg.group == "dspam") {
94 dspam.gid = config.ids.gids.dspam;
97 environment.systemPackages = [ dspam ];
99 environment.etc."dspam/dspam.conf".source = cfgfile;
101 systemd.services.dspam = {
102 description = "dspam spam filtering daemon";
103 wantedBy = [ "multi-user.target" ];
104 after = [ "postgresql.service" ];
105 restartTriggers = [ cfgfile ];
108 ExecStart = "${dspam}/bin/dspam --daemon --nofork";
111 RuntimeDirectory = lib.optional (cfg.domainSocket == defaultSock) "dspam";
112 RuntimeDirectoryMode = lib.optional (cfg.domainSocket == defaultSock) "0750";
113 StateDirectory = "dspam";
114 StateDirectoryMode = "0750";
115 LogsDirectory = "dspam";
116 LogsDirectoryMode = "0750";
117 # DSPAM segfaults on just about every error
118 Restart = "on-abort";
124 (lib.mkIf (cfg.maintenanceInterval != null) {
125 systemd.timers.dspam-maintenance = {
126 description = "Timer for dspam maintenance script";
127 wantedBy = [ "timers.target" ];
129 OnCalendar = cfg.maintenanceInterval;
130 Unit = "dspam-maintenance.service";
134 systemd.services.dspam-maintenance = {
135 description = "dspam maintenance script";
136 restartTriggers = [ cfgfile ];
139 ExecStart = "${dspam}/bin/dspam_maintenance --verbose";