2021-12-08 16:39:00 +00:00
|
|
|
{ pkgs, ... }:
|
2021-08-07 12:38:18 +01:00
|
|
|
|
2021-12-08 16:39:00 +00:00
|
|
|
let
|
|
|
|
domain = "matrix.giugl.io";
|
|
|
|
webui_domain = "chat.giugl.io";
|
|
|
|
network = import ./network.nix;
|
|
|
|
in {
|
2021-08-07 12:38:18 +01:00
|
|
|
services = {
|
|
|
|
matrix-synapse = {
|
|
|
|
enable = true;
|
2021-12-08 16:39:00 +00:00
|
|
|
server_name = "${domain}";
|
2021-09-07 10:24:11 +01:00
|
|
|
database_name = "synapse";
|
2021-12-08 16:39:00 +00:00
|
|
|
public_baseurl = "https://${domain}";
|
2021-08-07 12:38:18 +01:00
|
|
|
registration_shared_secret = "runas!";
|
2022-02-15 10:58:08 +00:00
|
|
|
url_preview_enabled = true;
|
2021-08-07 12:38:18 +01:00
|
|
|
dynamic_thumbnails = true;
|
2022-02-15 10:58:08 +00:00
|
|
|
withJemalloc = true;
|
2021-11-25 11:42:32 +00:00
|
|
|
# enable_registration = true;
|
|
|
|
app_service_config_files = [
|
|
|
|
"/var/lib/matrix-synapse/discord-registration.yaml"
|
2022-03-15 15:58:04 +00:00
|
|
|
# "/var/lib/matrix-synapse/hookshot-registration.yml"
|
2022-02-15 10:58:08 +00:00
|
|
|
# "/var/lib/matrix-synapse/telegram-registration.yaml"
|
2021-08-31 15:36:42 +01:00
|
|
|
];
|
2021-08-07 12:38:18 +01:00
|
|
|
extraConfig = ''
|
|
|
|
auto_join_rooms:
|
|
|
|
- "#general:matrix.giugl.io"
|
2022-03-15 15:58:04 +00:00
|
|
|
max_upload_size: "50M"
|
2021-08-07 12:38:18 +01:00
|
|
|
'';
|
2021-11-25 11:42:32 +00:00
|
|
|
listeners = [{
|
|
|
|
port = 8008;
|
|
|
|
bind_address = "::1";
|
|
|
|
type = "http";
|
|
|
|
tls = false;
|
|
|
|
x_forwarded = true;
|
|
|
|
resources = [{
|
|
|
|
names = [ "client" "federation" ];
|
|
|
|
compress = false;
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
turn_uris = [
|
|
|
|
"turns:turn.giugl.io:5349?transport=udp"
|
|
|
|
"turns:turn.giugl.io:5349?transport=tcp"
|
2021-08-07 12:38:18 +01:00
|
|
|
];
|
2021-11-25 11:42:32 +00:00
|
|
|
turn_shared_secret = "69duck duck fuck420";
|
|
|
|
turn_user_lifetime = "1h";
|
2022-02-15 10:58:08 +00:00
|
|
|
logConfig = ''
|
|
|
|
version: 1
|
|
|
|
|
|
|
|
# In systemd's journal, loglevel is implicitly stored, so let's omit it
|
|
|
|
# from the message text.
|
|
|
|
formatters:
|
|
|
|
journal_fmt:
|
|
|
|
format: '%(name)s: [%(request)s] %(message)s'
|
|
|
|
|
|
|
|
filters:
|
|
|
|
context:
|
|
|
|
(): synapse.util.logcontext.LoggingContextFilter
|
|
|
|
request: ""
|
|
|
|
|
|
|
|
handlers:
|
|
|
|
journal:
|
|
|
|
class: systemd.journal.JournalHandler
|
|
|
|
formatter: journal_fmt
|
|
|
|
filters: [context]
|
|
|
|
SYSLOG_IDENTIFIER: synapse
|
|
|
|
|
|
|
|
root:
|
|
|
|
level: WARN
|
|
|
|
handlers: [journal]
|
|
|
|
|
|
|
|
disable_existing_loggers: False
|
|
|
|
'';
|
2021-08-07 12:38:18 +01:00
|
|
|
};
|
|
|
|
|
2021-09-07 10:24:11 +01:00
|
|
|
postgresql = {
|
|
|
|
enable = true;
|
2021-12-08 15:48:02 +00:00
|
|
|
package = pkgs.postgresql_11;
|
2021-09-07 10:24:11 +01:00
|
|
|
ensureDatabases = [ "synapse" ];
|
2021-11-25 11:42:32 +00:00
|
|
|
ensureUsers = [{
|
|
|
|
name = "matrix-synapse";
|
|
|
|
ensurePermissions = { "DATABASE synapse" = "ALL PRIVILEGES"; };
|
|
|
|
}];
|
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"; };
|
2021-08-07 12:38:18 +01:00
|
|
|
in ''
|
|
|
|
add_header Content-Type application/json;
|
|
|
|
return 200 '${builtins.toJSON server}';
|
|
|
|
'';
|
|
|
|
|
2021-11-25 11:42:32 +00:00
|
|
|
locations."= /.well-known/matrix/client".extraConfig = let
|
|
|
|
client = {
|
2021-12-08 16:39:00 +00:00
|
|
|
"m.homeserver" = { "base_url" = "https://${domain}:443"; };
|
2021-11-25 11:42:32 +00:00
|
|
|
"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" = {
|
|
|
|
proxyPass = "http://[::1]:8008"; # without a trailing /
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# 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 = {
|
2021-12-08 16:39:00 +00:00
|
|
|
domain = domain;
|
|
|
|
homeserverUrl = "https://${domain}";
|
2021-08-07 12:38:18 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-08-31 15:36:42 +01:00
|
|
|
|
|
|
|
# telegram bridge
|
|
|
|
|
2022-03-15 15:58:04 +00:00
|
|
|
# mautrix-telegram = {
|
|
|
|
# enable = true;
|
|
|
|
# environmentFile = /secrets/mautrix-telegram/mautrix-telegram.env;
|
|
|
|
|
|
|
|
# settings = {
|
|
|
|
# homeserver = {
|
|
|
|
# address = "https://${domain}";
|
|
|
|
# domain = "${domain}";
|
|
|
|
# };
|
|
|
|
|
|
|
|
# appservice = {
|
|
|
|
# provisioning.enabled = false;
|
|
|
|
# id = "telegram";
|
|
|
|
# };
|
|
|
|
|
|
|
|
# bridge = {
|
|
|
|
# permissions = {
|
|
|
|
# "@pepe:${domain}" = "admin";
|
|
|
|
# "${domain}" = "puppeting";
|
|
|
|
# };
|
|
|
|
|
|
|
|
# # Animated stickers conversion requires additional packages in the
|
|
|
|
# # service's path.
|
|
|
|
# # If this isn't a fresh installation, clearing the bridge's uploaded
|
|
|
|
# # file cache might be necessary (make a database backup first!):
|
|
|
|
# # delete from telegram_file where \
|
|
|
|
# # mime_type in ('application/gzip', 'application/octet-stream')
|
|
|
|
# animated_sticker = {
|
|
|
|
# target = "gif";
|
|
|
|
# args = {
|
|
|
|
# width = 256;
|
|
|
|
# height = 256;
|
|
|
|
# fps = 30; # only for webm
|
|
|
|
# background = "020202"; # only for gif, transparency not supported
|
|
|
|
# };
|
|
|
|
# };
|
|
|
|
|
|
|
|
# encryption = {
|
|
|
|
# allow = true;
|
|
|
|
# default = true;
|
|
|
|
# };
|
|
|
|
# };
|
|
|
|
# };
|
|
|
|
# };
|
2021-08-31 15:36:42 +01:00
|
|
|
|
2021-11-25 11:42:32 +00:00
|
|
|
};
|
2021-08-07 12:38:18 +01:00
|
|
|
|
2022-03-15 15:58:04 +00:00
|
|
|
# systemd.services.mautrix-telegram.path = with pkgs; [
|
|
|
|
# lottieconverter # for animated stickers conversion, unfree package
|
|
|
|
# ffmpeg # if converting animated stickers to webm (very slow!)
|
|
|
|
# ];
|
2021-08-31 15:36:42 +01:00
|
|
|
|
2021-11-25 11:42:32 +00:00
|
|
|
networking.extraHosts = ''
|
2021-12-08 16:39:00 +00:00
|
|
|
${network.architect-lan} ${domain} ${webui_domain}
|
|
|
|
${network.architect-wg} ${domain} ${webui_domain}
|
2021-11-25 11:42:32 +00:00
|
|
|
'';
|
2021-08-07 12:38:18 +01:00
|
|
|
|
|
|
|
}
|