From 6af01120a6e861527d5a8a3e4fc3f875730ac1ea Mon Sep 17 00:00:00 2001 From: Christoph Hrdinka Date: Fri, 10 Jan 2025 13:34:16 +0100 Subject: [PATCH 1/2] postgresql: fix build if pythonSupport is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since https://github.com/NixOS/nixpkgs/commit/445371f309a62e9107ad78fb3c65fff768efb43c (which added `strictDeps = true;`) the build of PostgreSQL is broken if python support is enabled (via argument `pythonSupport = true`). The problem seems to be that PostgreSQL’s build system is unable to find the supplied Python installation. This commit fixes the build by setting the `PYTHON` environment variable within the build environment, as document here: https://www.postgresql.org/docs/current/install-make.html#CONFIGURE-ENVVARS-PYTHON Closes #372333 --- pkgs/servers/sql/postgresql/generic.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/servers/sql/postgresql/generic.nix b/pkgs/servers/sql/postgresql/generic.nix index 2effd687e8e4..a6bbe3871dc3 100644 --- a/pkgs/servers/sql/postgresql/generic.nix +++ b/pkgs/servers/sql/postgresql/generic.nix @@ -247,9 +247,11 @@ let # flags will remove unused sections from all shared libraries and binaries - including # those paths. This avoids a lot of circular dependency problems with different outputs, # and allows splitting them cleanly. - env.CFLAGS = - "-fdata-sections -ffunction-sections" - + (if stdenv'.cc.isClang then " -flto" else " -fmerge-constants -Wl,--gc-sections"); + env = { + CFLAGS = + "-fdata-sections -ffunction-sections" + + (if stdenv'.cc.isClang then " -flto" else " -fmerge-constants -Wl,--gc-sections"); + } // lib.optionalAttrs pythonSupport { PYTHON = "${python3}/bin/python"; }; configureFlags = let From b6773ad79eb3bc735e3a8d6c230240b327d1254c Mon Sep 17 00:00:00 2001 From: Christoph Hrdinka Date: Fri, 10 Jan 2025 13:36:28 +0100 Subject: [PATCH 2/2] postgresql: add PYTHONPATH via wrapProgram Currently `PYTHONPATH` is not set when building PostgreSQL. This results in Python modules not being available within `pl/python3u`. This commit adds `PYTHONPATH` of the supplied `python3` via `wrapProgram`, which is especially useful when supplying a custom Python env. --- pkgs/servers/sql/postgresql/generic.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkgs/servers/sql/postgresql/generic.nix b/pkgs/servers/sql/postgresql/generic.nix index a6bbe3871dc3..82ae3d4ac21f 100644 --- a/pkgs/servers/sql/postgresql/generic.nix +++ b/pkgs/servers/sql/postgresql/generic.nix @@ -380,10 +380,14 @@ let --replace-fail '-bundle_loader $(bindir)/postgres' "-bundle_loader $out/bin/postgres" ''; - postFixup = lib.optionalString stdenv'.hostPlatform.isGnu '' - # initdb needs access to "locale" command from glibc. - wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin - ''; + postFixup = + lib.optionalString stdenv'.hostPlatform.isGnu '' + # initdb needs access to "locale" command from glibc. + wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin + '' + + lib.optionalString pythonSupport '' + wrapProgram "$out/bin/postgres" --set PYTHONPATH "${python3}/${python3.sitePackages}" + ''; # Running tests as "install check" to work around SIP issue on macOS: # https://www.postgresql.org/message-id/flat/4D8E1BC5-BBCF-4B19-8226-359201EA8305%40gmail.com