2023-10-28 00:21:34 +00:00
|
|
|
{
|
|
|
|
flake,
|
|
|
|
config,
|
2024-10-26 00:03:31 +00:00
|
|
|
lib,
|
2023-10-28 00:21:34 +00:00
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
2024-05-08 17:47:47 +00:00
|
|
|
publicDomain = "matrix.${config.pub-solar-os.networking.domain}";
|
|
|
|
serverDomain = "${config.pub-solar-os.networking.domain}";
|
2023-10-28 00:21:34 +00:00
|
|
|
in
|
|
|
|
{
|
2024-10-30 16:57:33 +00:00
|
|
|
options.pub-solar-os = {
|
|
|
|
matrix = {
|
|
|
|
enable = lib.mkEnableOption "Enable matrix-synapse and matrix-authentication-service to run on the node";
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-30 16:57:33 +00:00
|
|
|
synapse = {
|
|
|
|
app-service-config-files = lib.mkOption {
|
|
|
|
description = "List of app service config files";
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ ];
|
|
|
|
};
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-30 16:57:33 +00:00
|
|
|
extra-config-files = lib.mkOption {
|
|
|
|
description = "List of extra synapse config files";
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ ];
|
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
|
2024-10-30 16:57:33 +00:00
|
|
|
signing_key_path = lib.mkOption {
|
|
|
|
description = "Path to file containing the signing key";
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "${config.services.matrix-synapse.dataDir}/homeserver.signing.key";
|
|
|
|
};
|
|
|
|
|
|
|
|
sliding-sync.enable = lib.mkEnableOption {
|
|
|
|
description = "Whether to enable a sliding-sync proxy, no longer needed with synapse version 1.114+";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
matrix-authentication-service = {
|
|
|
|
extra-config-files = lib.mkOption {
|
|
|
|
description = "List of extra mas config files";
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
};
|
2024-10-27 16:27:17 +00:00
|
|
|
};
|
2023-12-16 12:53:34 +00:00
|
|
|
};
|
|
|
|
|
2024-10-30 16:57:33 +00:00
|
|
|
config = lib.mkIf config.pub-solar-os.matrix.enable {
|
2024-10-26 00:03:31 +00:00
|
|
|
services.matrix-synapse = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
server_name = serverDomain;
|
|
|
|
public_baseurl = "https://${publicDomain}/";
|
|
|
|
database = {
|
|
|
|
name = "psycopg2";
|
|
|
|
args = {
|
|
|
|
host = "/run/postgresql";
|
|
|
|
cp_max = 10;
|
|
|
|
cp_min = 5;
|
|
|
|
database = "matrix";
|
|
|
|
};
|
|
|
|
allow_unsafe_locale = false;
|
|
|
|
txn_limit = 0;
|
2023-10-28 00:21:34 +00:00
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
listeners = [
|
|
|
|
{
|
|
|
|
bind_addresses = [ "127.0.0.1" ];
|
|
|
|
port = 8008;
|
|
|
|
resources = [
|
|
|
|
{
|
|
|
|
compress = true;
|
|
|
|
names = [ "client" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
compress = false;
|
|
|
|
names = [ "federation" ];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
tls = false;
|
|
|
|
type = "http";
|
|
|
|
x_forwarded = true;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
bind_addresses = [ "127.0.0.1" ];
|
|
|
|
port = 8012;
|
|
|
|
resources = [ { names = [ "metrics" ]; } ];
|
|
|
|
tls = false;
|
|
|
|
type = "metrics";
|
|
|
|
}
|
|
|
|
];
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
account_threepid_delegates.msisdn = "";
|
|
|
|
alias_creation_rules = [
|
|
|
|
{
|
|
|
|
action = "allow";
|
|
|
|
alias = "*";
|
|
|
|
room_id = "*";
|
|
|
|
user_id = "*";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
allow_guest_access = false;
|
|
|
|
allow_public_rooms_over_federation = true;
|
|
|
|
allow_public_rooms_without_auth = false;
|
|
|
|
auto_join_rooms = [
|
|
|
|
"#community:${serverDomain}"
|
|
|
|
"#general:${serverDomain}"
|
|
|
|
];
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
autocreate_auto_join_rooms = true;
|
|
|
|
caches.global_factor = 0.5;
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
default_room_version = "10";
|
|
|
|
disable_msisdn_registration = true;
|
|
|
|
enable_media_repo = true;
|
|
|
|
enable_metrics = true;
|
|
|
|
mau_stats_only = true;
|
|
|
|
enable_registration = false;
|
|
|
|
enable_registration_captcha = false;
|
|
|
|
enable_registration_without_verification = false;
|
|
|
|
enable_room_list_search = true;
|
|
|
|
encryption_enabled_by_default_for_room_type = "off";
|
|
|
|
event_cache_size = "100K";
|
2024-11-20 17:58:20 +00:00
|
|
|
experimental = {
|
|
|
|
msc4108_enabled = true;
|
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
federation_rr_transactions_per_room_per_second = 50;
|
|
|
|
federation_client_minimum_tls_version = "1.2";
|
|
|
|
forget_rooms_on_leave = true;
|
|
|
|
include_profile_data_on_invite = true;
|
|
|
|
instance_map = { };
|
|
|
|
limit_profile_requests_to_users_who_share_rooms = false;
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
max_spider_size = "10M";
|
|
|
|
max_upload_size = "50M";
|
|
|
|
media_storage_providers = [ ];
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
password_config = {
|
|
|
|
enabled = false;
|
|
|
|
localdb_enabled = false;
|
|
|
|
pepper = "";
|
|
|
|
};
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
presence.enabled = true;
|
|
|
|
push.include_content = false;
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
rc_admin_redaction = {
|
|
|
|
burst_count = 50;
|
|
|
|
per_second = 1;
|
2023-10-28 00:21:34 +00:00
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
rc_federation = {
|
|
|
|
concurrent = 3;
|
|
|
|
reject_limit = 50;
|
|
|
|
sleep_delay = 500;
|
|
|
|
sleep_limit = 10;
|
|
|
|
window_size = 1000;
|
2023-10-28 00:21:34 +00:00
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
rc_invites = {
|
|
|
|
per_issuer = {
|
|
|
|
burst_count = 10;
|
|
|
|
per_second = 0.3;
|
|
|
|
};
|
|
|
|
per_room = {
|
|
|
|
burst_count = 10;
|
|
|
|
per_second = 0.3;
|
|
|
|
};
|
|
|
|
per_user = {
|
|
|
|
burst_count = 5;
|
|
|
|
per_second = 3.0e-3;
|
|
|
|
};
|
2023-10-28 00:21:34 +00:00
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
rc_joins = {
|
|
|
|
local = {
|
|
|
|
burst_count = 10;
|
|
|
|
per_second = 0.1;
|
|
|
|
};
|
|
|
|
remote = {
|
|
|
|
burst_count = 10;
|
|
|
|
per_second = 1.0e-2;
|
|
|
|
};
|
2023-10-28 00:21:34 +00:00
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
rc_login = {
|
|
|
|
account = {
|
|
|
|
burst_count = 3;
|
|
|
|
per_second = 0.17;
|
|
|
|
};
|
|
|
|
address = {
|
|
|
|
burst_count = 3;
|
|
|
|
per_second = 0.17;
|
|
|
|
};
|
|
|
|
failed_attempts = {
|
|
|
|
burst_count = 3;
|
|
|
|
per_second = 0.17;
|
|
|
|
};
|
2023-10-28 00:21:34 +00:00
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
rc_message = {
|
|
|
|
burst_count = 10;
|
|
|
|
per_second = 0.2;
|
2023-10-28 00:21:34 +00:00
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
rc_registration = {
|
2023-10-28 00:21:34 +00:00
|
|
|
burst_count = 3;
|
|
|
|
per_second = 0.17;
|
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
redaction_retention_period = "7d";
|
|
|
|
forgotten_room_retention_period = "7d";
|
|
|
|
redis.enabled = false;
|
|
|
|
registration_requires_token = false;
|
|
|
|
registrations_require_3pid = [ "email" ];
|
|
|
|
report_stats = false;
|
|
|
|
require_auth_for_profile_requests = false;
|
|
|
|
room_list_publication_rules = [
|
|
|
|
{
|
|
|
|
action = "allow";
|
|
|
|
alias = "*";
|
|
|
|
room_id = "*";
|
|
|
|
user_id = "*";
|
|
|
|
}
|
|
|
|
];
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-30 17:34:25 +00:00
|
|
|
signing_key_path = config.pub-solar-os.matrix.synapse.signing_key_path;
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
stream_writers = { };
|
|
|
|
trusted_key_servers = [ { server_name = "matrix.org"; } ];
|
|
|
|
suppress_key_server_warning = true;
|
2023-11-19 16:22:09 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
turn_allow_guests = false;
|
|
|
|
turn_uris = [
|
|
|
|
"turn:${config.services.coturn.realm}:3478?transport=udp"
|
|
|
|
"turn:${config.services.coturn.realm}:3478?transport=tcp"
|
|
|
|
];
|
|
|
|
turn_user_lifetime = "1h";
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
url_preview_accept_language = [
|
|
|
|
"en-US"
|
|
|
|
"en"
|
|
|
|
];
|
|
|
|
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"
|
|
|
|
"::1/128"
|
|
|
|
"fe80::/10"
|
|
|
|
"fc00::/7"
|
|
|
|
"2001:db8::/32"
|
|
|
|
"ff00::/8"
|
|
|
|
"fec0::/10"
|
|
|
|
];
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
user_directory = {
|
|
|
|
prefer_local_users = false;
|
|
|
|
search_all_users = false;
|
|
|
|
};
|
|
|
|
user_ips_max_age = "28d";
|
2024-01-25 19:21:50 +00:00
|
|
|
|
2024-10-30 17:34:25 +00:00
|
|
|
app_service_config_files = config.pub-solar-os.matrix.synapse.app-service-config-files;
|
2024-10-26 00:03:31 +00:00
|
|
|
};
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
withJemalloc = true;
|
2023-10-28 00:21:34 +00:00
|
|
|
|
2024-10-30 17:34:25 +00:00
|
|
|
extraConfigFiles = config.pub-solar-os.matrix.synapse.extra-config-files;
|
2023-12-02 14:35:02 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
extras = [
|
|
|
|
"oidc"
|
|
|
|
"redis"
|
|
|
|
];
|
2023-12-16 12:53:34 +00:00
|
|
|
|
2024-10-26 00:03:31 +00:00
|
|
|
plugins = [ config.services.matrix-synapse.package.plugins.matrix-synapse-shared-secret-auth ];
|
2023-12-16 12:53:34 +00:00
|
|
|
};
|
2023-12-03 12:11:25 +00:00
|
|
|
|
2024-10-30 16:57:33 +00:00
|
|
|
services.matrix-authentication-service = {
|
|
|
|
enable = true;
|
|
|
|
createDatabase = true;
|
|
|
|
extraConfigFiles = config.pub-solar-os.matrix.matrix-authentication-service.extra-config-files;
|
|
|
|
|
2024-11-19 12:57:23 +00:00
|
|
|
# https://element-hq.github.io/matrix-authentication-service/reference/configuration.html
|
2024-10-30 16:57:33 +00:00
|
|
|
settings = {
|
2024-11-19 12:57:23 +00:00
|
|
|
account.email_change_allowed = false;
|
2024-10-30 16:57:33 +00:00
|
|
|
http.public_base = "https://mas.${config.pub-solar-os.networking.domain}";
|
|
|
|
http.issuer = "https://mas.${config.pub-solar-os.networking.domain}";
|
|
|
|
http.listeners = [
|
|
|
|
{
|
|
|
|
name = "web";
|
|
|
|
resources = [
|
|
|
|
{ name = "discovery"; }
|
|
|
|
{ name = "human"; }
|
|
|
|
{ name = "oauth"; }
|
|
|
|
{ name = "compat"; }
|
|
|
|
{ name = "graphql"; }
|
|
|
|
{
|
|
|
|
name = "assets";
|
|
|
|
path = "${config.services.matrix-authentication-service.package}/share/matrix-authentication-service/assets";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
binds = [
|
|
|
|
{
|
|
|
|
host = "0.0.0.0";
|
|
|
|
port = 8090;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
proxy_protocol = false;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "internal";
|
|
|
|
resources = [
|
|
|
|
{ name = "health"; }
|
|
|
|
];
|
|
|
|
binds = [
|
|
|
|
{
|
|
|
|
host = "0.0.0.0";
|
|
|
|
port = 8081;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
proxy_protocol = false;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
passwords.enabled = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-27 16:27:17 +00:00
|
|
|
services.matrix-sliding-sync = {
|
2024-10-30 17:34:25 +00:00
|
|
|
enable = config.pub-solar-os.matrix.synapse.sliding-sync.enable;
|
2024-10-27 16:27:17 +00:00
|
|
|
settings = {
|
|
|
|
SYNCV3_SERVER = "https://${publicDomain}";
|
|
|
|
SYNCV3_BINDADDR = "127.0.0.1:8011";
|
|
|
|
# The bind addr for Prometheus metrics, which will be accessible at
|
|
|
|
# /metrics at this address
|
|
|
|
SYNCV3_PROM = "127.0.0.1:9100";
|
|
|
|
};
|
2024-10-30 19:32:47 +00:00
|
|
|
environmentFile = config.age.secrets."matrix-synapse-sliding-sync-secret".path;
|
2024-10-27 16:27:17 +00:00
|
|
|
};
|
2024-10-26 00:03:31 +00:00
|
|
|
|
|
|
|
pub-solar-os.backups.restic.matrix-synapse = {
|
|
|
|
paths = [
|
|
|
|
"/var/lib/matrix-synapse"
|
|
|
|
"/var/lib/matrix-appservice-irc"
|
|
|
|
"/var/lib/mautrix-telegram"
|
|
|
|
"/tmp/matrix-synapse-backup.sql"
|
|
|
|
];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "*-*-* 05:00:00 Etc/UTC";
|
|
|
|
};
|
|
|
|
initialize = true;
|
|
|
|
backupPrepareCommand = ''
|
|
|
|
${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/pg_dump -d matrix > /tmp/matrix-synapse-backup.sql
|
|
|
|
'';
|
|
|
|
backupCleanupCommand = ''
|
|
|
|
rm /tmp/matrix-synapse-backup.sql
|
|
|
|
'';
|
|
|
|
pruneOpts = [
|
|
|
|
"--keep-daily 7"
|
|
|
|
"--keep-weekly 4"
|
|
|
|
"--keep-monthly 3"
|
|
|
|
];
|
2023-12-03 12:11:25 +00:00
|
|
|
};
|
|
|
|
};
|
2023-10-28 00:21:34 +00:00
|
|
|
}
|