1{
2 config,
3 lib,
4 pkgs,
5 options,
6 ...
7}:
8
9let
10 cfg = config.services.prometheus.exporters.pihole;
11 inherit (lib)
12 mkOption
13 types
14 mkRemovedOptionModule
15 optionalString
16 ;
17in
18{
19 imports = [
20 (mkRemovedOptionModule [ "interval" ] "This option has been removed.")
21 ({
22 options.warnings = options.warnings;
23 options.assertions = options.assertions;
24 })
25 ];
26
27 port = 9617;
28 extraOpts = {
29 apiToken = mkOption {
30 type = types.str;
31 default = "";
32 example = "580a770cb40511eb85290242ac130003580a770cb40511eb85290242ac130003";
33 description = ''
34 Pi-Hole API token which can be used instead of a password
35 '';
36 };
37 password = mkOption {
38 type = types.str;
39 default = "";
40 example = "password";
41 description = ''
42 The password to login into Pi-Hole. An api token can be used instead.
43 '';
44 };
45 piholeHostname = mkOption {
46 type = types.str;
47 default = "pihole";
48 example = "127.0.0.1";
49 description = ''
50 Hostname or address where to find the Pi-Hole webinterface
51 '';
52 };
53 piholePort = mkOption {
54 type = types.port;
55 default = 80;
56 example = 443;
57 description = ''
58 The port Pi-Hole webinterface is reachable on
59 '';
60 };
61 protocol = mkOption {
62 type = types.enum [
63 "http"
64 "https"
65 ];
66 default = "http";
67 example = "https";
68 description = ''
69 The protocol which is used to connect to Pi-Hole
70 '';
71 };
72 timeout = mkOption {
73 type = types.str;
74 default = "5s";
75 description = ''
76 Controls the timeout to connect to a Pi-Hole instance
77 '';
78 };
79 };
80 serviceOpts = {
81 serviceConfig = {
82 ExecStart = ''
83 ${pkgs.prometheus-pihole-exporter}/bin/pihole-exporter \
84 ${optionalString (cfg.apiToken != "") "-pihole_api_token ${cfg.apiToken}"} \
85 -pihole_hostname ${cfg.piholeHostname} \
86 ${optionalString (cfg.password != "") "-pihole_password ${cfg.password}"} \
87 -pihole_port ${toString cfg.piholePort} \
88 -pihole_protocol ${cfg.protocol} \
89 -port ${toString cfg.port} \
90 -timeout ${cfg.timeout}
91 '';
92 };
93 };
94}