{ config, lib, ... }:
let
  fqdn = config.khscodes.networking.fqdn;
  cfg = config.khscodes.infrastructure.mailserver;
in
{
  config = lib.mkIf cfg.enable {
    services.stalwart-mail.settings = {
      config.local-keys = [ "metrics.prometheus.*" ];
      metrics.prometheus = {
        enable = true;
      };
    };
    # Don't expose the endpoint
    khscodes.services.nginx.virtualHosts."${fqdn}".locations."=/metrics/prometheus" = {
      return = 404;
    };
  };
}
