summaryrefslogtreecommitdiff
path: root/modules/services/monitoring/netdata.nix
blob: da0809c992741fbfd3c283619717ddefe626ff3b (plain)
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
{ config, lib, pkgs, ... }:
with lib;
let
  cfg = config.services.netdata;

in {
  meta.maintainers = [ lib.maintainers.rsrohitsingh682 or "rsrohitsingh682" ];

  options = {
    services.netdata = {
      enable = mkEnableOption "Netdata daemon";

      package = lib.mkPackageOption pkgs "netdata" {};

      config = mkOption {
        type = types.lines;
        default = "";
        description = "Custom configuration for Netdata";
      };

      workDir = mkOption {
        type = types.path;
        default = "/var/lib/netdata";
        description = "Working directory for Netdata";
      };

      logDir = mkOption {
        type = types.path;
        default = "/var/log/netdata";
        description = "Log directory for Netdata";
      };
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [ cfg.package ];

    launchd.daemons.netdata = {
      serviceConfig = {
        Label = "netdata";
        KeepAlive = true;
        WorkingDirectory = cfg.workDir;
        StandardErrorPath = "${cfg.logDir}/netdata.log";
        StandardOutPath = "${cfg.logDir}/netdata.log";
      };
      command = lib.getExe cfg.package;
    };

    environment.etc."netdata/netdata.conf".text = cfg.config;

    system.activationScripts.preActivation.text = ''
      mkdir -p ${cfg.workDir}
    '';
  };
}