|
1 | 1 | { lib, pkgs, config, ... }:
|
2 | 2 | with lib;
|
3 | 3 | let cfg = config.mayniklas.matrix;
|
4 |
| -in |
5 |
| -{ |
| 4 | +in { |
6 | 5 |
|
7 | 6 | options.mayniklas.matrix = {
|
8 | 7 | enable = mkEnableOption "activate matrix";
|
|
15 | 14 | };
|
16 | 15 | };
|
17 | 16 |
|
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 { |
19 | 28 |
|
20 | 29 | # 1. get the path of the postgresql versions
|
21 | 30 | # > nix build --print-out-paths nixpkgs#postgresql_14
|
|
58 | 67 | forceSSL = true;
|
59 | 68 |
|
60 | 69 | 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; |
70 | 71 |
|
71 | 72 | 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; |
84 | 74 |
|
85 | 75 | # Reverse proxy for Matrix client-server and server-server communication
|
86 | 76 | # Or do a redirect instead of the 404, or whatever is appropriate for you.
|
|
103 | 93 | enable = true;
|
104 | 94 | settings = {
|
105 | 95 | server_name = "${cfg.host}";
|
| 96 | + public_baseurl = baseUrl; |
106 | 97 | enable_registration = false;
|
107 | 98 | listeners = [{
|
108 | 99 | port = 8008;
|
|
112 | 103 | x_forwarded = true;
|
113 | 104 | resources = [{
|
114 | 105 | names = [ "client" "federation" ];
|
115 |
| - compress = false; |
| 106 | + compress = true; |
116 | 107 | }];
|
117 | 108 | }];
|
118 | 109 | # TODO: is this enough?
|
|
0 commit comments