From 8dda0d26b63e95126c733b36243081426d0e9bba Mon Sep 17 00:00:00 2001 From: liberodark Date: Wed, 4 Dec 2024 14:39:54 +0100 Subject: [PATCH] nixos/glpi-agent: init --- .../services/monitoring/glpi-agent.nix | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 nixos/modules/services/monitoring/glpi-agent.nix diff --git a/nixos/modules/services/monitoring/glpi-agent.nix b/nixos/modules/services/monitoring/glpi-agent.nix new file mode 100644 index 00000000000000..646599e6e594a1 --- /dev/null +++ b/nixos/modules/services/monitoring/glpi-agent.nix @@ -0,0 +1,106 @@ +{ + 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; + description = '' + The URLs of the GLPI servers to connect to. + ''; + 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 { + users.users.glpi-agent = { + description = "GLPI Agent user"; + isSystemUser = true; + group = "glpi-agent"; + home = "/var/lib/glpi-agent"; + }; + + users.groups.glpi-agent = { }; + + systemd.tmpfiles.settings."glpi-agent" = { + "/var/lib/glpi-agent".d = { + mode = "0755"; + user = "glpi-agent"; + group = "glpi-agent"; + }; + + "/var/lib/glpi-agent/var".d = { + mode = "0755"; + user = "glpi-agent"; + group = "glpi-agent"; + }; + + "/etc/glpi-agent".d = { + mode = "0755"; + user = "glpi-agent"; + group = "glpi-agent"; + }; + + "/etc/glpi-agent/agent.cfg".C = { + mode = "0644"; + user = "glpi-agent"; + group = "glpi-agent"; + argument = toString configFile; + }; + }; + + systemd.services.glpi-agent = { + description = "GLPI Agent"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + serviceConfig = { + ExecStart = "${lib.getExe cfg.package} --conf-file /etc/glpi-agent/agent.cfg --vardir /var/lib/glpi-agent/var --daemon --no-fork"; + User = "glpi-agent"; + Group = "glpi-agent"; + Restart = "on-failure"; + StateDirectory = "glpi-agent"; + ConfigurationDirectory = "glpi-agent"; + RuntimeDirectory = "glpi-agent"; + WorkingDirectory = "/var/lib/glpi-agent"; + }; + }; + }; +}