|
445 | 445 | then static_package |
446 | 446 | else throw "If you see this, nixpkgs #61682 has been fixed and ${name} should be overridden"; |
447 | 447 |
|
| 448 | + # Takes a zlib derivation and overrides it to have both .a and .so files. |
| 449 | + statify_zlib = zlib_drv: |
| 450 | + (zlib_drv.override { |
| 451 | + static = false; |
| 452 | + shared = true; |
| 453 | + }).overrideAttrs (old: { dontDisableStatic = true; }); |
| 454 | + |
| 455 | + # Takes a curl derivation and overrides it to have both .a and .so files, |
| 456 | + # and have the `curl` executable be statically linked. |
| 457 | + statify_curl_including_exe = curl_drv: |
| 458 | + (curl_drv.override (old: { |
| 459 | + # Disable gss support, because that requires `krb5`, which |
| 460 | + # (as mentioned in note [krb5 can only be static XOR shared]) is a |
| 461 | + # library that cannot build both .a and .so files in its build system. |
| 462 | + # That means that if we enable it, we can no longer build the |
| 463 | + # dynamically-linked `curl` binary from the overlay |
| 464 | + # `archiveFilesOverlay` below where `statify_curl_including_exe` is used. |
| 465 | + gssSupport = false; |
| 466 | + zlib = statify_zlib old.zlib; |
| 467 | + })).overrideAttrs (old: { |
| 468 | + dontDisableStatic = true; |
| 469 | + |
| 470 | + # Additionally, flags to also build a static `curl` executable: |
| 471 | + |
| 472 | + # Note: It is important that in the eventual `libtool` invocation, |
| 473 | + # `-all-static` comes before (or instead of) `-static`. |
| 474 | + # This is because the first of them "wins setting the mode". |
| 475 | + # See https://lists.gnu.org/archive/html/libtool/2006-12/msg00047.html |
| 476 | + # libtool makes various problems with static linking. |
| 477 | + # Some of them are is well-described by |
| 478 | + # https://github.com/sabotage-linux/sabotage/commit/57a989a2e23c9e46501da1227f371da59d212ae4 |
| 479 | + # However, so far, `-all-static` seems to have the same effect |
| 480 | + # of convincing libtool to NOT drop the `-static` flag. |
| 481 | + # Other places where this was dicussed (in case you have to debug this in |
| 482 | + # the future) are: |
| 483 | + # https://debbugs.gnu.org/cgi/bugreport.cgi?bug=11064 |
| 484 | + # https://github.com/esnet/iperf/issues/632 |
| 485 | + # Another common thing that people do is to pass `-static --static`, |
| 486 | + # with the intent that `--static` isn't eaten by libtool but still |
| 487 | + # accepted by e.g. gcc. In our case as of writing (nixpkgs commit bc94dcf50), |
| 488 | + # this isn't enough. That is because: |
| 489 | + # * The `--with-*=/path` options given to curl's `./configure` |
| 490 | + # are usually `.lib` split outputs that contain only headers and |
| 491 | + # pkg-config `.pc` files. OK so far. |
| 492 | + # * For some of these, e.g. for libssh2, curl's `./configure` turns them |
| 493 | + # into `LDFLAGS=-L/...libssh2-dev/lib`, which doesn't do anything to |
| 494 | + # libtool, gcc or ld, because `*-dev/lib` contains only `lib/pkgconfig` |
| 495 | + # and no libraries. |
| 496 | + # * But for others, e.g. for libnghttp2, curl's `./configure` resolves |
| 497 | + # them by taking the actual `-L` flags out of the `.pc` file, and turns |
| 498 | + # them into e.g. `LDFLAGS=-L/...nghttp2-lib/lib`, which contains |
| 499 | + # `{ *.la, *.a, *.so }`. |
| 500 | + # * When libtool is invoked with such `LDFLAGS`, it adds two entries to |
| 501 | + # `./lib/libcurl.la`'s `dependency_libs=`: `-L/...nghttp2-lib/lib` and |
| 502 | + # `/...nghttp2-lib/lib/*.la`. |
| 503 | + # When the `.la` path is given, libtool will read it, and pass the |
| 504 | + # `.so` file referred to within as a positional argument to e.g. gcc, |
| 505 | + # even when linking statically, which will result in linker error |
| 506 | + # ld: attempted static link of dynamic object `/...-nghttp2-lib/lib/libnghttp2.so' |
| 507 | + # I believe this is what |
| 508 | + # https://github.com/sabotage-linux/sabotage/commit/57a989a2e23c9e46501da1227f371da59d212ae4 |
| 509 | + # fixes. |
| 510 | + # If we pass `-all-static` to libtool, it won't do the things in the last |
| 511 | + # bullet point, causing static linking to succeed. |
| 512 | + makeFlags = [ "curl_LDFLAGS=-all-static" ]; |
| 513 | + # TODO This will become unnecessary once https://github.com/NixOS/nixpkgs/pull/66490 is merged |
| 514 | + LDFLAGS = [ "-lz" ]; |
| 515 | + }); |
| 516 | + |
448 | 517 | # Overlay that enables `.a` files for as many system packages as possible. |
449 | 518 | # This is in *addition* to `.so` files. |
450 | 519 | # See also https://github.com/NixOS/nixpkgs/issues/61575 |
@@ -483,12 +552,18 @@ let |
483 | 552 | patchelf_static = previous.patchelf.overrideAttrs (old: { dontDisableStatic = true; }); |
484 | 553 | pcre_static = previous.pcre.overrideAttrs (old: { dontDisableStatic = true; }); |
485 | 554 | xz_static = previous.xz.overrideAttrs (old: { dontDisableStatic = true; }); |
| 555 | + # TODO All 3 zlibs below can be simplified/removed once https://github.com/NixOS/nixpkgs/pull/66490 is available |
486 | 556 | zlib_static = (previous.zlib.override { |
487 | 557 | static = true; |
488 | 558 | shared = true; |
489 | 559 | # If both `static` and `dynamic` are enabled, then the zlib package |
490 | 560 | # puts the static libs into the `.static` split-output. |
491 | 561 | }).static; |
| 562 | + zlib_static_only = (previous.zlib.override { |
| 563 | + static = true; |
| 564 | + shared = false; |
| 565 | + }); |
| 566 | + zlib_both = statify_zlib previous.zlib; |
492 | 567 | # Also override the original packages with a throw (which as of writing |
493 | 568 | # has no effect) so we can know when the bug gets fixed in the future. |
494 | 569 | acl = issue_61682_throw "acl" previous.acl; |
@@ -555,20 +630,62 @@ let |
555 | 630 |
|
556 | 631 | openblas = previous.openblas.override { enableStatic = true; }; |
557 | 632 |
|
| 633 | + openssl = previous.openssl.override { static = true; }; |
| 634 | + |
558 | 635 | krb5 = previous.krb5.override { |
559 | | - # Note krb5 does not support building both static and shared at the same time. |
| 636 | + # Note [krb5 can only be static XOR shared] |
| 637 | + # krb5 does not support building both static and shared at the same time. |
| 638 | + # That means *anything* on top of this overlay trying to link krb5 |
| 639 | + # dynamically from this overlay will fail with linker errors. |
560 | 640 | staticOnly = true; |
561 | 641 | }; |
562 | 642 |
|
563 | | - openssl = previous.openssl.override { static = true; }; |
| 643 | + # See comments on `statify_curl_including_exe` for the interaction with krb5! |
| 644 | + curl = statify_curl_including_exe previous.curl; |
| 645 | + |
| 646 | + # TODO: All of this can be removed once https://github.com/NixOS/nixpkgs/pull/66506 |
| 647 | + # is available. |
| 648 | + # Given that we override `krb5` (above) in this overlay so that it has |
| 649 | + # static libs only, the `curl` used by `fetchurl` (e.g. via `fetchpatch`, |
| 650 | + # which some packages may use) cannot be dynamically linked against it. |
| 651 | + # Note this `curl` via `fetchurl` is NOT EXACTLY the same curl as our `curl` above |
| 652 | + # in the overlay, but has a peculiarity: |
| 653 | + # It forces `gssSupport = true` on Linux, undoing us setting it to `false` above! |
| 654 | + # See https://github.com/NixOS/nixpkgs/blob/73493b2a2df75b487c6056e577b6cf3e6aa9fc91/pkgs/top-level/all-packages.nix#L295 |
| 655 | + # So we have to turn it back off again here, *inside* `fetchurl`. |
| 656 | + # Because `fetchurl` is a form of boostrap package, |
| 657 | + # (which make ssense, as `curl`'s source code itself must be fetchurl'd), |
| 658 | + # we can't just `fetchurl.override { curl = the_curl_from_the_overlay_above; }`; |
| 659 | + # that would give an infinite evaluation loop. |
| 660 | + # Instead, we have override the `curl` *after* `all-packages.nix` has force-set |
| 661 | + # `gssSupport = false`. |
| 662 | + # Other alternatives are to just use a statically linked `curl` binary for |
| 663 | + # `fetchurl`, or to keep `gssSupport = true` and give it a `krb5` that has |
| 664 | + # static libs switched off again. |
| 665 | + # |
| 666 | + # Note: This needs the commit from https://github.com/NixOS/nixpkgs/pull/66503 to work, |
| 667 | + # which allows us to do `fetchurl.override`. |
| 668 | + fetchurl = previous.fetchurl.override (old: { |
| 669 | + curl = |
| 670 | + # We have the 3 choices mentioned above: |
564 | 671 |
|
565 | | - # Disable gss support, because that requires `krb5`, |
566 | | - # which (as mentioned above) is a library that cannot build both |
567 | | - # .a and .so files in its build system. |
568 | | - # That means that if we enable it, we can no longer build the |
569 | | - # dynamically-linked `curl` binary from this overlay. |
570 | | - curl = (previous.curl.override { gssSupport = false; }).overrideAttrs (old: { |
571 | | - dontDisableStatic = true; |
| 672 | + # 1) Turning `gssSupport` back off: |
| 673 | + |
| 674 | + (old.curl.override { gssSupport = false; }).overrideAttrs (old: { |
| 675 | + makeFlags = builtins.filter (x: x != "curl_LDFLAGS=-all-static") (old.makeFlags or []); |
| 676 | + }); |
| 677 | + |
| 678 | + # 2) Static `curl` binary: |
| 679 | + |
| 680 | + # statify_curl old.curl; |
| 681 | + |
| 682 | + # 3) Non-statick krb5: |
| 683 | + |
| 684 | + # (old.curl.override (old: { |
| 685 | + # libkrb5 = old.libkrb5.override { staticOnly = false; }; |
| 686 | + # })).overrideAttrs (old: { |
| 687 | + # makeFlags = builtins.filter (x: x != "curl_LDFLAGS=-all-static") old.makeFlags; |
| 688 | + # }); |
572 | 689 | }); |
573 | 690 | }; |
574 | 691 |
|
|
0 commit comments