Skip to content

Create pkgsWithGhc package set #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 45 additions & 40 deletions survey/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -864,15 +864,31 @@ let

};


pkgsWithArchiveFiles = pkgs.extend archiveFilesOverlay;

fixGhc = ghcPackage0: lib.pipe ghcPackage0 [
# musl does not support libdw's alleged need for `dlopen()`, see:
# https://github.com/nh2/static-haskell-nix/pull/116#issuecomment-1585786484
#
# Nixpkgs has the `enableDwarf` argument only for GHCs versions that are built
# with Hadrian (`common-hadrian.nix`), which in nixpkgs is the case for GHC >= 9.6.
# So set `enableDwarf = true`, but not for older versions known to not use Hadrian.
(ghcPackage:
if lib.any (prefix: lib.strings.hasPrefix prefix compiler) ["ghc8" "ghc90" "ghc92" "ghc94"]
then ghcPackage # GHC < 9.6, no Hadrian
else ghcPackage.override { enableDwarf = false; }
)
(ghcPackage:
ghcPackage.override {
enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell;
enableShared = !useArchiveFilesForTemplateHaskell;
}
)
];

# This overlay "fixes up" Haskell libraries so that static linking works.
# See note "Don't add new packages here" below!
haskellLibsReadyForStaticLinkingOverlay = final: previous:
setupGhcOverlay = final: previous:
let
previousHaskellPackages =
initialHaskellPackages =
if integer-simple
# Note we don't have to set the `-finteger-simple` flag for packages that GHC
# depends on (e.g. text), because nix + GHC already do this for us:
Expand All @@ -882,6 +898,27 @@ let
else previous.haskell.packages."${compiler}";
in
{
haskellPackages = initialHaskellPackages.override (old: {

# To override GHC, we need to override both `ghc` and the one in
# `buildHaskellPackages` because otherwise this code in `geneic-builder.nix`
# will make our package depend on 2 different GHCs:
# nativeGhc = buildHaskellPackages.ghc;
# depsBuildBuild = [ nativeGhc ] ...
# nativeBuildInputs = [ ghc removeReferencesTo ] ...
#
ghc = fixGhc old.ghc;
buildHaskellPackages = old.buildHaskellPackages.override (oldBuildHaskellPackages: {
ghc = fixGhc oldBuildHaskellPackages.ghc;
});
});
};

pkgsWithGhc = pkgsWithArchiveFiles.extend setupGhcOverlay;

# This overlay "fixes up" Haskell libraries so that static linking works.
# See note "Don't add new packages here" below!
haskellLibsReadyForStaticLinkingOverlay = final: previous: {
# Helper function to add pkg-config static lib flags to a Haskell derivation.
# We put it directly into the `pkgs` package set so that following overlays
# can use it as well if they want to.
Expand Down Expand Up @@ -922,7 +959,7 @@ let
});


haskellPackages = previousHaskellPackages.override (old: {
haskellPackages = previous.haskellPackages.override (old: {
overrides = final.lib.composeExtensions (old.overrides or (_: _: {})) (self: super:
with final.haskell.lib;
with final.staticHaskellHelpers;
Expand Down Expand Up @@ -1557,44 +1594,11 @@ let
};


pkgsWithHaskellLibsReadyForStaticLinking = pkgsWithArchiveFiles.extend haskellLibsReadyForStaticLinkingOverlay;

fixGhc = ghcPackage0: lib.pipe ghcPackage0 [
# musl does not support libdw's alleged need for `dlopen()`, see:
# https://github.com/nh2/static-haskell-nix/pull/116#issuecomment-1585786484
#
# Nixpkgs has the `enableDwarf` argument only for GHCs versions that are built
# with Hadrian (`common-hadrian.nix`), which in nixpkgs is the case for GHC >= 9.6.
# So set `enableDwarf = true`, but not for older versions known to not use Hadrian.
(ghcPackage:
if lib.any (prefix: lib.strings.hasPrefix prefix compiler) ["ghc8" "ghc90" "ghc92" "ghc94"]
then ghcPackage # GHC < 9.6, no Hadrian
else ghcPackage.override { enableDwarf = false; }
)
(ghcPackage:
ghcPackage.override {
enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell;
enableShared = !useArchiveFilesForTemplateHaskell;
}
)
];
pkgsWithHaskellLibsReadyForStaticLinking = pkgsWithGhc.extend haskellLibsReadyForStaticLinkingOverlay;

# Overlay all Haskell executables are statically linked.
staticHaskellBinariesOverlay = final: previous: {
haskellPackages = previous.haskellPackages.override (old: {

# To override GHC, we need to override both `ghc` and the one in
# `buildHaskellPackages` because otherwise this code in `geneic-builder.nix`
# will make our package depend on 2 different GHCs:
# nativeGhc = buildHaskellPackages.ghc;
# depsBuildBuild = [ nativeGhc ] ...
# nativeBuildInputs = [ ghc removeReferencesTo ] ...
#
ghc = fixGhc old.ghc;
buildHaskellPackages = old.buildHaskellPackages.override (oldBuildHaskellPackages: {
ghc = fixGhc oldBuildHaskellPackages.ghc;
});

overrides = final.lib.composeExtensions (old.overrides or (_: _: {})) (self: super:
let
# We have to use `useFixedCabal` here, and cannot just rely on the
Expand Down Expand Up @@ -1740,6 +1744,7 @@ in

inherit lib;

inherit pkgsWithGhc;
inherit pkgsWithArchiveFiles;
inherit pkgsWithStaticHaskellBinaries;

Expand Down