mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-15 22:36:23 +01:00
6c5ab28fce
This was done by generating a truly hilarious configuration: rg 'services\.[^.]+\.enable\t' opts-tags | cut -f1 > allonconfig.nix The following were not tested due to other evaluation errors. They should probably be manually audited. services.amule services.castopod services.ceph services.chatgpt-retrieval-plugin services.clamsmtp services.clight services.dante services.dex services.discourse services.dwm-status services.engelsystem services.foundationdb services.frigate services.frp services.grocy services.guacamole-client services.hedgedoc services.home-assistant services.honk services.imaginary services.jitsi-meet services.kerberos_server services.limesurvey services.mastodon services.mediawiki services.mobilizon services.moodle services.mosquitto services.nextcloud services.nullmailer services.patroni services.pfix-srsd services.pgpkeyserver-lite services.postfixadmin services.roundcube services.schleuder services.self-deploy services.slskd services.spacecookie services.statsd services.step-ca services.sympa services.tsmBackup services.vdirsyncer services.vikunja services.yandex-disk services.zabbixWeb
91 lines
2.8 KiB
Nix
91 lines
2.8 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.services.telegraf;
|
|
|
|
settingsFormat = pkgs.formats.toml {};
|
|
configFile = settingsFormat.generate "config.toml" cfg.extraConfig;
|
|
in {
|
|
###### interface
|
|
options = {
|
|
services.telegraf = {
|
|
enable = mkEnableOption (lib.mdDoc "telegraf server");
|
|
|
|
package = mkPackageOption pkgs "telegraf" { };
|
|
|
|
environmentFiles = mkOption {
|
|
type = types.listOf types.path;
|
|
default = [];
|
|
example = [ "/run/keys/telegraf.env" ];
|
|
description = lib.mdDoc ''
|
|
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 = mkOption {
|
|
default = {};
|
|
description = lib.mdDoc "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 = 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;
|
|
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 = {};
|
|
};
|
|
}
|