Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/glpi-agent: init #361759

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@
./services/monitoring/fusion-inventory.nix
./services/monitoring/gatus.nix
./services/monitoring/glances.nix
./services/monitoring/glpi-agent.nix
./services/monitoring/goss.nix
./services/monitoring/grafana-agent.nix
./services/monitoring/grafana-image-renderer.nix
Expand Down
86 changes: 86 additions & 0 deletions nixos/modules/services/monitoring/glpi-agent.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
config,
lib,
pkgs,
...
}:

let
cfg = config.services.glpiAgent;

settingsType =
with lib.types;
attrsOf (oneOf [
bool
int
str
(listOf str)
]);

formatValue =
v:
if lib.isBool v then
if v then "1" else "0"
else if lib.isList v then
lib.concatStringsSep "," v
else
toString v;

configContent = lib.concatStringsSep "\n" (
lib.mapAttrsToList (k: v: "${k} = ${formatValue v}") cfg.settings
);

configFile = pkgs.writeText "agent.cfg" configContent;

in
{
options = {
services.glpiAgent = {
enable = lib.mkEnableOption "GLPI Agent";

package = lib.mkPackageOption pkgs "glpi-agent" { };

settings = lib.mkOption {
type = settingsType;
Comment on lines +43 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we go RFC42-style freeformType here ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it doesn't support arbitrary nesting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do wonder if there's a way to reuse one of the existing writers for this though.

Copy link
Contributor Author

@liberodark liberodark Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settingsType seems more relevant to me compared to GLPI but I could be wrong.
https://glpi-agent.readthedocs.io/en/latest/configuration.html#parameter-syntax


services.glpiAgent = {
    enable = true;
    settings = {
      server = [ "https://server.com" ];
      delaytime = 3600;
      lazy = false;
      "scan-homedirs" = false;
      "scan-profiles" = false;
      html = false;
      "backend-collect-timeout" = 30;
      force = true;
      "no-p2p" = false;
      tasks = [ "inventory" ];
      user = "USER";
      password = "PWD";
      timeout = 180;
      "no-httpd" = true;
      logger = [ "stderr" ];
      logfacility = "LOG_USER";
      color = false;
      debug = 0;
    };
  };

default = { };
description = ''
GLPI Agent configuration options.
See https://glpi-agent.readthedocs.io/en/latest/configuration.html for all available options.

The 'server' option is mandatory and must point to your GLPI server.
'';
example = lib.literalExpression ''
{
server = [ "https://glpi.example.com/inventory" ];
delaytime = 3600;
tag = "production";
logger = [ "stderr" "file" ];
debug = 1;
"no-category" = [ "printer" "software" ];
}
'';
};
};
};

config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.settings ? server;
message = "GLPI Agent requires a server to be configured in settings.server";
}
];

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

serviceConfig = {
ExecStart = "${lib.getExe cfg.package} --conf-file ${configFile} --vardir /var/lib/glpi-agent --daemon --no-fork";
Restart = "on-failure";
StateDirectory = "glpi-agent";
};
};
};
}