2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
2012-07-24 08:51:17 +01:00
|
|
|
let
|
|
|
|
fprotUser = "fprot";
|
|
|
|
stateDir = "/var/lib/fprot";
|
|
|
|
fprotGroup = fprotUser;
|
|
|
|
cfg = config.services.fprot;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.fprot = {
|
|
|
|
updater = {
|
2020-04-20 19:05:26 +01:00
|
|
|
enable = mkEnableOption "automatic F-Prot virus definitions database updates";
|
2014-04-08 23:17:16 +01:00
|
|
|
|
|
|
|
productData = mkOption {
|
|
|
|
description = ''
|
|
|
|
product.data file. Defaults to the one supplied with installation package.
|
|
|
|
'';
|
2021-01-26 20:04:20 +00:00
|
|
|
type = types.path;
|
2014-04-08 23:17:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
frequency = mkOption {
|
|
|
|
default = 30;
|
2021-01-26 20:04:20 +00:00
|
|
|
type = types.int;
|
2014-04-08 23:17:16 +01:00
|
|
|
description = ''
|
|
|
|
Update virus definitions every X minutes.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
licenseKeyfile = mkOption {
|
2021-01-26 20:04:20 +00:00
|
|
|
type = types.path;
|
2014-04-08 23:17:16 +01:00
|
|
|
description = ''
|
|
|
|
License keyfile. Defaults to the one supplied with installation package.
|
|
|
|
'';
|
|
|
|
};
|
2012-07-24 08:51:17 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.updater.enable {
|
2014-04-08 23:09:31 +01:00
|
|
|
|
2014-04-08 23:17:16 +01:00
|
|
|
services.fprot.updater.productData = mkDefault "${pkgs.fprot}/opt/f-prot/product.data";
|
|
|
|
services.fprot.updater.licenseKeyfile = mkDefault "${pkgs.fprot}/opt/f-prot/license.key";
|
2014-04-08 23:09:31 +01:00
|
|
|
|
2012-07-24 08:51:17 +01:00
|
|
|
environment.systemPackages = [ pkgs.fprot ];
|
2019-09-14 18:51:29 +01:00
|
|
|
environment.etc."f-prot.conf" = {
|
2012-07-24 08:51:17 +01:00
|
|
|
source = "${pkgs.fprot}/opt/f-prot/f-prot.conf";
|
|
|
|
};
|
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
users.users.${fprotUser} =
|
|
|
|
{ uid = config.ids.uids.fprot;
|
2012-07-24 08:51:17 +01:00
|
|
|
description = "F-Prot daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
users.groups.${fprotGroup} =
|
|
|
|
{ gid = config.ids.gids.fprot; };
|
2012-07-24 08:51:17 +01:00
|
|
|
|
|
|
|
services.cron.systemCronJobs = [ "*/${toString cfg.updater.frequency} * * * * root start fprot-updater" ];
|
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
systemd.services.fprot-updater = {
|
2016-01-06 06:50:18 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = false;
|
2014-04-08 23:17:16 +01:00
|
|
|
};
|
2016-01-06 06:50:18 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2012-07-24 08:51:17 +01:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
# have to copy fpupdate executable because it insists on storing the virus database in the same dir
|
|
|
|
preStart = ''
|
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
|
|
chown ${fprotUser}:${fprotGroup} ${stateDir}
|
|
|
|
cp ${pkgs.fprot}/opt/f-prot/fpupdate ${stateDir}
|
|
|
|
ln -sf ${cfg.updater.productData} ${stateDir}/product.data
|
|
|
|
'';
|
2012-07-24 08:51:17 +01:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
script = "/var/lib/fprot/fpupdate --keyfile ${cfg.updater.licenseKeyfile}";
|
|
|
|
};
|
|
|
|
};
|
2014-04-08 23:17:16 +01:00
|
|
|
}
|