|
576 | 576 | makeFlags = [ "curl_LDFLAGS=-all-static" ]; |
577 | 577 | }); |
578 | 578 |
|
| 579 | + fixGhc = ghcPackage0: lib.pipe ghcPackage0 [ |
| 580 | + # musl does not support libdw's alleged need for `dlopen()`, see: |
| 581 | + # https://github.com/nh2/static-haskell-nix/pull/116#issuecomment-1585786484 |
| 582 | + # |
| 583 | + # Nixpkgs has the `enableDwarf` argument only for GHCs versions that are built |
| 584 | + # with Hadrian (`common-hadrian.nix`), which in nixpkgs is the case for GHC >= 9.6. |
| 585 | + # So set `enableDwarf = true`, but not for older versions known to not use Hadrian. |
| 586 | + (ghcPackage: |
| 587 | + if lib.any (prefix: lib.strings.hasPrefix prefix compiler) ["ghc8" "ghc90" "ghc92" "ghc94"] |
| 588 | + then ghcPackage # GHC < 9.6, no Hadrian |
| 589 | + else ghcPackage.override { enableDwarf = false; } |
| 590 | + ) |
| 591 | + (ghcPackage: |
| 592 | + ghcPackage.override { |
| 593 | + enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell; |
| 594 | + enableShared = !useArchiveFilesForTemplateHaskell; |
| 595 | + } |
| 596 | + ) |
| 597 | + ]; |
| 598 | + |
| 599 | + setupGhcOverlay = final: previous: |
| 600 | + let |
| 601 | + initialHaskellPackages = |
| 602 | + if integer-simple |
| 603 | + # Note we don't have to set the `-finteger-simple` flag for packages that GHC |
| 604 | + # depends on (e.g. text), because nix + GHC already do this for us: |
| 605 | + # https://github.com/ghc/ghc/blob/ghc-8.4.3-release/ghc.mk#L620-L626 |
| 606 | + # https://github.com/peterhoeg/nixpkgs/commit/50050f3cc9e006daa6800f15a29e258c6e6fa4b3#diff-2f6f8fd152c14d37ebd849aa6382257aR35 |
| 607 | + then previous.haskell.packages.integer-simple."${compiler}" |
| 608 | + else previous.haskell.packages."${compiler}"; |
| 609 | + in |
| 610 | + { |
| 611 | + haskellPackages = initialHaskellPackages.override (old: { |
| 612 | + |
| 613 | + # To override GHC, we need to override both `ghc` and the one in |
| 614 | + # `buildHaskellPackages` because otherwise this code in `geneic-builder.nix` |
| 615 | + # will make our package depend on 2 different GHCs: |
| 616 | + # nativeGhc = buildHaskellPackages.ghc; |
| 617 | + # depsBuildBuild = [ nativeGhc ] ... |
| 618 | + # nativeBuildInputs = [ ghc removeReferencesTo ] ... |
| 619 | + # |
| 620 | + ghc = fixGhc old.ghc; |
| 621 | + buildHaskellPackages = old.buildHaskellPackages.override (oldBuildHaskellPackages: { |
| 622 | + ghc = fixGhc oldBuildHaskellPackages.ghc; |
| 623 | + }); |
| 624 | + }); |
| 625 | + }; |
| 626 | + |
| 627 | + pkgsWithGhc = pkgs.extend setupGhcOverlay; |
| 628 | + |
579 | 629 | # Overlay that enables `.a` files for as many system packages as possible. |
580 | 630 | # This is in *addition* to `.so` files. |
581 | 631 | # See also https://github.com/NixOS/nixpkgs/issues/61575 |
@@ -869,23 +919,12 @@ let |
869 | 919 | }; |
870 | 920 |
|
871 | 921 |
|
872 | | - pkgsWithArchiveFiles = pkgs.extend archiveFilesOverlay; |
| 922 | + pkgsWithArchiveFiles = pkgsWithGhc.extend archiveFilesOverlay; |
873 | 923 |
|
874 | 924 |
|
875 | 925 | # This overlay "fixes up" Haskell libraries so that static linking works. |
876 | 926 | # See note "Don't add new packages here" below! |
877 | | - haskellLibsReadyForStaticLinkingOverlay = final: previous: |
878 | | - let |
879 | | - previousHaskellPackages = |
880 | | - if integer-simple |
881 | | - # Note we don't have to set the `-finteger-simple` flag for packages that GHC |
882 | | - # depends on (e.g. text), because nix + GHC already do this for us: |
883 | | - # https://github.com/ghc/ghc/blob/ghc-8.4.3-release/ghc.mk#L620-L626 |
884 | | - # https://github.com/peterhoeg/nixpkgs/commit/50050f3cc9e006daa6800f15a29e258c6e6fa4b3#diff-2f6f8fd152c14d37ebd849aa6382257aR35 |
885 | | - then previous.haskell.packages.integer-simple."${compiler}" |
886 | | - else previous.haskell.packages."${compiler}"; |
887 | | - in |
888 | | - { |
| 927 | + haskellLibsReadyForStaticLinkingOverlay = final: previous: { |
889 | 928 | # Helper function to add pkg-config static lib flags to a Haskell derivation. |
890 | 929 | # We put it directly into the `pkgs` package set so that following overlays |
891 | 930 | # can use it as well if they want to. |
|
926 | 965 | }); |
927 | 966 |
|
928 | 967 |
|
929 | | - haskellPackages = previousHaskellPackages.override (old: { |
| 968 | + haskellPackages = previous.haskellPackages.override (old: { |
930 | 969 | overrides = final.lib.composeExtensions (old.overrides or (_: _: {})) (self: super: |
931 | 970 | with final.haskell.lib; |
932 | 971 | with final.staticHaskellHelpers; |
@@ -1563,42 +1602,9 @@ let |
1563 | 1602 |
|
1564 | 1603 | pkgsWithHaskellLibsReadyForStaticLinking = pkgsWithArchiveFiles.extend haskellLibsReadyForStaticLinkingOverlay; |
1565 | 1604 |
|
1566 | | - fixGhc = ghcPackage0: lib.pipe ghcPackage0 [ |
1567 | | - # musl does not support libdw's alleged need for `dlopen()`, see: |
1568 | | - # https://github.com/nh2/static-haskell-nix/pull/116#issuecomment-1585786484 |
1569 | | - # |
1570 | | - # Nixpkgs has the `enableDwarf` argument only for GHCs versions that are built |
1571 | | - # with Hadrian (`common-hadrian.nix`), which in nixpkgs is the case for GHC >= 9.6. |
1572 | | - # So set `enableDwarf = true`, but not for older versions known to not use Hadrian. |
1573 | | - (ghcPackage: |
1574 | | - if lib.any (prefix: lib.strings.hasPrefix prefix compiler) ["ghc8" "ghc90" "ghc92" "ghc94"] |
1575 | | - then ghcPackage # GHC < 9.6, no Hadrian |
1576 | | - else ghcPackage.override { enableDwarf = false; } |
1577 | | - ) |
1578 | | - (ghcPackage: |
1579 | | - ghcPackage.override { |
1580 | | - enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell; |
1581 | | - enableShared = !useArchiveFilesForTemplateHaskell; |
1582 | | - } |
1583 | | - ) |
1584 | | - ]; |
1585 | | - |
1586 | 1605 | # Overlay all Haskell executables are statically linked. |
1587 | 1606 | staticHaskellBinariesOverlay = final: previous: { |
1588 | 1607 | haskellPackages = previous.haskellPackages.override (old: { |
1589 | | - |
1590 | | - # To override GHC, we need to override both `ghc` and the one in |
1591 | | - # `buildHaskellPackages` because otherwise this code in `geneic-builder.nix` |
1592 | | - # will make our package depend on 2 different GHCs: |
1593 | | - # nativeGhc = buildHaskellPackages.ghc; |
1594 | | - # depsBuildBuild = [ nativeGhc ] ... |
1595 | | - # nativeBuildInputs = [ ghc removeReferencesTo ] ... |
1596 | | - # |
1597 | | - ghc = fixGhc old.ghc; |
1598 | | - buildHaskellPackages = old.buildHaskellPackages.override (oldBuildHaskellPackages: { |
1599 | | - ghc = fixGhc oldBuildHaskellPackages.ghc; |
1600 | | - }); |
1601 | | - |
1602 | 1608 | overrides = final.lib.composeExtensions (old.overrides or (_: _: {})) (self: super: |
1603 | 1609 | let |
1604 | 1610 | # We have to use `useFixedCabal` here, and cannot just rely on the |
|
1744 | 1750 |
|
1745 | 1751 | inherit lib; |
1746 | 1752 |
|
| 1753 | + inherit pkgsWithGhc; |
1747 | 1754 | inherit pkgsWithArchiveFiles; |
1748 | 1755 | inherit pkgsWithStaticHaskellBinaries; |
1749 | 1756 |
|
|
0 commit comments