Skip to content

Commit

Permalink
feat(matrix): replace conduit with dendrite!
Browse files Browse the repository at this point in the history
  • Loading branch information
uku3lig committed Apr 9, 2024
1 parent 4406844 commit 0e2babb
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 18 deletions.
14 changes: 14 additions & 0 deletions secrets/etna/dendriteKey.age
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBXUXIwUHJvMGlqMThoNDJQ
bW9jb1paekhHN25MSDIrdWxDa29EbGExaWtvCkJGQmt2d0VTYXd5eTZDS25KVlhQ
dm1CeW1acDVkMHZORGJpaDNEUER3N0EKLT4gWDI1NTE5IHpRaFB5cWZjSTlocGda
SitEbC9TQ1JxUi8vQ3dCbkxWbmkvOVdkQlM4UlUKYnlOMVM3YmRrT1Vld3VDMzlt
Z1VLeEZvZzFEME85OVJjcVBRZU1taTc5TQotPiBYMjU1MTkgSi9velVpRUJrcXA3
L05EVDNGdEZqR0JOUVpjV1hQZ3VIa2hRT1RVZWtTdwpQMWVNYzJKZyttOFlyRDNQ
RnhxQ3dsVno2UldGQjJCZGp0ZThVVExmanEwCi0tLSBTK1hqUTNMV1MvVFNpbmsy
Zm9PWjM4N2VCbkRkN0JxVFBiZHB4TnR1a1c0Cn+cp0DpgCFW2dIiZ6DQllFG4eTh
GrFXVyxw65wz/rjZlNE2xp4R5h7et7m1uUQf50UzFXw47NwiNqhw3/baegxdDUDk
fHx93pRl7UvZuBm/FLNxUN25+oEpx29adZud+ij/TfUhx864k3LXrWec0o2DQzfv
TmpzvpGX4Fq+oBSw2RHnUByDPYW9idnYdvoEetjOegoAcUhfqAUriZyddtRgn8Ka
n3u/Ss03
-----END AGE ENCRYPTED FILE-----
1 change: 1 addition & 0 deletions secrets/secrets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ in {
"etna/ngrokEnv.age".publicKeys = main ++ [etna];
"etna/minecraftEnv.age".publicKeys = main ++ [etna];
"etna/atticEnv.age".publicKeys = main ++ [etna];
"etna/dendriteKey.age".publicKeys = main ++ [etna];
}
6 changes: 6 additions & 0 deletions systems/etna/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in {

./minecraft.nix
./attic.nix
./matrix.nix
];

age.secrets = let
Expand All @@ -21,6 +22,11 @@ in {
group = "cloudflared";
};

dendriteKey = {
file = "${path}/dendriteKey.age";
mode = "444";
};

apiRsEnv.file = "${path}/apiRsEnv.age";
ukubotRsEnv.file = "${path}/ukubotRsEnv.age";
ngrokEnv.file = "${path}/ngrokEnv.age";
Expand Down
74 changes: 56 additions & 18 deletions systems/etna/matrix.nix
Original file line number Diff line number Diff line change
@@ -1,39 +1,77 @@
{pkgs, ...}: {
{config, ...}: {
cfTunnels."m.uku.moe" = "http://localhost:80";

services = {
matrix-conduit = {
dendrite = let
database = {
connection_string = "postgres:///dendrite?host=/run/postgresql";
max_open_conns = 50;
max_idle_conns = 5;
conn_max_lifetime = -1;
};
in {
enable = true;
settings.global = {
server_name = "m.uku.moe";
allow_registration = true;
port = 6167;
httpPort = 8008;
settings = {
global = {
server_name = "m.uku.moe";
private_key = config.age.secrets.dendriteKey.path;
inherit database;
};

client_api = {
registration_disabled = true;
};

app_service_api = {inherit database;};
federation_api = {inherit database;};
key_server = {inherit database;};
media_api = {inherit database;};
mscs = {inherit database;};
relay_api = {inherit database;};
room_server = {inherit database;};
sync_api = {inherit database;};
user_api = {
account_database = database;
device_database = database;
};
};
};

postgresql = {
enable = true;
ensureDatabases = ["dendrite"];
ensureUsers = [
{
name = "dendrite";
ensureDBOwnership = true;
}
];
};

nginx = {
enable = true;
recommendedProxySettings = true;

virtualHosts."m.uku.moe" = {
locations."=/.well-known/matrix/server" = let
filename = "server-well-known";
content = builtins.toJSON {"m.server" = "m.uku.moe:443";};
server = {"m.server" = "m.uku.moe:443";};
in {
alias = builtins.toString (pkgs.writeTextDir filename content) + "/";
tryFiles = "${filename} =200";
extraConfig = ''
default_type application/json;
'';
return = "200 '${builtins.toJSON server}'";
};

locations."=/.well-known/matrix/client" = let
client = {"m.homeserver"."base_url" = "https://my.hostname.com";};
in {
return = "200 '${builtins.toJSON client}'";
};

locations."/" = {
proxyPass = "http://localhost:6167/";
proxyPass = "http://localhost:8008";
proxyWebsockets = true;
extraConfig = ''
proxy_set_header Host $host;
proxy_buffering off;
client_max_body_size 100M;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 600;
'';
};
};
Expand Down

0 comments on commit 0e2babb

Please sign in to comment.