nixos/telegraf: add environmentFile option
This commit is contained in:
parent
9750813b89
commit
157d7354d6
|
@ -26,6 +26,19 @@ in {
|
||||||
type = types.package;
|
type = types.package;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
environmentFile = mkOption {
|
||||||
|
type = types.nullOr types.path;
|
||||||
|
default = null;
|
||||||
|
example = "/run/keys/telegraf.env";
|
||||||
|
description = ''
|
||||||
|
File to load as environment file. Environment variables
|
||||||
|
from this file will be interpolated into the config file
|
||||||
|
using envsubst with this syntax:
|
||||||
|
<literal>$ENVIRONMENT ''${VARIABLE}</literal>
|
||||||
|
This is useful to avoid putting secrets into the nix store.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
extraConfig = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
description = "Extra configuration options for telegraf";
|
description = "Extra configuration options for telegraf";
|
||||||
|
@ -51,15 +64,23 @@ in {
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
config = mkIf config.services.telegraf.enable {
|
config = mkIf config.services.telegraf.enable {
|
||||||
systemd.services.telegraf = {
|
systemd.services.telegraf = let
|
||||||
|
finalConfigFile = if config.services.telegraf.environmentFile == null
|
||||||
|
then configFile
|
||||||
|
else "/tmp/config.toml";
|
||||||
|
in {
|
||||||
description = "Telegraf Agent";
|
description = "Telegraf Agent";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart=''${cfg.package}/bin/telegraf -config "${configFile}"'';
|
EnvironmentFile = config.services.telegraf.environmentFile;
|
||||||
|
ExecStartPre = lib.optional (config.services.telegraf.environmentFile != null)
|
||||||
|
''${pkgs.envsubst}/bin/envsubst -o /tmp/config.toml -i "${configFile}"'';
|
||||||
|
ExecStart=''${cfg.package}/bin/telegraf -config ${finalConfigFile}'';
|
||||||
ExecReload="${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
ExecReload="${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||||
User = "telegraf";
|
User = "telegraf";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
|
PrivateTmp = true;
|
||||||
# for ping probes
|
# for ping probes
|
||||||
AmbientCapabilities = [ "CAP_NET_RAW" ];
|
AmbientCapabilities = [ "CAP_NET_RAW" ];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue