summaryrefslogtreecommitdiff
path: root/nixos/hosts/tente/matrix.nix
blob: ab6931e4ce97ec8bdf566579fc4abda26fedcc36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{ config, lib, pkgs, ... }:

let
  cfg = config.matrix;
in
{
  options.matrix = {
    port = lib.mkOption {
      type = lib.types.int;
    };
    serverName = lib.mkOption {
      type = lib.types.str;
    };
    apiDomain = lib.mkOption {
      type = lib.types.str;
    };
  };

  config = {
    services = {
      matrix-synapse = {
        enable = true;
        settings = {
          server_name = cfg.serverName;
          listeners = [{
            # This listener matches the default of NixOS 24.11 (replicated here to make the port configurable).
            bind_addresses = ["127.0.0.1"];
            port = cfg.port;
            resources = [
              {
                compress = true;
                names = ["client"];
              }
              {
                compress = false;
                names = ["federation"];
              }
            ];
            tls = false;
            type = "http";
            x_forwarded = true;
          }];
        };
      };

      nginx.virtualHosts.${cfg.apiDomain} = {
        enableACME = true;
        forceSSL = true;

        # TODO: add locations."/" with some message

        # Forward all Matrix API calls to the synapse Matrix homeserver. A trailing slash
        # *must not* be used here.
        locations."/_matrix".proxyPass = "http://127.0.0.1:${toString cfg.port}";
        # Forward requests for e.g. SSO and password-resets.
        locations."/_synapse/client".proxyPass = "http://127.0.0.1:${toString cfg.port}";
      };
    };
  };
}