{ config, pkgs, lib, mkDomain, ... }:
{
  # Mattermost
  # Open-source, self-hosted Slack-alternative

  services.mattermost = {
    enable = true;
    # will create and use a psql db
    listenAddress = "[::1]:8065";
    siteName = "Spis meg";
    siteUrl = "https://${mkDomain "mattermost"}";
    #mutableConfig = true; # default is false, if true, see also "preferNixConfig"
    extraConfig = {
      # https://docs.mattermost.com/configure/configuration-settings.html#reporting
      # TODO: smtp
    };
    matterircd = {
      #enable = true; # default is false
      parameters = [
        "-mmserver chat.example.com"
        "-bind [::]:6667"
      ];
    };
  };
  services.nginx.virtualHosts.${mkDomain "mattermost"} = lib.mkIf config.services.mattermost.enable {
    forceSSL = true; # addSSL = true;
    enableACME = true; #useACMEHost = acmeDomain;
    locations."/" = {
      proxyPass = "http://${config.services.mattermost.listenAddress}";
      proxyWebsockets = true;
    };
  };

}
