@@ -1,8 +1,10 @@
1−{ config, pkgs, lib, ... }:
2−
3−with lib;
1+{ config, pkgs, lib, options, ... }:
42
53let
4+ inherit (lib) concatStrings foldl foldl' genAttrs literalExample maintainers
5+ mapAttrsToList mkDefault mkEnableOption mkIf mkMerge mkOption
6+ optional types;
7+
68 cfg = config.services.prometheus.exporters;
79
810 # each attribute in `exporterOpts` is expected to have specified:
@@ -17,25 +19,28 @@ let
1719 # Note that `extraOpts` is optional, but a script for the exporter's
1820 # systemd service must be provided by specifying either
1921 # `serviceOpts.script` or `serviceOpts.serviceConfig.ExecStart`
20− exporterOpts = {
21− blackbox = import ./exporters/blackbox.nix { inherit config lib pkgs; };
22− collectd = import ./exporters/collectd.nix { inherit config lib pkgs; };
23− dnsmasq = import ./exporters/dnsmasq.nix { inherit config lib pkgs; };
24− dovecot = import ./exporters/dovecot.nix { inherit config lib pkgs; };
25− fritzbox = import ./exporters/fritzbox.nix { inherit config lib pkgs; };
26− json = import ./exporters/json.nix { inherit config lib pkgs; };
27− minio = import ./exporters/minio.nix { inherit config lib pkgs; };
28− nginx = import ./exporters/nginx.nix { inherit config lib pkgs; };
29− node = import ./exporters/node.nix { inherit config lib pkgs; };
30− postfix = import ./exporters/postfix.nix { inherit config lib pkgs; };
31− snmp = import ./exporters/snmp.nix { inherit config lib pkgs; };
32− surfboard = import ./exporters/surfboard.nix { inherit config lib pkgs; };
33− tor = import ./exporters/tor.nix { inherit config lib pkgs; };
34− unifi = import ./exporters/unifi.nix { inherit config lib pkgs; };
35− varnish = import ./exporters/varnish.nix { inherit config lib pkgs; };
36− bind = import ./exporters/bind.nix { inherit config lib pkgs; };
37− wireguard = import ./exporters/wireguard.nix { inherit config lib pkgs; };
38− };
22+
23+ exporterOpts = genAttrs [
24+ "bind"
25+ "blackbox"
26+ "collectd"
27+ "dnsmasq"
28+ "dovecot"
29+ "fritzbox"
30+ "json"
31+ "minio"
32+ "nginx"
33+ "node"
34+ "postfix"
35+ "snmp"
36+ "surfboard"
37+ "tor"
38+ "unifi"
39+ "varnish"
40+ "wireguard"
41+ ] (name:
42+ import (./. + "/exporters/${name}.nix") { inherit config lib pkgs options; }
43+ );
3944
4045 mkExporterOpts = ({ name, port }: {
4146 enable = mkEnableOption "the prometheus ${name} exporter";
@@ -97,9 +102,10 @@ let
97102 };
98103 });
99104
100− mkSubModule = { name, port, extraOpts, ... }: {
105+ mkSubModule = { name, port, extraOpts, imports }: {
101106 ${name} = mkOption {
102107 type = types.submodule {
108+ inherit imports;
103109 options = (mkExporterOpts {
104110 inherit name port;
105111 } // extraOpts);
@@ -112,13 +118,15 @@ let
112118 mkSubModules = (foldl' (a: b: a//b) {}
113119 (mapAttrsToList (name: opts: mkSubModule {
114120 inherit name;
115− inherit (opts) port serviceOpts;
121+ inherit (opts) port;
116122 extraOpts = opts.extraOpts or {};
123+ imports = opts.imports or [];
117124 }) exporterOpts)
118125 );
119126
120127 mkExporterConf = { name, conf, serviceOpts }:
121128 mkIf conf.enable {
129+ warnings = conf.warnings or [];
122130 networking.firewall.extraCommands = mkIf conf.openFirewall (concatStrings [
123131 "ip46tables -A nixos-fw ${conf.firewallFilter} "
124132 "-m comment --comment ${name}-exporter -j nixos-fw-accept"