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