aboutsummaryrefslogtreecommitdiff
path: root/modules/vanta-daemon/module.nix
blob: 251ac0da96f5f8d549e53c7a8a98d62b0209ab48 (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
{ config, pkgs, lib, ... }:
with lib;

let
  cfg = config.services.vanta;
in
{
  options.services.vanta = {
    enable = mkOption {
      type = types.bool;
      default = false;
      description = '' Vanta daemon service  '';
    };

    agentKey = mkOption {
      type = types.str;
    };

    email = mkOption {
      type = types.str;
    };
  };

  config = mkIf cfg.enable (
    let
      vanta = pkgs.callPackage ./default.nix {};
    in
      {
        environment.systemPackages = [ vanta ];

        systemd.services.vanta =
          {
            after = [ "network.service" "syslog.service" ];
            description = "Vanta monitoring software";
            wantedBy = [ "multi-user.target" ];
            preStart = ''
              cp -a ${vanta}/var/vanta /var
              sed \
                -e 's/\("AGENT_KEY": "\)"/\1${cfg.agentKey}"/1' \
                -e 's/\("OWNER_EMAIL": "\)"/\1${cfg.email}"/' \
                ${vanta}/etc/vanta.conf > /etc/vanta.conf
            '';
            script = ''
              /var/vanta/metalauncher
            '';

            serviceConfig = {
              TimeoutStartSec = 0;
              Restart = "on-failure";
              KillMode = "control-group";
              KillSignal = "SIGTERM";
            };
          };
      }
  );
}