Skip to content

Commit

Permalink
postgres: use major version 17 if available (#149)
Browse files Browse the repository at this point in the history
* postgres: use major version 17 if available

* postgres: remove cluster from update script

we don't upgrade any clusters..

* postgres: don't fail if any services fails to stop
  • Loading branch information
SuperSandro2000 authored Oct 28, 2024
1 parent a1c5ef9 commit 1d1ba30
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions modules/postgres.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let
cfg = config.services.postgresql;
cfgu = config.services.postgresql.upgrade;
latestVersion = "16";
latestVersion = if pkgs?postgresql_17 then "17" else "16";
in
{
options.services.postgresql = {
Expand Down Expand Up @@ -39,7 +39,7 @@ in
refreshCollation = libS.mkOpinionatedOption "refresh collation on startup. This prevents errors when initializing new DBs after a glibc upgrade";

upgrade = {
enable = libS.mkOpinionatedOption "install the upgrade-pg-cluster script to update postgres";
enable = libS.mkOpinionatedOption "install the upgrade-postgres script to update postgres";

extraArgs = lib.mkOption {
type = with lib.types; listOf str;
Expand All @@ -52,7 +52,7 @@ in
}) // {
description = ''
The postgres package to which should be updated.
After running upgrade-pg-cluster this must be set to services.postgresql.package to complete the update.
After running upgrade-postgres this must be set to services.postgresql.package to complete the update.
'';
};

Expand Down Expand Up @@ -107,7 +107,7 @@ in
oldData = config.services.postgresql.dataDir;
oldBin = "${if cfg.extraPlugins == [] then oldPackage else oldPackage.withPackages cfg.extraPlugins}/bin";
in
pkgs.writeScriptBin "upgrade-pg-cluster" /* bash */ ''
pkgs.writeScriptBin "upgrade-postgres" /* bash */ ''
set -eu
echo "Current version: ${cfg.package.version}"
Expand All @@ -118,7 +118,9 @@ in
exit 2
fi
systemctl stop postgresql ${lib.concatStringsSep " " cfgu.stopServices}
# don't fail when any unit cannot be stopped
systemctl stop ${lib.concatStringsSep " " cfgu.stopServices} || true
systemctl stop postgresql
install -d -m 0700 -o postgres -g postgres "${newData}"
cd "${newData}"
Expand Down

0 comments on commit 1d1ba30

Please sign in to comment.