on iko/ghcjs-patch-master help sign in
Work around for packages in lts that do not install. (#1437)

For ghc 9.0.2 Haskell.nix will use the `stm`and `filepath` source that came with `ghc` when the version desired matches. This is because 9.0.2 shipped with packages that differ from the same version in hackage. `reinstallableLibGhc` is fixed for GHC 8.10 and above. Rather than including a patch file this works by: * Setting the `subDir` to the `compiler` directory when building. That way relative paths to other parts of the `ghc` source tree (outside the `compiler` directory) still work. * Files that are needed, but generated when `ghc` builds are added from the `generated` output of the ghc derivation. `nonReinstallablePkgs` is now sorted and deduplicated before it is used (this reduces the chance of rebuilds when the list is refactored).

commitf3ea06dcacc8a46b4a207a6a1fad14bc5ea41b19 authorHamish Mackenzie <Hamish.K.Mackenzie@gmail.com> dateWed 20 Apr 2022, 15:25 (4 years ago) parentc357208
8 files changed+81−31
builder/hspkg-builder.nix+10−2 builder/make-config-files.nix+7−3 ci.nix+10−4 compiler/ghc/default.nix+10−1 modules/component-driver.nix+4−2 overlays/ghc-packages.nix+33−15 test/setup-deps/default.nix+2−4 test/setup-deps/pkg/Setup.hs+5
builder/hspkg-builder.nix+10−2
@@ -23,7 +23,14 @@ assert (if ghc.isHaskellNixCompiler or false then true
2323 + pkgs.lib.optionalString (name != null) (" for " + name)));
2424
2525let
26− cabalFile = if revision == null || revision == 0 then null else
26+ # Some packages bundled with GHC are not the same as they are in hackage.
27+ bundledSrc = {
28+ # These are problematic because the hackage versions will not install and are part of LTS.
29+ "ghc902/stm-2.5.0.0" = "/libraries/stm";
30+ "ghc902/filepath-1.4.2.1" = "/libraries/filepath";
31+ }."${compiler-nix-name}/${name}" or null;
32+ src = if bundledSrc == null then pkg.src else ghc.configured-src + bundledSrc;
33+ cabalFile = if revision == null || revision == 0 || bundledSrc != null then null else
2734 fetchurl {
2835 name = "${name}-${toString revision}.cabal";
2936 url = "https://hackage.haskell.org/package/${name}/revision/${toString revision}.cabal";
@@ -94,7 +101,8 @@ let
94101 synopsis = null;
95102 license = "MIT";
96103 };
97− src = null; cleanSrc = buildPackages.runCommand "default-Setup-src" {} ''
104+ src = null;
105+ cleanSrc = buildPackages.runCommand "default-Setup-src" {} ''
98106 mkdir $out
99107 cat ${defaultSetupSrc} > $out/Setup.hs
100108 '';
builder/make-config-files.nix+7−3
@@ -3,6 +3,10 @@
33{ identifier, component, fullName, flags ? {}, needsProfiling ? false, enableDWARF ? false, chooseDrv ? drv: drv, nonReinstallablePkgs ? defaults.nonReinstallablePkgs }:
44
55let
6+ # Sort and remove duplicates from nonReinstallablePkgs.
7+ # That way changes to the order of nonReinstallablePkgs does not require rebuilds.
8+ nonReinstallablePkgs' = __attrNames (lib.genAttrs nonReinstallablePkgs (x: x));
9+
610 ghc = if enableDWARF then defaults.ghc.dwarf else defaults.ghc;
711
812 flagsAndConfig = field: xs: lib.optionalString (xs != []) ''
@@ -93,7 +97,7 @@ let
9397 ghc=${ghc}
9498 ${ # Copy over the nonReinstallablePkgs from the global package db.
9599 ''
96− for p in ${lib.concatStringsSep " " nonReinstallablePkgs}; do
100+ for p in ${lib.concatStringsSep " " nonReinstallablePkgs'}; do
97101 find $ghc/lib/${ghc.name}/package.conf.d -name $p'*.conf' -exec cp -f {} $out/${packageCfgDir} \;
98102 done
99103 ''}
@@ -152,13 +156,13 @@ let
152156 cat $p/exactDep/cabal.config >> $out/cabal.config
153157 ''}
154158 done
155− for p in ${lib.concatStringsSep " " (lib.remove "ghc" nonReinstallablePkgs)}; do
159+ for p in ${lib.concatStringsSep " " (lib.remove "ghc" nonReinstallablePkgs')}; do
156160 if [ -e $ghc/envDeps/$p ]; then
157161 cat $ghc/envDeps/$p >> $out/ghc-environment
158162 fi
159163 done
160164 '' + lib.optionalString component.doExactConfig ''
161− for p in ${lib.concatStringsSep " " nonReinstallablePkgs}; do
165+ for p in ${lib.concatStringsSep " " nonReinstallablePkgs'}; do
162166 if [ -e $ghc/exactDeps/$p ]; then
163167 cat $ghc/exactDeps/$p/configure-flags >> $out/configure-flags
164168 cat $ghc/exactDeps/$p/cabal.config >> $out/cabal.config
ci.nix+10−4
@@ -44,10 +44,16 @@
4444 ghc810420210212 = false;
4545 });
4646 systems = nixpkgsName: nixpkgs: compiler-nix-name: nixpkgs.lib.genAttrs (
47− nixpkgs.lib.filter (v: v != "aarch64-darwin" || (
48− # aarch64-darwin requires ghc 8.10.7 and does not work on older nixpkgs
49− !__elem compiler-nix-name ["ghc865" "ghc884" "ghc8104" "ghc810420210212" "ghc8105" "ghc8106" "ghc901"]
50− && !__elem nixpkgsName ["R2105"])) supportedSystems) (v: v);
47+ nixpkgs.lib.filter (v:
48+ # We have less x86_64-darwin build capacity so build fewer GhC versions and no R2105
49+ (v != "x86_64-darwin" || (
50+ !__elem compiler-nix-name ["ghc8104" "ghc810420210212" "ghc8105" "ghc8106" "ghc901" "ghc921"]
51+ && !__elem nixpkgsName ["R2105"]))
52+ &&
53+ # aarch64-darwin requires ghc 8.10.7 and does not work on older nixpkgs
54+ (v != "aarch64-darwin" || (
55+ !__elem compiler-nix-name ["ghc865" "ghc884" "ghc8104" "ghc810420210212" "ghc8105" "ghc8106" "ghc901" "ghc921"]
56+ && !__elem nixpkgsName ["R2105"]))) supportedSystems) (v: v);
5157 crossSystems = nixpkgsName: nixpkgs: compiler-nix-name: system:
5258 # We need to use the actual nixpkgs version we're working with here, since the values
5359 # of 'lib.systems.examples' are not understood between all versions
compiler/ghc/default.nix+10−1
@@ -288,7 +288,7 @@ stdenv.mkDerivation (rec {
288288 $i
289289 done
290290
291− # Save generated files for needed when building ghcjs
291+ # Save generated files for needed when building ghc and ghcjs
292292 mkdir -p $generated/includes/dist-derivedconstants/header
293293 cp includes/dist-derivedconstants/header/GHCConstantsHaskell*.hs \
294294 $generated/includes/dist-derivedconstants/header
@@ -299,6 +299,15 @@ stdenv.mkDerivation (rec {
299299 fi
300300 mkdir -p $generated/compiler/stage2/build
301301 cp compiler/stage2/build/Config.hs $generated/compiler/stage2/build || true
302+ if [[ -f compiler/stage2/build/GHC/Platform/Constants.hs ]]; then
303+ mkdir -p $generated/compiler/stage2/build/GHC/Platform
304+ cp compiler/stage2/build/GHC/Platform/Constants.hs $generated/compiler/stage2/build/GHC/Platform
305+ fi
306+ if [[ -f compiler/stage2/build/GHC/Settings/Config.hs ]]; then
307+ mkdir -p $generated/compiler/stage2/build/GHC/Settings
308+ cp compiler/stage2/build/GHC/Settings/Config.hs $generated/compiler/stage2/build/GHC/Settings
309+ fi
310+ cp compiler/stage2/build/*.hs-incl $generated/compiler/stage2/build || true
302311 mkdir -p $generated/rts/build
303312 cp rts/build/config.hs-incl $generated/rts/build || true
304313
modules/component-driver.nix+4−2
@@ -54,7 +54,7 @@ in
5454 # without reinstallable-lib:ghc, this is significantly larger.
5555
5656 config.nonReinstallablePkgs =
57− [ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
57+ [ "rts" "ghc-prim" "integer-gmp" "integer-simple" "base"
5858 "deepseq" "array" "ghc-boot-th" "pretty" "template-haskell"
5959 # ghcjs custom packages
6060 "ghcjs-prim" "ghcjs-th"
@@ -72,6 +72,9 @@ in
7272 "mtl" "parsec" "process" "text" "time" "transformers"
7373 "unix" "xhtml" "terminfo"
7474 # "stm"
75+ ]
76+ ++ lib.optionals (!config.reinstallableLibGhc || __elem config.compiler.nix-name ["ghc865"]) [
77+ "ghc-heap"
7578 ];
7679
7780 options.bootPkgs = lib.mkOption {
@@ -80,7 +83,6 @@ in
8083
8184 config.bootPkgs = [
8285 "rts" "ghc-boot-th"
83− "ghc-heap" # since ghc 8.6.
8486 "ghcjs-prim"
8587 ] ++ lib.optional (!config.reinstallableLibGhc) "ghc"
8688 ++ lib.optionals (
overlays/ghc-packages.nix+33−15
@@ -106,24 +106,42 @@ let
106106in rec {
107107 ghc-boot-packages-src-and-nix = builtins.mapAttrs
108108 (ghcName: ghc: builtins.mapAttrs
109− (pkgName: dir: rec {
109+ (pkgName: subDir: rec {
110110 src =
111111 # Add in the generated files needed by ghc-boot
112− if dir == "libraries/ghc-boot"
113− then final.evalPackages.runCommand "ghc-boot-src" {} ''
114− cp -Lr ${ghc.passthru.configured-src}/${dir} $out
115− chmod -R +w $out
116− cp -Lr ${ghc.generated}/libraries/ghc-boot/dist-install/build/GHC/* $out/GHC
112+ if subDir == "libraries/ghc-boot"
113+ then final.evalPackages.runCommand "ghc-boot-src" { nativeBuildInputs = [final.evalPackages.xorg.lndir]; } ''
114+ mkdir $out
115+ lndir -silent ${ghc.passthru.configured-src}/${subDir} $out
116+ lndir -silent ${ghc.generated}/libraries/ghc-boot/dist-install/build/GHC $out/GHC
117117 ''
118− else if dir == "compiler"
119− then final.evalPackages.runCommand "ghc-src" {} ''
120− cp -Lr ${ghc.passthru.configured-src}/${dir} $out
121− chmod -R +w $out
122− if [[ -f ${ghc.generated}/compiler/stage2/build/Config.hs ]]; then
123− cp -Lr ${ghc.generated}/compiler/stage2/build/Config.hs $out
124− fi
125− ''
126− else "${ghc.passthru.configured-src}/${dir}";
118+ else if subDir == "compiler"
119+ then final.haskell-nix.haskellLib.cleanSourceWith {
120+ src = final.evalPackages.runCommand "ghc-src" { nativeBuildInputs = [final.evalPackages.xorg.lndir]; } ''
121+ mkdir $out
122+ lndir -silent ${ghc.passthru.configured-src} $out
123+ if [[ -f ${ghc.generated}/libraries/ghc-boot/dist-install/build/GHC/Version.hs ]]; then
124+ ln -s ${ghc.generated}/libraries/ghc-boot/dist-install/build/GHC/Version.hs $out/libraries/ghc-boot/GHC
125+ fi
126+ if [[ -f ${ghc.generated}/libraries/ghc-boot/dist-install/build/GHC/Platform/Host.hs ]]; then
127+ ln -s ${ghc.generated}/libraries/ghc-boot/dist-install/build/GHC/Platform/Host.hs $out/libraries/ghc-boot/GHC/Platform
128+ fi
129+ if [[ -f ${ghc.generated}/compiler/stage2/build/Config.hs ]]; then
130+ ln -s ${ghc.generated}/compiler/stage2/build/Config.hs $out/compiler
131+ fi
132+ if [[ -f ${ghc.generated}/compiler/stage2/build/GHC/Platform/Constants.hs ]]; then
133+ ln -s ${ghc.generated}/compiler/stage2/build/GHC/Platform/Constants.hs $out/compiler/GHC/Platform
134+ fi
135+ if [[ -f ${ghc.generated}/compiler/stage2/build/GHC/Settings/Config.hs ]]; then
136+ ln -s ${ghc.generated}/compiler/stage2/build/GHC/Settings/Config.hs $out/compiler/GHC/Settings
137+ fi
138+ ln -s ${ghc.generated}/includes/dist-derivedconstants/header/* $out/compiler
139+ ln -s ${ghc.generated}/compiler/stage2/build/*.hs-incl $out/compiler
140+ '';
141+ inherit subDir;
142+ includeSiblings = true;
143+ }
144+ else "${ghc.passthru.configured-src}/${subDir}";
127145 nix = callCabal2Nix ghcName "${ghcName}-${pkgName}" src;
128146 }) (ghc-extra-pkgs ghc.version))
129147 final.buildPackages.haskell-nix.compiler;
test/setup-deps/default.nix+2−4
@@ -17,15 +17,13 @@ let
1717
1818 meta = {
1919 platforms = platforms.unix;
20− # Building reinstallable lib GHC is broken on 8.10, and we require lib ghc so this won't work with cross-compiling.
20+ # We require lib ghc so this won't work with cross-compiling.
2121 # Moreover, even building the plan doesn't seem to work in these circumstances.
22− disabled = stdenv.buildPlatform != stdenv.hostPlatform || stdenv.hostPlatform.isMusl || __elem compiler-nix-name ["ghc8101" "ghc8102" "ghc8103" "ghc8104" "ghc8105" "ghc8106" "ghc8107" "ghc810420210212"];
22+ disabled = stdenv.buildPlatform != stdenv.hostPlatform || stdenv.hostPlatform.isMusl;
2323 };
2424in
2525
2626recurseIntoAttrs ({
27− meta.disabled = __elem compiler-nix-name ["ghc901" "ghc902" "ghc921" "ghc922"];
28−
2927 ifdInputs = {
3028 plan-nix = addMetaAttrs meta project.plan-nix;
3129 };
test/setup-deps/pkg/Setup.hs+5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12import Distribution.Simple
23
34-- https://github.com/snoyberg/conduit#readme
@@ -7,7 +8,11 @@ import System.Directory (removeFile)
78
89-- Make sure Cabal and ghc were included
910import Distribution.Package ()
11+#if MIN_VERSION_ghc(9,0,0)
12+import GHC.SysTools.Ar ()
13+#else
1014import Ar ()
15+#endif
1116
1217example = do
1318 -- Pure operations: summing numbers.