···
rspamdCfg = config.services.rspamd;
cfg = config.services.rmilter;
10
-
inetSockets = map (sock: let s = splitString ":" sock; in "inet:${last s}@${head s}") cfg.bindInetSockets;
11
-
unixSockets = map (sock: "unix:${sock}") cfg.bindUnixSockets;
10
+
inetSocket = addr: port: "inet:[${toString port}@${addr}]";
11
+
unixSocket = sock: "unix:${sock}";
13
-
allSockets = unixSockets ++ inetSockets;
13
+
systemdSocket = if cfg.bindSocket.type == "unix" then cfg.bindSocket.path
14
+
else "${cfg.bindSocket.address}:${toString cfg.bindSocket.port}";
15
+
rmilterSocket = if cfg.bindSocket.type == "unix" then unixSocket cfg.bindSocket.path
16
+
else inetSocket cfg.bindSocket.address cfg.bindSocket.port;
pidfile = /run/rmilter/rmilter.pid;
17
-
bind_socket = ${if cfg.socketActivation then "fd:3" else last inetSockets};
20
+
bind_socket = ${if cfg.socketActivation then "fd:3" else rmilterSocket};
'' + (with cfg.rspamd; if enable then ''
···
rspamd_metric = "default";
35
-
'' else "") + cfg.extraConfig;
38
+
'' else "") + cfg.extraConfig;
rmilterConfigFile = pkgs.writeText "rmilter.conf" rmilterConf;
···
default = cfg.rspamd.enable;
description = "Whether to run the rmilter daemon.";
description = "Whether to run the rmilter daemon in debug mode.";
···
75
-
bindUnixSockets = mkOption {
76
-
type = types.listOf types.str;
77
-
default = ["/run/rmilter/rmilter.sock"];
80
+
bindSocket.type = mkOption {
81
+
type = types.enum [ "unix" "inet" ];
79
-
Unix domain sockets to listen for MTA requests.
84
+
What kind of socket rmilter should listen on. Either "unix"
85
+
for an Unix domain socket or "inet" for a TCP socket.
82
-
[ "/run/rmilter.sock"]
89
+
bindSocket.path = mkOption {
91
+
default = "/run/rmilter/rmilter.sock";
93
+
Path to Unix domain socket to listen on.
86
-
bindInetSockets = mkOption {
87
-
type = types.listOf types.str;
97
+
bindSocket.address = mkOption {
100
+
example = "0.0.0.0";
90
-
Inet addresses to listen (in format accepted by systemd.socket)
102
+
Inet address to listen on.
106
+
bindSocket.port = mkOption {
110
+
Inet port to listen on.
···
Disabling socket activation is not recommended when a Unix
domain socket is used and could lead to incorrect
105
-
permissions. Therefore, setting this to false will
106
-
configure rmilter to use an inet socket only.
default = rspamdCfg.enable;
description = "Whether to use rspamd to filter mails";
···
description = "Addon to postfix configuration";
161
-
smtpd_milters = ${head allSockets}
162
-
# or for TCP socket
163
-
# # smtpd_milters = inet:localhost:9900
164
-
milter_protocol = 6
165
-
milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}
166
-
# skip mail without checks if milter will die
167
-
milter_default_action = accept
178
+
smtpd_milters = ${rmilterSocket}
179
+
milter_protocol = 6
180
+
milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}
···
179
-
config = mkIf cfg.enable {
196
+
users.extraUsers = singleton {
198
+
description = "rmilter daemon";
199
+
uid = config.ids.uids.rmilter;
181
-
users.extraUsers = singleton {
183
-
description = "rspamd daemon";
184
-
uid = config.ids.uids.rmilter;
203
+
users.extraGroups = singleton {
205
+
gid = config.ids.gids.rmilter;
188
-
users.extraGroups = singleton {
190
-
gid = config.ids.gids.rmilter;
208
+
systemd.services.rmilter = {
209
+
description = "Rmilter Service";
193
-
systemd.services.rmilter = {
194
-
description = "Rmilter Service";
211
+
wantedBy = [ "multi-user.target" ];
212
+
after = [ "network.target" ];
196
-
wantedBy = [ "multi-user.target" ];
197
-
after = [ "network.target" ];
215
+
ExecStart = "${pkgs.rmilter}/bin/rmilter ${optionalString cfg.debug "-d"} -n -c ${rmilterConfigFile}";
216
+
ExecReload = "${pkgs.coreutils}/bin/kill -USR1 $MAINPID";
219
+
PermissionsStartOnly = true;
220
+
Restart = "always";
221
+
RuntimeDirectory = "rmilter";
222
+
RuntimeDirectoryMode = "0755";
200
-
ExecStart = "${pkgs.rmilter}/bin/rmilter ${optionalString cfg.debug "-d"} -n -c ${rmilterConfigFile}";
201
-
ExecReload = "${pkgs.coreutils}/bin/kill -USR1 $MAINPID";
204
-
PermissionsStartOnly = true;
205
-
Restart = "always";
206
-
RuntimeDirectory = "rmilter";
207
-
RuntimeDirectoryMode = "0755";
212
-
systemd.sockets.rmilter = mkIf cfg.socketActivation {
213
-
description = "Rmilter service socket";
214
-
wantedBy = [ "sockets.target" ];
216
-
ListenStream = cfg.bindUnixSockets ++ cfg.bindInetSockets;
217
-
SocketUser = cfg.user;
218
-
SocketGroup = cfg.group;
219
-
SocketMode = "0666";
227
+
systemd.sockets.rmilter = mkIf cfg.socketActivation {
228
+
description = "Rmilter service socket";
229
+
wantedBy = [ "sockets.target" ];
231
+
ListenStream = systemdSocket;
232
+
SocketUser = cfg.user;
233
+
SocketGroup = cfg.group;
234
+
SocketMode = "0666";
223
-
services.postfix.extraConfig = optionalString cfg.postfix.enable cfg.postfix.configFragment;
224
-
users.users.postfix.extraGroups = [ cfg.group ];
239
+
(mkIf (cfg.enable && cfg.postfix.enable) {
241
+
services.postfix.extraConfig = cfg.postfix.configFragment;
242
+
users.users.postfix.extraGroups = [ cfg.group ];