From 239d802869a30bb45d4403e8f63a57a61f6910d9 Mon Sep 17 00:00:00 2001 From: Rohit Singh Date: Thu, 3 Oct 2024 23:42:10 +0530 Subject: [PATCH] netdata: add netdata service in nix-darwin. --- modules/module-list.nix | 1 + modules/services/monitoring/netdata.nix | 55 +++++++++++++++++++++++++ release.nix | 1 + tests/services-netdata.nix | 19 +++++++++ 4 files changed, 76 insertions(+) create mode 100644 modules/services/monitoring/netdata.nix create mode 100644 tests/services-netdata.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 0b62158a..c7099642 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -69,6 +69,7 @@ ./services/mail/offlineimap.nix ./services/mopidy.nix ./services/monitoring/telegraf.nix + ./services/monitoring/netdata.nix ./services/netbird.nix ./services/nix-daemon.nix ./services/nix-gc diff --git a/modules/services/monitoring/netdata.nix b/modules/services/monitoring/netdata.nix new file mode 100644 index 00000000..da0809c9 --- /dev/null +++ b/modules/services/monitoring/netdata.nix @@ -0,0 +1,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} + ''; + }; +} diff --git a/release.nix b/release.nix index 648e9a24..39a5b477 100644 --- a/release.nix +++ b/release.nix @@ -128,6 +128,7 @@ let tests.services-nix-gc = makeTest ./tests/services-nix-gc.nix; tests.services-nix-optimise = makeTest ./tests/services-nix-optimise.nix; tests.services-nextdns = makeTest ./tests/services-nextdns.nix; + tests.services-netdata = makeTest ./tests/services-netdata.nix; tests.services-ofborg = makeTest ./tests/services-ofborg.nix; tests.services-offlineimap = makeTest ./tests/services-offlineimap.nix; tests.services-privoxy = makeTest ./tests/services-privoxy.nix; diff --git a/tests/services-netdata.nix b/tests/services-netdata.nix new file mode 100644 index 00000000..6759677d --- /dev/null +++ b/tests/services-netdata.nix @@ -0,0 +1,19 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + netdata = pkgs.runCommand "netdata-0.0.0" {} "mkdir $out"; +in +{ + services.netdata = { + enable = true; + package = netdata; + }; + + test = '' + echo >&2 "checking netdata service in launchd daemons" + grep "netdata" ${config.out}/Library/LaunchDaemons/netdata.plist + grep "${netdata}/bin/netdata" ${config.out}/Library/LaunchDaemons/netdata.plist + ''; +}