dotfiles/nixos/modules/telegraf.nix
magic_rb aff0158ef7
Reformat the whole flake using alejandra
Signed-off-by: magic_rb <magic_rb@redalder.org>
2024-03-02 22:17:03 +01:00

77 lines
1.9 KiB
Nix

{
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.services.telegraf-magic;
settingsFormat = pkgs.formats.toml {};
configFile = settingsFormat.generate "config.toml" cfg.settings;
in {
options = {
services.telegraf-magic = {
enable = mkEnableOption (lib.mdDoc "telegraf server");
package = mkOption {
default = pkgs.telegraf;
defaultText = literalExpression "pkgs.telegraf";
description = lib.mdDoc "Which telegraf derivation to use";
type = types.package;
};
settings = 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;
};
};
};
systemd = mkOption {
default = {};
description = lib.mdDoc "Applied to `systemd.services.telegraf`.";
type = types.unspecified;
};
};
};
config = mkIf cfg.enable {
systemd.services.telegraf = mkMerge [
(cfg.systemd)
{
description = "Telegraf Agent";
wantedBy = ["multi-user.target"];
after = ["network-online.target"];
serviceConfig = {
ExecStart = "${cfg.package}/bin/telegraf -config ${configFile}";
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 = {};
};
}