nixos/telegraf: allow multiple env files
This commit is contained in:
parent
8edc4619ab
commit
7534d92648
@ -20,9 +20,9 @@ in {
|
|||||||
type = types.package;
|
type = types.package;
|
||||||
};
|
};
|
||||||
|
|
||||||
environmentFile = mkOption {
|
environmentFiles = mkOption {
|
||||||
type = types.nullOr types.path;
|
type = types.nullOr (types.listOf types.path);
|
||||||
default = null;
|
default = [];
|
||||||
example = "/run/keys/telegraf.env";
|
example = "/run/keys/telegraf.env";
|
||||||
description = ''
|
description = ''
|
||||||
File to load as environment file. Environment variables
|
File to load as environment file. Environment variables
|
||||||
@ -59,7 +59,7 @@ in {
|
|||||||
###### implementation
|
###### implementation
|
||||||
config = mkIf config.services.telegraf.enable {
|
config = mkIf config.services.telegraf.enable {
|
||||||
systemd.services.telegraf = let
|
systemd.services.telegraf = let
|
||||||
finalConfigFile = if config.services.telegraf.environmentFile == null
|
finalConfigFile = if config.services.telegraf.environmentFiles == []
|
||||||
then configFile
|
then configFile
|
||||||
else "/var/run/telegraf/config.toml";
|
else "/var/run/telegraf/config.toml";
|
||||||
in {
|
in {
|
||||||
@ -67,8 +67,8 @@ in {
|
|||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
EnvironmentFile = config.services.telegraf.environmentFile;
|
EnvironmentFile = config.services.telegraf.environmentFiles;
|
||||||
ExecStartPre = lib.optional (config.services.telegraf.environmentFile != null)
|
ExecStartPre = lib.optional (config.services.telegraf.environmentFiles != [])
|
||||||
(pkgs.writeShellScript "pre-start" ''
|
(pkgs.writeShellScript "pre-start" ''
|
||||||
umask 077
|
umask 077
|
||||||
${pkgs.envsubst}/bin/envsubst -i "${configFile}" > /var/run/telegraf/config.toml
|
${pkgs.envsubst}/bin/envsubst -i "${configFile}" > /var/run/telegraf/config.toml
|
||||||
|
@ -6,9 +6,9 @@ import ./make-test-python.nix ({ pkgs, ...} : {
|
|||||||
|
|
||||||
machine = { ... }: {
|
machine = { ... }: {
|
||||||
services.telegraf.enable = true;
|
services.telegraf.enable = true;
|
||||||
services.telegraf.environmentFile = pkgs.writeText "secrets" ''
|
services.telegraf.environmentFiles = [pkgs.writeText "secrets" ''
|
||||||
SECRET=example
|
SECRET=example
|
||||||
'';
|
''];
|
||||||
services.telegraf.extraConfig = {
|
services.telegraf.extraConfig = {
|
||||||
agent.interval = "1s";
|
agent.interval = "1s";
|
||||||
agent.flush_interval = "1s";
|
agent.flush_interval = "1s";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user