nixos/services.clamsmtp: remove with lib;
This commit is contained in:
parent
2c2cb598fe
commit
68dee151ef
@ -1,6 +1,4 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
let
|
let
|
||||||
cfg = config.services.clamsmtp;
|
cfg = config.services.clamsmtp;
|
||||||
clamdSocket = "/run/clamav/clamd.ctl"; # See services/security/clamav.nix
|
clamdSocket = "/run/clamav/clamd.ctl"; # See services/security/clamav.nix
|
||||||
@ -9,17 +7,17 @@ in
|
|||||||
##### interface
|
##### interface
|
||||||
options = {
|
options = {
|
||||||
services.clamsmtp = {
|
services.clamsmtp = {
|
||||||
enable = mkOption {
|
enable = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Whether to enable clamsmtp.";
|
description = "Whether to enable clamsmtp.";
|
||||||
};
|
};
|
||||||
|
|
||||||
instances = mkOption {
|
instances = lib.mkOption {
|
||||||
description = "Instances of clamsmtp to run.";
|
description = "Instances of clamsmtp to run.";
|
||||||
type = types.listOf (types.submodule { options = {
|
type = lib.types.listOf (lib.types.submodule { options = {
|
||||||
action = mkOption {
|
action = lib.mkOption {
|
||||||
type = types.enum [ "bounce" "drop" "pass" ];
|
type = lib.types.enum [ "bounce" "drop" "pass" ];
|
||||||
default = "drop";
|
default = "drop";
|
||||||
description = ''
|
description = ''
|
||||||
Action to take when a virus is detected.
|
Action to take when a virus is detected.
|
||||||
@ -29,8 +27,8 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
header = mkOption {
|
header = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
example = "X-Virus-Scanned: ClamAV using ClamSMTP";
|
example = "X-Virus-Scanned: ClamAV using ClamSMTP";
|
||||||
description = ''
|
description = ''
|
||||||
@ -39,8 +37,8 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
keepAlives = mkOption {
|
keepAlives = lib.mkOption {
|
||||||
type = types.int;
|
type = lib.types.int;
|
||||||
default = 0;
|
default = 0;
|
||||||
description = ''
|
description = ''
|
||||||
Number of seconds to wait between each NOOP sent to the sending
|
Number of seconds to wait between each NOOP sent to the sending
|
||||||
@ -51,8 +49,8 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
listen = mkOption {
|
listen = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
example = "127.0.0.1:10025";
|
example = "127.0.0.1:10025";
|
||||||
description = ''
|
description = ''
|
||||||
Address to wait for incoming SMTP connections on. See
|
Address to wait for incoming SMTP connections on. See
|
||||||
@ -60,8 +58,8 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
quarantine = mkOption {
|
quarantine = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to quarantine files that contain viruses by leaving them
|
Whether to quarantine files that contain viruses by leaving them
|
||||||
@ -69,22 +67,22 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
maxConnections = mkOption {
|
maxConnections = lib.mkOption {
|
||||||
type = types.int;
|
type = lib.types.int;
|
||||||
default = 64;
|
default = 64;
|
||||||
description = "Maximum number of connections to accept at once.";
|
description = "Maximum number of connections to accept at once.";
|
||||||
};
|
};
|
||||||
|
|
||||||
outAddress = mkOption {
|
outAddress = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
description = ''
|
description = ''
|
||||||
Address of the SMTP server to send email to once it has been
|
Address of the SMTP server to send email to once it has been
|
||||||
scanned.
|
scanned.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
tempDirectory = mkOption {
|
tempDirectory = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "/tmp";
|
default = "/tmp";
|
||||||
description = ''
|
description = ''
|
||||||
Temporary directory that needs to be accessible to both clamd
|
Temporary directory that needs to be accessible to both clamd
|
||||||
@ -92,20 +90,20 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
timeout = mkOption {
|
timeout = lib.mkOption {
|
||||||
type = types.int;
|
type = lib.types.int;
|
||||||
default = 180;
|
default = 180;
|
||||||
description = "Time-out for network connections.";
|
description = "Time-out for network connections.";
|
||||||
};
|
};
|
||||||
|
|
||||||
transparentProxy = mkOption {
|
transparentProxy = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Enable clamsmtp's transparent proxy support.";
|
description = "Enable clamsmtp's transparent proxy support.";
|
||||||
};
|
};
|
||||||
|
|
||||||
virusAction = mkOption {
|
virusAction = lib.mkOption {
|
||||||
type = with types; nullOr path;
|
type = with lib.types; nullOr path;
|
||||||
default = null;
|
default = null;
|
||||||
description = ''
|
description = ''
|
||||||
Command to run when a virus is found. Please see VIRUS ACTION in
|
Command to run when a virus is found. Please see VIRUS ACTION in
|
||||||
@ -113,8 +111,8 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
xClient = mkOption {
|
xClient = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Send the XCLIENT command to the receiving server, for forwarding
|
Send the XCLIENT command to the receiving server, for forwarding
|
||||||
@ -143,19 +141,19 @@ in
|
|||||||
TimeOut: ${toString conf.timeout}
|
TimeOut: ${toString conf.timeout}
|
||||||
TransparentProxy: ${if conf.transparentProxy then "on" else "off"}
|
TransparentProxy: ${if conf.transparentProxy then "on" else "off"}
|
||||||
User: clamav
|
User: clamav
|
||||||
${optionalString (conf.virusAction != null) "VirusAction: ${conf.virusAction}"}
|
${lib.optionalString (conf.virusAction != null) "VirusAction: ${conf.virusAction}"}
|
||||||
XClient: ${if conf.xClient then "on" else "off"}
|
XClient: ${if conf.xClient then "on" else "off"}
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
mkIf cfg.enable {
|
lib.mkIf cfg.enable {
|
||||||
assertions = [
|
assertions = [
|
||||||
{ assertion = config.services.clamav.daemon.enable;
|
{ assertion = config.services.clamav.daemon.enable;
|
||||||
message = "clamsmtp requires clamav to be enabled";
|
message = "clamsmtp requires clamav to be enabled";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.services = listToAttrs (imap1 (i: conf:
|
systemd.services = lib.listToAttrs (lib.imap1 (i: conf:
|
||||||
nameValuePair "clamsmtp-${toString i}" {
|
lib.nameValuePair "clamsmtp-${toString i}" {
|
||||||
description = "ClamSMTP instance ${toString i}";
|
description = "ClamSMTP instance ${toString i}";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
script = "exec ${pkgs.clamsmtp}/bin/clamsmtpd -f ${configfile conf}";
|
script = "exec ${pkgs.clamsmtp}/bin/clamsmtpd -f ${configfile conf}";
|
||||||
|
Loading…
Reference in New Issue
Block a user