Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgres: use major version 17 if available #149

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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