1 { config, lib, pkgs, options, ... }:
4 logPrefix = "services.prometheus.exporter.blackbox";
5 cfg = config.services.prometheus.exporters.blackbox;
13 # This ensures that we can deal with string paths, path types and
14 # store-path strings with context.
15 coerceConfigFile = file:
16 if (builtins.isPath file) || (lib.isStorePath file) then
20 ${logPrefix}: configuration file "${file}" is being copied to the nix-store.
21 If you would like to avoid that, please set enableConfigCheck to false.
23 checkConfigLocation = file:
24 if lib.hasPrefix "/tmp/" file then
26 "${logPrefix}: configuration file must not reside within /tmp - it won't be visible to the systemd service."
30 pkgs.runCommand "checked-blackbox-exporter.conf" {
31 preferLocalBuild = true;
32 nativeBuildInputs = [ pkgs.buildPackages.prometheus-blackbox-exporter ];
34 ln -s ${coerceConfigFile file} $out
35 blackbox_exporter --config.check --config.file $out
40 configFile = mkOption {
43 Path to configuration file.
46 enableConfigCheck = mkOption {
50 Whether to run a correctness check for the configuration file. This depends
51 on the configuration file residing in the nix-store. Paths passed as string will
52 be copied to the store.
58 adjustedConfigFile = if cfg.enableConfigCheck then
59 checkConfig cfg.configFile
61 checkConfigLocation cfg.configFile;
64 AmbientCapabilities = [ "CAP_NET_RAW" ]; # for ping probes
66 ${pkgs.prometheus-blackbox-exporter}/bin/blackbox_exporter \
67 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
68 --config.file ${escapeShellArg adjustedConfigFile} \
69 ${concatStringsSep " \\\n " cfg.extraFlags}
71 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";