streamlining
This commit is contained in:
parent
a19d4d78f2
commit
a86f2aa7bd
|
@ -1,97 +1,51 @@
|
||||||
{ pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
|
||||||
fqdn =
|
|
||||||
let
|
|
||||||
join = hostName: domain: hostName + optionalString (domain != null) ".${domain}";
|
|
||||||
in join config.networking.hostName config.networking.domain;
|
|
||||||
in {
|
|
||||||
networking = {
|
|
||||||
hostName = "matrix";
|
|
||||||
domain = "hacc.space";
|
|
||||||
};
|
|
||||||
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
|
||||||
|
|
||||||
services.postgresql.enable = true;
|
{
|
||||||
services.postgresql.initialScript = pkgs.writeText "synapse-init.sql" ''
|
containers.matrix-synapse = {
|
||||||
CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse';
|
privateNetwork = true;
|
||||||
CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse"
|
hostAddress = "192.168.100.4";
|
||||||
TEMPLATE template0
|
localAddress = "192.168.100.5";
|
||||||
LC_COLLATE = "C"
|
autoStart = true;
|
||||||
LC_CTYPE = "C";
|
config = { config, lib, pkgs, ... }: {
|
||||||
'';
|
networking.firewall.enable = false;
|
||||||
|
services.coredns = {
|
||||||
services.nginx = {
|
enable = true;
|
||||||
enable = true;
|
config = ''
|
||||||
# only recommendedProxySettings and recommendedGzipSettings are strictly required,
|
.:53 {
|
||||||
# but the rest make sense as well
|
forward . 1.1.1.1
|
||||||
recommendedTlsSettings = true;
|
}
|
||||||
recommendedOptimisation = true;
|
|
||||||
recommendedGzipSettings = true;
|
|
||||||
recommendedProxySettings = true;
|
|
||||||
|
|
||||||
virtualHosts = {
|
|
||||||
# This host section can be placed on a different host than the rest,
|
|
||||||
# i.e. to delegate from the host being accessible as ${config.networking.domain}
|
|
||||||
# to another host actually running the Matrix homeserver.
|
|
||||||
"${config.networking.domain}" = {
|
|
||||||
locations."= /.well-known/matrix/server".extraConfig =
|
|
||||||
let
|
|
||||||
# use 443 instead of the default 8448 port to unite
|
|
||||||
# the client-server and server-server port for simplicity
|
|
||||||
server = { "m.server" = "${fqdn}:443"; };
|
|
||||||
in ''
|
|
||||||
add_header Content-Type application/json;
|
|
||||||
return 200 '${builtins.toJSON server}';
|
|
||||||
'';
|
|
||||||
locations."= /.well-known/matrix/client".extraConfig =
|
|
||||||
let
|
|
||||||
client = {
|
|
||||||
"m.homeserver" = { "base_url" = "https://${fqdn}"; };
|
|
||||||
"m.identity_server" = { "base_url" = "https://vector.im"; };
|
|
||||||
};
|
|
||||||
# ACAO required to allow element-web on any URL to request this json file
|
|
||||||
in ''
|
|
||||||
add_header Content-Type application/json;
|
|
||||||
add_header Access-Control-Allow-Origin *;
|
|
||||||
return 200 '${builtins.toJSON client}';
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
# Reverse proxy for Matrix client-server and server-server communication
|
|
||||||
${fqdn} = {
|
|
||||||
enableACME = true;
|
|
||||||
forceSSL = true;
|
|
||||||
|
|
||||||
# Or do a redirect instead of the 404, or whatever is appropriate for you.
|
|
||||||
# But do not put a Matrix Web client here! See the Element web section below.
|
|
||||||
locations."/".extraConfig = ''
|
|
||||||
return 404;
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# forward all Matrix API calls to the synapse Matrix homeserver
|
|
||||||
locations."/_matrix" = {
|
|
||||||
proxyPass = "http://[::1]:8008"; # without a trailing /
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
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.matrix-synapse = {
|
||||||
|
enable = true;
|
||||||
|
server_name = matrix.hanich.hacc.space;
|
||||||
|
listeners = [ {
|
||||||
|
port = 8008;
|
||||||
|
bind_address = "0.0.0.0";
|
||||||
|
type = "http";
|
||||||
|
tls = false;
|
||||||
|
x_forwarded = true;
|
||||||
|
resources = [ {
|
||||||
|
names = [ "client" "federation" ];
|
||||||
|
compress = false;
|
||||||
|
} ];
|
||||||
|
|
||||||
|
} ];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
services.matrix-synapse = {
|
# nginx proxy here
|
||||||
enable = true;
|
|
||||||
server_name = config.networking.domain;
|
|
||||||
listeners = [
|
|
||||||
{
|
|
||||||
port = 8008;
|
|
||||||
bind_address = "::1";
|
|
||||||
type = "http";
|
|
||||||
tls = false;
|
|
||||||
x_forwarded = true;
|
|
||||||
resources = [
|
|
||||||
{
|
|
||||||
names = [ "client" "federation" ];
|
|
||||||
compress = false;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue