Merge pull request #317488 from asbish/master

nixos/prometheus-snmp-exporter: add environmentFile option
This commit is contained in:
Sandro
2024-07-14 16:17:05 +02:00
committed by GitHub
@@ -81,6 +81,33 @@ in
Only log messages with the given severity or above.
'';
};
environmentFile = mkOption {
type = types.nullOr types.path;
default = null;
example = "/root/prometheus-snmp-exporter.env";
description = ''
EnvironmentFile as defined in {manpage}`systemd.exec(5)`.
Secrets may be passed to the service without adding them to the
world-readable Nix store, by specifying placeholder variables as
the option value in Nix and setting these variables accordingly in the
environment file.
Environment variables from this file will be interpolated into the
config file using envsubst with this syntax:
`$ENVIRONMENT ''${VARIABLE}`
For variables to use see [Prometheus Configuration](https://github.com/prometheus/snmp_exporter#prometheus-configuration).
If the file path is set to this option, the parameter
`--config.expand-environment-variables` is implicitly added to
`ExecStart`.
Note that this file needs to be available on the host on which
this exporter is running.
'';
};
};
serviceOpts = let
uncheckedConfigFile = if cfg.configurationPath != null
@@ -92,9 +119,12 @@ in
uncheckedConfigFile;
in {
serviceConfig = {
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) [ cfg.environmentFile ];
ExecStart = ''
${pkgs.prometheus-snmp-exporter}/bin/snmp_exporter \
--config.file=${escapeShellArg configFile} \
${lib.optionalString (cfg.environmentFile != null)
"--config.expand-environment-variables"} \
--log.format=${escapeShellArg cfg.logFormat} \
--log.level=${cfg.logLevel} \
--web.listen-address=${cfg.listenAddress}:${toString cfg.port} \