matrix-synapse: create database with right collation also when postgresql already exists
This commit is contained in:
parent
cb103c7772
commit
dd77dd8130
|
@ -13,6 +13,7 @@ in
|
|||
domain = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "The domain name of the matrix server";
|
||||
example = "example.com";
|
||||
};
|
||||
};
|
||||
config = lib.mkIf cfg.enable {
|
||||
|
@ -52,8 +53,29 @@ in
|
|||
extraConfigFiles = [ "/var/lib/matrix-synapse/registration_shared_secret.yaml" ];
|
||||
};
|
||||
systemd.services.matrix-synapse.serviceConfig.ExecStartPre = [
|
||||
"+${pkgs.writeScript "copy_registration_shared_secret" ''
|
||||
#!/bin/sh
|
||||
"+${pkgs.writeShellScript "create-matrix-synapse-db" ''
|
||||
export PATH=${
|
||||
lib.makeBinPath [
|
||||
config.services.postgresql.package
|
||||
pkgs.util-linux
|
||||
pkgs.gnugrep
|
||||
]
|
||||
}
|
||||
psql() { runuser -u postgres -- psql "$@"; }
|
||||
# wait for postgres to be ready
|
||||
while ! runuser -u postgres pg_isready; do
|
||||
sleep 1
|
||||
done
|
||||
if ! psql -tAc "SELECT 1 FROM pg_database WHERE datname = 'matrix-synapse'" | grep -q 1; then
|
||||
psql -c "CREATE DATABASE \"matrix-synapse\" TEMPLATE template0 LC_COLLATE = 'C' LC_CTYPE = 'C'"
|
||||
fi
|
||||
# create user if it doesn't exist and make it owner of the database
|
||||
if ! psql -tAc "SELECT 1 FROM pg_user WHERE usename = 'matrix-synapse'" | grep -q 1; then
|
||||
psql -c "CREATE USER \"matrix-synapse\""
|
||||
psql -c "ALTER DATABASE \"matrix-synapse\" OWNER TO \"matrix-synapse\""
|
||||
fi
|
||||
''}"
|
||||
"+${pkgs.writeShellScript "copy-registration-shared-secret" ''
|
||||
cp ${config.clanCore.facts.services.matrix-synapse.secret.synapse-registration_shared_secret.path} /var/lib/matrix-synapse/registration_shared_secret.yaml
|
||||
chown matrix-synapse:matrix-synapse /var/lib/matrix-synapse/registration_shared_secret.yaml
|
||||
chmod 600 /var/lib/matrix-synapse/registration_shared_secret.yaml
|
||||
|
@ -72,22 +94,6 @@ in
|
|||
};
|
||||
|
||||
services.postgresql.enable = true;
|
||||
# we need to use both ensusureDatabases and initialScript, because the former runs everytime but with the wrong collation
|
||||
services.postgresql = {
|
||||
ensureDatabases = [ "matrix-synapse" ];
|
||||
ensureUsers = [
|
||||
{
|
||||
name = "matrix-synapse";
|
||||
ensureDBOwnership = true;
|
||||
}
|
||||
];
|
||||
initialScript = pkgs.writeText "synapse-init.sql" ''
|
||||
CREATE DATABASE "matrix-synapse"
|
||||
TEMPLATE template0
|
||||
LC_COLLATE = "C"
|
||||
LC_CTYPE = "C";
|
||||
'';
|
||||
};
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
virtualHosts = {
|
||||
|
@ -117,9 +123,6 @@ in
|
|||
locations."/_matrix" = {
|
||||
proxyPass = "http://localhost:8008";
|
||||
};
|
||||
locations."/test".extraConfig = ''
|
||||
return 200 "Hello, world!";
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user