about summary refs log tree commit diff
path: root/matrix.nix
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-05-12 18:03:16 +0900
committerNguyễn Gia Phong <mcsinyx@disroot.org>2022-05-12 18:03:16 +0900
commitdc212c3c203f2fb9835ce2648888f8caf35e99dc (patch)
tree7bd8d0a7aecad613a56f29176a6d6f947316de43 /matrix.nix
parent1c2a3ebe9da70a85589c3adcf5087281a95ac7b4 (diff)
downloadnixos-conf-dc212c3c203f2fb9835ce2648888f8caf35e99dc.tar.gz
Host Element at than.loang.net
Diffstat (limited to 'matrix.nix')
-rw-r--r--matrix.nix58
1 files changed, 54 insertions, 4 deletions
diff --git a/matrix.nix b/matrix.nix
index 6fb9d35..5d34644 100644
--- a/matrix.nix
+++ b/matrix.nix
@@ -1,5 +1,18 @@
 { config, pkgs, ... }:
-let domain = config.networking.domain;
+let
+  client = {
+    "m.homeserver" = {
+      base_url = "https://${domain}";
+      server_name = domain;
+    };
+    "m.identity_server" = {
+      base_url = ""; # disable
+    };
+  };
+  domain = config.networking.domain;
+  server = {
+    "m.server" = "${domain}:443"; # unify with client-server
+  };
 in {
   services = {
     dendrite = {
@@ -25,9 +38,34 @@ in {
       };
     };
 
-    nginx.virtualHosts.${domain}.locations."/_matrix".proxyPass = let
-      port = toString config.services.dendrite.httpPort;
-    in "http://localhost:${port}";
+    nginx.virtualHosts = {
+      "${domain}".locations = {
+        "= /.well-known/matrix/client" = {
+          extraConfig = ''
+            add_header Content-Type application/json;
+            add_header Access-Control-Allow-Origin *;
+          '';
+          return = "200 '${builtins.toJSON client}'";
+        };
+
+        "= /.well-known/matrix/server" = {
+          extraConfig = ''
+            add_header Content-Type application/json;
+          '';
+          return = "200 '${builtins.toJSON server}'";
+        };
+
+        "/_matrix".proxyPass = let
+          port = toString config.services.dendrite.httpPort;
+        in "http://localhost:${port}";
+      };
+
+      "than.${domain}" = {
+        enableACME = true;
+        forceSSL = true;
+        locations."/".proxyPass = "http://localhost:8080";
+      };
+    };
 
     postgresql = {
       enable = true;
@@ -41,4 +79,16 @@ in {
       package = pkgs.postgresql;
     };
   };
+
+  users.users.root.packages = let
+    element-ipfs = pkgs.callPackage ./element-ipfs.nix {
+      conf = {
+        default_server_config = client;
+        default_theme = "dark";
+        room_directory = {
+          servers = [ "loang.net" ];
+        };
+      };
+    };
+  in [ element-ipfs ];
 }