Skip to content

Commit e7d3033

Browse files
committed
update matrix config
1 parent 1ceeca5 commit e7d3033

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

modules/matrix/default.nix

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{ lib, pkgs, config, ... }:
22
with lib;
33
let cfg = config.mayniklas.matrix;
4-
in
5-
{
4+
in {
65

76
options.mayniklas.matrix = {
87
enable = mkEnableOption "activate matrix";
@@ -15,7 +14,17 @@ in
1514
};
1615
};
1716

18-
config = mkIf cfg.enable {
17+
config = let
18+
fqdn = "${cfg.host}";
19+
baseUrl = "https://${fqdn}";
20+
clientConfig."m.homeserver".base_url = baseUrl;
21+
serverConfig."m.server" = "${fqdn}:443";
22+
mkWellKnown = data: ''
23+
default_type application/json;
24+
add_header Access-Control-Allow-Origin *;
25+
return 200 '${builtins.toJSON data}';
26+
'';
27+
in mkIf cfg.enable {
1928

2029
# 1. get the path of the postgresql versions
2130
# > nix build --print-out-paths nixpkgs#postgresql_14
@@ -58,29 +67,10 @@ in
5867
forceSSL = true;
5968

6069
locations."= /.well-known/matrix/server".extraConfig =
61-
let
62-
# use 443 instead of the default 8448 port to unite
63-
# the client-server and server-server port for simplicity
64-
server = { "m.server" = "${cfg.host}:443"; };
65-
in
66-
''
67-
add_header Content-Type application/json;
68-
return 200 '${builtins.toJSON server}';
69-
'';
70+
mkWellKnown serverConfig;
7071

7172
locations."= /.well-known/matrix/client".extraConfig =
72-
let
73-
client = {
74-
"m.homeserver" = { "base_url" = "https://${cfg.host}"; };
75-
"m.identity_server" = { "base_url" = "https://vector.im"; };
76-
};
77-
# ACAO required to allow element-web on any URL to request this json file
78-
in
79-
''
80-
add_header Content-Type application/json;
81-
add_header Access-Control-Allow-Origin *;
82-
return 200 '${builtins.toJSON client}';
83-
'';
73+
mkWellKnown clientConfig;
8474

8575
# Reverse proxy for Matrix client-server and server-server communication
8676
# Or do a redirect instead of the 404, or whatever is appropriate for you.
@@ -103,6 +93,7 @@ in
10393
enable = true;
10494
settings = {
10595
server_name = "${cfg.host}";
96+
public_baseurl = baseUrl;
10697
enable_registration = false;
10798
listeners = [{
10899
port = 8008;
@@ -112,7 +103,7 @@ in
112103
x_forwarded = true;
113104
resources = [{
114105
names = [ "client" "federation" ];
115-
compress = false;
106+
compress = true;
116107
}];
117108
}];
118109
# TODO: is this enough?

0 commit comments

Comments
 (0)