10 cfg = config.services.prometheus.exporters.dmarc;
11 inherit (lib) mkOption types optionalString;
13 json = builtins.toJSON {
14 inherit (cfg) folders port;
15 listen_addr = cfg.listenAddress;
16 storage_path = "$STATE_DIRECTORY";
17 imap = (builtins.removeAttrs cfg.imap [ "passwordFile" ]) // {
18 password = "$IMAP_PASSWORD";
21 poll_interval_seconds = cfg.pollIntervalSeconds;
22 deduplication_max_seconds = cfg.deduplicationMaxSeconds;
25 disable_existing_loggers = false;
35 default = "localhost";
37 Hostname of IMAP server to connect to.
44 Port of the IMAP server to connect to.
49 example = "postmaster@example.org";
51 Login username for the IMAP connection.
54 passwordFile = mkOption {
56 example = "/run/secrets/dovecot_pw";
58 File containing the login password for the IMAP connection.
67 IMAP mailbox that is checked for incoming DMARC aggregate reports
74 IMAP mailbox that successfully processed reports are moved to.
81 IMAP mailbox that emails are moved to that could not be processed.
85 pollIntervalSeconds = mkOption {
86 type = types.ints.unsigned;
89 How often to poll the IMAP server in seconds.
92 deduplicationMaxSeconds = mkOption {
93 type = types.ints.unsigned;
95 defaultText = "7 days (in seconds)";
97 How long individual report IDs will be remembered to avoid
98 counting double delivered reports twice.
105 Whether to declare enable `--debug`.
115 StateDirectory = "prometheus-dmarc-exporter";
116 WorkingDirectory = "/var/lib/prometheus-dmarc-exporter";
117 ExecStart = "${pkgs.writeShellScript "setup-cfg" ''
118 export IMAP_PASSWORD="$(<${cfg.imap.passwordFile})"
120 -i ${pkgs.writeText "dmarc-exporter.json.template" json} \
121 -o ''${STATE_DIRECTORY}/dmarc-exporter.json
123 exec ${pkgs.dmarc-metrics-exporter}/bin/dmarc-metrics-exporter \
124 --configuration /var/lib/prometheus-dmarc-exporter/dmarc-exporter.json \
125 ${optionalString cfg.debug "--debug"}