1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8let 9 cfg = config.services.prometheus.exporters.postfix; 10 inherit (lib) 11 mkOption 12 types 13 mkIf 14 escapeShellArg 15 concatStringsSep 16 optional 17 ; 18in 19{ 20 port = 9154; 21 extraOpts = { 22 package = lib.mkPackageOption pkgs "prometheus-postfix-exporter" { }; 23 group = mkOption { 24 type = types.str; 25 description = '' 26 Group under which the postfix exporter shall be run. 27 It should match the group that is allowed to access the 28 `showq` socket in the `queue/public/` directory. 29 Defaults to `services.postfix.setgidGroup` when postfix is enabled. 30 ''; 31 }; 32 telemetryPath = mkOption { 33 type = types.str; 34 default = "/metrics"; 35 description = '' 36 Path under which to expose metrics. 37 ''; 38 }; 39 logfilePath = mkOption { 40 type = types.path; 41 default = "/var/log/postfix_exporter_input.log"; 42 example = "/var/log/mail.log"; 43 description = '' 44 Path where Postfix writes log entries. 45 This file will be truncated by this exporter! 46 ''; 47 }; 48 showqPath = mkOption { 49 type = types.path; 50 default = "/var/lib/postfix/queue/public/showq"; 51 example = "/var/spool/postfix/public/showq"; 52 description = '' 53 Path where Postfix places its showq socket. 54 ''; 55 }; 56 systemd = { 57 enable = mkOption { 58 type = types.bool; 59 default = true; 60 description = '' 61 Whether to enable reading metrics from the systemd journal instead of from a logfile 62 ''; 63 }; 64 unit = mkOption { 65 type = types.str; 66 default = "postfix.service"; 67 description = '' 68 Name of the postfix systemd unit. 69 ''; 70 }; 71 slice = mkOption { 72 type = types.nullOr types.str; 73 default = null; 74 description = '' 75 Name of the postfix systemd slice. 76 This overrides the {option}`systemd.unit`. 77 ''; 78 }; 79 journalPath = mkOption { 80 type = types.nullOr types.path; 81 default = null; 82 description = '' 83 Path to the systemd journal. 84 ''; 85 }; 86 }; 87 }; 88 serviceOpts = { 89 after = mkIf cfg.systemd.enable [ cfg.systemd.unit ]; 90 serviceConfig = { 91 DynamicUser = false; 92 # By default, each prometheus exporter only gets AF_INET & AF_INET6, 93 # but AF_UNIX is needed to read from the `showq`-socket. 94 RestrictAddressFamilies = [ "AF_UNIX" ]; 95 SupplementaryGroups = mkIf cfg.systemd.enable [ "systemd-journal" ]; 96 ExecStart = '' 97 ${lib.getExe cfg.package} \ 98 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ 99 --web.telemetry-path ${cfg.telemetryPath} \ 100 --postfix.showq_path ${escapeShellArg cfg.showqPath} \ 101 ${concatStringsSep " \\\n " ( 102 cfg.extraFlags 103 ++ optional cfg.systemd.enable "--systemd.enable" 104 ++ optional cfg.systemd.enable ( 105 if cfg.systemd.slice != null then 106 "--systemd.slice ${cfg.systemd.slice}" 107 else 108 "--systemd.unit ${cfg.systemd.unit}" 109 ) 110 ++ optional ( 111 cfg.systemd.enable && (cfg.systemd.journalPath != null) 112 ) "--systemd.journal_path ${escapeShellArg cfg.systemd.journalPath}" 113 ++ optional (!cfg.systemd.enable) "--postfix.logfile_path ${escapeShellArg cfg.logfilePath}" 114 )} 115 ''; 116 }; 117 }; 118}