# SPDX-FileCopyrightText: 2020 Luke Granger-Brown # # SPDX-License-Identifier: Apache-2.0 { config, depot, pkgs, lib, ... }: let inherit (depot.ops) secrets; machineSecrets = secrets.machineSpecific.bvm-matrix; in { imports = [ ../lib/bvm.nix ]; # Networking! networking = { hostName = "bvm-matrix"; hostId = "1c2786ad"; interfaces.enp1s0 = { ipv4.addresses = [{ address = "10.100.0.205"; prefixLength = 23; }]; }; interfaces.enp2s0 = { ipv4.addresses = [{ address = "92.118.28.6"; prefixLength = 24; }]; ipv6.addresses = [{ address = "2a09:a441::6"; prefixLength = 32; }]; }; defaultGateway = { address = "92.118.28.1"; interface = "enp2s0"; }; defaultGateway6 = { address = "2a09:a441::1"; interface = "enp2s0"; }; firewall.allowedUDPPorts = [ 3478 # TURN ]; firewall.allowedTCPPorts = [ 80 443 # HTTP/S 3478 # TURN ]; }; my.ip.tailscale = "100.74.197.67"; services.postgresql = { enable = true; ensureDatabases = [ "matrix-synapse" ]; ensureUsers = [{ name = "matrix-synapse"; ensurePermissions = { "DATABASE \"matrix-synapse\"" = "ALL PRIVILEGES"; }; }]; }; services.coturn = { enable = true; use-auth-secret = true; realm = "matrix.zxcvbnm.ninja"; static-auth-secret = machineSecrets.turnSecret; cert = "${config.security.acme.certs."matrix.zxcvbnm.ninja".directory}/fullchain.pem"; pkey = "${config.security.acme.certs."matrix.zxcvbnm.ninja".directory}/key.pem"; }; services.nginx = { enable = true; recommendedTlsSettings = true; recommendedOptimisation = true; recommendedGzipSettings = true; recommendedProxySettings = true; virtualHosts = { "zxcvbnm.ninja" = { forceSSL = true; useACMEHost = "matrix.zxcvbnm.ninja"; locations = let inherit (lib) mapAttrs' nameValuePair; wellKnown = { "matrix/server" = { "m.server" = "matrix.zxcvbnm.ninja:443"; }; "matrix/client" = { "m.homeserver" = { "base_url" = "https://matrix.zxcvbnm.ninja"; }; "m.identity_server" = { "base_url" = "https://vector.im"; }; }; }; in mapAttrs' (name: value: nameValuePair "= /.well-known/${name}" { extraConfig = '' add_header Content-Type application/json; add_header Access-Control-Allow-Origin *; return 200 '${builtins.toJSON value}'; ''; }) wellKnown; }; "matrix.zxcvbnm.ninja" = { forceSSL = true; useACMEHost = "matrix.zxcvbnm.ninja"; locations."/".return = "301 https://element.zxcvbnm.ninja$request_uri"; locations."/_matrix".proxyPass = "http://[::1]:8008"; }; }; }; services.matrix-synapse = { enable = true; server_name = "zxcvbnm.ninja"; listeners = [{ port = 8008; bind_address = "::1"; type = "http"; tls = false; x_forwarded = true; resources = [{ names = [ "client" "federation" ]; compress = false; }]; }]; }; # Users allowed to use SSL certificate for matrix.zxcvbnm.ninja. users.groups.matrixcert = { members = [ "turnserver" "nginx" ]; }; security.acme = { acceptTerms = true; email = "letsencrypt@lukegb.com"; certs."matrix.zxcvbnm.ninja" = { group = "matrixcert"; dnsProvider = "cloudflare"; credentialsFile = secrets.cloudflareCredentials; extraDomainNames = [ "element.zxcvbnm.ninja" "zxcvbnm.ninja" ]; }; }; system.stateVersion = "21.05"; }