/nix/store/dlwqlnbaj5vfm9aw20r1yxk8y56lmgif-repo/header.tmpl
nichts/modules/services/matrix.mod.nix

73 lines
1.8 KiB
Nix
Raw Permalink Normal View History

2025-09-05 16:06:57 +02:00
{
config,
lib,
pkgs,
2025-09-04 23:23:06 +02:00
self,
2025-09-05 16:06:57 +02:00
...
}:
let
inherit (lib.modules) mkIf;
inherit (lib.options) mkEnableOption;
2025-09-05 16:21:40 +02:00
inherit (lib.lists) singleton;
2025-09-05 17:13:06 +02:00
inherit (builtins) toJSON;
2025-09-05 16:06:57 +02:00
cfg = config.modules.system.services.matrix;
port = 4926;
2025-09-05 17:13:06 +02:00
domain = "faukah.com";
# Taken from Max Privatevoid.
serverFederation = pkgs.writeText "server_federation.json" (toJSON {
"m.server" = "matrix.${domain}:443";
});
clientFederation = pkgs.writeText "client_federation.json" (toJSON {
"m.homeserver".base_url = "https://matrix.${domain}";
});
2025-09-05 16:06:57 +02:00
in
{
options.modules.system.services.matrix.enable = mkEnableOption "matrix";
config = mkIf cfg.enable {
2025-09-04 23:23:06 +02:00
age.secrets.registrationToken.file = "${self}/secrets/tuwunel_token_file.age";
2025-09-05 16:06:57 +02:00
services = {
nginx = {
enable = true;
virtualHosts.${domain} = {
addSSL = true;
enableACME = true;
2025-09-05 17:13:06 +02:00
locations = {
"= /.well-known/matrix/server".alias = serverFederation;
"= /.well-known/matrix/client".alias = clientFederation;
2025-09-05 16:06:57 +02:00
};
};
2025-09-05 17:13:06 +02:00
virtualHosts."matrix.${domain}" = {
addSSL = true;
enableACME = true;
locations."/_matrix".proxyPass = "http://localhost:${toString port}";
};
2025-09-05 16:06:57 +02:00
};
matrix-tuwunel = {
enable = true;
package = pkgs.matrix-tuwunel;
settings = {
global = {
2025-09-05 16:21:40 +02:00
port = singleton port;
2025-09-05 16:06:57 +02:00
address = [
"127.0.0.1"
"::1"
];
server_name = domain;
allow_registration = true;
allow_federation = true;
allow_encryption = true;
2025-09-05 17:13:06 +02:00
new_user_displayname_suffix = "";
2025-09-04 23:23:06 +02:00
registration_token_file = config.age.secrets.registrationToken.path;
2025-09-05 16:06:57 +02:00
};
};
};
};
};
}