1 { config, lib, pkgs, ... }:
4 cfg = config.services.ocsinventory-agent;
6 settingsFormat = pkgs.formats.keyValue {
7 mkKeyValue = lib.generators.mkKeyValueDefault { } "=";
13 doc = ./ocsinventory-agent.md;
14 maintainers = with lib.maintainers; [ anthonyroussel ];
18 services.ocsinventory-agent = {
19 enable = lib.mkEnableOption "OCS Inventory Agent";
21 package = lib.mkPackageOption pkgs "ocsinventory-agent" { };
23 settings = lib.mkOption {
24 type = lib.types.submodule {
25 freeformType = settingsFormat.type.nestedTypes.elemType;
28 server = lib.mkOption {
29 type = lib.types.nullOr lib.types.str;
30 example = "https://ocsinventory.localhost:8080/ocsinventory";
33 The URI of the OCS Inventory server where to send the inventory file.
35 This option is ignored if {option}`services.ocsinventory-agent.settings.local` is set.
39 local = lib.mkOption {
40 type = lib.types.nullOr lib.types.path;
41 example = "/var/lib/ocsinventory-agent/reports";
44 If specified, the OCS Inventory Agent will run in offline mode
45 and the resulting inventory file will be stored in the specified path.
50 type = lib.types.path;
51 default = "/etc/ssl/certs/ca-certificates.crt";
53 Path to CA certificates file in PEM format, for server
54 SSL certificate validation.
59 type = lib.types.nullOr lib.types.str;
61 example = "01234567890123";
62 description = "Tag for the generated inventory.";
65 debug = lib.mkEnableOption "debug mode";
70 ca = "/etc/ssl/certs/ca-certificates.crt";
72 server = "https://ocsinventory.localhost:8080/ocsinventory";
73 tag = "01234567890123";
76 Configuration for /etc/ocsinventory-agent/ocsinventory-agent.cfg.
79 {manpage}`ocsinventory-agent(1)` for available options.
83 interval = lib.mkOption {
88 How often we run the ocsinventory-agent service. Runs by default every daily.
90 The format is described in
91 {manpage}`systemd.time(7)`.
99 configFile = settingsFormat.generate "ocsinventory-agent.cfg" cfg.settings;
101 in lib.mkIf cfg.enable {
102 # Path of the configuration file is hard-coded and cannot be changed
103 # https://github.com/OCSInventory-NG/UnixAgent/blob/v2.10.0/lib/Ocsinventory/Agent/Config.pm#L78
105 environment.etc."ocsinventory-agent/ocsinventory-agent.cfg".source = configFile;
107 systemd.services.ocsinventory-agent = {
108 description = "OCS Inventory Agent service";
109 wantedBy = [ "multi-user.target" ];
110 after = [ "network.target" ];
112 reloadTriggers = [ configFile ];
115 ExecStart = lib.getExe cfg.package;
116 ConfigurationDirectory = "ocsinventory-agent";
117 StateDirectory = "ocsinventory-agent";
121 systemd.timers.ocsinventory-agent = {
122 description = "Launch OCS Inventory Agent regularly";
123 wantedBy = [ "timers.target" ];
126 OnCalendar = cfg.interval;
128 RandomizedDelaySec = 240;
130 Unit = "ocsinventory-agent.service";