about summary refs log tree commit diff
diff options
context:
space:
mode:
-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;
+    };
+  };
+}