2022-04-12 15:11:56 +00:00
|
|
|
# Registration of new users is disabled for the public, but I can create
|
|
|
|
|
# them by the following commands:
|
|
|
|
|
# nix run nixpkgs.matrix-synapse
|
|
|
|
|
# register_new_matrix_user -k "B9EoPr2WV9hzwc7uL2Sx1JmvCeKDEOGCpB0uginQcQtEH4wzRtkSIdo7lltrjSQa" http://localhost:8448
|
2024-10-03 15:21:56 -05:00
|
|
|
{ config, ... }:
|
2022-04-12 15:11:56 +00:00
|
|
|
let
|
2024-10-03 11:26:39 -05:00
|
|
|
domain = "${config.networking.domain}";
|
|
|
|
|
fqdn = "matrix.${domain}";
|
2022-04-12 15:11:56 +00:00
|
|
|
in
|
|
|
|
|
{
|
2024-10-03 11:26:39 -05:00
|
|
|
services.nginx = {
|
|
|
|
|
virtualHosts = {
|
|
|
|
|
# Server the '.well-known' files to find the Matrix API server
|
|
|
|
|
"${domain}" = {
|
|
|
|
|
enableACME = true;
|
|
|
|
|
forceSSL = true;
|
2022-04-12 15:11:56 +00:00
|
|
|
|
2024-10-03 11:26:39 -05:00
|
|
|
# This is needed so that servers contacting hellings.com can find
|
|
|
|
|
# the actual application server at matrix.thehellings.com
|
|
|
|
|
locations."= /.well-known/matrix/server".extraConfig =
|
|
|
|
|
let
|
2024-10-19 01:19:59 -05:00
|
|
|
server = {
|
|
|
|
|
"m.server" = "${fqdn}:443";
|
|
|
|
|
};
|
2024-10-03 11:26:39 -05:00
|
|
|
in
|
|
|
|
|
''
|
|
|
|
|
add_header Content-Type application/json;
|
|
|
|
|
return 200 '${builtins.toJSON server}';
|
|
|
|
|
'';
|
2022-04-12 15:11:56 +00:00
|
|
|
|
2024-10-03 11:26:39 -05:00
|
|
|
locations."= /.well-known/matrix/client".extraConfig =
|
|
|
|
|
let
|
|
|
|
|
client = {
|
2024-10-19 01:19:59 -05:00
|
|
|
"m.homeserver" = {
|
|
|
|
|
"base_url" = "https://${fqdn}";
|
|
|
|
|
};
|
|
|
|
|
"m.identity_server" = {
|
|
|
|
|
"base_url" = "https://vector.im";
|
|
|
|
|
};
|
2024-10-03 11:26:39 -05:00
|
|
|
};
|
|
|
|
|
in
|
|
|
|
|
''
|
|
|
|
|
add_header Content-Type application/json;
|
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
|
return 200 '${builtins.toJSON client}';
|
|
|
|
|
'';
|
|
|
|
|
};
|
2022-04-12 15:11:56 +00:00
|
|
|
|
2024-10-03 11:26:39 -05:00
|
|
|
# Reverse proxy in front of the actual Matrix server
|
|
|
|
|
"${fqdn}" = {
|
|
|
|
|
enableACME = true;
|
|
|
|
|
forceSSL = true;
|
2022-04-12 15:11:56 +00:00
|
|
|
|
2024-10-03 11:26:39 -05:00
|
|
|
# Not the appropriate place for the chat client
|
|
|
|
|
locations."/".extraConfig = "return 404;";
|
2022-04-12 15:11:56 +00:00
|
|
|
|
2024-10-03 11:26:39 -05:00
|
|
|
locations."/_matrix" = {
|
|
|
|
|
proxyPass = "http://matrix.shire-zebra.ts.net:8448"; # Lacking the trailing / is correct
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
2022-04-12 15:11:56 +00:00
|
|
|
|
2024-10-03 11:26:39 -05:00
|
|
|
# Open networking ports for the server
|
|
|
|
|
networking.firewall = {
|
|
|
|
|
enable = true;
|
2024-10-19 01:19:59 -05:00
|
|
|
allowedTCPPorts = [
|
|
|
|
|
80
|
|
|
|
|
443
|
|
|
|
|
];
|
2024-10-03 11:26:39 -05:00
|
|
|
};
|
2022-04-12 15:11:56 +00:00
|
|
|
}
|