2023-01-17 10:30:20 +01:00
|
|
|
{ config, lib, pkgs, values, ... }:
|
2021-10-17 11:00:52 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.matrix-synapse-next;
|
|
|
|
|
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 {
|
|
|
|
sops.secrets."matrix/synapse/dbconfig" = {
|
|
|
|
owner = config.users.users.matrix-synapse.name;
|
|
|
|
group = config.users.users.matrix-synapse.group;
|
|
|
|
};
|
|
|
|
|
2022-12-09 06:24:28 +01:00
|
|
|
sops.secrets."matrix/synapse/signing_key" = {
|
|
|
|
owner = config.users.users.matrix-synapse.name;
|
|
|
|
group = config.users.users.matrix-synapse.group;
|
|
|
|
};
|
|
|
|
|
2021-10-17 11:00:52 +02:00
|
|
|
services.matrix-synapse-next = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
dataDir = "/data/synapse";
|
|
|
|
|
2022-12-14 10:25:29 +01:00
|
|
|
workers.federationSenders = 2;
|
2022-12-07 10:14:39 +01:00
|
|
|
workers.federationReceivers = 1;
|
2022-12-09 10:53:49 +01:00
|
|
|
workers.initialSyncers = 1;
|
|
|
|
workers.normalSyncers = 1;
|
2022-12-14 09:16:43 +01:00
|
|
|
workers.eventPersisters = 1;
|
2022-12-14 10:15:37 +01:00
|
|
|
workers.useUserDirectoryWorker = true;
|
2022-12-07 10:14:39 +01:00
|
|
|
|
|
|
|
enableNginx = true;
|
|
|
|
|
|
|
|
extraConfigFiles = [
|
|
|
|
config.sops.secrets."matrix/synapse/dbconfig".path
|
|
|
|
];
|
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
|
|
|
|
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;
|
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
enable_registration = false;
|
2021-12-15 18:14:48 +01:00
|
|
|
|
2022-01-22 21:10:17 +01:00
|
|
|
password_config.enabled = lib.mkForce false;
|
|
|
|
|
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"
|
|
|
|
];
|
2022-01-22 21:10:17 +01:00
|
|
|
|
2021-12-15 18:14:48 +01:00
|
|
|
saml2_config = {
|
|
|
|
sp_config.metadata.remote = [
|
|
|
|
{ url = "https://idp.pvv.ntnu.no/simplesaml/saml2/idp/metadata.php"; }
|
|
|
|
];
|
|
|
|
|
|
|
|
description = [ "Matrix Synapse SP" "en" ];
|
|
|
|
name = [ "Matrix Synapse SP" "en" ];
|
|
|
|
|
|
|
|
ui_info = {
|
|
|
|
display_name = [
|
|
|
|
{
|
|
|
|
lang = "en";
|
|
|
|
text = "PVV Matrix login";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
description = [
|
|
|
|
{
|
|
|
|
lang = "en";
|
|
|
|
text = "Matrix is a modern free and open federated chat protocol";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
#information_url = [
|
|
|
|
# {
|
|
|
|
# lang = "en";
|
|
|
|
# text = "";
|
|
|
|
# };
|
|
|
|
#];
|
|
|
|
#privacy_statement_url = [
|
|
|
|
# {
|
|
|
|
# lang = "en";
|
|
|
|
# text = "";
|
|
|
|
# };
|
|
|
|
#];
|
|
|
|
keywords = [
|
|
|
|
{
|
|
|
|
lang = "en";
|
|
|
|
text = [ "Matrix" "Element" ];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
#logo = [
|
|
|
|
# {
|
|
|
|
# lang = "en";
|
|
|
|
# text = "";
|
|
|
|
# width = "";
|
|
|
|
# height = "";
|
|
|
|
# }
|
|
|
|
#];
|
|
|
|
};
|
|
|
|
|
|
|
|
organization = {
|
|
|
|
name = "Programvareverkstedet";
|
|
|
|
display_name = [ "Programvareverkstedet" "en" ];
|
|
|
|
url = "https://www.pvv.ntnu.no";
|
|
|
|
};
|
|
|
|
contact_person = [
|
2022-12-07 10:14:39 +01:00
|
|
|
{ given_name = "Drift";
|
2021-12-15 18:14:48 +01:00
|
|
|
sur_name = "King";
|
|
|
|
email_adress = [ "drift@pvv.ntnu.no" ];
|
|
|
|
contact_type = "technical";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
user_mapping_provider = {
|
|
|
|
config = {
|
|
|
|
mxid_source_attribute = "uid"; # What is this supposed to be?
|
|
|
|
mxid_mapping = "hexencode";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#attribute_requirements = [
|
|
|
|
# {attribute = "userGroup"; value = "medlem";} # Do we have this?
|
|
|
|
#];
|
2021-10-17 11:00:52 +02:00
|
|
|
};
|
|
|
|
};
|
2022-12-07 10:14:39 +01:00
|
|
|
};
|
2021-10-17 11:00:52 +02:00
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
services.redis.servers."".enable = true;
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."matrix.pvv.ntnu.no" = lib.mkMerge [({
|
|
|
|
locations = let
|
|
|
|
isListenerType = type: listener: lib.lists.any (r: lib.lists.any (n: n == type) r.names) listener.resources;
|
|
|
|
isMetricsListener = l: isListenerType "metrics" l;
|
2021-10-17 11:00:52 +02:00
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
firstMetricsListener = w: lib.lists.findFirst isMetricsListener (throw "No metrics endpoint on worker") w.settings.worker_listeners;
|
|
|
|
|
|
|
|
wAddress = w: lib.lists.findFirst (_: true) (throw "No address in receiver") (firstMetricsListener w).bind_addresses;
|
|
|
|
wPort = w: (firstMetricsListener w).port;
|
2021-10-17 11:00:52 +02:00
|
|
|
|
2022-12-07 10:14:39 +01:00
|
|
|
socketAddress = w: "${wAddress w}:${toString (wPort w)}";
|
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
|
|
|
|
(metricsPath v) ({
|
|
|
|
proxyPass = proxyPath v;
|
|
|
|
extraConfig = ''
|
|
|
|
allow ${values.ildkule.ipv4};
|
2023-01-17 18:42:06 +01:00
|
|
|
allow ${values.ildkule.ipv6};
|
2023-01-17 18:23:42 +01:00
|
|
|
deny all;
|
|
|
|
'';
|
|
|
|
}))
|
2022-12-07 10:14:39 +01:00
|
|
|
cfg.workers.instances;
|
|
|
|
})
|
|
|
|
({
|
|
|
|
locations."/metrics/master/1" = {
|
|
|
|
proxyPass = "http://127.0.0.1:9000/_synapse/metrics";
|
2023-01-17 10:30:20 +01:00
|
|
|
extraConfig = ''
|
|
|
|
allow ${values.ildkule.ipv4};
|
2023-01-17 18:42:06 +01:00
|
|
|
allow ${values.ildkule.ipv6};
|
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 01:08:09 +01:00
|
|
|
# See https://github.com/matrix-org/synapse/blob/develop/docs/metrics-howto.md
|
|
|
|
staticConfigs = lib.pipe cfg.workers.instances [
|
2023-01-18 02:54:57 +01:00
|
|
|
(lib.mapAttrsToList (_: v: v))
|
2023-01-20 01:08:09 +01:00
|
|
|
# Add metrics for main process to the list of workers
|
|
|
|
(x: x ++ [{ type = "master"; index = 1; }])
|
|
|
|
(map (w: {
|
|
|
|
targets = [ "matrix.pvv.ntnu.no/metrics/${w.type}/${toString w.index}" ];
|
|
|
|
labels = {
|
|
|
|
instance = "matrix.pvv.ntnu.no";
|
|
|
|
job = w.type;
|
|
|
|
index = toString w.index;
|
|
|
|
};
|
|
|
|
}))
|
|
|
|
];
|
2022-12-07 10:14:39 +01:00
|
|
|
in {
|
2023-01-20 01:08:09 +01:00
|
|
|
alias = (pkgs.writeTextDir "/config.json" (builtins.toJSON staticConfigs)) + "/";
|
2021-10-17 11:00:52 +02:00
|
|
|
};
|
2022-12-07 10:14:39 +01:00
|
|
|
})];
|
2021-10-17 11:00:52 +02:00
|
|
|
}
|