nixos-config/config/services/synapse.nix

131 lines
3.6 KiB
Nix
Raw Normal View History

2022-06-12 15:39:15 +00:00
{
pkgs,
lib,
config,
...
}: {
2022-05-01 06:50:10 +00:00
services.matrix-synapse = {
enable = true;
settings = {
server_name = "chir.rs";
public_baseurl = "https://matrix.chir.rs/";
2022-06-12 15:39:15 +00:00
listeners = [
{
port = 8008;
tls = false;
type = "http";
x_forwarded = true;
bind_addresses = ["::1" "127.0.0.1"];
resources = [
{
names = ["client" "federation" "metrics"];
compress = false;
}
];
}
];
2022-05-01 06:50:10 +00:00
admin_contact = "mailto:lotte@chir.rs";
retention.enabled = true;
database = {
name = "psycopg2";
txn_limit = 10000;
args = {
host = "/run/postgresql";
user = "matrix-synapse";
database = "synapse";
};
};
enable_media_repo = false;
url_preview_enabled = true;
url_preview_ip_range_blacklist = [
"127.0.0.0/8"
"10.0.0.0/8"
"172.16.0.0/12"
"192.168.0.0/16"
"100.64.0.0/10"
"192.0.0.0/24"
"169.254.0.0/16"
"192.88.99.0/24"
"198.18.0.0/15"
"192.0.2.0/24"
"198.51.100.0/24"
"203.0.113.0/24"
"224.0.0.0/4"
"fe80::/10"
"fc00::/7"
"2001:db8::/32"
"ff00::/8"
"fec0::/10"
];
enable_registration = false;
app_service_config_files = [
"/var/lib/mautrix-telegram/telegram-registration.yaml"
2022-07-22 16:19:40 +00:00
#config.sops.secrets."services/synapse/discord-dev-registration.yaml".path
2022-05-01 06:50:10 +00:00
];
signing_key_path = config.sops.secrets."services/synapse/private_key".path;
encryption_enabled_by_default_for_room_type = "all";
2022-05-03 09:31:27 +00:00
enable_metrics = true;
2022-05-03 19:25:44 +00:00
experimental_features = {
msc2716_enabled = true;
spaces_enabled = true;
};
2022-05-28 08:34:31 +00:00
#sentry.dsn = "https://18e36e6f16b5490c83364101717cddba@o253952.ingest.sentry.io/6449283";
2022-05-01 06:50:10 +00:00
};
withJemalloc = true;
};
2022-06-12 15:39:15 +00:00
sops.secrets."services/synapse/private_key" = {owner = "matrix-synapse";};
sops.secrets."services/synapse/discord-dev-registration.yaml" = {owner = "matrix-synapse";};
2022-05-01 06:50:10 +00:00
services.postgresql.ensureDatabases = [
"synapse"
];
2022-06-12 15:39:15 +00:00
services.postgresql.ensureUsers = [
{
name = "matrix-synapse";
ensurePermissions = {
"DATABASE synapse" = "ALL PRIVILEGES";
};
}
];
2022-05-01 07:08:05 +00:00
systemd.services.matrix-synapse.serviceConfig.ExecStartPre = lib.mkForce (pkgs.writeShellScript "dummy" "true");
2022-06-12 15:39:15 +00:00
services.nginx.virtualHosts = let
2022-06-12 15:42:42 +00:00
inherit ((import ../../utils/getInternalIP.nix config)) listenIPs;
2022-06-12 15:39:15 +00:00
listenStatements =
lib.concatStringsSep "\n" (builtins.map (ip: "listen ${ip}:443 http3;") listenIPs)
+ ''
2022-05-01 07:04:58 +00:00
add_header Alt-Svc 'h3=":443"';
'';
2022-06-12 15:39:15 +00:00
synapse = {
forceSSL = false;
addSSL = true;
listenAddresses = listenIPs;
locations."/_matrix" = {
proxyPass = "http://localhost:8008";
2022-05-01 07:04:58 +00:00
};
2022-06-12 15:39:15 +00:00
locations."/_synapse" = {
proxyPass = "http://localhost:8008";
};
locations."/_matrix/media" = {
proxyPass = "https://matrix.chir.rs";
proxyWebsockets = true;
extraConfig = ''
proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Origin '*' always;
'';
};
};
in {
"matrix.chir.rs" =
synapse
// {
2022-05-01 07:04:58 +00:00
sslCertificate = "/var/lib/acme/chir.rs/cert.pem";
sslCertificateKey = "/var/lib/acme/chir.rs/key.pem";
};
2022-06-12 15:39:15 +00:00
"matrix.int.chir.rs" =
synapse
// {
2022-05-01 07:04:58 +00:00
sslCertificate = "/var/lib/acme/int.chir.rs/cert.pem";
sslCertificateKey = "/var/lib/acme/int.chir.rs/key.pem";
};
2022-06-12 15:39:15 +00:00
};
2022-05-01 06:50:10 +00:00
}