mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-04 12:03:21 +00:00
4f0dadbf38
After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-builda08b3a4d19
.tar.gz \ --argstr baseRevb32a094368
result/bin/apply-formatting $NIXPKGS_PATH
101 lines
3.0 KiB
Nix
101 lines
3.0 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.services.telegraf;
|
|
|
|
settingsFormat = pkgs.formats.toml { };
|
|
configFile = settingsFormat.generate "config.toml" cfg.extraConfig;
|
|
in
|
|
{
|
|
###### interface
|
|
options = {
|
|
services.telegraf = {
|
|
enable = lib.mkEnableOption "telegraf server";
|
|
|
|
package = lib.mkPackageOption pkgs "telegraf" { };
|
|
|
|
environmentFiles = lib.mkOption {
|
|
type = lib.types.listOf lib.types.path;
|
|
default = [ ];
|
|
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: `$ENVIRONMENT` or `''${VARIABLE}`.
|
|
This is useful to avoid putting secrets into the nix store.
|
|
'';
|
|
};
|
|
|
|
extraConfig = lib.mkOption {
|
|
default = { };
|
|
description = "Extra configuration options for telegraf";
|
|
type = settingsFormat.type;
|
|
example = {
|
|
outputs.influxdb = {
|
|
urls = [ "http://localhost:8086" ];
|
|
database = "telegraf";
|
|
};
|
|
inputs.statsd = {
|
|
service_address = ":8125";
|
|
delete_timings = true;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
###### implementation
|
|
config = lib.mkIf config.services.telegraf.enable {
|
|
services.telegraf.extraConfig = {
|
|
inputs = { };
|
|
outputs = { };
|
|
};
|
|
systemd.services.telegraf =
|
|
let
|
|
finalConfigFile =
|
|
if config.services.telegraf.environmentFiles == [ ] then
|
|
configFile
|
|
else
|
|
"/var/run/telegraf/config.toml";
|
|
in
|
|
{
|
|
description = "Telegraf Agent";
|
|
wantedBy = [ "multi-user.target" ];
|
|
wants = [ "network-online.target" ];
|
|
after = [ "network-online.target" ];
|
|
path =
|
|
lib.optional (config.services.telegraf.extraConfig.inputs ? procstat) pkgs.procps
|
|
++ lib.optional (config.services.telegraf.extraConfig.inputs ? ping) pkgs.iputils;
|
|
serviceConfig = {
|
|
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
|
|
''
|
|
);
|
|
ExecStart = "${cfg.package}/bin/telegraf -config ${finalConfigFile}";
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
RuntimeDirectory = "telegraf";
|
|
User = "telegraf";
|
|
Group = "telegraf";
|
|
Restart = "on-failure";
|
|
# for ping probes
|
|
AmbientCapabilities = [ "CAP_NET_RAW" ];
|
|
};
|
|
};
|
|
|
|
users.users.telegraf = {
|
|
uid = config.ids.uids.telegraf;
|
|
group = "telegraf";
|
|
description = "telegraf daemon user";
|
|
};
|
|
|
|
users.groups.telegraf = { };
|
|
};
|
|
}
|