services/{nginx,postgres,synapse}: init

This commit is contained in:
LavaDesu 2022-02-13 21:06:56 +07:00
parent accf26c1ea
commit 3bea2397f5
Signed by: cilly
GPG key ID: 6500251E087653C9
5 changed files with 148 additions and 14 deletions

View file

@ -14,6 +14,11 @@ let
}) paths
);
in {
services = mkAttrsFromPaths [
./services/nginx.nix
./services/postgres.nix
./services/synapse.nix
];
system = mkAttrsFromPaths [
./system/audio.nix
./system/base.nix

View file

@ -0,0 +1,22 @@
{ ... }: {
security.acme.acceptTerms = true;
security.acme.email = "me@lava.moe";
services.nginx = {
enable = true;
recommendedTlsSettings = true;
recommendedOptimisation = true;
recommendedGzipSettings = true;
recommendedProxySettings = true;
virtualHosts = {
"lava.moe" = {
enableACME = true;
forceSSL = true;
locations."/".extraConfig = ''
return 404;
'';
};
};
};
}

View file

@ -0,0 +1,12 @@
{ config, ... }:
let
dir = "/persist/postgresql/${config.services.postgresql.package.psqlSchema}";
uid = config.ids.uids.postgres;
gid = config.ids.gids.postgres;
in {
systemd.tmpfiles.rules = [ "d ${dir} 700 ${uid} ${gid}" ];
services.postgresql = {
enable = true;
dataDir = dir;
};
}

View file

@ -0,0 +1,89 @@
{ config, lib, pkgs, ... }:
let
dom = "lava.moe";
sub = "matrix.lava.moe";
dir = "/persist/matrix-synapse";
uid = config.ids.uids.matrix-synapse;
gid = config.ids.gids.matrix-synapse;
in {
networking.firewall.allowedTCPPorts = [ 80 443 ];
systemd.tmpfiles.rules = [ "d ${dir} 700 ${uid} ${gid}" ];
/*services.postgresql = {
ensureDatabases = [ "matrix-synapse" ];
ensureUsers = [{
name = "matrix-synapse";
ensurePermissions = {
"DATABASE matrix-synapse" = "ALL PRIVILEGES";
};
}];
};*/
# TODO this would be bad if we use postgres for other things too
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 = {
virtualHosts = {
${dom} = {
serverAliases = [ sub ];
locations."= /.well-known/matrix/server".extraConfig =
let
server = { "m.server" = "${sub}: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://${sub}"; };
"m.identity_server" = { "base_url" = "https://vector.im"; };
};
in ''
add_header Content-Type application/json;
add_header Access-Control-Allow-Origin *;
return 200 '${builtins.toJSON client}';
'';
};
${sub} = {
forceSSL = true;
useACMEHost = dom;
locations."/".extraConfig = ''
return 404;
'';
locations."/_matrix" = {
proxyPass = "http://[::1]:8008";
};
};
};
};
services.matrix-synapse = {
enable = true;
dataDir = dir;
server_name = dom;
listeners = [
{
port = 8008;
bind_address = "::1";
type = "http";
tls = false;
x_forwarded = true;
resources = [
{
names = [ "client" "federation" ];
compress = false;
}
];
}
];
};
}