diff options
author | sils <sils@sils.li> | 2023-06-19 18:58:33 +0200 |
---|---|---|
committer | sils <sils@sils.li> | 2023-06-19 18:58:33 +0200 |
commit | 50d5091865563a2983329bc5017bb45503414b2d (patch) | |
tree | 1b99c6da002e3599f6e5c0b018eb3023f53e8456 | |
parent | chore(version): v0.1.0 (diff) | |
download | nixos-server-50d5091865563a2983329bc5017bb45503414b2d.tar.gz nixos-server-50d5091865563a2983329bc5017bb45503414b2d.zip |
Feat(system/services): Add matrix synapse
-rw-r--r-- | system/services/default.nix | 1 | ||||
-rw-r--r-- | system/services/matrix/default.nix | 79 |
2 files changed, 80 insertions, 0 deletions
diff --git a/system/services/default.nix b/system/services/default.nix index d1f2c85..19a531f 100644 --- a/system/services/default.nix +++ b/system/services/default.nix @@ -2,6 +2,7 @@ imports = [ ./acme ./keycloak + ./matrix ./minecraft ./nginx ./nix diff --git a/system/services/matrix/default.nix b/system/services/matrix/default.nix new file mode 100644 index 0000000..d49fda2 --- /dev/null +++ b/system/services/matrix/default.nix @@ -0,0 +1,79 @@ +{ + pkgs, + lib, + config, + ... +}: let + fqdn = "matrix.vhack.eu"; + clientConfig."m.homeserver".base_url = "https://${fqdn}"; + serverConfig."m.server" = "${fqdn}:443"; + mkWellKnown = data: '' + add_header Content-Type application/json; + add_header Access-Control-Allow-Origin *; + return 200 '${builtins.toJSON data}'; + ''; +in { + networking.firewall.allowedTCPPorts = [80 443]; + + services.postgresql.enable = true; + services.postgresql.initialScript = pkgs.writeText "synapse-init.sql" '' + CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse'; + CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse" + TEMPLATE template0 + LC_COLLATE = "C" + LC_CTYPE = "C"; + ''; + + services.nginx = { + enable = true; + recommendedTlsSettings = true; + recommendedOptimisation = true; + recommendedGzipSettings = true; + recommendedProxySettings = true; + virtualHosts = { + "vhack.eu" = { + enableACME = true; + forceSSL = true; + locations."= /.well-known/matrix/server".extraConfig = mkWellKnown serverConfig; + locations."= /.well-known/matrix/client".extraConfig = mkWellKnown clientConfig; + }; + "matrix.vhack.eu" = { + enableACME = true; + forceSSL = true; + locations."/".extraConfig = '' + return 404; + ''; + locations = { + "/_matrix".proxyPass = "http://[::1]:8008"; + "/_synapse/client".proxyPass = "http://[::1]:8008"; + }; + }; + }; + }; + + services.matrix-synapse = { + enable = true; + dataDir = "/srv/matrix/data"; + configFile = "/srv/matrix"; + extraConfigFiles = ["/srv/matrix/oid/config.yaml"]; + settings = { + media_store_path = "/srv/matrix/media_store"; + server_name = "vhack.eu"; + listeners = [ + { + port = 8008; + bind_addresses = ["::1"]; + type = "http"; + tls = false; + x_forwarded = true; + resources = [ + { + names = ["client" "federation"]; + compress = true; + } + ]; + } + ]; + }; + }; +} |