2022-11-27 10:23:09 +00:00
|
|
|
{ pkgs, lib, ... }:
|
2021-08-07 12:38:18 +01:00
|
|
|
|
2021-12-08 16:39:00 +00:00
|
|
|
let
|
2022-11-27 10:23:09 +00:00
|
|
|
domain = "runas.rocks";
|
|
|
|
webui_domain = "webchat.runas.rocks";
|
2021-12-08 16:39:00 +00:00
|
|
|
network = import ./network.nix;
|
2022-11-27 10:23:09 +00:00
|
|
|
db_name = "matrix-synapse-runas.rocks";
|
|
|
|
in
|
|
|
|
{
|
2021-08-07 12:38:18 +01:00
|
|
|
services = {
|
|
|
|
matrix-synapse = {
|
|
|
|
enable = true;
|
2022-07-17 19:30:45 +01:00
|
|
|
settings = {
|
|
|
|
server_name = "${domain}";
|
2022-11-27 10:23:09 +00:00
|
|
|
database.args.database = db_name;
|
2022-07-17 19:30:45 +01:00
|
|
|
public_baseurl = "https://${domain}";
|
|
|
|
registration_shared_secret = "runas!";
|
|
|
|
url_preview_enabled = true;
|
|
|
|
dynamic_thumbnails = true;
|
|
|
|
withJemalloc = true;
|
|
|
|
app_service_config_files = [
|
|
|
|
"/var/lib/matrix-synapse/discord-registration.yaml"
|
|
|
|
# "/var/lib/matrix-synapse/hookshot-registration.yml"
|
|
|
|
# "/var/lib/matrix-synapse/telegram-registration.yaml"
|
|
|
|
];
|
2022-11-27 10:23:09 +00:00
|
|
|
|
|
|
|
oidc_providers = [{
|
|
|
|
idp_id = "keycloak";
|
|
|
|
idp_name = "Architect SSO";
|
|
|
|
issuer = "https://auth.giugl.io/realms/master";
|
|
|
|
client_id = "synapse";
|
|
|
|
client_secret = "hj7dkbAI75jIeggr1cW0JTRzAdvJUtq6";
|
|
|
|
scopes = [ "openid" "profile" ];
|
|
|
|
user_profile_method = "userinfo_endpoint";
|
|
|
|
user_mapping_provider.config = {
|
|
|
|
localpart_template = "{{ user.preferred_username }}";
|
|
|
|
display_name_template = "{{ user.name }}";
|
|
|
|
};
|
|
|
|
backchannel_logout_enabled = true;
|
|
|
|
}];
|
|
|
|
|
2022-07-17 19:30:45 +01:00
|
|
|
listeners = [{
|
|
|
|
port = 8008;
|
2022-11-11 18:12:24 +00:00
|
|
|
bind_addresses = [ "127.0.0.1" ];
|
2022-07-17 19:30:45 +01:00
|
|
|
type = "http";
|
|
|
|
tls = false;
|
|
|
|
x_forwarded = true;
|
|
|
|
resources = [{
|
|
|
|
names = [ "client" "federation" ];
|
|
|
|
compress = false;
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
};
|
2021-08-07 12:38:18 +01:00
|
|
|
};
|
|
|
|
|
2021-09-07 10:24:11 +01:00
|
|
|
postgresql = {
|
|
|
|
enable = true;
|
2022-07-25 20:33:32 +01:00
|
|
|
package = pkgs.postgresql;
|
2021-11-25 11:42:32 +00:00
|
|
|
ensureUsers = [{
|
2022-07-25 20:29:41 +01:00
|
|
|
name = db_name;
|
2022-07-25 20:33:32 +01:00
|
|
|
ensurePermissions = { "DATABASE \"${db_name}\"" = "ALL PRIVILEGES"; };
|
2021-11-25 11:42:32 +00:00
|
|
|
}];
|
2021-09-07 10:24:11 +01:00
|
|
|
};
|
|
|
|
|
2021-08-07 12:38:18 +01:00
|
|
|
nginx.virtualHosts = {
|
|
|
|
# server
|
2021-12-08 16:39:00 +00:00
|
|
|
${domain} = {
|
2021-08-07 12:38:18 +01:00
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
2021-12-08 15:48:02 +00:00
|
|
|
extraConfig = ''
|
|
|
|
client_max_body_size 30m;
|
|
|
|
'';
|
2021-08-07 12:38:18 +01:00
|
|
|
locations."= /.well-known/matrix/server".extraConfig =
|
2021-12-08 16:39:00 +00:00
|
|
|
let server = { "m.server" = "${domain}:443"; };
|
2022-11-27 10:23:09 +00:00
|
|
|
in
|
|
|
|
''
|
2021-08-07 12:38:18 +01:00
|
|
|
add_header Content-Type application/json;
|
|
|
|
return 200 '${builtins.toJSON server}';
|
|
|
|
'';
|
|
|
|
|
2022-11-27 10:23:09 +00:00
|
|
|
locations."= /.well-known/matrix/client".extraConfig =
|
|
|
|
let
|
|
|
|
client = {
|
|
|
|
"m.homeserver" = { "base_url" = "https://${domain}:443"; };
|
|
|
|
"m.identity_server" = { "base_url" = "https://vector.im"; };
|
|
|
|
};
|
|
|
|
# ACAO required to allow element-web on any URL to request this json file
|
|
|
|
in
|
|
|
|
''
|
|
|
|
add_header Content-Type application/json;
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
return 200 '${builtins.toJSON client}';
|
|
|
|
'';
|
2021-08-07 12:38:18 +01:00
|
|
|
|
2021-11-25 11:42:32 +00:00
|
|
|
locations."/".extraConfig = ''
|
|
|
|
return 404;
|
|
|
|
'';
|
2021-08-07 12:38:18 +01:00
|
|
|
|
|
|
|
# forward all Matrix API calls to the synapse Matrix homeserver
|
|
|
|
locations."/_matrix" = {
|
2022-11-11 18:12:24 +00:00
|
|
|
proxyPass = "http://127.0.0.1:8008"; # without a trailing /
|
2021-08-07 12:38:18 +01:00
|
|
|
};
|
2022-11-27 10:23:09 +00:00
|
|
|
|
|
|
|
locations."/_synapse" = {
|
|
|
|
proxyPass = "http://127.0.0.1:8008"; # without a trailing /
|
|
|
|
};
|
2021-08-07 12:38:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
# web client
|
2021-12-08 16:39:00 +00:00
|
|
|
"${webui_domain}" = {
|
2021-08-07 12:38:18 +01:00
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
|
2022-03-15 15:58:04 +00:00
|
|
|
root = pkgs.element-web.override {
|
2021-08-07 12:38:18 +01:00
|
|
|
conf = {
|
2022-03-15 15:58:04 +00:00
|
|
|
default_server_config."m.homeserver" = {
|
|
|
|
"base_url" = "https://${domain}";
|
|
|
|
"server_name" = "${domain}";
|
|
|
|
};
|
2021-08-07 12:38:18 +01:00
|
|
|
};
|
2022-03-15 15:58:04 +00:00
|
|
|
};
|
2021-08-07 12:38:18 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-08-31 15:36:42 +01:00
|
|
|
# discord bridge
|
2021-08-07 12:38:18 +01:00
|
|
|
matrix-appservice-discord = {
|
|
|
|
enable = true;
|
|
|
|
environmentFile = /secrets/matrix-appservice-discord/tokens.env;
|
|
|
|
# The appservice is pre-configured to use SQLite by default.
|
|
|
|
# It's also possible to use PostgreSQL.
|
|
|
|
settings = {
|
|
|
|
bridge = {
|
2022-11-27 10:23:09 +00:00
|
|
|
inherit domain;
|
2021-12-08 16:39:00 +00:00
|
|
|
homeserverUrl = "https://${domain}";
|
2021-08-07 12:38:18 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-11-25 11:42:32 +00:00
|
|
|
};
|
2021-08-07 12:38:18 +01:00
|
|
|
|
2021-11-25 11:42:32 +00:00
|
|
|
networking.extraHosts = ''
|
2022-11-27 10:23:09 +00:00
|
|
|
${network.architect-lan} ${lib.concatStringsSep " " [ domain webui_domain]}
|
|
|
|
${network.architect-wg} ${lib.concatStringsSep " " [ domain webui_domain ]}
|
2021-11-25 11:42:32 +00:00
|
|
|
'';
|
2021-08-07 12:38:18 +01:00
|
|
|
|
|
|
|
}
|