summary refs log tree commit diff
path: root/nixos/modules/services/security/fprot.nix
blob: 3a0b08b3c6d8398149ce96bd4ee648d11fdf03bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
{ config, lib, pkgs, ... }:
with lib;
let
  fprotUser = "fprot";
  stateDir = "/var/lib/fprot";
  fprotGroup = fprotUser;
  cfg = config.services.fprot;
in {
  options = {

    services.fprot = {
      updater = {
        enable = mkEnableOption "automatic F-Prot virus definitions database updates";

        productData = mkOption {
          description = ''
            product.data file. Defaults to the one supplied with installation package.
          '';
        };

        frequency = mkOption {
          default = 30;
          description = ''
            Update virus definitions every X minutes.
          '';
        };

        licenseKeyfile = mkOption {
          description = ''
            License keyfile. Defaults to the one supplied with installation package.
          '';
        };

      };
    };
  };

  ###### implementation

  config = mkIf cfg.updater.enable {

    services.fprot.updater.productData = mkDefault "${pkgs.fprot}/opt/f-prot/product.data";
    services.fprot.updater.licenseKeyfile = mkDefault "${pkgs.fprot}/opt/f-prot/license.key";

    environment.systemPackages = [ pkgs.fprot ];
    environment.etc."f-prot.conf" = {
      source = "${pkgs.fprot}/opt/f-prot/f-prot.conf";
    };

    users.users.${fprotUser} =
      { uid = config.ids.uids.fprot;
        description = "F-Prot daemon user";
        home = stateDir;
      };

    users.groups.${fprotGroup} =
      { gid = config.ids.gids.fprot; };

    services.cron.systemCronJobs = [ "*/${toString cfg.updater.frequency} * * * * root start fprot-updater" ];

    systemd.services.fprot-updater = {
      serviceConfig = {
        Type = "oneshot";
        RemainAfterExit = false;
      };
      wantedBy = [ "multi-user.target" ];

      # 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
      '';

      script = "/var/lib/fprot/fpupdate --keyfile ${cfg.updater.licenseKeyfile}";
    };
 };
}