about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-05-12 01:40:28 +0900
committerNguyễn Gia Phong <mcsinyx@disroot.org>2022-05-12 01:40:28 +0900
commit6753ad7cad7ea720fea73c91bff9df6f27d80368 (patch)
tree27902d376906d9f3c68b801a086a06b15d62cc66
parent9d80f26bcbf2150e31a3b626d28cf7fc6a878c82 (diff)
downloadnixos-conf-6753ad7cad7ea720fea73c91bff9df6f27d80368.tar.gz
Draft Dendrite set up
-rw-r--r--configuration.nix9
-rw-r--r--matrix.nix44
2 files changed, 50 insertions, 3 deletions
diff --git a/configuration.nix b/configuration.nix
index 9dc0a48..c68d76b 100644
--- a/configuration.nix
+++ b/configuration.nix
@@ -1,7 +1,7 @@
 { config, lib, pkgs, ... }:
 let
   certs = config.security.acme.certs.${domain};
-  domain = "loang.net";
+  domain = config.networking.domain;
   bindUserDirs = sources: target: lib.mapAttrs' (user: dir: {
     name = target + user;
     value = {
@@ -19,10 +19,13 @@ in {
     cnx = "www";
   } "${config.services.nginx.virtualHosts.${domain}.root}/~";
 
-  imports = [ ./vpsadminos.nix ];
+  imports = [
+    ./vpsadminos.nix
+    ./matrix.nix
+  ];
 
   networking = {
-    domain = domain;
+    domain = "loang.net";
 
     firewall = {
       allowedTCPPorts = [
diff --git a/matrix.nix b/matrix.nix
new file mode 100644
index 0000000..6fb9d35
--- /dev/null
+++ b/matrix.nix
@@ -0,0 +1,44 @@
+{ config, pkgs, ... }:
+let domain = config.networking.domain;
+in {
+  services = {
+    dendrite = {
+      enable = true;
+      settings = let
+        dburl = "postgres:///dendrite?host=/run/postgresql";
+        workingDir = "/var/lib/dendrite"; # hardcoded in service
+      in {
+        app_service_api.database.connection_string = dburl;
+        federation_api.database.connection_string = dburl;
+        global = {
+          server_name = domain;
+          private_key = "${workingDir}/matrix_key.pem";
+          trusted_third_party_id_servers = [ ];
+        };
+        key_server.database.connection_string = dburl;
+        media_api.database.connection_string = dburl;
+        mscs.database.connection_string = dburl;
+        room_server.database.connection_string = dburl;
+        sync_api.database.connection_string = dburl;
+        user_api.account_database.connection_string = dburl;
+        user_api.device_database.connection_string = dburl;
+      };
+    };
+
+    nginx.virtualHosts.${domain}.locations."/_matrix".proxyPass = let
+      port = toString config.services.dendrite.httpPort;
+    in "http://localhost:${port}";
+
+    postgresql = {
+      enable = true;
+      ensureDatabases = [ "dendrite" ];
+      ensureUsers = [
+        {
+          name = "dendrite";
+          ensurePermissions."DATABASE dendrite" = "ALL PRIVILEGES";
+        }
+      ];
+      package = pkgs.postgresql;
+    };
+  };
+}