Hi !
I am trying to configure telegraf to send a measurement to influxdb2 with the exec input. The exec.command must include the binary location, otherwise I get a binary not found in PATH error.
To get the path of a binary, I am trying to retrieve the derivation path of it. It is working great with ${pkgs.libraspberrypi}/bin/vcgencmd
for example.
I am stuck for few hours now, trying desperately to get the derivation path of the nixos-version binary (defined here?).
I am new to nix, and I don’t understand how I should import the derivation when it is not already accessible though a variable like pkgs
. I tried things like import
or calling callPackage
to mimic what is done with pkgs.* definition, but like everything nix related, if I don’t understand something it does not work ; and as much as it is tempting to just put /run/current-system/sw/bin/nixos-version
, I feel like it is not the right way of doing it.
Here is the full file
{
config,
pkgs,
...
}: {
services.telegraf = {
enable = true;
environmentFiles = [/run/secrets/services/telegraf/env];
extraConfig = {
inputs = {
cpu = {
percpu = true;
totalcpu = true;
collect_cpu_time = false;
report_active = false;
};
disk = {};
diskio = {};
mem = {};
net = {};
processes = {};
swap = {};
system = {};
temp = {
name_override = "temp_cpu";
};
exec = [
{
commands = ["${pkgs.libraspberrypi}/bin/vcgencmd measure_temp"];
name_override = "temp_gpu";
data_format = "grok";
grok_patterns = ["%{NUMBER:value:float}"];
}
{
commands = ["${???}/bin/nixos-version"];
name_override = "nixos_version";
}
];
};
outputs.influxdb_v2 = {
urls = ["myhost"];
token = "$INFLUX_TOKEN";
organization = "myorg";
bucket = "mybucket";
};
};
};
users.users.telegraf.extraGroups = ["video"];
sops.secrets."services/telegraf/env" = {
key = "services.telegraf.env";
owner = config.users.users.telegraf.name;
};
}
the interesting part being commands = ["${???}/bin/nixos-version"];
I hope I didn’t miss something too obvious, thanks in advance for the time you’ll spend helping me.
Alexis