{ mailserver, pkgs, config, ... }: 
{
  imports = [
    ./nginx
    mailserver.nixosModule
  ];

  mailserver = rec {
    enable = config.system.mailserver.enable;
    domains = [
      "${config.domains.p1}"
      "${config.domains.p2}"
      "${config.domains.luna}"
      "${config.domains.corn}"
    ];
    fqdn = "mx.${config.domains.p1}";
    certificateScheme = "acme-nginx";
    localDnsResolver = false;
    redis.port = 1515;

    # Passwords made with 'mkpasswd -sm bcrypt'
    loginAccounts = {
      "noreply@${config.domains.p2}" = {
        hashedPasswordFile = pkgs.writeText "noreply" config.secrets.noreplyMailHash;
        sendOnly = true;
      };    
      "jimbo@${config.domains.p2}" = {
        hashedPasswordFile = pkgs.writeText "jimbo" config.secrets.jimboMailHash;
        aliases = [
          "jimbo@${config.domains.p1}"
          "james@${config.domains.p2}"

          "vicee@${config.domains.p2}"
          "vice@${config.domains.p2}"
          "yara@${config.domains.p2}"
          "yaralis@${config.domains.p2}"

          "contact@${config.domains.p2}"
        ];
      };
      "luna@${config.domains.luna}" = {
        hashedPasswordFile = pkgs.writeText "luna" config.secrets.lunaMailHash;
      };
      "corn@${config.domains.corn}" = {
        hashedPasswordFile = pkgs.writeText "corn" config.secrets.cornMailHash;
      };
      "tiny@${config.domains.corn}" = {
        hashedPasswordFile = pkgs.writeText "tiny" config.secrets.tinyMailHash;
      };
    };
  };

  # Rspamd port from earlier to avoid overlap
  services.redis.servers.rspamd.port = 1515;
}
