1{ config, lib, pkgs, options }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.exporters.nut;
7in
8{
9 port = 9199;
10 extraOpts = {
11 nutServer = mkOption {
12 type = types.str;
13 default = "127.0.0.1";
14 description = lib.mdDoc ''
15 Hostname or address of the NUT server
16 '';
17 };
18 nutUser = mkOption {
19 type = types.str;
20 default = "";
21 example = "nut";
22 description = lib.mdDoc ''
23 The user to log in into NUT server. If set, passwordPath should
24 also be set.
25
26 Default NUT configs usually permit reading variables without
27 authentication.
28 '';
29 };
30 passwordPath = mkOption {
31 type = types.nullOr types.path;
32 default = null;
33 apply = final: if final == null then null else toString final;
34 description = lib.mdDoc ''
35 A run-time path to the nutUser password file, which should be
36 provisioned outside of Nix store.
37 '';
38 };
39 };
40 serviceOpts = {
41 script = ''
42 ${optionalString (cfg.passwordPath != null)
43 "export NUT_EXPORTER_PASSWORD=$(cat ${toString cfg.passwordPath})"}
44 ${pkgs.prometheus-nut-exporter}/bin/nut_exporter \
45 --nut.server=${cfg.nutServer} \
46 --web.listen-address="${cfg.listenAddress}:${toString cfg.port}" \
47 ${optionalString (cfg.nutUser != "") "--nut.username=${cfg.nutUser}"}
48 '';
49 };
50}