nixos-config/hosts/nuc/modules/matrix/default.nix

114 lines
2.7 KiB
Nix
Raw Permalink Normal View History

2023-10-17 10:39:14 +02:00
{ config, pkgs, ... }:
let
domain = "matrix.${config.networking.domain}";
2024-01-27 23:03:29 +01:00
domainClient = "chat.${config.networking.domain}";
clientConfig = {
"m.homeserver" = {
base_url = "https://${domain}:443";
};
};
2023-10-17 10:39:14 +02:00
in
{
2023-11-16 14:40:40 +01:00
age.secrets = {
"matrix/shared" = {
file = ../../../../secrets/nuc/matrix/shared.age;
2023-10-17 10:39:14 +02:00
owner = config.systemd.services.matrix-synapse.serviceConfig.User;
};
};
2024-08-22 11:35:09 +02:00
nixpkgs.config.permittedInsecurePackages = [
"jitsi-meet-1.0.8043"
"olm-3.2.16"
];
2023-10-17 10:39:14 +02:00
services = {
postgresql = {
enable = true;
ensureUsers = [{
name = "matrix-synapse";
}];
};
matrix-synapse = {
enable = true;
configureRedisLocally = true;
2024-05-21 18:44:04 +02:00
enableRegistrationScript = false;
2023-11-16 14:40:40 +01:00
extraConfigFiles = [ config.age.secrets."matrix/shared".path ];
log = {
root.level = "WARNING";
};
2023-10-17 10:39:14 +02:00
settings = {
server_name = config.networking.domain;
2024-06-06 20:50:33 +02:00
enable_metrics = true;
2023-10-17 10:39:14 +02:00
listeners = [{
2024-06-06 20:50:33 +02:00
bind_addresses = [ "0.0.0.0" "::1" ];
2024-05-25 22:31:20 +02:00
port = 8008;
tls = false;
2023-10-17 10:39:14 +02:00
type = "http";
x_forwarded = true;
resources = [{
2024-05-25 22:31:20 +02:00
names = [ "client" "federation" "metrics" ];
2023-10-17 10:39:14 +02:00
compress = false;
}];
}];
};
2024-01-04 00:13:32 +01:00
};
2023-10-17 10:39:14 +02:00
2024-05-21 18:44:04 +02:00
caddy = {
2023-10-17 10:39:14 +02:00
virtualHosts = {
# synapse
2024-05-21 18:44:04 +02:00
"${domain}".extraConfig = ''
2024-05-25 22:31:20 +02:00
reverse_proxy 127.0.0.1:8008
2024-06-22 16:27:40 +02:00
handle /_synapse/metrics* {
respond 404
}
2024-05-21 18:44:04 +02:00
'';
2024-01-27 23:03:29 +01:00
# element
2024-05-21 18:44:04 +02:00
"${domainClient}".extraConfig = ''
2024-05-23 09:25:08 +02:00
file_server browse
root * ${pkgs.element-web.override {
2024-01-27 23:03:29 +01:00
conf = {
default_server_config = {
inherit (clientConfig) "m.homeserver";
"m.identity_server".base_url = "";
};
disable_3pid_login = true;
};
2024-05-23 09:25:08 +02:00
}}
2024-05-21 18:44:04 +02:00
'';
2023-10-17 10:39:14 +02:00
};
};
};
2024-05-21 18:44:04 +02:00
systemd.services.matrix-synapse = {
after = [ "matrix-synapse-pgsetup.service" ];
serviceConfig = {
RuntimeDirectory = "matrix-synapse";
};
};
2023-10-17 10:39:14 +02:00
systemd.services.matrix-synapse-pgsetup = {
description = "Prepare Synapse postgres database";
wantedBy = [ "multi-user.target" ];
after = [ "networking.target" "postgresql.service" ];
serviceConfig.Type = "oneshot";
path = [ pkgs.sudo config.services.postgresql.package ];
# create database for synapse. will silently fail if it already exists
script = ''
sudo -u ${config.services.postgresql.superUser} psql <<SQL
CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse"
ENCODING 'UTF8'
TEMPLATE template0
LC_COLLATE = "C"
LC_CTYPE = "C";
SQL
'';
};
}