6565 # detection of crypt fails when using llvm stdenv, so we add it manually
6666 # for <13 (where it got removed: https://github.com/postgres/postgres/commit/c45643d618e35ec2fe91438df15abd4f3c0d85ca)
6767 libxcrypt ,
68-
69- isOrioleDB ? false ,
7068 } @args :
7169 let
7270 atLeast = lib . versionAtLeast version ;
@@ -108,43 +106,45 @@ let
108106 ] ;
109107 setOutputFlags = false ; # $out retains configureFlags :-/
110108
111- buildInputs = [
112- zlib
113- readline
114- openssl
115- ( libxml2 . override { python3 = python3 ; } )
116- # Pin ICU to version 75 to maintain collation version 153.120
117- # This prevents collation mismatch warnings when upgrading nixpkgs
118- icu75
119- ]
120- ++ lib . optionals ( olderThan "13" ) [ libxcrypt ]
121- ++ lib . optionals jitSupport [ llvmPackages . llvm ]
122- ++ lib . optionals lz4Enabled [ lz4 ]
123- ++ lib . optionals zstdEnabled [ zstd ]
124- ++ lib . optionals systemdSupport' [ systemd ]
125- ++ lib . optionals pythonSupport [ python3 ]
126- ++ lib . optionals gssSupport [ libkrb5 ]
127- ++ lib . optionals stdenv' . isLinux [ linux-pam ]
128- ++ lib . optionals ( ! stdenv' . isDarwin ) [ libossp_uuid ]
129- ++ lib . optionals ( isOrioleDB || ( lib . versionAtLeast version "17" ) ) [
130- perl
131- bison
132- flex
133- docbook_xsl
134- docbook_xml_dtd_45
135- docbook_xsl_ns
136- libxslt
137- ] ;
109+ buildInputs =
110+ [
111+ zlib
112+ readline
113+ openssl
114+ ( libxml2 . override { python3 = python3 ; } )
115+ # Pin ICU to version 75 to maintain collation version 153.120
116+ # This prevents collation mismatch warnings when upgrading nixpkgs
117+ icu75
118+ ]
119+ ++ lib . optionals ( olderThan "13" ) [ libxcrypt ]
120+ ++ lib . optionals jitSupport [ llvmPackages . llvm ]
121+ ++ lib . optionals lz4Enabled [ lz4 ]
122+ ++ lib . optionals zstdEnabled [ zstd ]
123+ ++ lib . optionals systemdSupport' [ systemd ]
124+ ++ lib . optionals pythonSupport [ python3 ]
125+ ++ lib . optionals gssSupport [ libkrb5 ]
126+ ++ lib . optionals stdenv' . isLinux [ linux-pam ]
127+ ++ lib . optionals ( ! stdenv' . isDarwin ) [ libossp_uuid ]
128+ ++ lib . optionals ( isOrioleDB || ( lib . versionAtLeast version "17" ) ) [
129+ perl
130+ bison
131+ flex
132+ docbook_xsl
133+ docbook_xml_dtd_45
134+ docbook_xsl_ns
135+ libxslt
136+ ] ;
138137
139- nativeBuildInputs = [
140- makeWrapper
141- pkg-config
142- ]
143- ++ lib . optionals jitSupport [
144- llvmPackages . llvm . dev
145- nukeReferences
146- patchelf
147- ] ;
138+ nativeBuildInputs =
139+ [
140+ makeWrapper
141+ pkg-config
142+ ]
143+ ++ lib . optionals jitSupport [
144+ llvmPackages . llvm . dev
145+ nukeReferences
146+ patchelf
147+ ] ;
148148
149149 enableParallelBuilding = true ;
150150
@@ -157,109 +157,113 @@ let
157157 # Fixed upstream in https://github.com/postgres/postgres/commit/0bc8cebdb889368abdf224aeac8bc197fe4c9ae6
158158 env . NIX_CFLAGS_COMPILE = lib . optionalString ( olderThan "13" ) "-I${ libxml2 . dev } /include/libxml2" ;
159159
160- configureFlags = [
161- "--with-openssl"
162- "--with-libxml"
163- "--with-icu"
164- "--sysconfdir=/etc"
165- "--libdir=$(lib)/lib"
166- "--with-system-tzdata=${ tzdata } /share/zoneinfo"
167- "--enable-debug"
168- ( lib . optionalString systemdSupport' "--with-systemd" )
169- ( if stdenv' . isDarwin then "--with-uuid=e2fs" else "--with-ossp-uuid" )
170- ]
171- ++ lib . optionals lz4Enabled [ "--with-lz4" ]
172- ++ lib . optionals zstdEnabled [ "--with-zstd" ]
173- ++ lib . optionals gssSupport [ "--with-gssapi" ]
174- ++ lib . optionals pythonSupport [ "--with-python" ]
175- ++ lib . optionals jitSupport [ "--with-llvm" ]
176- ++ lib . optionals stdenv' . isLinux [ "--with-pam" ] ;
177-
178- patches = [
179- (
180- if atLeast "16" then
181- ./patches/relative-to-symlinks-16+.patch
182- else
183- ./patches/relative-to-symlinks.patch
160+ configureFlags =
161+ [
162+ "--with-openssl"
163+ "--with-libxml"
164+ "--with-icu"
165+ "--sysconfdir=/etc"
166+ "--libdir=$(lib)/lib"
167+ "--with-system-tzdata=${ tzdata } /share/zoneinfo"
168+ "--enable-debug"
169+ ( lib . optionalString systemdSupport' "--with-systemd" )
170+ ( if stdenv' . isDarwin then "--with-uuid=e2fs" else "--with-ossp-uuid" )
171+ ]
172+ ++ lib . optionals lz4Enabled [ "--with-lz4" ]
173+ ++ lib . optionals zstdEnabled [ "--with-zstd" ]
174+ ++ lib . optionals gssSupport [ "--with-gssapi" ]
175+ ++ lib . optionals pythonSupport [ "--with-python" ]
176+ ++ lib . optionals jitSupport [ "--with-llvm" ]
177+ ++ lib . optionals stdenv' . isLinux [ "--with-pam" ] ;
178+
179+ patches =
180+ [
181+ (
182+ if atLeast "16" then
183+ ./patches/relative-to-symlinks-16+.patch
184+ else
185+ ./patches/relative-to-symlinks.patch
186+ )
187+ ./patches/less-is-more.patch
188+ ./patches/paths-for-split-outputs.patch
189+ ./patches/specify_pkglibdir_at_runtime.patch
190+ ./patches/paths-with-postgresql-suffix.patch
191+
192+ ( replaceVars ./patches/locale-binary-path.patch {
193+ locale = "${ if stdenv . isDarwin then darwin . adv_cmds else lib . getBin stdenv . cc . libc } /bin/locale" ;
194+ } )
195+ ]
196+ ++ lib . optionals stdenv' . hostPlatform . isMusl (
197+ # Using fetchurl instead of fetchpatch on purpose: https://github.com/NixOS/nixpkgs/issues/240141
198+ map fetchurl ( lib . attrValues muslPatches )
184199 )
185- ./patches/less-is-more.patch
186- ./patches/paths-for-split-outputs.patch
187- ./patches/specify_pkglibdir_at_runtime.patch
188- ./patches/paths-with-postgresql-suffix.patch
189-
190- ( replaceVars ./patches/locale-binary-path.patch {
191- locale = "${ if stdenv . isDarwin then darwin . adv_cmds else lib . getBin stdenv . cc . libc } /bin/locale" ;
192- } )
193- ]
194- ++ lib . optionals stdenv' . hostPlatform . isMusl (
195- # Using fetchurl instead of fetchpatch on purpose: https://github.com/NixOS/nixpkgs/issues/240141
196- map fetchurl ( lib . attrValues muslPatches )
197- )
198- ++ lib . optionals stdenv' . isLinux [
199- ( if atLeast "13" then ./patches/socketdir-in-run-13+.patch else ./patches/socketdir-in-run.patch )
200- ] ;
200+ ++ lib . optionals stdenv' . isLinux [
201+ ( if atLeast "13" then ./patches/socketdir-in-run-13+.patch else ./patches/socketdir-in-run.patch )
202+ ] ;
201203
202204 installTargets = [ "install-world-bin" ] ;
203205
204- postPatch = ''
205- # Hardcode the path to pgxs so pg_config returns the path in $out
206- substituteInPlace "src/common/config_info.c" --subst-var out
207- ''
208- + lib . optionalString jitSupport ''
209- # Force lookup of jit stuff in $out instead of $lib
210- substituteInPlace src/backend/jit/jit.c --replace pkglib_path \"$out/lib\"
211- substituteInPlace src/backend/jit/llvm/llvmjit.c --replace pkglib_path \"$out/lib\"
212- substituteInPlace src/backend/jit/llvm/llvmjit_inline.cpp --replace pkglib_path \"$out/lib\"
213- '' ;
214-
215- postInstall = ''
216- moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it
217- moveToOutput "lib/libpgcommon*.a" "$out"
218- moveToOutput "lib/libpgport*.a" "$out"
219- moveToOutput "lib/libecpg*" "$out"
220-
221- # Prevent a retained dependency on gcc-wrapper.
222- substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${ stdenv' . cc } /bin/ld ld
223-
224- if [ -z "'' ${dontDisableStatic:-}" ]; then
225- # Remove static libraries in case dynamic are available.
226- for i in $out/lib/*.a $lib/lib/*.a; do
227- name="$(basename "$i")"
228- ext="${ stdenv' . hostPlatform . extensions . sharedLibrary } "
229- if [ -e "$lib/lib/'' ${name%.a}$ext" ] || [ -e "'' ${i%.a}$ext" ]; then
230- rm "$i"
231- fi
232- done
233- fi
234- ''
235- + lib . optionalString jitSupport ''
236- # Move the bitcode and libllvmjit.so library out of $lib; otherwise, every client that
237- # depends on libpq.so will also have libLLVM.so in its closure too, bloating it
238- moveToOutput "lib/bitcode" "$out"
239- moveToOutput "lib/llvmjit*" "$out"
240-
241- # In the case of JIT support, prevent a retained dependency on clang-wrapper
242- substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${ stdenv' . cc } /bin/clang clang
243- nuke-refs $out/lib/llvmjit_types.bc $(find $out/lib/bitcode -type f)
244-
245- # Stop out depending on the default output of llvm
246- substituteInPlace $out/lib/pgxs/src/Makefile.global \
247- --replace ${ llvmPackages . llvm . out } /bin "" \
248- --replace '$(LLVM_BINPATH)/' ""
249-
250- # Stop out depending on the -dev output of llvm
251- substituteInPlace $out/lib/pgxs/src/Makefile.global \
252- --replace ${ llvmPackages . llvm . dev } /bin/llvm-config llvm-config \
253- --replace -I${ llvmPackages . llvm . dev } /include ""
254-
255- ${ lib . optionalString ( ! stdenv' . isDarwin ) ''
256- # Stop lib depending on the -dev output of llvm
257- rpath=$(patchelf --print-rpath $out/lib/llvmjit.so)
258- nuke-refs -e $out $out/lib/llvmjit.so
259- # Restore the correct rpath
260- patchelf $out/lib/llvmjit.so --set-rpath "$rpath"
261- '' }
262- '' ;
206+ postPatch =
207+ ''
208+ # Hardcode the path to pgxs so pg_config returns the path in $out
209+ substituteInPlace "src/common/config_info.c" --subst-var out
210+ ''
211+ + lib . optionalString jitSupport ''
212+ # Force lookup of jit stuff in $out instead of $lib
213+ substituteInPlace src/backend/jit/jit.c --replace pkglib_path \"$out/lib\"
214+ substituteInPlace src/backend/jit/llvm/llvmjit.c --replace pkglib_path \"$out/lib\"
215+ substituteInPlace src/backend/jit/llvm/llvmjit_inline.cpp --replace pkglib_path \"$out/lib\"
216+ '' ;
217+
218+ postInstall =
219+ ''
220+ moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it
221+ moveToOutput "lib/libpgcommon*.a" "$out"
222+ moveToOutput "lib/libpgport*.a" "$out"
223+ moveToOutput "lib/libecpg*" "$out"
224+
225+ # Prevent a retained dependency on gcc-wrapper.
226+ substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${ stdenv' . cc } /bin/ld ld
227+
228+ if [ -z "'' ${dontDisableStatic:-}" ]; then
229+ # Remove static libraries in case dynamic are available.
230+ for i in $out/lib/*.a $lib/lib/*.a; do
231+ name="$(basename "$i")"
232+ ext="${ stdenv' . hostPlatform . extensions . sharedLibrary } "
233+ if [ -e "$lib/lib/'' ${name%.a}$ext" ] || [ -e "'' ${i%.a}$ext" ]; then
234+ rm "$i"
235+ fi
236+ done
237+ fi
238+ ''
239+ + lib . optionalString jitSupport ''
240+ # Move the bitcode and libllvmjit.so library out of $lib; otherwise, every client that
241+ # depends on libpq.so will also have libLLVM.so in its closure too, bloating it
242+ moveToOutput "lib/bitcode" "$out"
243+ moveToOutput "lib/llvmjit*" "$out"
244+
245+ # In the case of JIT support, prevent a retained dependency on clang-wrapper
246+ substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${ stdenv' . cc } /bin/clang clang
247+ nuke-refs $out/lib/llvmjit_types.bc $(find $out/lib/bitcode -type f)
248+
249+ # Stop out depending on the default output of llvm
250+ substituteInPlace $out/lib/pgxs/src/Makefile.global \
251+ --replace ${ llvmPackages . llvm . out } /bin "" \
252+ --replace '$(LLVM_BINPATH)/' ""
253+
254+ # Stop out depending on the -dev output of llvm
255+ substituteInPlace $out/lib/pgxs/src/Makefile.global \
256+ --replace ${ llvmPackages . llvm . dev } /bin/llvm-config llvm-config \
257+ --replace -I${ llvmPackages . llvm . dev } /include ""
258+
259+ ${ lib . optionalString ( ! stdenv' . isDarwin ) ''
260+ # Stop lib depending on the -dev output of llvm
261+ rpath=$(patchelf --print-rpath $out/lib/llvmjit.so)
262+ nuke-refs -e $out $out/lib/llvmjit.so
263+ # Restore the correct rpath
264+ patchelf $out/lib/llvmjit.so --set-rpath "$rpath"
265+ '' }
266+ '' ;
263267
264268 postFixup = lib . optionalString ( ! stdenv' . isDarwin && stdenv' . hostPlatform . libc == "glibc" ) ''
265269 # initdb needs access to "locale" command from glibc.
@@ -313,21 +317,22 @@ let
313317 postgresql = this ;
314318 } this . pkgs ;
315319
316- tests = {
317- postgresql-wal-receiver = import ../../../../nixos/tests/postgresql-wal-receiver.nix {
318- inherit ( stdenv ) system ;
319- pkgs = self ;
320- package = this ;
321- } ;
322- pkg-config = testers . testMetaPkgConfig finalAttrs . finalPackage ;
323- }
324- // lib . optionalAttrs jitSupport {
325- postgresql-jit = import ../../../../nixos/tests/postgresql-jit.nix {
326- inherit ( stdenv ) system ;
327- pkgs = self ;
328- package = this ;
320+ tests =
321+ {
322+ postgresql-wal-receiver = import ../../../../nixos/tests/postgresql-wal-receiver.nix {
323+ inherit ( stdenv ) system ;
324+ pkgs = self ;
325+ package = this ;
326+ } ;
327+ pkg-config = testers . testMetaPkgConfig finalAttrs . finalPackage ;
328+ }
329+ // lib . optionalAttrs jitSupport {
330+ postgresql-jit = import ../../../../nixos/tests/postgresql-jit.nix {
331+ inherit ( stdenv ) system ;
332+ pkgs = self ;
333+ package = this ;
334+ } ;
329335 } ;
330- } ;
331336 } ;
332337
333338 meta = with lib ; {
0 commit comments