1 { config, lib, pkgs, options, ... }:
4 cfg = config.services.prometheus.exporters.rtl_433;
10 mkMatcherOptionType = field: description: with lib.types;
15 description = "Name to match.";
17 "${field}" = lib.mkOption {
19 description = description;
21 location = lib.mkOption {
23 description = "Location to match.";
29 rtl433Flags = lib.mkOption {
32 example = "-C si -R 19";
34 Flags passed verbatim to rtl_433 binary.
35 Having `-C si` (the default) is recommended since only Celsius temperatures are parsed.
38 channels = lib.mkOption {
39 type = mkMatcherOptionType "channel" "Channel to match.";
42 { name = "Acurite"; channel = 6543; location = "Kitchen"; }
45 List of channel matchers to export.
49 type = mkMatcherOptionType "id" "ID to match.";
52 { name = "Nexus"; id = 1; location = "Bedroom"; }
55 List of ID matchers to export.
62 # rtl-sdr udev rules make supported USB devices +rw by plugdev.
63 SupplementaryGroups = "plugdev";
64 # rtl_433 needs rw access to the USB radio.
65 PrivateDevices = lib.mkForce false;
66 DeviceAllow = lib.mkForce "char-usb_device rw";
67 RestrictAddressFamilies = [ "AF_NETLINK" ];
71 "--channel_matcher '${m.name},${toString m.channel},${m.location}'"
72 ) cfg.channels) ++ (map (m:
73 "--id_matcher '${m.name},${toString m.id},${m.location}'"
75 ${pkgs.prometheus-rtl_433-exporter}/bin/rtl_433_prometheus \
76 -listen ${cfg.listenAddress}:${toString cfg.port} \
77 -subprocess "${pkgs.rtl_433}/bin/rtl_433 -F json ${cfg.rtl433Flags}" \
78 ${lib.concatStringsSep " \\\n " matchers} \
79 ${lib.concatStringsSep " \\\n " cfg.extraFlags}