2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
2012-07-23 16:18:19 +02:00
|
|
|
let
|
|
|
|
clamavUser = "clamav";
|
|
|
|
stateDir = "/var/lib/clamav";
|
2015-12-12 13:45:48 +01:00
|
|
|
runDir = "/var/run/clamav";
|
|
|
|
logDir = "/var/log/clamav";
|
2012-07-23 16:18:19 +02:00
|
|
|
clamavGroup = clamavUser;
|
|
|
|
cfg = config.services.clamav;
|
2015-12-12 13:45:48 +01:00
|
|
|
clamdConfigFile = pkgs.writeText "clamd.conf" ''
|
|
|
|
DatabaseDirectory ${stateDir}
|
|
|
|
LocalSocket ${runDir}/clamd.ctl
|
|
|
|
LogFile ${logDir}/clamav.log
|
|
|
|
PidFile ${runDir}/clamd.pid
|
|
|
|
User clamav
|
|
|
|
|
|
|
|
${cfg.daemon.extraConfig}
|
|
|
|
'';
|
2012-07-23 16:18:19 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.clamav = {
|
2015-12-12 13:45:48 +01:00
|
|
|
daemon = {
|
|
|
|
enable = mkEnableOption "clamd daemon";
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra configuration for clamd. Contents will be added verbatim to the
|
|
|
|
configuration file.
|
2015-12-12 13:06:14 +01:00
|
|
|
'';
|
|
|
|
};
|
2015-12-12 13:45:48 +01:00
|
|
|
};
|
|
|
|
updater = {
|
|
|
|
enable = mkEnableOption "freshclam updater";
|
2012-07-23 16:18:19 +02:00
|
|
|
|
2015-12-12 13:06:14 +01:00
|
|
|
frequency = mkOption {
|
|
|
|
default = 12;
|
|
|
|
description = ''
|
|
|
|
Number of database checks per day.
|
|
|
|
'';
|
|
|
|
};
|
2012-07-23 16:18:19 +02:00
|
|
|
|
2015-12-12 13:06:14 +01:00
|
|
|
config = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra configuration for freshclam. Contents will be added verbatim to the
|
|
|
|
configuration file.
|
|
|
|
'';
|
|
|
|
};
|
2012-07-23 16:18:19 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-12-12 13:45:48 +01:00
|
|
|
config = mkIf cfg.updater.enable or cfg.daemon.enable {
|
2012-07-23 16:18:19 +02:00
|
|
|
environment.systemPackages = [ pkgs.clamav ];
|
2015-12-12 13:45:48 +01:00
|
|
|
users.extraUsers = singleton {
|
|
|
|
name = clamavUser;
|
|
|
|
uid = config.ids.uids.clamav;
|
|
|
|
description = "ClamAV daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
2012-07-23 16:18:19 +02:00
|
|
|
|
2015-12-12 13:45:48 +01:00
|
|
|
users.extraGroups = singleton {
|
|
|
|
name = clamavGroup;
|
|
|
|
gid = config.ids.gids.clamav;
|
|
|
|
};
|
2012-07-23 16:18:19 +02:00
|
|
|
|
2015-12-12 13:45:48 +01:00
|
|
|
services.clamav.updater.config = mkIf cfg.updater.enable ''
|
2012-07-23 16:18:19 +02:00
|
|
|
DatabaseDirectory ${stateDir}
|
|
|
|
Foreground yes
|
|
|
|
Checks ${toString cfg.updater.frequency}
|
|
|
|
DatabaseMirror database.clamav.net
|
|
|
|
'';
|
|
|
|
|
2015-12-12 13:45:48 +01:00
|
|
|
systemd.services.clamd = mkIf cfg.daemon.enable {
|
|
|
|
description = "ClamAV daemon (clamd)";
|
|
|
|
path = [ pkgs.clamav ];
|
|
|
|
after = [ "network.target" "freshclam.service" ];
|
|
|
|
requires = [ "freshclam.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
preStart = ''
|
|
|
|
mkdir -m 0755 -p ${logDir}
|
|
|
|
mkdir -m 0755 -p ${runDir}
|
|
|
|
chown ${clamavUser}:${clamavGroup} ${logDir}
|
|
|
|
chown ${clamavUser}:${clamavGroup} ${runDir}
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.clamav}/bin/clamd --config-file=${clamdConfigFile}";
|
|
|
|
Type = "forking";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
|
|
|
StartLimitInterval = "1min";
|
|
|
|
};
|
2012-07-23 16:18:19 +02:00
|
|
|
};
|
|
|
|
|
2015-12-12 13:45:48 +01:00
|
|
|
systemd.services.freshclam = mkIf cfg.updater.enable {
|
|
|
|
description = "ClamAV updater (freshclam)";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.clamav ];
|
|
|
|
preStart = ''
|
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
|
|
chown ${clamavUser}:${clamavGroup} ${stateDir}
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.clamav}/bin/freshclam --daemon --config-file=${pkgs.writeText "freshclam.conf" cfg.updater.config}";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
|
|
|
StartLimitInterval = "1min";
|
|
|
|
};
|
|
|
|
};
|
2012-07-23 16:18:19 +02:00
|
|
|
};
|
2014-09-01 09:41:19 +02:00
|
|
|
}
|