From 7df67599ea839982978a4c2c53a9fd34d69c53d0 Mon Sep 17 00:00:00 2001 From: Wulfsta Date: Sat, 16 Nov 2024 15:53:12 -0500 Subject: [PATCH] nixos/prometheus-postfix-exporter: add package option and format --- .../prometheus/exporters/postfix.nix | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix b/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix index 7aa3622f16d6..fdd7a0453603 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters/postfix.nix @@ -1,4 +1,9 @@ -{ config, lib, pkgs, options, ... }: +{ + config, + lib, + pkgs, + ... +}: let cfg = config.services.prometheus.exporters.postfix; @@ -14,6 +19,7 @@ in { port = 9154; extraOpts = { + package = lib.mkPackageOption pkgs "prometheus-postfix-exporter" { }; group = mkOption { type = types.str; description = '' @@ -88,18 +94,26 @@ in RestrictAddressFamilies = [ "AF_UNIX" ]; SupplementaryGroups = mkIf cfg.systemd.enable [ "systemd-journal" ]; ExecStart = '' - ${pkgs.prometheus-postfix-exporter}/bin/postfix_exporter \ + ${lib.getExe cfg.package} \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ --web.telemetry-path ${cfg.telemetryPath} \ --postfix.showq_path ${escapeShellArg cfg.showqPath} \ - ${concatStringsSep " \\\n " (cfg.extraFlags - ++ optional cfg.systemd.enable "--systemd.enable" - ++ optional cfg.systemd.enable (if cfg.systemd.slice != null - then "--systemd.slice ${cfg.systemd.slice}" - else "--systemd.unit ${cfg.systemd.unit}") - ++ optional (cfg.systemd.enable && (cfg.systemd.journalPath != null)) - "--systemd.journal_path ${escapeShellArg cfg.systemd.journalPath}" - ++ optional (!cfg.systemd.enable) "--postfix.logfile_path ${escapeShellArg cfg.logfilePath}")} + ${ + concatStringsSep " \\\n " ( + cfg.extraFlags + ++ optional cfg.systemd.enable "--systemd.enable" + ++ optional cfg.systemd.enable ( + if cfg.systemd.slice != null then + "--systemd.slice ${cfg.systemd.slice}" + else + "--systemd.unit ${cfg.systemd.unit}" + ) + ++ optional ( + cfg.systemd.enable && (cfg.systemd.journalPath != null) + ) "--systemd.journal_path ${escapeShellArg cfg.systemd.journalPath}" + ++ optional (!cfg.systemd.enable) "--postfix.logfile_path ${escapeShellArg cfg.logfilePath}" + ) + } ''; }; };