Skip to content

Commit

Permalink
postgresql: remove unnecessary store references
Browse files Browse the repository at this point in the history
This change removes Nix store references from the recorded pg_config
build configuration.
  • Loading branch information
tie committed Jun 24, 2024
1 parent ae3742c commit cc6fdd8
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions pkgs/servers/sql/postgresql/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +23,7 @@ let

# JIT
, jitSupport
, nukeReferences, patchelf, llvmPackages
, patchelf, llvmPackages

# PL/Python
, pythonSupport ? false
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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")
Expand Down Expand Up @@ -132,22 +135,45 @@ 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\"
substituteInPlace src/backend/jit/llvm/llvmjit.c --replace pkglib_path \"$out/lib\"
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=$(<fake-configure-args)
rm fake-configure-args
export fakeConfigureArgs
./configure "$@"
'';

postInstall =
''
moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it
moveToOutput "lib/libpgcommon*.a" "$out"
moveToOutput "lib/libpgport*.a" "$out"
moveToOutput "lib/libecpg*" "$out"
# Prevent a retained dependency on gcc-wrapper.
substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld
# Prevent an unused retained dependency on build inputs.
nuke-refs "$out/lib/pgxs/src/Makefile.global"
if [ -z "''${dontDisableStatic:-}" ]; then
# Remove static libraries in case dynamic are available.
Expand All @@ -166,7 +192,6 @@ let
moveToOutput "lib/llvmjit*" "$out"
# In the case of JIT support, prevent a retained dependency on clang-wrapper
substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/clang clang
nuke-refs $out/lib/llvmjit_types.bc $(find $out/lib/bitcode -type f)
# Stop out depending on the default output of llvm
Expand Down

0 comments on commit cc6fdd8

Please sign in to comment.