···
+
{ config, lib, pkgs, ... }:
+
cfg = config.services.clamsmtp;
+
clamdSocket = "/run/clamav/clamd.ctl"; # See services/security/clamav.nix
+
description = "Whether to enable clamsmtp.";
+
description = "Instances of clamsmtp to run.";
+
type = types.listOf (types.submodule { options = {
+
type = types.enum [ "bounce" "drop" "pass" ];
+
Action to take when a virus is detected.
+
Note that viruses often spoof sender addresses, so bouncing is
+
in most cases not a good idea.
+
example = "X-Virus-Scanned: ClamAV using ClamSMTP";
+
A header to add to scanned messages. See clamsmtpd.conf(5) for
+
more details. Empty means no header.
+
keepAlives = mkOption {
+
Number of seconds to wait between each NOOP sent to the sending
+
This is meant for slow servers where the sending MTA times out
+
waiting for clamd to scan the file.
+
example = "127.0.0.1:10025";
+
Address to wait for incoming SMTP connections on. See
+
clamsmtpd.conf(5) for more details.
+
quarantine = mkOption {
+
Whether to quarantine files that contain viruses by leaving them
+
in the temporary directory.
+
maxConnections = mkOption {
+
description = "Maximum number of connections to accept at once.";
+
outAddress = mkOption {
+
Address of the SMTP server to send email to once it has been
+
tempDirectory = mkOption {
+
Temporary directory that needs to be accessible to both clamd
+
description = "Time-out for network connections.";
+
transparentProxy = mkOption {
+
description = "Enable clamsmtp's transparent proxy support.";
+
virusAction = mkOption {
+
type = with types; nullOr path;
+
Command to run when a virus is found. Please see VIRUS ACTION in
+
clamsmtpd(8) for a discussion of this option and its safe use.
+
Send the XCLIENT command to the receiving server, for forwarding
+
client addresses and connection information if the receiving
+
server supports this feature.
+
configfile = conf: pkgs.writeText "clamsmtpd.conf"
+
ClamAddress: ${clamdSocket}
+
KeepAlives: ${toString conf.keepAlives}
+
Quarantine: ${if conf.quarantine then "on" else "off"}
+
MaxConnections: ${toString conf.maxConnections}
+
OutAddress: ${conf.outAddress}
+
TempDirectory: ${conf.tempDirectory}
+
TimeOut: ${toString conf.timeout}
+
TransparentProxy: ${if conf.transparentProxy then "on" else "off"}
+
${optionalString (conf.virusAction != null) "VirusAction: ${conf.virusAction}"}
+
XClient: ${if conf.xClient then "on" else "off"}
+
{ assertion = config.services.clamav.daemon.enable;
+
message = "clamsmtp requires clamav to be enabled";
+
systemd.services = listToAttrs (imap1 (i: conf:
+
nameValuePair "clamsmtp-${toString i}" {
+
description = "ClamSMTP instance ${toString i}";
+
wantedBy = [ "multi-user.target" ];
+
script = "exec ${pkgs.clamsmtp}/bin/clamsmtpd -f ${configfile conf}";
+
after = [ "clamav-daemon.service" ];
+
requires = [ "clamav-daemon.service" ];
+
serviceConfig.Type = "forking";
+
serviceConfig.PrivateTmp = "yes";
+
unitConfig.JoinsNamespaceOf = "clamav-daemon.service";