@@ -3,7 +3,7 @@
33let
44 inherit (lib) concatStrings foldl foldl' genAttrs literalExample maintainers
55 mapAttrsToList mkDefault mkEnableOption mkIf mkMerge mkOption
6− optional types;
6+ optional types mkOptionDefault flip attrNames;
77
88 cfg = config.services.prometheus.exporters;
99
@@ -32,6 +32,7 @@ let
3232 "fritzbox"
3333 "json"
3434 "keylight"
35+ "knot"
3536 "lnd"
3637 "mail"
3738 "mikrotik"
@@ -65,7 +66,7 @@ let
6566 mkExporterOpts = ({ name, port }: {
6667 enable = mkEnableOption "the prometheus ${name} exporter";
6768 port = mkOption {
68− type = types.int;
69+ type = types.port;
6970 default = port;
7071 description = ''
7172 Port to listen on.
@@ -93,9 +94,8 @@ let
9394 '';
9495 };
9596 firewallFilter = mkOption {
96− type = types.str;
97− default = "-p tcp -m tcp --dport ${toString cfg.${name}.port}";
98− defaultText = "-p tcp -m tcp --dport ${toString port}";
97+ type = types.nullOr types.str;
98+ default = null;
9999 example = literalExample ''
100100 "-i eth0 -p tcp -m tcp --dport ${toString port}"
101101 '';
@@ -123,12 +123,14 @@ let
123123
124124 mkSubModule = { name, port, extraOpts, imports }: {
125125 ${name} = mkOption {
126− type = types.submodule {
126+ type = types.submodule [{
127127 inherit imports;
128128 options = (mkExporterOpts {
129129 inherit name port;
130130 } // extraOpts);
131− };
131+ } ({ config, ... }: mkIf config.openFirewall {
132+ firewallFilter = mkOptionDefault "-p tcp -m tcp --dport ${toString config.port}";
133+ })];
132134 internal = true;
133135 default = {};
134136 };
@@ -233,7 +235,13 @@ in
233235 Please specify either 'services.prometheus.exporters.sql.configuration' or
234236 'services.prometheus.exporters.sql.configFile'
235237 '';
236− } ];
238+ } ] ++ (flip map (attrNames cfg) (exporter: {
239+ assertion = cfg.${exporter}.firewallFilter != null -> cfg.${exporter}.openFirewall;
240+ message = ''
241+ The `firewallFilter'-option of exporter ${exporter} doesn't have any effect unless
242+ `openFirewall' is set to `true'!
243+ '';
244+ }));
237245 }] ++ [(mkIf config.services.minio.enable {
238246 services.prometheus.exporters.minio.minioAddress = mkDefault "http://localhost:9000";
239247 services.prometheus.exporters.minio.minioAccessKey = mkDefault config.services.minio.accessKey;