1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-20 16:39:31 +03:00
nixpkgs/nixos/modules/services/monitoring/ocsinventory-agent.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

140 lines
4 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.ocsinventory-agent;
settingsFormat = pkgs.formats.keyValue {
mkKeyValue = lib.generators.mkKeyValueDefault { } "=";
};
in
{
meta = {
doc = ./ocsinventory-agent.md;
maintainers = with lib.maintainers; [ anthonyroussel ];
};
options = {
services.ocsinventory-agent = {
enable = lib.mkEnableOption "OCS Inventory Agent";
package = lib.mkPackageOption pkgs "ocsinventory-agent" { };
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type.nestedTypes.elemType;
options = {
server = lib.mkOption {
type = lib.types.nullOr lib.types.str;
example = "https://ocsinventory.localhost:8080/ocsinventory";
default = null;
description = ''
The URI of the OCS Inventory server where to send the inventory file.
This option is ignored if {option}`services.ocsinventory-agent.settings.local` is set.
'';
};
local = lib.mkOption {
type = lib.types.nullOr lib.types.path;
example = "/var/lib/ocsinventory-agent/reports";
default = null;
description = ''
If specified, the OCS Inventory Agent will run in offline mode
and the resulting inventory file will be stored in the specified path.
'';
};
ca = lib.mkOption {
type = lib.types.path;
default = "/etc/ssl/certs/ca-certificates.crt";
description = ''
Path to CA certificates file in PEM format, for server
SSL certificate validation.
'';
};
tag = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "01234567890123";
description = "Tag for the generated inventory.";
};
debug = lib.mkEnableOption "debug mode";
};
};
default = { };
example = {
ca = "/etc/ssl/certs/ca-certificates.crt";
debug = true;
server = "https://ocsinventory.localhost:8080/ocsinventory";
tag = "01234567890123";
};
description = ''
Configuration for /etc/ocsinventory-agent/ocsinventory-agent.cfg.
Refer to
{manpage}`ocsinventory-agent(1)` for available options.
'';
};
interval = lib.mkOption {
type = lib.types.str;
default = "daily";
example = "06:00";
description = ''
How often we run the ocsinventory-agent service. Runs by default every daily.
The format is described in
{manpage}`systemd.time(7)`.
'';
};
};
};
config =
let
configFile = settingsFormat.generate "ocsinventory-agent.cfg" cfg.settings;
in
lib.mkIf cfg.enable {
# Path of the configuration file is hard-coded and cannot be changed
# https://github.com/OCSInventory-NG/UnixAgent/blob/v2.10.0/lib/Ocsinventory/Agent/Config.pm#L78
#
environment.etc."ocsinventory-agent/ocsinventory-agent.cfg".source = configFile;
systemd.services.ocsinventory-agent = {
description = "OCS Inventory Agent service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
reloadTriggers = [ configFile ];
serviceConfig = {
ExecStart = lib.getExe cfg.package;
ConfigurationDirectory = "ocsinventory-agent";
StateDirectory = "ocsinventory-agent";
};
};
systemd.timers.ocsinventory-agent = {
description = "Launch OCS Inventory Agent regularly";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = cfg.interval;
AccuracySec = "1h";
RandomizedDelaySec = 240;
Persistent = true;
Unit = "ocsinventory-agent.service";
};
};
};
}