@@ -28,18 +28,14 @@ let
31− # For each architecture, we need to know two (somewhat ad-hoc) things:
32− # - What GHC version we should use for bootstrapping.
31+ # For each architecture, what GHC version we should use for bootstrapping.
33− # - What Happy version we should use for bootstrapping.
34 buildBootstrapper =
32 buildBootstrapper =
35 if final.targetPlatform.isAarch64 && final.buildPlatform.isAarch64
33 if final.targetPlatform.isAarch64 && final.buildPlatform.isAarch64
37 compilerNixName = "ghc882";
35 compilerNixName = "ghc882";
38− happyVersion = "1.19.12";
41 compilerNixName = "ghc844";
38 compilerNixName = "ghc844";
42− happyVersion = "1.19.11";
45 haskell-nix = prev.haskell-nix // {
41 haskell-nix = prev.haskell-nix // {
@@ -47,15 +43,9 @@ in {
47 compiler =
43 compiler =
48 let bootPkgs = with final.buildPackages; {
44 let bootPkgs = with final.buildPackages; {
49 ghc = final.buildPackages.buildPackages.haskell-nix.bootstrap.compiler."${buildBootstrapper.compilerNixName}";
45 ghc = final.buildPackages.buildPackages.haskell-nix.bootstrap.compiler."${buildBootstrapper.compilerNixName}";
50− alex = final.haskell-nix.bootstrap.packages.alex-tool {
46+ alex = final.haskell-nix.bootstrap.packages.alex-unchecked;
51− checkMaterialization = false;
53− happy = final.haskell-nix.bootstrap.packages.happy-tool {
47+ happy = final.haskell-nix.bootstrap.packages.happy-unchecked;
54− checkMaterialization = false;
56− hscolour = final.haskell-nix.bootstrap.packages.hscolour-tool {
48+ hscolour = final.haskell-nix.bootstrap.packages.hscolour-unchecked;
57− checkMaterialization = false;
60 sphinx = with final.buildPackages; (python3Packages.sphinx_1_7_9 or python3Packages.sphinx);
50 sphinx = with final.buildPackages; (python3Packages.sphinx_1_7_9 or python3Packages.sphinx);
61 hsc2hs-align-conditionals-patch = final.fetchpatch {
51 hsc2hs-align-conditionals-patch = final.fetchpatch {
@@ -147,7 +137,11 @@ in {
147 ghc844 = final.callPackage ../compiler/ghc {
137 ghc844 = final.callPackage ../compiler/ghc {
148 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc844; };
138 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc844; };
150− inherit bootPkgs sphinx installDeps;
140+ inherit sphinx installDeps;
141+ bootPkgs = bootPkgs // {
142+ # GHC 8.6.5 and earlier need happy 1.19.11
143+ happy = final.haskell-nix.bootstrap.packages.happy-old-unchecked;
152 buildLlvmPackages = final.buildPackages.llvmPackages_5;
146 buildLlvmPackages = final.buildPackages.llvmPackages_5;
153 llvmPackages = final.llvmPackages_5;
147 llvmPackages = final.llvmPackages_5;
@@ -165,7 +159,11 @@ in {
165 ghc861 = final.callPackage ../compiler/ghc {
159 ghc861 = final.callPackage ../compiler/ghc {
166 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc861; };
160 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc861; };
168− inherit bootPkgs sphinx installDeps;
162+ inherit sphinx installDeps;
163+ bootPkgs = bootPkgs // {
164+ # GHC 8.6.5 and earlier need happy 1.19.11
165+ happy = final.haskell-nix.bootstrap.packages.happy-old-unchecked;
170 buildLlvmPackages = final.buildPackages.llvmPackages_6;
168 buildLlvmPackages = final.buildPackages.llvmPackages_6;
171 llvmPackages = final.llvmPackages_6;
169 llvmPackages = final.llvmPackages_6;
@@ -181,7 +179,11 @@ in {
181 ghc862 = final.callPackage ../compiler/ghc {
179 ghc862 = final.callPackage ../compiler/ghc {
182 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc862; };
180 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc862; };
184− inherit bootPkgs sphinx installDeps;
182+ inherit sphinx installDeps;
183+ bootPkgs = bootPkgs // {
184+ # GHC 8.6.5 and earlier need happy 1.19.11
185+ happy = final.haskell-nix.bootstrap.packages.happy-old-unchecked;
186 buildLlvmPackages = final.buildPackages.llvmPackages_6;
188 buildLlvmPackages = final.buildPackages.llvmPackages_6;
187 llvmPackages = final.llvmPackages_6;
189 llvmPackages = final.llvmPackages_6;
@@ -198,7 +200,11 @@ in {
198 ghc863 = final.callPackage ../compiler/ghc {
200 ghc863 = final.callPackage ../compiler/ghc {
199 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc863; };
201 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc863; };
201− inherit bootPkgs sphinx installDeps;
203+ inherit sphinx installDeps;
204+ bootPkgs = bootPkgs // {
205+ # GHC 8.6.5 and earlier need happy 1.19.11
206+ happy = final.haskell-nix.bootstrap.packages.happy-old-unchecked;
203 buildLlvmPackages = final.buildPackages.llvmPackages_6;
209 buildLlvmPackages = final.buildPackages.llvmPackages_6;
204 llvmPackages = final.llvmPackages_6;
210 llvmPackages = final.llvmPackages_6;
@@ -215,7 +221,11 @@ in {
215 ghc864 = final.callPackage ../compiler/ghc {
221 ghc864 = final.callPackage ../compiler/ghc {
216 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc864; };
222 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc864; };
218− inherit bootPkgs sphinx installDeps;
224+ inherit sphinx installDeps;
225+ bootPkgs = bootPkgs // {
226+ # GHC 8.6.5 and earlier need happy 1.19.11
227+ happy = final.haskell-nix.bootstrap.packages.happy-old-unchecked;
220 buildLlvmPackages = final.buildPackages.llvmPackages_6;
230 buildLlvmPackages = final.buildPackages.llvmPackages_6;
221 llvmPackages = final.llvmPackages_6;
231 llvmPackages = final.llvmPackages_6;
@@ -232,7 +242,11 @@ in {
232 ghc865 = final.callPackage ../compiler/ghc {
242 ghc865 = final.callPackage ../compiler/ghc {
233 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc865; };
243 extra-passthru = { buildGHC = final.buildPackages.haskell-nix.compiler.ghc865; };
235− inherit bootPkgs sphinx installDeps;
245+ inherit sphinx installDeps;
246+ bootPkgs = bootPkgs // {
247+ # GHC 8.6.5 and earlier need happy 1.19.11
248+ happy = final.haskell-nix.bootstrap.packages.happy-old-unchecked;
237 buildLlvmPackages = final.buildPackages.llvmPackages_6;
251 buildLlvmPackages = final.buildPackages.llvmPackages_6;
238 llvmPackages = final.llvmPackages_6;
252 llvmPackages = final.llvmPackages_6;
@@ -302,8 +316,6 @@ in {
303 bootPkgs = bootPkgs // {
317 bootPkgs = bootPkgs // {
304 ghc = buildPkgs.haskell-nix.compiler.ghc883;
318 ghc = buildPkgs.haskell-nix.compiler.ghc883;
305− alex = buildPkgs.haskell-nix.haskellPackages.alex.components.exes.alex;
306− happy = buildPkgs.haskell-nix.haskellPackages.happy.components.exes.happy;
308 inherit sphinx installDeps;
320 inherit sphinx installDeps;
@@ -365,41 +377,27 @@ in {
365 '' + installDeps targetPrefix);
377 '' + installDeps targetPrefix);
368− # Need to use something from 8.8.x as the default to build aarch64 native compiler:
369− defaultCompilerNixName =
370− if final.targetPlatform.isAarch64 && final.buildPlatform.isAarch64
373− ghc = final.haskell-nix.compiler."${final.haskell-nix.defaultCompilerNixName}";
374 # Both `cabal-install` and `nix-tools` are needed for `cabalProject`
380 # Both `cabal-install` and `nix-tools` are needed for `cabalProject`
375 # to check materialized results. We need to take care that when
381 # to check materialized results. We need to take care that when
376 # it is doing this we do not check the materialization of the
382 # it is doing this we do not check the materialization of the
377 # tools used or there will be infinite recursion.
383 # tools used or there will be infinite recursion.
378 # always has `checkMaterialization = false` to avoid infinite
384 # always has `checkMaterialization = false` to avoid infinite
379 # recursion.
385 # recursion.
380− cabal-install-tool = args:
386+ cabal-install-tool = {compiler-nix-name, ...}@args:
381− # Hackage version of cabal-install does not compiler with ghc 8.10.1 yet.
382− let compiler-nix-name = args.compiler-nix-name or
383− (if final.haskell-nix.defaultCompilerNixName == "ghc8101"
387+ (final.haskell-nix.hackage-package ({
384− then "ghc883"
388+ name = "cabal-install";
385− else final.haskell-nix.defaultCompilerNixName);
386− in final.haskell-nix.tool "cabal" ({
387 version = "3.2.0.0";
389 version = "3.2.0.0";
388 index-state = final.haskell-nix.internalHackageIndexState;
390 index-state = final.haskell-nix.internalHackageIndexState;
389− inherit compiler-nix-name;
390 # When building cabal-install (only happens when checking materialization)
391 # When building cabal-install (only happens when checking materialization)
391 # disable checking of the tools used to avoid infinite recursion.
392 # disable checking of the tools used to avoid infinite recursion.
392− cabal-install = final.evalPackages.haskell-nix.cabal-install-tool
393+ cabal-install = final.evalPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name};
393− (args // { checkMaterialization = false; });
394− nix-tools = final.evalPackages.haskell-nix.nix-tools-set
394+ nix-tools = final.evalPackages.haskell-nix.nix-tools-unchecked.${compiler-nix-name};
395− (args // { checkMaterialization = false; });
396 materialized = ../materialized + "/${compiler-nix-name}/cabal-install";
395 materialized = ../materialized + "/${compiler-nix-name}/cabal-install";
397− } // args);
396+ } // args)).components.exes.cabal;
398− cabal-install = final.buildPackages.haskell-nix.cabal-install-tool {};
399− nix-tools-set = args:
397+ nix-tools-set = { compiler-nix-name, ... }@args:
401− exes =
399+ project =
402− (final.haskell-nix.cabalProject ({
400+ final.haskell-nix.cabalProject ({
403 name = "nix-tools";
401 name = "nix-tools";
404 src = final.haskell-nix.sources.nix-tools;
402 src = final.haskell-nix.sources.nix-tools;
405 index-state = final.haskell-nix.internalHackageIndexState;
403 index-state = final.haskell-nix.internalHackageIndexState;
@@ -409,13 +407,9 @@ in {
410 # When building cabal-install (only happens when checking materialization)
408 # When building cabal-install (only happens when checking materialization)
411 # disable checking of the tools used to avoid infinite recursion.
409 # disable checking of the tools used to avoid infinite recursion.
412− cabal-install = final.evalPackages.haskell-nix.cabal-install-tool
410+ cabal-install = final.evalPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name};
413− (args // { checkMaterialization = false; });
414− nix-tools = final.evalPackages.haskell-nix.nix-tools-set
411+ nix-tools = final.evalPackages.haskell-nix.nix-tools-unchecked.${compiler-nix-name};
415− (args // { checkMaterialization = false; });
416− materialized = ../materialized + "/${
412+ materialized = ../materialized + "/${compiler-nix-name}/nix-tools";
417− args.compiler-nix-name or final.haskell-nix.defaultCompilerNixName
419 modules = [{
413 modules = [{
420 packages.transformers-compat.components.library.doExactConfig = true;
414 packages.transformers-compat.components.library.doExactConfig = true;
421 packages.time-compat.components.library.doExactConfig = true;
415 packages.time-compat.components.library.doExactConfig = true;
@@ -432,7 +426,8 @@ in {
432 "unix" "xhtml"
426 "unix" "xhtml"
435− } // args)).nix-tools.components.exes;
430+ exes = project.nix-tools.components.exes // project.hpack.components.exes;
436 tools = [
431 tools = [
437 final.buildPackages.nix
432 final.buildPackages.nix
438 # Double buildPackages is intentional, see comment in lib/default.nix for details.
433 # Double buildPackages is intentional, see comment in lib/default.nix for details.
@@ -452,23 +447,39 @@ in {
455− nix-tools = final.buildPackages.haskell-nix.nix-tools-set {};
450+
456− alex-tool = args: final.haskell-nix.tool "alex" ({
451+ # Memoize the cabal-install and nix-tools derivations by adding:
457− version = "3.2.5";
452+ # haskell-nix.cabal-install.ghcXXX
458− index-state = final.haskell-nix.internalHackageIndexState;
453+ # haskell-nix.cabal-install-unchecked.ghcXXX
459− materialized = ../materialized + "/${
454+ # haskell-nix.nix-tools.ghcXXX
460− args.compiler-nix-name or final.haskell-nix.defaultCompilerNixName
455+ # haskell-nix.nix-tools-unchecked.ghcXXX
461− }/alex";
456+ # Using these avoids unecessary calls to mkDerivation.
462− } // args);
457+ # For cabal projects we match the versions used to the compiler
463− alex = final.buildPackages.haskell-nix.alex-tool {};
458+ # selected for the project to avoid the chance of a dependency
464− happy-tool = args: final.haskell-nix.tool "happy" ({
459+ # another GHC version (particularly useful on macOS where
465− version = "1.19.12";
460+ # executables are dynamically linked to GHC itself, which means
466− index-state = final.haskell-nix.internalHackageIndexState;
461+ # that if you use a tool built with a different GHC you will get
467− materialized = ../materialized + "/${
462+ # that GHC itself in your closure).
468− args.compiler-nix-name or final.haskell-nix.defaultCompilerNixName
463+ cabal-install = final.lib.mapAttrs (compiler-nix-name: _:
469− }/happy";
464+ final.haskell-nix.cabal-install-tool { inherit compiler-nix-name; }) final.haskell-nix.compiler;
470− } // args);
465+ cabal-install-unchecked = final.lib.mapAttrs (compiler-nix-name: _:
471− happy = final.buildPackages.haskell-nix.happy-tool {};
466+ final.haskell-nix.cabal-install-tool { inherit compiler-nix-name; checkMaterialization = false; }) final.haskell-nix.compiler;
467+ nix-tools = final.lib.mapAttrs (compiler-nix-name: _:
468+ final.haskell-nix.nix-tools-set { inherit compiler-nix-name; }) final.haskell-nix.compiler;
469+ nix-tools-unchecked = final.lib.mapAttrs (compiler-nix-name: _:
470+ final.haskell-nix.nix-tools-set { inherit compiler-nix-name; checkMaterialization = false; }) final.haskell-nix.compiler;
472+ # These `internal` versions are used for:
473+ # * `nix-tools` for stack projects (since we use `nix-tools` to process
474+ # the `stack.yaml` file we cannot match the ghc of the project the
475+ # way we do for cabal projects).
476+ # * Scripts are used to update stackage and hackage
477+ # Updating the version of GHC selected here should be fairly safe as
478+ # there should be no difference in the behaviour of these tools.
479+ # (stack projects on macOS may see a significant change in the
480+ # closure size of their build dependencies due to dynamic linking).
481+ internal-cabal-install = final.haskell-nix.cabal-install.ghc883;
482+ internal-nix-tools = final.haskell-nix.nix-tools.ghc883;
473 # WARN: The `import ../. {}` will prevent
484 # WARN: The `import ../. {}` will prevent
474 # any cross to work, as we will loose
485 # any cross to work, as we will loose
@@ -497,7 +508,16 @@ in {
498 # the bootstrap infra structure (pre-compiled ghc; bootstrapped cabal-install, ...)
509 # the bootstrap infra structure (pre-compiled ghc; bootstrapped cabal-install, ...)
499 bootstrap = with final.haskell-nix;
510 bootstrap = with final.haskell-nix;
512+ # This compiler-nix-name will only be used to build nix-tools and cabal-install
513+ # when checking materialization of alex, happy and hscolour.
514+ compiler-nix-name = "ghc865";
515+ nix-tools = final.evalPackages.haskell-nix.nix-tools.${compiler-nix-name};
516+ cabal-install = final.evalPackages.haskell-nix.cabal-install.${compiler-nix-name};
517+ # The ghc boot compiler to use to compile alex, happy and hscolour
500− let ghc = final.buildPackages.haskell-nix.bootstrap.compiler."${buildBootstrapper.compilerNixName}";
518+ ghc = final.buildPackages.haskell-nix.bootstrap.compiler."${buildBootstrapper.compilerNixName}";
519+ ghcOverride = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
520+ index-state = final.haskell-nix.internalHackageIndexState;
502 # XXX: import ../. will throw away all other overlays, config values, ...
522 # XXX: import ../. will throw away all other overlays, config values, ...
503 # this is not ideal!
523 # this is not ideal!
@@ -525,31 +545,31 @@ in {
525 # building ghc itself (since GHC is a dependency
545 # building ghc itself (since GHC is a dependency
526 # of the materialization check it would cause
546 # of the materialization check it would cause
527 # infinite recusion).
547 # infinite recusion).
528− alex-tool = args: tool "alex" ({
548+ alex-tool = args: tool buildBootstrapper.compilerNixName "alex" ({
529 version = "3.2.4";
549 version = "3.2.4";
530− # Only a boot compiler is suitable here
550+ inherit ghcOverride nix-tools cabal-install index-state;
531− ghcOverride = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
532− index-state = final.haskell-nix.internalHackageIndexState;
533 materialized = ../materialized/bootstrap + "/${buildBootstrapper.compilerNixName}/alex";
551 materialized = ../materialized/bootstrap + "/${buildBootstrapper.compilerNixName}/alex";
534 } // args);
552 } // args);
535 alex = bootstrap.packages.alex-tool {};
553 alex = bootstrap.packages.alex-tool {};
554+ alex-unchecked = bootstrap.packages.alex-tool { checkMaterialization = false; };
536− happy-tool = args: tool "happy" ({
555+ happy-tool = { version ? "1.19.12", ... }@args: tool buildBootstrapper.compilerNixName "happy" ({
537− version = buildBootstrapper.happyVersion;
556+ inherit version ghcOverride nix-tools cabal-install index-state;
538− # Only a boot compiler is suitable here
539− ghcOverride = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
540− index-state = final.haskell-nix.internalHackageIndexState;
541− materialized = ../materialized/bootstrap + "/${buildBootstrapper.compilerNixName}/happy-${buildBootstrapper.happyVersion}";
557+ materialized = ../materialized/bootstrap + "/${buildBootstrapper.compilerNixName}/happy-${version}";
542 } // args);
558 } // args);
543 happy = bootstrap.packages.happy-tool {};
559 happy = bootstrap.packages.happy-tool {};
560+ happy-unchecked = bootstrap.packages.happy-tool { checkMaterialization = false; };
561+ # Older version needed when building ghc 8.6.5
562+ happy-old = bootstrap.packages.happy-tool { version = "1.19.11"; };
563+ happy-old-unchecked = bootstrap.packages.happy-tool { version = "1.19.11"; checkMaterialization = false; };
544 hscolour-tool = args: (hackage-package ({
564 hscolour-tool = args: (hackage-package ({
565+ compiler-nix-name = buildBootstrapper.compilerNixName;
545 name = "hscolour";
566 name = "hscolour";
546 version = "1.24.4";
567 version = "1.24.4";
547− # Only a boot compiler is suitable here
568+ inherit ghcOverride nix-tools cabal-install index-state;
548− ghcOverride = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
549− index-state = final.haskell-nix.internalHackageIndexState;
550 materialized = ../materialized/bootstrap + "/${buildBootstrapper.compilerNixName}/hscolour";
569 materialized = ../materialized/bootstrap + "/${buildBootstrapper.compilerNixName}/hscolour";
551 } // args)).components.exes.HsColour;
570 } // args)).components.exes.HsColour;
552 hscolour = bootstrap.packages.hscolour-tool {};
571 hscolour = bootstrap.packages.hscolour-tool {};
572+ hscolour-unchecked = bootstrap.packages.hscolour-tool { checkMaterialization = false; };