39 lines
1.1 KiB
Nix
39 lines
1.1 KiB
Nix
{ pkgs, config, ... }: {
|
|
services = {
|
|
postgresql = {
|
|
enable = true;
|
|
};
|
|
|
|
postgresqlBackup = {
|
|
enable = true;
|
|
};
|
|
};
|
|
|
|
# Postgres upgrades: https://nixos.org/manual/nixos/stable/index.html#module-services-postgres-upgrading
|
|
environment.systemPackages = [
|
|
(pkgs.writeScriptBin "upgrade-pg-cluster" ''
|
|
set -eux
|
|
# XXX it's perhaps advisable to stop all services that depend on postgresql
|
|
systemctl stop postgresql
|
|
|
|
# XXX replace `<new version>` with the psqlSchema here
|
|
export NEWDATA="/var/lib/postgresql/11.1"
|
|
|
|
# XXX specify the postgresql package you'd like to upgrade to
|
|
export NEWBIN="${pkgs.postgresql_12}/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 \
|
|
"$@"
|
|
'')
|
|
];
|
|
}
|