2024-05-08 17:47:47 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}:
|
2023-10-29 03:48:26 +00:00
|
|
|
let
|
|
|
|
commonHeaders = ''
|
|
|
|
add_header Permissions-Policy interest-cohort=() always;
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
add_header X-XSS-Protection "1; mode=block";
|
|
|
|
'';
|
2024-10-26 00:03:31 +00:00
|
|
|
clientConfig = import ./element-client-config.nix { inherit config lib pkgs; };
|
2023-11-16 19:10:39 +00:00
|
|
|
wellKnownClient = domain: {
|
|
|
|
"m.homeserver".base_url = "https://matrix.${domain}";
|
|
|
|
"m.identity_server".base_url = "https://matrix.${domain}";
|
2024-10-26 00:03:31 +00:00
|
|
|
"org.matrix.msc2965.authentication" = {
|
|
|
|
issuer = "https://mas.${domain}/";
|
|
|
|
account = "https://mas.${domain}/account";
|
|
|
|
};
|
2023-11-07 14:19:55 +00:00
|
|
|
"im.vector.riot.e2ee".default = true;
|
|
|
|
"io.element.e2ee" = {
|
|
|
|
default = true;
|
|
|
|
secure_backup_required = false;
|
|
|
|
secure_backup_setup_methods = [ ];
|
|
|
|
};
|
|
|
|
};
|
2023-11-18 16:34:33 +00:00
|
|
|
wellKnownServer = domain: { "m.server" = "matrix.${domain}:8448"; };
|
2023-11-25 13:25:46 +00:00
|
|
|
wellKnownSupport = {
|
|
|
|
contacts = [
|
|
|
|
{
|
|
|
|
email_address = "crew@pub.solar";
|
|
|
|
matrix_id = "@b12f:pub.solar";
|
|
|
|
role = "m.role.admin";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
email_address = "crew@pub.solar";
|
|
|
|
matrix_id = "@hensoko:pub.solar";
|
|
|
|
role = "m.role.admin";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
email_address = "crew@pub.solar";
|
|
|
|
matrix_id = "@teutat3s:pub.solar";
|
|
|
|
role = "m.role.admin";
|
|
|
|
}
|
|
|
|
];
|
2024-05-08 17:47:47 +00:00
|
|
|
support_page = "https://${config.pub-solar-os.networking.domain}/about";
|
2023-11-25 13:25:46 +00:00
|
|
|
};
|
2023-10-29 03:48:26 +00:00
|
|
|
mkWellKnown = data: ''
|
|
|
|
add_header Content-Type application/json;
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
return 200 '${builtins.toJSON data}';
|
|
|
|
'';
|
2023-11-16 19:10:39 +00:00
|
|
|
wellKnownLocations = domain: {
|
|
|
|
"= /.well-known/matrix/server".extraConfig = mkWellKnown (wellKnownServer domain);
|
|
|
|
"= /.well-known/matrix/client".extraConfig = mkWellKnown (wellKnownClient domain);
|
2023-11-25 13:25:46 +00:00
|
|
|
"= /.well-known/matrix/support".extraConfig = mkWellKnown wellKnownSupport;
|
2023-10-29 03:48:26 +00:00
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
services.nginx.virtualHosts = {
|
2023-11-07 14:19:55 +00:00
|
|
|
|
|
|
|
#####################################
|
|
|
|
# This is already in production use #
|
|
|
|
#####################################
|
|
|
|
|
2024-05-08 17:47:47 +00:00
|
|
|
"${config.pub-solar-os.networking.domain}" = {
|
|
|
|
locations = wellKnownLocations "${config.pub-solar-os.networking.domain}";
|
2023-10-29 03:48:26 +00:00
|
|
|
};
|
|
|
|
|
2024-05-08 17:47:47 +00:00
|
|
|
"chat.${config.pub-solar-os.networking.domain}" = {
|
2023-10-29 03:48:26 +00:00
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
root = pkgs.element-web.override { conf = clientConfig; };
|
|
|
|
};
|
|
|
|
|
2024-05-08 17:47:47 +00:00
|
|
|
"stickers.chat.${config.pub-solar-os.networking.domain}" = {
|
2024-04-29 22:52:07 +00:00
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
root = pkgs.element-stickerpicker;
|
|
|
|
};
|
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
"mas.${config.pub-solar-os.networking.domain}" = {
|
|
|
|
root = "/dev/null";
|
|
|
|
|
|
|
|
forceSSL = lib.mkDefault true;
|
|
|
|
enableACME = lib.mkDefault true;
|
|
|
|
|
|
|
|
locations = {
|
|
|
|
"/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:8090";
|
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
${commonHeaders}
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
|
|
|
# Forward the client IP address
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-08 17:47:47 +00:00
|
|
|
"matrix.${config.pub-solar-os.networking.domain}" = {
|
2023-10-29 03:48:26 +00:00
|
|
|
root = "/dev/null";
|
|
|
|
|
|
|
|
forceSSL = lib.mkDefault true;
|
|
|
|
enableACME = lib.mkDefault true;
|
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
server_tokens off;
|
|
|
|
gzip on;
|
|
|
|
gzip_types text/plain application/json;
|
|
|
|
'';
|
2023-11-18 16:34:33 +00:00
|
|
|
locations = {
|
2023-11-19 14:47:25 +00:00
|
|
|
# For telegram
|
2023-10-29 03:48:26 +00:00
|
|
|
"/c3c3f34b-29fb-5feb-86e5-98c75ec8214b" = {
|
2024-10-26 00:03:31 +00:00
|
|
|
priority = 100;
|
2023-10-29 03:48:26 +00:00
|
|
|
proxyPass = "http://127.0.0.1:8009";
|
|
|
|
extraConfig = commonHeaders;
|
|
|
|
};
|
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
# Forward to the auth service
|
|
|
|
"~ ^/_matrix/client/(.*)/(login|logout|refresh)" = {
|
|
|
|
priority = 100;
|
|
|
|
proxyPass = "http://127.0.0.1:8090";
|
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
${commonHeaders}
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
|
|
|
# Forward the client IP address
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
'';
|
2023-12-16 12:53:34 +00:00
|
|
|
};
|
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
# Forward to Synapse
|
|
|
|
# as per https://element-hq.github.io/synapse/latest/reverse_proxy.html#nginx
|
|
|
|
"~ ^(/_matrix|/_synapse/client)" = {
|
|
|
|
priority = 200;
|
2023-10-29 03:48:26 +00:00
|
|
|
proxyPass = "http://127.0.0.1:8008";
|
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
${commonHeaders}
|
2024-10-26 00:03:31 +00:00
|
|
|
proxy_set_header X-Forwarded-For $remote_addr;
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
2023-10-29 03:48:26 +00:00
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
|
|
|
client_body_buffer_size 25M;
|
|
|
|
client_max_body_size 50M;
|
|
|
|
proxy_max_temp_file_size 0;
|
2024-10-26 00:03:31 +00:00
|
|
|
proxy_http_version 1.1;
|
2023-10-29 03:48:26 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-05-08 17:47:47 +00:00
|
|
|
"matrix.${config.pub-solar-os.networking.domain}-federation" = {
|
|
|
|
serverName = "matrix.${config.pub-solar-os.networking.domain}";
|
2023-10-29 03:48:26 +00:00
|
|
|
forceSSL = lib.mkDefault true;
|
|
|
|
enableACME = lib.mkDefault true;
|
|
|
|
listen = [
|
|
|
|
{
|
|
|
|
port = 8448;
|
|
|
|
addr = "0.0.0.0";
|
|
|
|
ssl = true;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
port = 8448;
|
|
|
|
addr = "[::]";
|
|
|
|
ssl = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
root = "/dev/null";
|
|
|
|
extraConfig = ''
|
|
|
|
server_tokens off;
|
|
|
|
|
|
|
|
gzip on;
|
|
|
|
gzip_types text/plain application/json;
|
|
|
|
'';
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:8008";
|
|
|
|
extraConfig = ''
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
|
|
|
|
|
|
|
|
client_body_buffer_size 25M;
|
|
|
|
client_max_body_size 150M;
|
|
|
|
proxy_max_temp_file_size 0;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = [ 8448 ];
|
|
|
|
}
|