From dc212c3c203f2fb9835ce2648888f8caf35e99dc Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Thu, 12 May 2022 18:03:16 +0900 Subject: Host Element at than.loang.net --- matrix.nix | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) (limited to 'matrix.nix') 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 ]; } -- cgit 1.4.1