Skip to content

Commit 79945d6

Browse files
jonathanlkingnh2
authored andcommitted
Create pkgsWithGhc package set
1 parent 42d492a commit 79945d6

File tree

1 file changed

+54
-47
lines changed

1 file changed

+54
-47
lines changed

survey/default.nix

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,56 @@ let
576576
makeFlags = [ "curl_LDFLAGS=-all-static" ];
577577
});
578578

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+
579629
# Overlay that enables `.a` files for as many system packages as possible.
580630
# This is in *addition* to `.so` files.
581631
# See also https://github.com/NixOS/nixpkgs/issues/61575
@@ -869,23 +919,12 @@ let
869919
};
870920

871921

872-
pkgsWithArchiveFiles = pkgs.extend archiveFilesOverlay;
922+
pkgsWithArchiveFiles = pkgsWithGhc.extend archiveFilesOverlay;
873923

874924

875925
# This overlay "fixes up" Haskell libraries so that static linking works.
876926
# 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: {
889928
# Helper function to add pkg-config static lib flags to a Haskell derivation.
890929
# We put it directly into the `pkgs` package set so that following overlays
891930
# can use it as well if they want to.
@@ -926,7 +965,7 @@ let
926965
});
927966

928967

929-
haskellPackages = previousHaskellPackages.override (old: {
968+
haskellPackages = previous.haskellPackages.override (old: {
930969
overrides = final.lib.composeExtensions (old.overrides or (_: _: {})) (self: super:
931970
with final.haskell.lib;
932971
with final.staticHaskellHelpers;
@@ -1563,42 +1602,9 @@ let
15631602

15641603
pkgsWithHaskellLibsReadyForStaticLinking = pkgsWithArchiveFiles.extend haskellLibsReadyForStaticLinkingOverlay;
15651604

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-
15861605
# Overlay all Haskell executables are statically linked.
15871606
staticHaskellBinariesOverlay = final: previous: {
15881607
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-
16021608
overrides = final.lib.composeExtensions (old.overrides or (_: _: {})) (self: super:
16031609
let
16041610
# We have to use `useFixedCabal` here, and cannot just rely on the
@@ -1744,6 +1750,7 @@ in
17441750

17451751
inherit lib;
17461752

1753+
inherit pkgsWithGhc;
17471754
inherit pkgsWithArchiveFiles;
17481755
inherit pkgsWithStaticHaskellBinaries;
17491756

0 commit comments

Comments
 (0)