2023-05-11 05:33:08 +07:00
|
|
|
{ config
|
|
|
|
, lib
|
2024-06-06 23:20:08 +07:00
|
|
|
, pkgs
|
2023-05-11 05:33:08 +07:00
|
|
|
, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.server;
|
|
|
|
matrixServerJson = {
|
|
|
|
"m.server" = "matrix.${cfg.domainName}:443";
|
|
|
|
};
|
|
|
|
matrixClientJson = {
|
2023-12-24 14:27:43 +07:00
|
|
|
"m.homeserver".base_url = "https://matrix.${cfg.domainName}";
|
|
|
|
"m.identity_server".base_url = "https://vector.im";
|
2024-08-24 03:01:12 +07:00
|
|
|
"org.matrix.msc3575.proxy".url = "https://matrix.${cfg.domainName}";
|
2023-05-11 05:33:08 +07:00
|
|
|
};
|
|
|
|
matrixServerConfigResponse = ''
|
|
|
|
add_header Content-Type application/json;
|
2023-12-24 14:27:43 +07:00
|
|
|
return 200 ${builtins.toJSON (builtins.toJSON matrixServerJson)};
|
2023-05-11 05:33:08 +07:00
|
|
|
'';
|
|
|
|
matrixClientConfigResponse = ''
|
|
|
|
add_header Content-Type application/json;
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
2023-12-24 14:27:43 +07:00
|
|
|
return 200 ${builtins.toJSON (builtins.toJSON matrixClientJson)};
|
2023-05-11 05:33:08 +07:00
|
|
|
'';
|
|
|
|
matrixAddr = "::1";
|
|
|
|
matrixPort = 8008;
|
|
|
|
in {
|
|
|
|
imports = [ ./maubot.nix ];
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ 8008 8448 ];
|
2023-08-04 08:30:16 +07:00
|
|
|
systemd.services.matrix-synapse.serviceConfig.TimeoutStartSec = 900;
|
2023-05-11 05:33:08 +07:00
|
|
|
|
|
|
|
services.nginx.virtualHosts."${cfg.domainName}" = {
|
|
|
|
locations."= /.well-known/matrix/server".extraConfig = matrixServerConfigResponse;
|
|
|
|
locations."= /.well-known/matrix/client".extraConfig = matrixClientConfigResponse;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."matrix.${cfg.domainName}" = {
|
2023-07-28 09:59:47 +07:00
|
|
|
quic = true;
|
2023-05-11 05:33:08 +07:00
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations = {
|
|
|
|
"= /.well-known/matrix/server".extraConfig = matrixServerConfigResponse;
|
|
|
|
"= /.well-known/matrix/client".extraConfig = matrixClientConfigResponse;
|
2024-09-13 23:01:22 +07:00
|
|
|
"~ ^/(_matrix(?!/maubot)|_synapse/client|$)".proxyPass = "http://${lib.quoteListenAddr matrixAddr}:${toString matrixPort}";
|
2024-08-24 03:01:12 +07:00
|
|
|
"~ ^/(client/|_matrix/client/unstable/org.matrix.msc3575/)".proxyPass = "http://${config.services.matrix-sliding-sync.settings.SYNCV3_BINDADDR}";
|
2023-05-11 05:33:08 +07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-06-11 21:48:35 +07:00
|
|
|
# systemd.services.heisenbridge.wants = [ "matrix-synapse.service" ];
|
|
|
|
# systemd.services.heisenbridge.after = [ "matrix-synapse.service" ];
|
2023-05-11 05:33:08 +07:00
|
|
|
services.heisenbridge = {
|
|
|
|
enable = true;
|
2023-05-17 06:29:03 +07:00
|
|
|
homeserver = "http://${lib.quoteListenAddr matrixAddr}:${toString matrixPort}/";
|
2023-05-11 05:33:08 +07:00
|
|
|
};
|
|
|
|
|
2024-06-06 23:20:08 +07:00
|
|
|
services.matrix-appservice-discord = {
|
|
|
|
enable = true;
|
|
|
|
environmentFile = "/secrets/discord-bridge-token";
|
|
|
|
settings = {
|
|
|
|
auth.usePrivilegedIntents = true;
|
|
|
|
database.filename = "";
|
|
|
|
bridge = {
|
|
|
|
domain = "matrix.${cfg.domainName}";
|
|
|
|
homeserverUrl = "https://matrix.${cfg.domainName}";
|
|
|
|
enableSelfServiceBridging = true;
|
|
|
|
disablePresence = true;
|
|
|
|
disablePortalBridging = true;
|
|
|
|
disableInviteNotifications = true;
|
|
|
|
disableJoinLeaveNotifications = true;
|
|
|
|
disableRoomTopicNotifications = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-23 10:48:53 +07:00
|
|
|
environment.systemPackages = with pkgs; [ matrix-synapse-tools.rust-synapse-compress-state ];
|
|
|
|
|
2023-05-11 05:33:08 +07:00
|
|
|
services.matrix-synapse = {
|
|
|
|
enable = true;
|
|
|
|
extraConfigFiles = [ "/var/lib/matrix-synapse/config.yaml" ];
|
2024-09-13 23:01:22 +07:00
|
|
|
log.root.level = "WARNING";
|
2023-05-11 05:33:08 +07:00
|
|
|
settings = {
|
|
|
|
app_service_config_files = [
|
|
|
|
"/var/lib/heisenbridge/registration.yml"
|
2024-06-06 23:20:08 +07:00
|
|
|
"/var/lib/matrix-synapse/discord-registration.yaml"
|
2023-05-11 05:33:08 +07:00
|
|
|
];
|
|
|
|
allow_guest_access = true;
|
|
|
|
url_preview_enabled = true;
|
2023-07-28 09:59:47 +07:00
|
|
|
# tls_certificate_path = config.security.acme.certs."matrix.${cfg.domainName}".directory + "/fullchain.pem";
|
|
|
|
# tls_private_key_path = config.security.acme.certs."matrix.${cfg.domainName}".directory + "/key.pem";
|
2023-05-11 05:33:08 +07:00
|
|
|
public_baseurl = "https://matrix.${cfg.domainName}/";
|
|
|
|
server_name = "matrix.${cfg.domainName}";
|
|
|
|
max_upload_size = "100M";
|
|
|
|
email = {
|
2023-08-28 00:46:51 +07:00
|
|
|
smtp_host = "mail.${cfg.domainName}";
|
2023-05-11 05:33:08 +07:00
|
|
|
smtp_port = 587;
|
|
|
|
smtp_user = "noreply";
|
|
|
|
smtp_password = cfg.unhashedNoreplyPassword;
|
|
|
|
notif_from = "${cfg.domainName} matrix homeserver <noreply@${cfg.domainName}>";
|
|
|
|
app_name = cfg.domainName;
|
|
|
|
notif_for_new_users = false;
|
|
|
|
enable_notifs = true;
|
|
|
|
};
|
|
|
|
listeners = [{
|
|
|
|
port = matrixPort;
|
|
|
|
bind_addresses = [ matrixAddr ];
|
|
|
|
type = "http";
|
|
|
|
tls = false;
|
|
|
|
x_forwarded = true;
|
|
|
|
resources = [{
|
|
|
|
names = [ "client" "federation" ];
|
|
|
|
compress = false;
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
};
|
2024-08-24 03:01:12 +07:00
|
|
|
|
|
|
|
services.matrix-sliding-sync = {
|
|
|
|
enable = true;
|
|
|
|
environmentFile = "/secrets/sliding-sync/env";
|
|
|
|
settings = {
|
|
|
|
SYNCV3_BINDADDR = "[::]:8010";
|
|
|
|
SYNCV3_SERVER = "https://matrix.pavluk.org";
|
|
|
|
};
|
|
|
|
};
|
2023-05-11 05:33:08 +07:00
|
|
|
}
|