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

  config = lib.mkIf config.services.mailserver.enable {
    mailserver = {
      enable = true;
      fqdn = "mx.nixfox.ca";
      domains = [
        "nixfox.ca"
        "bloxelcom.net"
        "freecorn1854.win"
        "lunamoonlight.xyz"
      ];
      certificateScheme = "acme-nginx";
      localDnsResolver = false;
      redis.port = 1515;

      # Passwords made with 'mkpasswd -sm bcrypt'
      loginAccounts = {
        "jimbo@nixfox.ca" = {
          hashedPassword = config.secrets.mailHash.bun;
          aliases = [
            "james@nixfox.ca"
            "jimbo@bloxelcom.net"

            "yara@nixfox.ca"
            "bun@nixfox.ca"
            "bun@bloxelcom.net"

            "contact@nixfox.ca"
          ];
        };

        "luna@lunamoonlight.xyz" = {
          hashedPassword = config.secrets.mailHash.luna;
          aliases = [
            "luna@bloxelcom.net"
            "contact@bloxelcom.net"
            "ibu@bloxelcom.net"
          ];
        };

        "contact@freecorn1854.win" = {
          hashedPassword = config.secrets.mailHash.corn;
          aliases = [ "freecorn@bloxelcom.net" ];
        };

	# Noreply emails
        "noreply@nixfox.ca" = {
          hashedPassword = config.secrets.mailHash.nixfoxNoReply;
          sendOnly = true;
        };
        "noreply@bloxelcom.net" = {
          hashedPassword = config.secrets.mailHash.bloxelNoReply;
          sendOnly = true;
        };
      };
    };

    services = {
      redis.servers.rspamd.port = config.mailserver.redis.port;
      cloudflare-dyndns.domains = [ config.mailserver.fqdn ];
    };

    environment.persistence."/persist".directories = [
      "/var/vmail"
      "/var/lib/dovecot"
      "/var/lib/postfix"
      "/var/lib/redis-rspamd"
    ];
  };
}
