Skip to content

Commit

Permalink
pkgsStatic.postgresql: fix build
Browse files Browse the repository at this point in the history
The underlying problem was fixed as a side-effect of [1], for reasons
unknown to me. In the current state, it's enough to disable a few
breaking dependencies to make the build pass.

Note, that this builds the full package, including backend. However, the
backend is not working, yet: Loading shared modules, which PostgreSQL
heavily depends is still broken. Further, all binaries in the default
output, even client binaries such as psql, are currently dynamically
linked against libpq.so. While the current autoconf based build system
doesn't support changing this, this might be possible in the future with
meson.

However, not all is bad: Fixing the build allows using the static
libpq.a library, which is probably the one thing that most users want
from pkgsStatic.postgresql anyway.

Resolves NixOS#191920

[1]: 7797728
  • Loading branch information
wolfgangwalther committed Sep 29, 2024
1 parent 51a8ed1 commit 7d752ac
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pkgs/servers/sql/postgresql/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ let
readline
openssl
(libxml2.override {enableHttp = true;})
icu
]
++ lib.optionals (!stdenv'.hostPlatform.isStatic) [ icu ]
++ lib.optionals (olderThan "13") [ libxcrypt ]
++ lib.optionals jitSupport [ llvmPackages.llvm ]
++ lib.optionals lz4Enabled [ lz4 ]
++ lib.optionals zstdEnabled [ zstd ]
++ lib.optionals systemdSupport' [ systemdLibs ]
++ lib.optionals pythonSupport [ python3 ]
++ lib.optionals gssSupport [ libkrb5 ]
++ lib.optionals stdenv'.hostPlatform.isLinux [ linux-pam ]
++ lib.optionals (stdenv'.hostPlatform.isLinux && !stdenv'.hostPlatform.isStatic) [ linux-pam ]
++ lib.optionals (!stdenv'.hostPlatform.isDarwin) [ libossp_uuid ];

nativeBuildInputs = [
Expand Down Expand Up @@ -133,7 +133,7 @@ let
configureFlags = [
"--with-openssl"
"--with-libxml"
"--with-icu"
(lib.withFeature (!stdenv'.hostPlatform.isStatic) "icu")
"--sysconfdir=/etc"
"--with-system-tzdata=${tzdata}/share/zoneinfo"
"--enable-debug"
Expand All @@ -144,7 +144,7 @@ let
++ lib.optionals gssSupport [ "--with-gssapi" ]
++ lib.optionals pythonSupport [ "--with-python" ]
++ lib.optionals jitSupport [ "--with-llvm" ]
++ lib.optionals stdenv'.hostPlatform.isLinux [ "--with-pam" ]
++ lib.optionals (stdenv'.hostPlatform.isLinux && !stdenv'.hostPlatform.isStatic) [ "--with-pam" ]
# This could be removed once the upstream issue is resolved:
# https://postgr.es/m/flat/427c7c25-e8e1-4fc5-a1fb-01ceff185e5b%40technowledgy.de
++ lib.optionals (stdenv'.hostPlatform.isDarwin && atLeast "16") [ "LDFLAGS_EX_BE=-Wl,-export_dynamic" ];
Expand Down Expand Up @@ -201,7 +201,7 @@ let
# because there is a realistic use-case for extensions to locate the /lib directory to
# load other shared modules.
remove-references-to -t "$dev" -t "$doc" -t "$man" "$out/bin/postgres"
'' + lib.optionalString (!stdenv'.hostPlatform.isStatic) ''
if [ -z "''${dontDisableStatic:-}" ]; then
# Remove static libraries in case dynamic are available.
for i in $lib/lib/*.a; do
Expand All @@ -212,6 +212,7 @@ let
fi
done
fi
'' + ''
# The remaining static libraries are libpgcommon.a, libpgport.a and related.
# Those are only used when building e.g. extensions, so go to $dev.
moveToOutput "lib/*.a" "$dev"
Expand All @@ -229,7 +230,7 @@ let
wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin
'';

doCheck = !stdenv'.hostPlatform.isDarwin;
doCheck = !(stdenv'.hostPlatform.isDarwin || stdenv'.hostPlatform.isStatic);
# autodetection doesn't seem to able to find this, but it's there.
checkTarget = "check";

Expand Down

0 comments on commit 7d752ac

Please sign in to comment.