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