diff --git a/nixos/modules/services/monitoring/glpi-agent.nix b/nixos/modules/services/monitoring/glpi-agent.nix new file mode 100644 index 00000000000000..157add3e540a10 --- /dev/null +++ b/nixos/modules/services/monitoring/glpi-agent.nix @@ -0,0 +1,69 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.glpiAgent; + + configFile = pkgs.writeText "agent.cfg" '' + # Server configuration + server = ${lib.concatStringsSep ", " cfg.servers} + + # Configuration + ${cfg.extraConfig} + ''; + +in +{ + options = { + services.glpiAgent = { + enable = lib.mkEnableOption "GLPI Agent"; + + package = lib.mkPackageOption pkgs "glpi-agent" { + }; + + servers = lib.mkOption { + type = lib.types.listOf lib.types.str; + example = [ "https://glpi.example.com/inventory" ]; + }; + + extraConfig = lib.mkOption { + type = lib.types.lines; + default = ""; + description = '' + Configuration options that will be written to the configuration file. + ''; + example = '' + delaytime = 3600 + timeout = 180 + tag = mytag + logger = stderr + ''; + }; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.services.glpi-agent = { + description = "GLPI Agent"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + serviceConfig = { + ExecStartPre = [ + "+${pkgs.coreutils}/bin/mkdir -p /var/lib/glpi-agent/var" + ]; + ExecStart = "${lib.getExe cfg.package} --conf-file ${configFile} --vardir /var/lib/glpi-agent/var --daemon --no-fork"; + DynamicUser = true; + Restart = "on-failure"; + StateDirectory = "glpi-agent"; + ConfigurationDirectory = "glpi-agent"; + RuntimeDirectory = "glpi-agent"; + WorkingDirectory = "/var/lib/glpi-agent"; + }; + }; + }; +}