@@ -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
@@ -93,9 +93,8 @@ let
9393 '';
9494 };
9595 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}";
96+ type = types.nullOr types.str;
97+ default = null;
9998 example = literalExample ''
10099 "-i eth0 -p tcp -m tcp --dport ${toString port}"
101100 '';
@@ -123,12 +122,14 @@ let
123122
124123 mkSubModule = { name, port, extraOpts, imports }: {
125124 ${name} = mkOption {
126− type = types.submodule {
125+ type = types.submodule [{
127126 inherit imports;
128127 options = (mkExporterOpts {
129128 inherit name port;
130129 } // extraOpts);
131− };
130+ } ({ config, ... }: mkIf config.openFirewall {
131+ firewallFilter = mkOptionDefault "-p tcp -m tcp --dport ${toString config.port}";
132+ })];
132133 internal = true;
133134 default = {};
134135 };
@@ -233,7 +234,13 @@ in
233234 Please specify either 'services.prometheus.exporters.sql.configuration' or
234235 'services.prometheus.exporters.sql.configFile'
235236 '';
236− } ];
237+ } ] ++ (flip map (attrNames cfg) (exporter: {
238+ assertion = cfg.${exporter}.firewallFilter != null -> cfg.${exporter}.openFirewall;
239+ message = ''
240+ The `firewallFilter'-option of exporter ${exporter} doesn't have any effect unless
241+ `openFirewall' is set to `true'!
242+ '';
243+ }));
237244 }] ++ [(mkIf config.services.minio.enable {
238245 services.prometheus.exporters.minio.minioAddress = mkDefault "http://localhost:9000";
239246 services.prometheus.exporters.minio.minioAccessKey = mkDefault config.services.minio.accessKey;