2023-12-01 15:07:47 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2023-04-12 17:21:24 +02:00
|
|
|
{
|
2023-11-16 01:27:01 +01:00
|
|
|
# set default options for virtualHosts
|
|
|
|
options = with lib; {
|
|
|
|
services.nginx.virtualHosts = mkOption {
|
|
|
|
type = types.attrsOf (types.submodule
|
|
|
|
({ name, ... }: {
|
2024-03-25 19:06:38 +01:00
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
2023-12-23 17:30:04 +01:00
|
|
|
# enable http3 for all hosts
|
|
|
|
quic = true;
|
|
|
|
http3 = true;
|
2023-11-16 01:27:01 +01:00
|
|
|
# split up nginx access logs per vhost
|
|
|
|
extraConfig = ''
|
|
|
|
access_log /var/log/nginx/${name}_access.log;
|
|
|
|
error_log /var/log/nginx/${name}_error.log;
|
2024-04-03 00:01:40 +02:00
|
|
|
add_header Alt-Svc 'h3=":443"; ma=86400';
|
2023-11-16 01:27:01 +01:00
|
|
|
'';
|
|
|
|
})
|
|
|
|
);
|
2023-05-24 16:37:45 +02:00
|
|
|
};
|
2023-05-05 23:43:40 +02:00
|
|
|
};
|
2023-11-16 01:27:01 +01:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
# matrix homeserver discovery
|
|
|
|
matrix_domain = "matrix.${config.networking.domain}";
|
|
|
|
serverConfig = {
|
|
|
|
"m.server" = "${matrix_domain}:443";
|
|
|
|
};
|
|
|
|
clientConfig = {
|
|
|
|
"m.homeserver" = {
|
|
|
|
base_url = "https://${matrix_domain}";
|
|
|
|
# server_name = config.networking.domain;
|
|
|
|
};
|
|
|
|
"org.matrix.msc3575.proxy" = {
|
|
|
|
url = "https://${matrix_domain}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
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 ];
|
2023-12-19 22:42:38 +01:00
|
|
|
networking.firewall.allowedUDPPorts = [ 443 ];
|
2023-11-16 01:27:01 +01:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
2023-12-19 22:42:38 +01:00
|
|
|
package = pkgs.nginxQuic;
|
2023-11-16 01:27:01 +01:00
|
|
|
recommendedTlsSettings = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
virtualHosts."${config.networking.domain}" = {
|
|
|
|
root = "/srv/web/${config.networking.domain}";
|
2023-12-01 15:07:47 +01:00
|
|
|
locations = {
|
|
|
|
"/.well-known/matrix/client".extraConfig = mkWellKnown clientConfig;
|
|
|
|
"/.well-known/matrix/server".extraConfig = mkWellKnown serverConfig;
|
|
|
|
};
|
2023-11-16 01:27:01 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
security.acme = {
|
|
|
|
acceptTerms = true;
|
|
|
|
defaults = {
|
|
|
|
email = "rouven@${config.networking.domain}";
|
|
|
|
};
|
|
|
|
};
|
2023-04-12 17:21:24 +02:00
|
|
|
};
|
|
|
|
}
|