Skip to content

Commit

Permalink
nixos/glpi-agent: init
Browse files Browse the repository at this point in the history
  • Loading branch information
liberodark committed Dec 13, 2024
1 parent 61aa4ba commit 9a03b8d
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions nixos/modules/services/monitoring/glpi-agent.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
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" {
default = [ "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
# etc...
'';
};
};
};

config = lib.mkIf cfg.enable {
# User and group
users.users.glpi-agent = {
description = "GLPI Agent user";
isSystemUser = true;
group = "glpi-agent";
home = "/var/lib/glpi-agent";
createHome = true;
};

users.groups.glpi-agent = { };

# Create directories and manage configuration file
systemd.tmpfiles = {
settings = {
"glpi-agent-var" = {
d = {
"/var/lib/glpi-agent" = {
mode = "0755";
user = "glpi-agent";
group = "glpi-agent";
};
"/var/lib/glpi-agent/var" = {
mode = "0755";
user = "glpi-agent";
group = "glpi-agent";
};
"/etc/glpi-agent" = {
mode = "0755";
user = "glpi-agent";
group = "glpi-agent";
};
};
C = {
"/etc/glpi-agent/agent.cfg" = {
mode = "0644";
user = "glpi-agent";
group = "glpi-agent";
argument = "${configFile}";
};
};
};
};
};

# Service
systemd.services.glpi-agent = {
description = "GLPI Agent";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];

serviceConfig = {
ExecStart = "${cfg.package}/bin/glpi-agent --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";
RestartSec = "60s";
StateDirectory = "glpi-agent";
ConfigurationDirectory = "glpi-agent";
RuntimeDirectory = "glpi-agent";
WorkingDirectory = "/var/lib/glpi-agent";
};
};
};
}

0 comments on commit 9a03b8d

Please sign in to comment.