nixos/opentelemetry-collector: validate config (#392701)

This commit is contained in:
Sandro
2025-10-21 15:30:11 +00:00
committed by GitHub
2 changed files with 36 additions and 22 deletions
@@ -435,3 +435,5 @@
- The `open-webui` package's postgres support have been moved to optional dependencies to comply with upstream changes in 0.6.26.
- `prl-tools` has been moved out of `linuxPackages` because Parallels Guest Tools become driverless since 26.1.0.
- `services.opentelemetry-collector` has a new option `validateConfigFile` option that checks the configuration file during build. It is enabled by default if the configuration file is in the Nix store.
@@ -13,12 +13,27 @@ let
mkOption
types
getExe
isStorePath
literalMD
;
cfg = config.services.opentelemetry-collector;
opentelemetry-collector = cfg.package;
settingsFormat = pkgs.formats.yaml { };
generatedConf =
if cfg.configFile == null then
settingsFormat.generate "config.yaml" cfg.settings
else
cfg.configFile;
conf =
if cfg.validateConfigFile then
pkgs.runCommandLocal "config.yaml" { inherit generatedConf; } ''
cp $generatedConf $out
${getExe opentelemetry-collector} validate --config=file:$out
''
else
generatedConf;
in
{
options.services.opentelemetry-collector = {
@@ -43,6 +58,11 @@ in
Specify a path to a configuration file that Opentelemetry Collector should use.
'';
};
validateConfigFile = lib.mkEnableOption "Validate configuration file" // {
defaultText = literalMD "`true` if `configFile` is a store path";
default = isStorePath cfg.configFile;
};
};
config = mkIf cfg.enable {
@@ -61,28 +81,20 @@ in
description = "Opentelemetry Collector Service Daemon";
wantedBy = [ "multi-user.target" ];
serviceConfig =
let
conf =
if cfg.configFile == null then
settingsFormat.generate "config.yaml" cfg.settings
else
cfg.configFile;
in
{
ExecStart = "${getExe opentelemetry-collector} --config=file:${conf}";
DynamicUser = true;
Restart = "always";
ProtectSystem = "full";
DevicePolicy = "closed";
NoNewPrivileges = true;
WorkingDirectory = "%S/opentelemetry-collector";
StateDirectory = "opentelemetry-collector";
SupplementaryGroups = [
# allow to read the systemd journal for opentelemetry-collector
"systemd-journal"
];
};
serviceConfig = {
ExecStart = "${getExe opentelemetry-collector} --config=file:${conf}";
DynamicUser = true;
Restart = "always";
ProtectSystem = "full";
DevicePolicy = "closed";
NoNewPrivileges = true;
WorkingDirectory = "%S/opentelemetry-collector";
StateDirectory = "opentelemetry-collector";
SupplementaryGroups = [
# allow to read the systemd journal for opentelemetry-collector
"systemd-journal"
];
};
};
};
}