1 { config, lib, pkgs, ... }:
4 inherit (lib) mkEnableOption mkPackageOption mkIf mkOption types getExe;
6 cfg = config.services.opentelemetry-collector;
7 opentelemetry-collector = cfg.package;
9 settingsFormat = pkgs.formats.yaml { };
12 options.services.opentelemetry-collector = {
13 enable = mkEnableOption "Opentelemetry Collector";
15 package = mkPackageOption pkgs "opentelemetry-collector" { };
18 type = settingsFormat.type;
21 Specify the configuration for Opentelemetry Collector in Nix.
23 See https://opentelemetry.io/docs/collector/configuration/ for available options.
27 configFile = mkOption {
28 type = types.nullOr types.path;
31 Specify a path to a configuration file that Opentelemetry Collector should use.
36 config = mkIf cfg.enable {
39 (cfg.settings == { }) != (cfg.configFile == null)
42 Please specify a configuration for Opentelemetry Collector with either
43 'services.opentelemetry-collector.settings' or
44 'services.opentelemetry-collector.configFile'.
48 systemd.services.opentelemetry-collector = {
49 description = "Opentelemetry Collector Service Daemon";
50 wantedBy = [ "multi-user.target" ];
55 if cfg.configFile == null
56 then settingsFormat.generate "config.yaml" cfg.settings
60 ExecStart = "${getExe opentelemetry-collector} --config=file:${conf}";
63 ProtectSystem = "full";
64 DevicePolicy = "closed";
65 NoNewPrivileges = true;
66 WorkingDirectory = "%S/opentelemetry-collector";
67 StateDirectory = "opentelemetry-collector";
68 SupplementaryGroups = [
69 # allow to read the systemd journal for opentelemetry-collector