2023-10-06 05:33:28 +02:00
|
|
|
{ pkgs, config, ... }:
|
|
|
|
|
|
|
|
{
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
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";
|
|
|
|
'';
|
|
|
|
|
|
|
|
dataDir = "/mnt/data/postgresql/${config.services.postgresql.package.psqlSchema}";
|
|
|
|
};
|
2023-12-06 00:46:47 +01:00
|
|
|
|
|
|
|
# Modified version of the script for upgrading PostgreSQL from here:
|
|
|
|
# https://nixos.org/manual/nixos/stable/#module-services-postgres-upgrading
|
|
|
|
environment.systemPackages = [
|
|
|
|
(let
|
|
|
|
newPostgres = pkgs.postgresql_15;
|
|
|
|
in pkgs.writeScriptBin "upgrade-pg-cluster" ''
|
|
|
|
set -eux
|
|
|
|
|
|
|
|
systemctl stop matrix-synapse.service
|
|
|
|
systemctl stop postgresql.service
|
|
|
|
|
|
|
|
export NEWDATA="/mnt/data/postgresql/${newPostgres.psqlSchema}"
|
|
|
|
|
|
|
|
export NEWBIN="${newPostgres}/bin"
|
|
|
|
|
|
|
|
export OLDDATA="${config.services.postgresql.dataDir}"
|
|
|
|
export OLDBIN="${config.services.postgresql.package}/bin"
|
|
|
|
|
|
|
|
install -d -m 0700 -o postgres -g postgres "$NEWDATA"
|
|
|
|
cd "$NEWDATA"
|
|
|
|
sudo -u postgres $NEWBIN/initdb -D "$NEWDATA"
|
|
|
|
|
|
|
|
sudo -u postgres $NEWBIN/pg_upgrade \
|
|
|
|
--old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
|
|
|
|
--old-bindir $OLDBIN --new-bindir $NEWBIN \
|
|
|
|
"$@"
|
|
|
|
'')
|
|
|
|
];
|
2023-10-06 05:33:28 +02:00
|
|
|
}
|