2023-01-20 08:24:02 +01:00
|
|
|
{ config, lib, pkgs, values, inputs, ... }:
|
2021-10-17 11:00:52 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.matrix-synapse-next;
|
|
|
|
|
2023-01-20 08:24:02 +01:00
|
|
|
matrix-lib = inputs.matrix-next.lib;
|
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
imap0Attrs = with lib; f: set:
|
|
|
|
listToAttrs (imap0 (i: attr: nameValuePair attr (f i attr set.${attr})) (attrNames set));
|
|
|
|
in {
|
2022-12-09 06:24:28 +01:00
|
|
|
sops.secrets."matrix/synapse/signing_key" = {
|
2023-05-07 10:14:09 +02:00
|
|
|
key = "synapse/signing_key";
|
|
|
|
sopsFile = ../../../../secrets/bicep/matrix.yaml;
|
2022-12-09 06:24:28 +01:00
|
|
|
owner = config.users.users.matrix-synapse.name;
|
|
|
|
group = config.users.users.matrix-synapse.group;
|
|
|
|
};
|
|
|
|
|
2023-02-13 00:19:14 +01:00
|
|
|
sops.secrets."matrix/synapse/user_registration" = {
|
2023-05-07 10:14:09 +02:00
|
|
|
sopsFile = ../../../../secrets/bicep/matrix.yaml;
|
|
|
|
key = "synapse/signing_key";
|
2023-02-13 00:19:14 +01:00
|
|
|
owner = config.users.users.matrix-synapse.name;
|
|
|
|
group = config.users.users.matrix-synapse.group;
|
|
|
|
};
|
|
|
|
|
2023-10-22 02:33:40 +02:00
|
|
|
sops.secrets."matrix/sliding-sync/env" = {
|
|
|
|
sopsFile = ../../../../secrets/bicep/matrix.yaml;
|
|
|
|
key = "sliding-sync/env";
|
|
|
|
};
|
|
|
|
|
2021-10-17 11:00:52 +02:00
|
|
|
services.matrix-synapse-next = {
|
|
|
|
enable = true;
|
|
|
|
|
2023-10-22 01:10:03 +02:00
|
|
|
plugins = [
|
|
|
|
(pkgs.python3Packages.callPackage ./smtp-authenticator { })
|
|
|
|
];
|
|
|
|
|
2021-10-17 11:00:52 +02:00
|
|
|
dataDir = "/data/synapse";
|
|
|
|
|
2023-02-06 02:11:07 +01:00
|
|
|
workers.federationSenders = 2;
|
|
|
|
workers.federationReceivers = 2;
|
2022-12-09 10:53:49 +01:00
|
|
|
workers.initialSyncers = 1;
|
|
|
|
workers.normalSyncers = 1;
|
2023-02-06 02:11:07 +01:00
|
|
|
workers.eventPersisters = 2;
|
2022-12-14 10:15:37 +01:00
|
|
|
workers.useUserDirectoryWorker = true;
|
2022-12-07 10:14:39 +01:00
|
|
|
|
2023-10-22 02:33:40 +02:00
|
|
|
enableSlidingSync = true;
|
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
enableNginx = true;
|
|
|
|
|
2021-10-17 11:00:52 +02:00
|
|
|
settings = {
|
|
|
|
server_name = "pvv.ntnu.no";
|
2021-10-19 15:54:22 +02:00
|
|
|
public_baseurl = "https://matrix.pvv.ntnu.no";
|
2021-10-17 11:00:52 +02:00
|
|
|
|
2022-12-09 06:24:28 +01:00
|
|
|
signing_key_path = config.sops.secrets."matrix/synapse/signing_key".path;
|
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
media_store_path = "${cfg.dataDir}/media";
|
2021-10-17 11:00:52 +02:00
|
|
|
|
2023-09-15 06:41:49 +02:00
|
|
|
database = {
|
|
|
|
name = "psycopg2";
|
|
|
|
args = {
|
|
|
|
host = "/var/run/postgresql";
|
|
|
|
dbname = "synapse";
|
|
|
|
user = "matrix-synapse";
|
|
|
|
cp_min = 1;
|
|
|
|
cp_max = 5;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-02-02 18:39:08 +01:00
|
|
|
presence.enabled = false;
|
|
|
|
|
2023-05-26 02:22:18 +02:00
|
|
|
event_cache_size = "20K"; # Default is 10K but I can't find the factor for this cache
|
2023-03-08 03:18:57 +01:00
|
|
|
caches = {
|
|
|
|
per_cache_factors = {
|
|
|
|
_event_auth_cache = 2.0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
autocreate_auto_join_rooms = false;
|
|
|
|
auto_join_rooms = [
|
|
|
|
"#pvv:pvv.ntnu.no" # Main space
|
|
|
|
"#announcements:pvv.ntnu.no"
|
|
|
|
"#general:pvv.ntnu.no"
|
2021-10-17 11:00:52 +02:00
|
|
|
];
|
|
|
|
|
2022-12-09 15:58:40 +01:00
|
|
|
allow_public_rooms_over_federation = true;
|
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
max_upload_size = "150M";
|
2021-10-17 11:00:52 +02:00
|
|
|
|
|
|
|
enable_metrics = true;
|
2023-02-01 19:42:49 +01:00
|
|
|
mau_stats_only = true;
|
2021-10-17 11:00:52 +02:00
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
enable_registration = false;
|
2023-09-13 04:53:56 +02:00
|
|
|
registration_shared_secret_path = config.sops.secrets."matrix/synapse/user_registration".path;
|
2021-12-15 18:14:48 +01:00
|
|
|
|
2023-10-22 01:10:03 +02:00
|
|
|
password_config.enabled = true;
|
|
|
|
|
|
|
|
modules = [
|
|
|
|
{ module = "smtp_auth_provider.SMTPAuthProvider";
|
|
|
|
config = {
|
|
|
|
smtp_host = "smtp.pvv.ntnu.no";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2022-01-22 21:10:17 +01:00
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
trusted_key_servers = [
|
|
|
|
{ server_name = "matrix.org"; }
|
|
|
|
{ server_name = "dodsorf.as"; }
|
|
|
|
];
|
2022-01-22 21:10:17 +01:00
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
url_preview_enabled = true;
|
|
|
|
url_preview_ip_range_blacklist = [
|
|
|
|
# synapse example config
|
|
|
|
"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"
|
|
|
|
|
|
|
|
# NTNU
|
|
|
|
"129.241.0.0/16"
|
|
|
|
"2001:700:300::/44"
|
|
|
|
];
|
2021-10-17 11:00:52 +02:00
|
|
|
};
|
2022-12-07 10:14:39 +01:00
|
|
|
};
|
2021-10-17 11:00:52 +02:00
|
|
|
|
2023-10-22 02:33:40 +02:00
|
|
|
services.matrix-synapse.sliding-sync.environmentFile = config.sops.secrets."matrix/sliding-sync/env".path;
|
|
|
|
|
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
services.redis.servers."".enable = true;
|
2024-08-04 02:30:25 +02:00
|
|
|
|
2023-11-28 08:36:56 +01:00
|
|
|
services.nginx.virtualHosts."matrix.pvv.ntnu.no" = lib.mkMerge [
|
2024-08-04 01:45:57 +02:00
|
|
|
{
|
2024-04-10 22:01:19 +02:00
|
|
|
kTLS = true;
|
2024-08-04 01:45:57 +02:00
|
|
|
}
|
|
|
|
{
|
2023-11-28 08:36:56 +01:00
|
|
|
locations."/.well-known/matrix/server" = {
|
|
|
|
return = ''
|
|
|
|
200 '{"m.server": "matrix.pvv.ntnu.no:443"}'
|
|
|
|
'';
|
|
|
|
extraConfig = ''
|
|
|
|
default_type application/json;
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
'';
|
|
|
|
};
|
2024-08-04 01:45:57 +02:00
|
|
|
}
|
2024-09-01 00:34:22 +02:00
|
|
|
{
|
|
|
|
locations."/_synapse/admin" = {
|
|
|
|
proxyPass = "http://$synapse_backend";
|
|
|
|
extraConfig = ''
|
|
|
|
allow 127.0.0.1;
|
|
|
|
allow ::1;
|
|
|
|
allow ${values.hosts.bicep.ipv4};
|
|
|
|
allow ${values.hosts.bicep.ipv6};
|
|
|
|
deny all;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|
2024-08-04 01:45:57 +02:00
|
|
|
{
|
2022-12-07 10:14:39 +01:00
|
|
|
locations = let
|
2023-01-20 08:24:02 +01:00
|
|
|
connectionInfo = w: matrix-lib.workerConnectionResource "metrics" w;
|
2024-08-04 01:45:57 +02:00
|
|
|
socketAddress = w: let c = connectionInfo w; in "${c.host}:${toString c.port}";
|
2021-10-17 11:00:52 +02:00
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
metricsPath = w: "/metrics/${w.type}/${toString w.index}";
|
|
|
|
proxyPath = w: "http://${socketAddress w}/_synapse/metrics";
|
2023-01-17 18:23:42 +01:00
|
|
|
in lib.mapAttrs' (n: v: lib.nameValuePair
|
2024-08-04 01:45:57 +02:00
|
|
|
(metricsPath v) {
|
2023-01-17 18:23:42 +01:00
|
|
|
proxyPass = proxyPath v;
|
|
|
|
extraConfig = ''
|
2023-01-21 19:51:10 +01:00
|
|
|
allow ${values.hosts.ildkule.ipv4};
|
|
|
|
allow ${values.hosts.ildkule.ipv6};
|
2024-04-24 03:03:48 +02:00
|
|
|
allow ${values.hosts.ildkule.ipv4_global};
|
|
|
|
allow ${values.hosts.ildkule.ipv6_global};
|
2023-01-17 18:23:42 +01:00
|
|
|
deny all;
|
|
|
|
'';
|
2024-08-04 01:45:57 +02:00
|
|
|
})
|
2022-12-07 10:14:39 +01:00
|
|
|
cfg.workers.instances;
|
2024-08-04 01:45:57 +02:00
|
|
|
}
|
|
|
|
{
|
2022-12-07 10:14:39 +01:00
|
|
|
locations."/metrics/master/1" = {
|
|
|
|
proxyPass = "http://127.0.0.1:9000/_synapse/metrics";
|
2023-01-17 10:30:20 +01:00
|
|
|
extraConfig = ''
|
2023-01-21 19:51:10 +01:00
|
|
|
allow ${values.hosts.ildkule.ipv4};
|
|
|
|
allow ${values.hosts.ildkule.ipv6};
|
2024-04-24 03:03:48 +02:00
|
|
|
allow ${values.hosts.ildkule.ipv4_global};
|
|
|
|
allow ${values.hosts.ildkule.ipv6_global};
|
2023-01-17 10:30:20 +01:00
|
|
|
deny all;
|
|
|
|
'';
|
2021-10-17 11:00:52 +02:00
|
|
|
};
|
2022-12-07 10:14:39 +01:00
|
|
|
|
|
|
|
locations."/metrics/" = let
|
2023-01-20 05:04:16 +01:00
|
|
|
endpoints = lib.pipe cfg.workers.instances [
|
2023-01-18 02:54:57 +01:00
|
|
|
(lib.mapAttrsToList (_: v: v))
|
2023-01-20 05:04:16 +01:00
|
|
|
(map (w: "${w.type}/${toString w.index}"))
|
|
|
|
(map (w: "matrix.pvv.ntnu.no/metrics/${w}"))
|
|
|
|
] ++ [ "matrix.pvv.ntnu.no/metrics/master/1" ];
|
2022-12-07 10:14:39 +01:00
|
|
|
in {
|
2023-01-20 05:04:16 +01:00
|
|
|
alias = pkgs.writeTextDir "/config.json"
|
|
|
|
(builtins.toJSON [
|
|
|
|
{ targets = endpoints;
|
|
|
|
labels = { };
|
|
|
|
}]) + "/";
|
2021-10-17 11:00:52 +02:00
|
|
|
};
|
2024-08-04 01:45:57 +02:00
|
|
|
}];
|
2021-10-17 11:00:52 +02:00
|
|
|
}
|