mirror of
https://forge.darkest.space/mara/nixos-configs.git
synced 2026-11-23 04:49:43 +01:00
deploy tuwunel
This commit is contained in:
parent
14b9dc3b37
commit
7577f9df1c
2 changed files with 79 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
./hardware.nix
|
||||
./forgejo.nix
|
||||
./nginx.nix
|
||||
./matrix.nix
|
||||
./truth-machine.nix
|
||||
];
|
||||
|
||||
|
|
|
|||
78
nixosConfigurations/hyperforge/matrix.nix
Normal file
78
nixosConfigurations/hyperforge/matrix.nix
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
{ config, lib, ... }:
|
||||
let
|
||||
# matrix server name (user ids look like @user:darkest.space)
|
||||
serverName = "darkest.space";
|
||||
# host that actually serves the matrix API
|
||||
domain = "matrix.darkest.space";
|
||||
# created by the tuwunel unit (RuntimeDirectory=tuwunel, group tuwunel, mode 0750)
|
||||
socket = "/run/tuwunel/tuwunel.sock";
|
||||
stateDir = "/var/lib/${config.services.matrix-tuwunel.stateDirectory}";
|
||||
in
|
||||
{
|
||||
services.matrix-tuwunel = {
|
||||
enable = true;
|
||||
settings.global = {
|
||||
server_name = serverName;
|
||||
unix_socket_path = socket;
|
||||
# 10 MB upload limit; nginx client_max_body_size follows this
|
||||
max_request_size = 10000000;
|
||||
allow_registration = true;
|
||||
# token placed manually, owned by tuwunel; the first registered user becomes admin
|
||||
registration_token_file = "/etc/secrets/tuwunel-registration-token";
|
||||
};
|
||||
};
|
||||
|
||||
# nginx reaches the socket through the tuwunel group
|
||||
users.users.nginx.extraGroups = [ config.services.matrix-tuwunel.group ];
|
||||
|
||||
# Run as the static tuwunel user (not DynamicUser) so the dedicated volume
|
||||
# can be mounted directly at /var/lib/tuwunel.
|
||||
systemd.services.tuwunel = {
|
||||
serviceConfig.DynamicUser = lib.mkForce false;
|
||||
unitConfig.RequiresMountsFor = [ stateDir ];
|
||||
};
|
||||
|
||||
# dedicated hetzner volume "tuwunel" (ext4), so the database can never end up on the root disk
|
||||
fileSystems.${stateDir} = {
|
||||
device = "/dev/disk/by-id/scsi-0HC_Volume_107575600";
|
||||
fsType = "ext4";
|
||||
options = [
|
||||
"discard"
|
||||
"nofail"
|
||||
"defaults"
|
||||
];
|
||||
};
|
||||
|
||||
services.nginx.virtualHosts = {
|
||||
${domain} = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
extraConfig = ''
|
||||
client_max_body_size ${toString config.services.matrix-tuwunel.settings.global.max_request_size};
|
||||
'';
|
||||
locations = {
|
||||
"/_matrix/".proxyPass = "http://unix:${socket}";
|
||||
"/".return = "404 \"\"";
|
||||
};
|
||||
};
|
||||
|
||||
# apex: only delegate the matrix server name to ${domain}, 404 on everything else
|
||||
${serverName} = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations = {
|
||||
"= /.well-known/matrix/server".extraConfig = ''
|
||||
default_type application/json;
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
return 200 '${builtins.toJSON { "m.server" = "${domain}:443"; }}';
|
||||
'';
|
||||
"= /.well-known/matrix/client".extraConfig = ''
|
||||
default_type application/json;
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
return 200 '${builtins.toJSON { "m.homeserver".base_url = "https://${domain}"; }}';
|
||||
'';
|
||||
"/".return = "404 \"\"";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue