nix-config/modules/pi-sensors.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.0 KiB
Nix
Raw Normal View History

2021-09-29 21:58:29 +02:00
{ pkgs, config, lib, ... }:
2022-06-12 17:26:32 +02:00
2021-09-29 21:58:29 +02:00
{
options.c3d2.pi-sensors = lib.mkOption {
default = [];
2021-10-31 19:00:03 +01:00
type = with lib.types; listOf (submodule (_: {
2021-09-29 21:58:29 +02:00
options = {
type = lib.mkOption {
description = "Sensor type";
type = enum ["dht22"];
};
pin = lib.mkOption {
description = "GPIO pin";
type = int;
};
location = lib.mkOption {
description = "Sensor location";
type = str;
};
};
}));
};
config = lib.mkIf (config.c3d2.pi-sensors != []) {
# GPIO requires access to /dev/mem
security.wrappers.pi-sensors = {
setuid = true;
owner = "root";
group = "root";
source = "${pkgs.pi-sensors}/bin/pi-sensors";
};
services.collectd.plugins.exec = ''
Exec "${config.services.collectd.user}" "/run/wrappers/bin/pi-sensors" "2"${lib.concatMapStrings (s: " \"${s}\"") (
2021-09-29 21:58:29 +02:00
lib.concatMap ({ type, pin, location }:
[ type (toString pin) location ]
) config.c3d2.pi-sensors
)}
'';
};
}