nixos/telegraf: allow multiple env files

This commit is contained in:
Jörg Thalheim 2020-11-12 13:49:00 +01:00
parent 8edc4619ab
commit 7534d92648
No known key found for this signature in database
GPG key ID: 003F2096411B5F92
2 changed files with 8 additions and 8 deletions

View file

@ -20,9 +20,9 @@ in {
type = types.package;
};
environmentFile = mkOption {
type = types.nullOr types.path;
default = null;
environmentFiles = mkOption {
type = types.nullOr (types.listOf types.path);
default = [];
example = "/run/keys/telegraf.env";
description = ''
File to load as environment file. Environment variables
@ -59,7 +59,7 @@ in {
###### implementation
config = mkIf config.services.telegraf.enable {
systemd.services.telegraf = let
finalConfigFile = if config.services.telegraf.environmentFile == null
finalConfigFile = if config.services.telegraf.environmentFiles == []
then configFile
else "/var/run/telegraf/config.toml";
in {
@ -67,8 +67,8 @@ in {
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
serviceConfig = {
EnvironmentFile = config.services.telegraf.environmentFile;
ExecStartPre = lib.optional (config.services.telegraf.environmentFile != null)
EnvironmentFile = config.services.telegraf.environmentFiles;
ExecStartPre = lib.optional (config.services.telegraf.environmentFiles != [])
(pkgs.writeShellScript "pre-start" ''
umask 077
${pkgs.envsubst}/bin/envsubst -i "${configFile}" > /var/run/telegraf/config.toml

View file

@ -6,9 +6,9 @@ import ./make-test-python.nix ({ pkgs, ...} : {
machine = { ... }: {
services.telegraf.enable = true;
services.telegraf.environmentFile = pkgs.writeText "secrets" ''
services.telegraf.environmentFiles = [pkgs.writeText "secrets" ''
SECRET=example
'';
''];
services.telegraf.extraConfig = {
agent.interval = "1s";
agent.flush_interval = "1s";