Skip to content

Commit

Permalink
ghc 9.2.7, ghc 9.6.1 and replace old-ghc-nix with nixpkgs ghc (#1854)
Browse files Browse the repository at this point in the history
* GHC 9.6.1 and 9.2.7

* Support for building with nixpkgs GHC

* Use nixpkgs ghc instead of old-ghc-nix to boot GHC

* Builds boot tools with nixpkgs ghc

* Combines GHC config derivation into the component derivation

* Sharing of defaultSetup derivation

---------

Co-authored-by: Moritz Angermann <moritz.angermann@gmail.com>
Co-authored-by: Drew Hess <src@drewhess.com>
  • Loading branch information
3 people authored Mar 16, 2023
1 parent 3ed59e0 commit cfd757a
Show file tree
Hide file tree
Showing 820 changed files with 103,670 additions and 1,763 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: "Check that evaluation of hydra jobs works without using remote builders"
run: nix-instantiate release.nix -A x86_64-darwin.required-unstable-ghc8107-native --show-trace --builders ''
run: nix path-info --derivation .#requiredJobs.x86_64-darwin.required-unstable-ghc8107-native --show-trace --builders ''

hix-cabal:
runs-on: [self-hosted, linux]
Expand Down
3 changes: 2 additions & 1 deletion build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ in rec {
tools = pkgs.lib.optionalAttrs (ifdLevel >= 3) (
pkgs.recurseIntoAttrs ({
cabal-latest = tool compiler-nix-name "cabal" { inherit evalPackages; };
} // pkgs.lib.optionalAttrs (__compareVersions haskell.compiler.${compiler-nix-name}.version "9.6" < 0) {
hlint-latest = tool compiler-nix-name "hlint" {
inherit evalPackages;
version = {
Expand All @@ -39,7 +40,7 @@ in rec {
"ghc8107" = "3.4.1";
}.${compiler-nix-name} or "latest";
};
} // pkgs.lib.optionalAttrs (!__elem compiler-nix-name ["ghc941" "ghc942" "ghc943" "ghc944"]) {
} // pkgs.lib.optionalAttrs (__compareVersions haskell.compiler.${compiler-nix-name}.version "9.4" < 0) {
stack = tool compiler-nix-name "stack" { version = "2.9.3"; inherit evalPackages; };
hls-latest = tool compiler-nix-name "haskell-language-server" {
inherit evalPackages;
Expand Down
49 changes: 35 additions & 14 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, stdenv, buildPackages, ghc, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, haddockBuilder, ghcForComponent, hsPkgs, compiler, runCommand, libffi, gmp, windows, zlib, ncurses, nodejs }@defaults:
{ pkgs, stdenv, buildPackages, ghc, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, haddockBuilder, ghcForComponent, hsPkgs, compiler, runCommand, libffi, gmp, windows, zlib, ncurses, nodejs, nonReinstallablePkgs }@defaults:
lib.makeOverridable (
let self =
{ componentId
Expand Down Expand Up @@ -81,7 +81,7 @@ let self =
, enableTSanRTS ? false

# LLVM
, useLLVM ? ghc.useLLVM
, useLLVM ? ghc.useLLVM or false
, smallAddressSpace ? false

}@drvArgs:
Expand Down Expand Up @@ -161,7 +161,7 @@ let
if configureAllComponents
then ["--enable-tests" "--enable-benchmarks"]
else ["${haskellLib.componentTarget componentId}"]
) ++ [ "$(cat ${configFiles}/configure-flags)"
) ++ [ "$(cat $configFiles/configure-flags)"
] ++ commonConfigureFlags);

# From nixpkgs 20.09, the pkg-config exe has a prefix matching the ghc one
Expand Down Expand Up @@ -343,9 +343,14 @@ let
config = component;
srcSubDir = cleanSrc.subDir;
srcSubDirPath = cleanSrc.root + cleanSrc.subDir;
inherit configFiles executableToolDepends exeName enableDWARF;
inherit executableToolDepends exeName enableDWARF;
exePath = drv + "/bin/${exeName}";
env = shellWrappers;
env = shellWrappers.drv;
shell = drv.overrideAttrs (attrs: {
pname = nameOnly + "-shell";
inherit (package.identifier) version;
nativeBuildInputs = [shellWrappers.drv] ++ attrs.nativeBuildInputs;
});
profiled = self (drvArgs // { enableLibraryProfiling = true; });
dwarf = self (drvArgs // { enableDWARF = true; });
} // lib.optionalAttrs (haskellLib.isLibrary componentId) ({
Expand Down Expand Up @@ -377,19 +382,22 @@ let
# Not sure why pkgconfig needs to be propagatedBuildInputs but
# for gi-gtk-hs it seems to help.
++ map pkgs.lib.getDev (builtins.concatLists pkgconfig)
# These only need to be propagated for library components (otherwise they
# will be in `buildInputs`)
++ lib.optionals (haskellLib.isLibrary componentId) configFiles.libDeps
++ lib.optionals (stdenv.hostPlatform.isWindows)
(lib.flatten component.libs
++ map haskellLib.dependToLib component.depends);
(lib.flatten component.libs);

buildInputs = lib.optionals (!stdenv.hostPlatform.isWindows)
(lib.flatten component.libs
++ map haskellLib.dependToLib component.depends);
buildInputs =
lib.optionals (!haskellLib.isLibrary componentId) configFiles.libDeps
++ lib.optionals (!stdenv.hostPlatform.isWindows)
(lib.flatten component.libs);

nativeBuildInputs =
[shellWrappers buildPackages.removeReferencesTo]
[ghc buildPackages.removeReferencesTo]
++ executableToolDepends;

outputs = ["out" ]
outputs = ["out" "configFiles" "ghc"]
++ (lib.optional enableSeparateDataOutput "data")
++ (lib.optional keepSource "source")
++ (lib.optional writeHieFiles "hie");
Expand All @@ -409,6 +417,18 @@ let
'') + commonAttrs.prePatch;

configurePhase = ''
mkdir -p $configFiles
mkdir -p $ghc
wrappedGhc=$ghc
${configFiles.script}
${shellWrappers.script}
''
# Remove any ghc docs pages so nixpkgs does not include them in $out
# (this can result in unwanted dependencies on GHC)
+ ''
rm -rf $wrappedGhc/share/doc $wrappedGhc/share/man $wrappedGhc/share/devhelp/books
PATH=$wrappedGhc/bin:$PATH
runHook preConfigure
echo Configure flags:
printf "%q " ${finalConfigureFlags}
Expand Down Expand Up @@ -489,7 +509,7 @@ let
${lib.optionalString (haskellLib.isLibrary componentId) ''
$SETUP_HS register --gen-pkg-config=${name}.conf
${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/${configFiles.packageCfgDir} -f $out/package.conf.d register ${name}.conf
${ghc.targetPrefix}ghc-pkg -v0 --package-db $configFiles/${configFiles.packageCfgDir} -f $out/package.conf.d register ${name}.conf
mkdir -p $out/exactDep
touch $out/exactDep/configure-flags
Expand Down Expand Up @@ -521,6 +541,7 @@ let
if id=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" id --simple-output); then
name=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" name --simple-output)
echo "--dependency=''${name#z-${package.identifier.name}-z-}=$id" >> $out/exactDep/configure-flags
echo "package-id $id" >> $out/envDep
''
# Allow `package-name:sublib-name` to work in `build-depends`
# by adding the same `--dependency` again, but with the package
Expand Down Expand Up @@ -616,7 +637,7 @@ let
'';

shellHook = ''
export PATH="${shellWrappers}/bin:$PATH"
export PATH=$ghc/bin:$PATH
${shellHookApplied}
'';
}
Expand Down
16 changes: 9 additions & 7 deletions builder/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let
# Builds a single component of a package.
comp-builder = haskellLib.weakCallPackage pkgs ./comp-builder.nix {
inherit ghc haskellLib makeConfigFiles haddockBuilder ghcForComponent hsPkgs compiler;
inherit ghc haskellLib makeConfigFiles haddockBuilder ghcForComponent hsPkgs compiler nonReinstallablePkgs;
};

haddockBuilder = haskellLib.weakCallPackage pkgs ./haddock-builder.nix {
Expand Down Expand Up @@ -44,7 +44,11 @@ let


hoogleLocal = let
nixpkgsHoogle = import (pkgs.path + /pkgs/development/haskell-modules/hoogle.nix);
# Use hoogle.nix from at least nixpkgs 22.05
nixpkgs = if lib.versionAtLeast lib.trivial.release "22.05"
then pkgs.path
else pkgs.haskell-nix.sources.nixpkgs-2205;
nixpkgsHoogle = import (nixpkgs + /pkgs/development/haskell-modules/hoogle.nix);
in { packages ? [], hoogle ? pkgs.buildPackages.haskell-nix.tool "ghc8107" "hoogle" {
inherit evalPackages;
version = "5.0.18.3";
Expand All @@ -59,11 +63,9 @@ let
else ghc;
inherit packages hoogle;
};
in if lib.versionAtLeast lib.trivial.release "22.05"
then haskellLib.weakCallPackage pkgs nixpkgsHoogle {
inherit haskellPackages;
} (p: p.packages)
else haskellLib.weakCallPackage pkgs nixpkgsHoogle haskellPackages;
in haskellLib.weakCallPackage pkgs nixpkgsHoogle {
inherit haskellPackages;
} (p: p.packages);

# Same as haskellPackages.shellFor in nixpkgs.
shellFor = haskellLib.weakCallPackage pkgs ./shell-for.nix {
Expand Down
91 changes: 51 additions & 40 deletions builder/ghc-for-component-wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,42 @@ let
ghc = if enableDWARF then defaults.ghc.dwarf else defaults.ghc;

inherit (configFiles) targetPrefix ghcCommand ghcCommandCaps packageCfgDir;
libDir = "$out/${configFiles.libDir}";
docDir = "$out/share/doc/ghc/html";
libDir = "$wrappedGhc/${configFiles.libDir}";
docDir = "$wrappedGhc/share/doc/ghc/html";
# For musl we can use haddock from the buildGHC
haddock = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl && !haskellLib.isNativeMusl
then ghc.buildGHC
else ghc;

in runCommand "${componentName}-${ghc.name}-env" {
preferLocalBuild = true;
passthru = {
inherit (ghc) version meta;
inherit targetPrefix;
baseGhc = ghc;
};
} (
''
script = ''
. ${makeWrapper}/nix-support/setup-hook
''
# Start with a ghc and remove all of the package directories
+ ''
mkdir -p $out/bin
${lndir}/bin/lndir -silent ${ghc} $out
mkdir -p $wrappedGhc/bin
${lndir}/bin/lndir -silent $unwrappedGhc $wrappedGhc
rm -rf ${libDir}/*/
''
# ... but retain the lib/ghc/bin directory. This contains `unlit' and friends.
+ ''
ln -s ${ghc}/lib/${ghcCommand}-${ghc.version}/bin ${libDir}
ln -s $unwrappedGhc/lib/${ghcCommand}-${ghc.version}/bin ${libDir}
''
# ... and the ghcjs shim's if they are available ...
+ ''
if [ -d ${ghc}/lib/${ghcCommand}-${ghc.version}/shims ]; then
ln -s ${ghc}/lib/${ghcCommand}-${ghc.version}/shims ${libDir}
if [ -d $unwrappedGhc/lib/${ghcCommand}-${ghc.version}/shims ]; then
ln -s $unwrappedGhc/lib/${ghcCommand}-${ghc.version}/shims ${libDir}
fi
''
# ... and node modules ...
+ ''
if [ -d ${ghc}/lib/${ghcCommand}-${ghc.version}/ghcjs-node ]; then
ln -s ${ghc}/lib/${ghcCommand}-${ghc.version}/ghcjs-node ${libDir}
if [ -d $unwrappedGhc/lib/${ghcCommand}-${ghc.version}/ghcjs-node ]; then
ln -s $unwrappedGhc/lib/${ghcCommand}-${ghc.version}/ghcjs-node ${libDir}
fi
''
# Replace the package database with the one from target package config.
+ ''
ln -s ${configFiles}/${packageCfgDir} $out/${packageCfgDir}
ln -s $configFiles/${packageCfgDir} $wrappedGhc/${packageCfgDir}
''
# Set the GHC_PLUGINS environment variable according to the plugins for the component.
Expand All @@ -77,9 +69,9 @@ in runCommand "${componentName}-${ghc.name}-env" {
GHC_PLUGINS="["
LIST_PREFIX=""
${builtins.concatStringsSep "\n" (map (plugin: ''
id=$(${ghc}/bin/ghc-pkg --package-db ${plugin.library}/package.conf.d field ${plugin.library.package.identifier.name} id --simple-output)
lib_dir=$(${ghc}/bin/ghc-pkg --package-db ${plugin.library}/package.conf.d field ${plugin.library.package.identifier.name} dynamic-library-dirs --simple-output)
lib_base=$(${ghc}/bin/ghc-pkg --package-db ${plugin.library}/package.conf.d field ${plugin.library.package.identifier.name} hs-libraries --simple-output)
id=$($unwrappedGhc/bin/ghc-pkg --package-db ${plugin.library}/package.conf.d field ${plugin.library.package.identifier.name} id --simple-output)
lib_dir=$($unwrappedGhc/bin/ghc-pkg --package-db ${plugin.library}/package.conf.d field ${plugin.library.package.identifier.name} dynamic-library-dirs --simple-output)
lib_base=$($unwrappedGhc/bin/ghc-pkg --package-db ${plugin.library}/package.conf.d field ${plugin.library.package.identifier.name} hs-libraries --simple-output)
lib="$(echo ''${lib_dir}/lib''${lib_base}*)"
GHC_PLUGINS="''${GHC_PLUGINS}''${LIST_PREFIX}(\"''${lib}\",\"''${id}\",\"${plugin.moduleName}\",["
LIST_PREFIX=""
Expand All @@ -103,25 +95,25 @@ in runCommand "${componentName}-${ghc.name}-env" {
# The NIX_ variables are used by the patched Paths_ghc module.
+ ''
for prg in ${ghcCommand} ${ghcCommand}i ${ghcCommand}-${ghc.version} ${ghcCommand}i-${ghc.version}; do
if [[ -x "${ghc}/bin/$prg" ]]; then
rm -f $out/bin/$prg
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
if [[ -x "$unwrappedGhc/bin/$prg" ]]; then
rm -f $wrappedGhc/bin/$prg
makeWrapper $unwrappedGhc/bin/$prg $wrappedGhc/bin/$prg \
--add-flags '"-B$NIX_${ghcCommandCaps}_LIBDIR"' \
--set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \
--set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \
--set "NIX_${ghcCommandCaps}" "$wrappedGhc/bin/${ghcCommand}" \
--set "NIX_${ghcCommandCaps}PKG" "$wrappedGhc/bin/${ghcCommand}-pkg" \
--set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
--set "GHC_PLUGINS" "$GHC_PLUGINS" \
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
fi
done
for prg in "${targetPrefix}runghc" "${targetPrefix}runhaskell"; do
if [[ -x "${ghc}/bin/$prg" ]]; then
rm -f $out/bin/$prg
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
--add-flags "-f $out/bin/${ghcCommand}" \
--set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \
--set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \
if [[ -x "$unwrappedGhc/bin/$prg" ]]; then
rm -f $wrappedGhc/bin/$prg
makeWrapper $unwrappedGhc/bin/$prg $wrappedGhc/bin/$prg \
--add-flags "-f $wrappedGhc/bin/${ghcCommand}" \
--set "NIX_${ghcCommandCaps}" "$wrappedGhc/bin/${ghcCommand}" \
--set "NIX_${ghcCommandCaps}PKG" "$wrappedGhc/bin/${ghcCommand}-pkg" \
--set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
--set "GHC_PLUGINS" "$GHC_PLUGINS" \
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
Expand All @@ -132,8 +124,8 @@ in runCommand "${componentName}-${ghc.name}-env" {
# Wrap haddock, if the base GHC provides it.
+ ''
if [[ -x "${haddock}/bin/haddock" ]]; then
rm -f $out/bin/haddock
makeWrapper ${haddock}/bin/haddock $out/bin/haddock \
rm -f $wrappedGhc/bin/haddock
makeWrapper ${haddock}/bin/haddock $wrappedGhc/bin/haddock \
--add-flags '"-B$NIX_${ghcCommandCaps}_LIBDIR"' \
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
fi
Expand All @@ -143,12 +135,31 @@ in runCommand "${componentName}-${ghc.name}-env" {
# --global-package-db flag.
+ ''
for prg in ${ghcCommand}-pkg ${ghcCommand}-pkg-${ghc.version}; do
if [[ -x "${ghc}/bin/$prg" ]]; then
rm -f $out/bin/$prg
makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "--global-package-db=$out/${packageCfgDir}"
if [[ -x "$unwrappedGhc/bin/$prg" ]]; then
rm -f $wrappedGhc/bin/$prg
makeWrapper $unwrappedGhc/bin/$prg $wrappedGhc/bin/$prg --add-flags "--global-package-db=$wrappedGhc/${packageCfgDir}"
fi
done
${postInstall}
''
)
'';

drv = runCommand "${componentName}-${ghc.name}-env" {
preferLocalBuild = true;
passthru = {
inherit script targetPrefix;
inherit (ghc) version meta;
};
propagatedBuildInputs = configFiles.libDeps;
nativeBuildInputs = [ghc];
} (''
mkdir -p $out/configFiles
configFiles=$out/configFiles
${configFiles.script}
wrappedGhc=$out
${script}
'');
in {
inherit script drv targetPrefix;
baseGhc = ghc;
}
25 changes: 15 additions & 10 deletions builder/haddock-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let
finalConfigureFlags = lib.concatStringsSep " " (
[ "--prefix=${componentDrv}"
"${haskellLib.componentTarget componentId}"
"$(cat ${docsConfigFiles}/configure-flags)"
"$(cat $configFiles/configure-flags)"
]
++ commonConfigureFlags
++ lib.optional doHaddock' " --docdir=${docdir "$doc"}");
Expand All @@ -62,28 +62,33 @@ let
name = fullName;

passthru = {
configFiles = docsConfigFiles;

# The directory containing the haddock documentation.
haddockDir = if doHaddock' then "${docdir drv.doc}/html" else null;
haddockDir = lib.const (if doHaddock' then "${docdir drv.doc}/html" else null);
};

# `out` contains the `package.conf.d` files used for building the
# haddock files.
# `doc` contains just the haddock output files.
outputs = ["out"]
outputs = ["out" "configFiles" "ghc"]
++ lib.optional doHaddock' "doc";

propagatedBuildInputs = builtins.concatLists pkgconfig;
propagatedBuildInputs =
builtins.concatLists pkgconfig
++ configFiles.libDeps;

buildInputs = component.libs
++ map (d: d.components.library.haddock or d) component.depends;
buildInputs = component.libs;

nativeBuildInputs =
[ shellWrappers buildPackages.removeReferencesTo ]
[ ghc buildPackages.removeReferencesTo ]
++ componentDrv.executableToolDepends;

configurePhase = ''
mkdir -p $configFiles
mkdir -p $ghc
wrappedGhc=$ghc
${docsConfigFiles.script}
${shellWrappers.script}
PATH=$wrappedGhc/bin:$PATH
runHook preConfigure
echo Configure flags:
printf "%q " ${finalConfigureFlags}
Expand Down Expand Up @@ -144,7 +149,7 @@ let
# working hyper links.
pkg=$(basename "$i")
sed -e "s|haddock-interfaces:.*|haddock-interfaces: $docdir/html/${componentId.cname}.haddock|" -e "s|haddock-html:.*|haddock-html: $docdir/html/|" "$i" > "$pkg"
${ghc.targetPrefix}ghc-pkg -v0 --package-db ${docsConfigFiles}/${configFiles.packageCfgDir} -f $out/package.conf.d register "$pkg"
${ghc.targetPrefix}ghc-pkg -v0 --package-db $configFiles/${configFiles.packageCfgDir} -f $out/package.conf.d register "$pkg"
done
ln -s ${componentDrv}/exactDep $out/exactDep
Expand Down
Loading

0 comments on commit cfd757a

Please sign in to comment.