at 21.11-pre 1.5 kB view raw
1{ config, lib, pkgs, options }: 2 3with lib; 4 5let 6 cfg = config.services.prometheus.exporters.py-air-control; 7 8 workingDir = "/var/lib/${cfg.stateDir}"; 9 10in 11{ 12 port = 9896; 13 extraOpts = { 14 deviceHostname = mkOption { 15 type = types.str; 16 example = "192.168.1.123"; 17 description = '' 18 The hostname of the air purification device from which to scrape the metrics. 19 ''; 20 }; 21 protocol = mkOption { 22 type = types.str; 23 default = "http"; 24 description = '' 25 The protocol to use when communicating with the air purification device. 26 Available: [http, coap, plain_coap] 27 ''; 28 }; 29 stateDir = mkOption { 30 type = types.str; 31 default = "prometheus-py-air-control-exporter"; 32 description = '' 33 Directory below <literal>/var/lib</literal> to store runtime data. 34 This directory will be created automatically using systemd's StateDirectory mechanism. 35 ''; 36 }; 37 }; 38 serviceOpts = { 39 serviceConfig = { 40 DynamicUser = false; 41 StateDirectory = cfg.stateDir; 42 WorkingDirectory = workingDir; 43 ExecStart = '' 44 ${pkgs.python3Packages.py-air-control-exporter}/bin/py-air-control-exporter \ 45 --host ${cfg.deviceHostname} \ 46 --protocol ${cfg.protocol} \ 47 --listen-port ${toString cfg.port} \ 48 --listen-address ${cfg.listenAddress} 49 ''; 50 Environment = [ "HOME=${workingDir}" ]; 51 }; 52 }; 53}