From 1b7f0bdfd616de46f23ae4240de775828a469725 Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Fri, 21 Jun 2024 06:42:31 +0300 Subject: [PATCH] postgresql: remove unnecessary store references This change removes Nix store references from the recorded pg_config build configuration. --- pkgs/servers/sql/postgresql/generic.nix | 41 ++++++++++++++++++++----- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/pkgs/servers/sql/postgresql/generic.nix b/pkgs/servers/sql/postgresql/generic.nix index 9104396a3f8c704..55e95b489d9bb66 100644 --- a/pkgs/servers/sql/postgresql/generic.nix +++ b/pkgs/servers/sql/postgresql/generic.nix @@ -2,7 +2,7 @@ let generic = # dependencies - { stdenv, lib, fetchurl, makeWrapper + { stdenv, lib, fetchurl, makeWrapper, writeScript, nukeReferences , glibc, zlib, readline, openssl, icu, lz4, zstd, systemd, libossp_uuid , pkg-config, libxml2, tzdata, libkrb5, substituteAll, darwin , linux-pam @@ -23,7 +23,7 @@ let # JIT , jitSupport - , nukeReferences, patchelf, llvmPackages + , patchelf, llvmPackages # PL/Python , pythonSupport ? false @@ -56,7 +56,9 @@ let hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ]; outputs = [ "out" "lib" "doc" "man" ]; - setOutputFlags = false; # $out retains configureFlags :-/ + # We manually set configure flags and move files to the appropriate outputs + # to avoid references (mostly from pg_config to {man,doc}dir). + setOutputFlags = false; buildInputs = [ zlib @@ -78,8 +80,9 @@ let nativeBuildInputs = [ makeWrapper pkg-config + nukeReferences ] - ++ lib.optionals jitSupport [ llvmPackages.llvm.dev nukeReferences patchelf ]; + ++ lib.optionals jitSupport [ llvmPackages.llvm.dev patchelf ]; enableParallelBuilding = true; @@ -96,7 +99,7 @@ let "--with-libxml" "--with-icu" "--sysconfdir=/etc" - "--libdir=$(lib)/lib" + "--libdir=${placeholder "lib"}/lib" "--with-system-tzdata=${tzdata}/share/zoneinfo" "--enable-debug" (lib.optionalString systemdSupport' "--with-systemd") @@ -132,6 +135,19 @@ let postPatch = '' # Hardcode the path to pgxs so pg_config returns the path in $out substituteInPlace "src/common/config_info.c" --subst-var out + + # Do not record CC and related build information. + substituteInPlace src/common/Makefile \ + --replace-fail \ + "override CPPFLAGS += -DVAL_" \ + "# override CPPFLAGS += -DVAL_" + + # Record arguments without store references. + substituteInPlace configure \ + --replace-fail \ + '#define CONFIGURE_ARGS "$ac_configure_args"' \ + '#define CONFIGURE_ARGS "$fakeConfigureArgs"' + touch -r configure.ac configure '' + lib.optionalString jitSupport '' # Force lookup of jit stuff in $out instead of $lib substituteInPlace src/backend/jit/jit.c --replace pkglib_path \"$out/lib\" @@ -139,6 +155,16 @@ let substituteInPlace src/backend/jit/llvm/llvmjit_inline.cpp --replace pkglib_path \"$out/lib\" ''; + # Avoid implicit references in the recorded configure arguments. + configureScript = writeScript "postgresql-configure-wrapper" '' + printf %s "''${*@Q}" >fake-configure-args + nuke-refs fake-configure-args + fakeConfigureArgs=$(