Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 728 lines 26 kB view raw
1let 2 3 generic = 4 # utils 5 { 6 stdenv, 7 fetchFromGitHub, 8 fetchurl, 9 lib, 10 replaceVars, 11 writeShellScriptBin, 12 13 # source specification 14 hash, 15 muslPatches ? { }, 16 rev, 17 version, 18 19 # runtime dependencies 20 darwin, 21 freebsd, 22 glibc, 23 libuuid, 24 libxml2, 25 lz4, 26 openssl, 27 readline, 28 tzdata, 29 zlib, 30 zstd, 31 32 # build dependencies 33 bison, 34 docbook-xsl-nons, 35 docbook_xml_dtd_45, 36 flex, 37 libxslt, 38 makeBinaryWrapper, 39 pkg-config, 40 removeReferencesTo, 41 42 # passthru 43 buildEnv, 44 buildPackages, 45 newScope, 46 nixosTests, 47 postgresqlTestHook, 48 self, 49 stdenvNoCC, 50 testers, 51 52 # Block size 53 # Changing the block size will break on-disk database compatibility. See: 54 # https://www.postgresql.org/docs/current/install-make.html#CONFIGURE-OPTION-WITH-BLOCKSIZE 55 withBlocksize ? null, 56 withWalBlocksize ? null, 57 58 # bonjour 59 bonjourSupport ? false, 60 61 # Curl 62 curlSupport ? 63 lib.versionAtLeast version "18" 64 && lib.meta.availableOn stdenv.hostPlatform curl 65 # Building statically fails with: 66 # configure: error: library 'curl' does not provide curl_multi_init 67 # https://www.postgresql.org/message-id/487dacec-6d8d-46c0-a36f-d5b8c81a56f1%40technowledgy.de 68 && !stdenv.hostPlatform.isStatic, 69 curl, 70 71 # GSSAPI 72 gssSupport ? with stdenv.hostPlatform; !isWindows && !isStatic, 73 libkrb5, 74 75 # icu 76 # Building with icu in pkgsStatic gives tons of "undefined reference" errors like this: 77 # /nix/store/452lkaak37d3mzzn3p9ak7aa3wzhdqaj-icu4c-74.2-x86_64-unknown-linux-musl/lib/libicuuc.a(chariter.ao): 78 # (.data.rel.ro._ZTIN6icu_7417CharacterIteratorE[_ZTIN6icu_7417CharacterIteratorE]+0x0): 79 # undefined reference to `vtable for __cxxabiv1::__si_class_type_info' 80 icuSupport ? !stdenv.hostPlatform.isStatic, 81 icu, 82 83 # JIT 84 jitSupport ? 85 stdenv.hostPlatform.canExecute stdenv.buildPlatform 86 # Building with JIT in pkgsStatic fails like this: 87 # fatal error: 'stdio.h' file not found 88 && !stdenv.hostPlatform.isStatic, 89 llvmPackages, 90 nukeReferences, 91 overrideCC, 92 93 # LDAP 94 ldapSupport ? false, 95 openldap, 96 97 # NLS 98 nlsSupport ? false, 99 gettext, 100 101 # NUMA 102 numaSupport ? 103 lib.versionAtLeast version "18" 104 && lib.meta.availableOn stdenv.hostPlatform numactl 105 # NUMA can fail in 18beta2 on some hardware with: 106 # ERROR: invalid NUMA node id outside of allowed range [0, 0]: 1 107 # https://github.com/NixOS/nixpkgs/pull/411958#issuecomment-3031680123 108 # https://www.postgresql.org/message-id/flat/E1u1tr8-003BbN-2E%40gemulon.postgresql.org 109 && version != "18beta2", 110 numactl, 111 112 # PAM 113 pamSupport ? 114 lib.meta.availableOn stdenv.hostPlatform linux-pam 115 # Building with linux-pam in pkgsStatic gives a few "undefined reference" errors like this: 116 # /nix/store/3s55icpsbc36sgn7sa8q3qq4z6al6rlr-linux-pam-static-x86_64-unknown-linux-musl-1.6.1/lib/libpam.a(pam_audit.o): 117 # in function `pam_modutil_audit_write':(.text+0x571): 118 # undefined reference to `audit_close' 119 && !stdenv.hostPlatform.isStatic, 120 linux-pam, 121 122 # PL/Perl 123 perlSupport ? 124 lib.meta.availableOn stdenv.hostPlatform perl 125 # Building with perl in pkgsStatic gives this error: 126 # configure: error: cannot build PL/Perl because libperl is not a shared library 127 && !stdenv.hostPlatform.isStatic 128 # configure tries to call the perl executable for the version 129 && stdenv.buildPlatform.canExecute stdenv.hostPlatform, 130 perl, 131 132 # PL/Python 133 pythonSupport ? 134 lib.meta.availableOn stdenv.hostPlatform python3 135 # Building with python in pkgsStatic gives this error: 136 # checking how to link an embedded Python application... configure: error: could not find shared library for Python 137 && !stdenv.hostPlatform.isStatic 138 # configure tries to call the python executable 139 && stdenv.buildPlatform.canExecute stdenv.hostPlatform, 140 python3, 141 142 # PL/Tcl 143 tclSupport ? 144 lib.meta.availableOn stdenv.hostPlatform tcl 145 # tcl is broken in pkgsStatic 146 && !stdenv.hostPlatform.isStatic 147 # configure fails with: 148 # configure: error: file 'tclConfig.sh' is required for Tcl 149 && stdenv.buildPlatform.canExecute stdenv.hostPlatform, 150 tcl, 151 152 # SELinux 153 selinuxSupport ? false, 154 libselinux, 155 156 # Systemd 157 systemdSupport ? lib.meta.availableOn stdenv.hostPlatform systemdLibs, 158 systemdLibs, 159 160 # Uring 161 uringSupport ? lib.versionAtLeast version "18" && lib.meta.availableOn stdenv.hostPlatform liburing, 162 liburing, 163 }@args: 164 let 165 atLeast = lib.versionAtLeast version; 166 olderThan = lib.versionOlder version; 167 lz4Enabled = atLeast "14"; 168 zstdEnabled = atLeast "15"; 169 170 dlSuffix = if olderThan "16" then ".so" else stdenv.hostPlatform.extensions.sharedLibrary; 171 172 stdenv' = 173 if !stdenv.cc.isClang then 174 overrideCC llvmPackages.stdenv ( 175 llvmPackages.stdenv.cc.override { 176 # LLVM bintools are not used by default, but are needed to make -flto work below. 177 bintools = llvmPackages.bintools; 178 } 179 ) 180 else 181 stdenv; 182 in 183 stdenv'.mkDerivation (finalAttrs: { 184 inherit version; 185 pname = "postgresql"; 186 187 src = fetchFromGitHub { 188 owner = "postgres"; 189 repo = "postgres"; 190 # rev, not tag, on purpose: allows updating when new versions 191 # are "stamped" a few days before release (tag). 192 inherit hash rev; 193 }; 194 195 __structuredAttrs = true; 196 197 outputs = [ 198 "out" 199 "dev" 200 "doc" 201 "lib" 202 "man" 203 ] 204 ++ lib.optionals jitSupport [ "jit" ] 205 ++ lib.optionals perlSupport [ "plperl" ] 206 ++ lib.optionals pythonSupport [ "plpython3" ] 207 ++ lib.optionals tclSupport [ "pltcl" ]; 208 209 outputChecks = { 210 out = { 211 disallowedReferences = [ 212 "dev" 213 "doc" 214 "man" 215 ] 216 ++ lib.optionals jitSupport [ "jit" ]; 217 disallowedRequisites = [ 218 stdenv'.cc 219 llvmPackages.llvm.out 220 llvmPackages.llvm.lib 221 ] 222 ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs)); 223 }; 224 225 lib = { 226 disallowedReferences = [ 227 "out" 228 "dev" 229 "doc" 230 "man" 231 ] 232 ++ lib.optionals jitSupport [ "jit" ]; 233 disallowedRequisites = [ 234 stdenv'.cc 235 llvmPackages.llvm.out 236 llvmPackages.llvm.lib 237 ] 238 ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs)); 239 }; 240 241 doc = { 242 disallowedReferences = [ 243 "out" 244 "dev" 245 "man" 246 ] 247 ++ lib.optionals jitSupport [ "jit" ]; 248 }; 249 250 man = { 251 disallowedReferences = [ 252 "out" 253 "dev" 254 "doc" 255 ] 256 ++ lib.optionals jitSupport [ "jit" ]; 257 }; 258 } 259 // lib.optionalAttrs jitSupport { 260 jit = { 261 disallowedReferences = [ 262 "dev" 263 "doc" 264 "man" 265 ]; 266 disallowedRequisites = [ 267 stdenv'.cc 268 llvmPackages.llvm.out 269 ] 270 ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs)); 271 }; 272 }; 273 274 strictDeps = true; 275 276 buildInputs = [ 277 zlib 278 readline 279 openssl 280 libxml2 281 libuuid 282 ] 283 ++ lib.optionals icuSupport [ icu ] 284 ++ lib.optionals jitSupport [ llvmPackages.llvm ] 285 ++ lib.optionals lz4Enabled [ lz4 ] 286 ++ lib.optionals zstdEnabled [ zstd ] 287 ++ lib.optionals systemdSupport [ systemdLibs ] 288 ++ lib.optionals uringSupport [ liburing ] 289 ++ lib.optionals curlSupport [ curl ] 290 ++ lib.optionals numaSupport [ numactl ] 291 ++ lib.optionals gssSupport [ libkrb5 ] 292 ++ lib.optionals pamSupport [ linux-pam ] 293 ++ lib.optionals perlSupport [ perl ] 294 ++ lib.optionals ldapSupport [ openldap ] 295 ++ lib.optionals selinuxSupport [ libselinux ] 296 ++ lib.optionals nlsSupport [ gettext ]; 297 298 nativeBuildInputs = [ 299 bison 300 docbook-xsl-nons 301 docbook_xml_dtd_45 302 flex 303 libxml2 304 libxslt 305 makeBinaryWrapper 306 perl 307 pkg-config 308 removeReferencesTo 309 ] 310 ++ lib.optionals jitSupport [ 311 llvmPackages.llvm.dev 312 nukeReferences 313 ]; 314 315 enableParallelBuilding = true; 316 317 separateDebugInfo = true; 318 319 buildFlags = [ "world" ]; 320 321 env = { 322 # libpgcommon.a and libpgport.a contain all paths returned by pg_config and are linked 323 # into all binaries. However, almost no binaries actually use those paths. The following 324 # flags will remove unused sections from all shared libraries and binaries - including 325 # those paths. This avoids a lot of circular dependency problems with different outputs, 326 # and allows splitting them cleanly. 327 CFLAGS = "-fdata-sections -ffunction-sections -flto"; 328 329 # This flag was introduced upstream in: 330 # https://github.com/postgres/postgres/commit/b6c7cfac88c47a9194d76f3d074129da3c46545a 331 # It causes errors when linking against libpq.a in pkgsStatic: 332 # undefined reference to `pg_encoding_to_char' 333 # Unsetting the flag fixes it. The upstream reasoning to introduce it is about the risk 334 # to have initdb load a libpq.so from a different major version and how to avoid that. 335 # This doesn't apply to us with Nix. 336 NIX_CFLAGS_COMPILE = "-UUSE_PRIVATE_ENCODING_FUNCS"; 337 } 338 // lib.optionalAttrs perlSupport { PERL = lib.getExe perl; } 339 // lib.optionalAttrs pythonSupport { PYTHON = lib.getExe python3; } 340 // lib.optionalAttrs tclSupport { TCLSH = "${lib.getBin tcl}/bin/tclsh"; }; 341 342 configureFlags = 343 let 344 inherit (lib) withFeature; 345 in 346 [ 347 "--with-openssl" 348 "--with-libxml" 349 (withFeature icuSupport "icu") 350 "--sysconfdir=/etc" 351 "--with-system-tzdata=${tzdata}/share/zoneinfo" 352 "--enable-debug" 353 (lib.optionalString systemdSupport "--with-systemd") 354 (if stdenv.hostPlatform.isFreeBSD then "--with-uuid=bsd" else "--with-uuid=e2fs") 355 (withFeature perlSupport "perl") 356 ] 357 ++ lib.optionals (withBlocksize != null) [ "--with-blocksize=${toString withBlocksize}" ] 358 ++ lib.optionals (withWalBlocksize != null) [ "--with-wal-blocksize=${toString withWalBlocksize}" ] 359 ++ lib.optionals lz4Enabled [ "--with-lz4" ] 360 ++ lib.optionals zstdEnabled [ "--with-zstd" ] 361 ++ lib.optionals uringSupport [ "--with-liburing" ] 362 ++ lib.optionals curlSupport [ "--with-libcurl" ] 363 ++ lib.optionals numaSupport [ "--with-libnuma" ] 364 ++ lib.optionals gssSupport [ "--with-gssapi" ] 365 ++ lib.optionals pythonSupport [ "--with-python" ] 366 ++ lib.optionals jitSupport [ "--with-llvm" ] 367 ++ lib.optionals pamSupport [ "--with-pam" ] 368 # This can be removed once v17 is removed. v18+ ships with it. 369 ++ lib.optionals (stdenv'.hostPlatform.isDarwin && atLeast "16" && olderThan "18") [ 370 "LDFLAGS_EX_BE=-Wl,-export_dynamic" 371 ] 372 # some version of this flag is required in all cross configurations 373 # since it cannot be automatically detected 374 ++ 375 lib.optionals 376 ( 377 (!stdenv'.hostPlatform.isDarwin) 378 && (!(stdenv'.buildPlatform.canExecute stdenv.hostPlatform)) 379 && atLeast "16" 380 ) 381 [ 382 "LDFLAGS_EX_BE=-Wl,--export-dynamic" 383 ] 384 ++ lib.optionals ldapSupport [ "--with-ldap" ] 385 ++ lib.optionals tclSupport [ "--with-tcl" ] 386 ++ lib.optionals selinuxSupport [ "--with-selinux" ] 387 ++ lib.optionals nlsSupport [ "--enable-nls" ] 388 ++ lib.optionals bonjourSupport [ "--with-bonjour" ]; 389 390 patches = [ 391 ( 392 if atLeast "16" then 393 ./patches/relative-to-symlinks-16+.patch 394 else 395 ./patches/relative-to-symlinks.patch 396 ) 397 ( 398 if atLeast "15" then 399 ./patches/empty-pg-config-view-15+.patch 400 else 401 ./patches/empty-pg-config-view.patch 402 ) 403 ./patches/less-is-more.patch 404 ./patches/paths-for-split-outputs.patch 405 ./patches/paths-with-postgresql-suffix.patch 406 407 (replaceVars ./patches/locale-binary-path.patch { 408 locale = "${ 409 if stdenv.hostPlatform.isDarwin then 410 darwin.adv_cmds 411 else if stdenv.hostPlatform.isFreeBSD then 412 freebsd.locale 413 else 414 lib.getBin stdenv.cc.libc 415 }/bin/locale"; 416 }) 417 ] 418 ++ lib.optionals stdenv'.hostPlatform.isMusl ( 419 # Using fetchurl instead of fetchpatch on purpose: https://github.com/NixOS/nixpkgs/issues/240141 420 map fetchurl (lib.attrValues muslPatches) 421 ) 422 ++ lib.optionals stdenv'.hostPlatform.isLinux [ 423 ./patches/socketdir-in-run-13+.patch 424 ] 425 ++ lib.optionals (stdenv'.hostPlatform.isDarwin && olderThan "16") [ 426 ./patches/export-dynamic-darwin-15-.patch 427 ]; 428 429 installTargets = [ "install-world" ]; 430 431 postPatch = '' 432 substituteInPlace "src/Makefile.global.in" --subst-var out 433 substituteInPlace "src/common/config_info.c" --subst-var dev 434 cat ${./pg_config.env.mk} >> src/common/Makefile 435 '' 436 # This check was introduced upstream to prevent calls to "exit" inside libpq. 437 # However, this doesn't work reliably with static linking, see this and following: 438 # https://postgr.es/m/flat/20210703001639.GB2374652%40rfd.leadboat.com#52584ca4bd3cb9dac376f3158c419f97 439 # Thus, disable the check entirely, as it would currently fail with this: 440 # > libpq.so.5.17: U atexit 441 # > libpq.so.5.17: U pthread_exit 442 # > libpq must not be calling any function which invokes exit 443 # Don't mind the fact that this checks libpq.**so** in pkgsStatic - that's correct, since PostgreSQL 444 # still needs a shared library internally. 445 + lib.optionalString (atLeast "15" && stdenv'.hostPlatform.isStatic) '' 446 substituteInPlace src/interfaces/libpq/Makefile \ 447 --replace-fail "echo 'libpq must not be calling any function which invokes exit'; exit 1;" "echo;" 448 ''; 449 450 postInstall = '' 451 moveToOutput "bin/ecpg" "$dev" 452 moveToOutput "lib/pgxs" "$dev" 453 '' 454 + lib.optionalString (stdenv'.buildPlatform.canExecute stdenv'.hostPlatform) '' 455 mkdir -p "$dev/nix-support" 456 "$out/bin/pg_config" > "$dev/nix-support/pg_config.expected" 457 '' 458 + '' 459 rm "$out/bin/pg_config" 460 make -C src/common pg_config.env 461 install -D src/common/pg_config.env "$dev/nix-support/pg_config.env" 462 463 # postgres exposes external symbols get_pkginclude_path and similar. Those 464 # can't be stripped away by --gc-sections/LTO, because they could theoretically 465 # be used by dynamically loaded modules / extensions. To avoid circular dependencies, 466 # references to -dev, -doc and -man are removed here. References to -lib must be kept, 467 # because there is a realistic use-case for extensions to locate the /lib directory to 468 # load other shared modules. 469 remove-references-to -t "$dev" -t "$doc" -t "$man" "$out/bin/postgres" 470 '' 471 + lib.optionalString (!stdenv'.hostPlatform.isStatic) '' 472 if [ -z "''${dontDisableStatic:-}" ]; then 473 # Remove static libraries in case dynamic are available. 474 for i in $lib/lib/*.a; do 475 name="$(basename "$i")" 476 ext="${stdenv'.hostPlatform.extensions.sharedLibrary}" 477 if [ -e "$lib/lib/''${name%.a}$ext" ] || [ -e "''${i%.a}$ext" ]; then 478 rm "$i" 479 fi 480 done 481 fi 482 '' 483 + '' 484 # The remaining static libraries are libpgcommon.a, libpgport.a and related. 485 # Those are only used when building e.g. extensions, so go to $dev. 486 moveToOutput "lib/*.a" "$dev" 487 '' 488 + lib.optionalString jitSupport '' 489 # In the case of JIT support, prevent useless dependencies on header files 490 find "$out/lib" -iname '*.bc' -type f -exec nuke-refs '{}' + 491 492 # Stop lib depending on the -dev output of llvm 493 remove-references-to -t ${llvmPackages.llvm.dev} "$out/lib/llvmjit${dlSuffix}" 494 495 moveToOutput "lib/bitcode" "$jit" 496 moveToOutput "lib/llvmjit*" "$jit" 497 '' 498 + lib.optionalString stdenv'.hostPlatform.isDarwin '' 499 # The darwin specific Makefile for PGXS contains a reference to the postgres 500 # binary. Some extensions (here: postgis), which are able to set bindir correctly 501 # to their own output for installation, will then fail to find "postgres" during linking. 502 substituteInPlace "$dev/lib/pgxs/src/Makefile.port" \ 503 --replace-fail '-bundle_loader $(bindir)/postgres' "-bundle_loader $out/bin/postgres" 504 '' 505 + lib.optionalString perlSupport '' 506 moveToOutput "lib/*plperl*" "$plperl" 507 moveToOutput "share/postgresql/extension/*plperl*" "$plperl" 508 '' 509 + lib.optionalString pythonSupport '' 510 moveToOutput "lib/*plpython3*" "$plpython3" 511 moveToOutput "share/postgresql/extension/*plpython3*" "$plpython3" 512 '' 513 + lib.optionalString tclSupport '' 514 moveToOutput "lib/*pltcl*" "$pltcl" 515 moveToOutput "share/postgresql/extension/*pltcl*" "$pltcl" 516 ''; 517 518 postFixup = lib.optionalString stdenv'.hostPlatform.isGnu '' 519 # initdb needs access to "locale" command from glibc. 520 wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin 521 ''; 522 523 # Running tests as "install check" to work around SIP issue on macOS: 524 # https://www.postgresql.org/message-id/flat/4D8E1BC5-BBCF-4B19-8226-359201EA8305%40gmail.com 525 # Also see <nixpkgs>/doc/stdenv/platform-notes.chapter.md 526 doCheck = false; 527 doInstallCheck = 528 !(stdenv'.hostPlatform.isStatic) 529 && 530 # Tests currently can't be run on darwin, because of a Nix bug: 531 # https://github.com/NixOS/nix/issues/12548 532 # https://git.lix.systems/lix-project/lix/issues/691 533 # The error appears as this in the initdb logs: 534 # FATAL: could not create shared memory segment: Cannot allocate memory 535 # Don't let yourself be fooled when trying to remove this condition: Running 536 # the tests works fine most of the time. But once the tests (or any package using 537 # postgresqlTestHook) fails on the same machine for a few times, enough IPC objects 538 # will be stuck around, and any future builds with the tests enabled *will* fail. 539 !(stdenv'.hostPlatform.isDarwin) 540 && 541 # Regression tests currently fail in pkgsMusl because of a difference in EXPLAIN output. 542 !(stdenv'.hostPlatform.isMusl) 543 && 544 # Modifying block sizes is expected to break regression tests. 545 # https://www.postgresql.org/message-id/E1TJOeZ-000717-Lg%40wrigleys.postgresql.org 546 (withBlocksize == null && withWalBlocksize == null); 547 installCheckTarget = "check-world"; 548 549 passthru = 550 let 551 this = self.callPackage generic args; 552 in 553 { 554 inherit dlSuffix; 555 556 psqlSchema = lib.versions.major version; 557 558 withJIT = this.withPackages (_: [ this.jit ]); 559 withoutJIT = this; 560 561 pkgs = 562 let 563 scope = { 564 inherit 565 jitSupport 566 pythonSupport 567 perlSupport 568 tclSupport 569 ; 570 inherit (llvmPackages) llvm; 571 postgresql = this; 572 stdenv = stdenv'; 573 postgresqlTestExtension = newSuper.callPackage ./postgresqlTestExtension.nix { }; 574 postgresqlBuildExtension = newSuper.callPackage ./postgresqlBuildExtension.nix { }; 575 }; 576 newSelf = self // scope; 577 newSuper = { 578 callPackage = newScope (scope // this.pkgs); 579 }; 580 in 581 import ./ext.nix newSelf newSuper; 582 583 withPackages = postgresqlWithPackages { 584 inherit buildEnv lib makeBinaryWrapper; 585 postgresql = this; 586 }; 587 588 pg_config = buildPackages.callPackage ./pg_config.nix { inherit (finalAttrs) finalPackage; }; 589 590 tests = { 591 postgresql = nixosTests.postgresql.postgresql.passthru.override finalAttrs.finalPackage; 592 postgresql-tls-client-cert = nixosTests.postgresql.postgresql-tls-client-cert.passthru.override finalAttrs.finalPackage; 593 postgresql-wal-receiver = nixosTests.postgresql.postgresql-wal-receiver.passthru.override finalAttrs.finalPackage; 594 pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; 595 } 596 // lib.optionalAttrs jitSupport { 597 postgresql-jit = nixosTests.postgresql.postgresql-jit.passthru.override finalAttrs.finalPackage; 598 }; 599 }; 600 601 meta = with lib; { 602 homepage = "https://www.postgresql.org"; 603 description = "Powerful, open source object-relational database system"; 604 license = licenses.postgresql; 605 changelog = "https://www.postgresql.org/docs/release/${finalAttrs.version}/"; 606 teams = [ teams.postgres ]; 607 pkgConfigModules = [ 608 "libecpg" 609 "libecpg_compat" 610 "libpgtypes" 611 "libpq" 612 ]; 613 platforms = platforms.unix; 614 615 # JIT support doesn't work with cross-compilation. It is attempted to build LLVM-bytecode 616 # (`%.bc` is the corresponding `make(1)`-rule) for each sub-directory in `backend/` for 617 # the JIT apparently, but with a $(CLANG) that can produce binaries for the build, not the 618 # host-platform. 619 # 620 # I managed to get a cross-build with JIT support working with 621 # `depsBuildBuild = [ llvmPackages.clang ] ++ buildInputs`, but considering that the 622 # resulting LLVM IR isn't platform-independent this doesn't give you much. 623 # In fact, I tried to test the result in a VM-test, but as soon as JIT was used to optimize 624 # a query, postgres would coredump with `Illegal instruction`. 625 # 626 # Note: This is "host canExecute build" on purpose, since this is about the LLVM that is called 627 # to do JIT at **runtime**. 628 broken = jitSupport && !stdenv.hostPlatform.canExecute stdenv.buildPlatform; 629 }; 630 }); 631 632 postgresqlWithPackages = 633 { 634 postgresql, 635 buildEnv, 636 lib, 637 makeBinaryWrapper, 638 }: 639 f: 640 let 641 installedExtensions = f postgresql.pkgs; 642 finalPackage = 643 (buildEnv { 644 name = "${postgresql.pname}-and-plugins-${postgresql.version}"; 645 paths = installedExtensions ++ [ 646 # consider keeping in-sync with `postBuild` below 647 postgresql 648 postgresql.man # in case user installs this into environment 649 ]; 650 651 pathsToLink = [ 652 "/" 653 "/bin" 654 "/share/postgresql/extension" 655 # Unbreaks Omnigres' build system 656 "/share/postgresql/timezonesets" 657 "/share/postgresql/tsearch_data" 658 ]; 659 660 nativeBuildInputs = [ makeBinaryWrapper ]; 661 postBuild = 662 let 663 args = lib.concatMap (ext: ext.wrapperArgs or [ ]) installedExtensions; 664 in 665 '' 666 wrapProgram "$out/bin/postgres" ${lib.concatStringsSep " " args} 667 668 mkdir -p "$dev/nix-support" 669 substitute "${lib.getDev postgresql}/nix-support/pg_config.env" "$dev/nix-support/pg_config.env" \ 670 --replace-fail "${postgresql}" "$out" \ 671 --replace-fail "${postgresql.man}" "$out" 672 ''; 673 674 passthru = { 675 inherit installedExtensions; 676 inherit (postgresql) 677 pkgs 678 psqlSchema 679 version 680 ; 681 682 pg_config = postgresql.pg_config.override { inherit finalPackage; }; 683 684 withJIT = postgresqlWithPackages { 685 inherit 686 buildEnv 687 lib 688 makeBinaryWrapper 689 postgresql 690 ; 691 } (_: installedExtensions ++ [ postgresql.jit ]); 692 withoutJIT = postgresqlWithPackages { 693 inherit 694 buildEnv 695 lib 696 makeBinaryWrapper 697 postgresql 698 ; 699 } (_: lib.remove postgresql.jit installedExtensions); 700 701 withPackages = 702 f': 703 postgresqlWithPackages { 704 inherit 705 buildEnv 706 lib 707 makeBinaryWrapper 708 postgresql 709 ; 710 } (ps: installedExtensions ++ f' ps); 711 }; 712 }).overrideAttrs 713 { 714 # buildEnv doesn't support passing `outputs`, so going via overrideAttrs. 715 outputs = [ 716 "out" 717 "dev" 718 ]; 719 }; 720 in 721 finalPackage; 722 723in 724# passed by <major>.nix 725versionArgs: 726# passed by default.nix 727{ self, ... }@defaultArgs: 728self.callPackage generic (defaultArgs // versionArgs)