about summary refs log tree commit diff
path: root/pkgs/development/tools/haskell/hadrian/make-hadrian.nix
blob: fb9ee89f7cdb9c9e1754342e65b87b74f57a2237 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Hadrian is the build system used to (exclusively) build GHC. It can
# (theoretically) be used starting with GHC 9.4 and is required since 9.6. It is
# developed in the GHC source tree and specific to the GHC version it is released
# with, i.e. Hadrian always needs to be built from the same GHC source tree as
# the GHC we want to build.
#
# This fact makes it impossible to integrate Hadrian into our Haskell package
# sets which are also used to bootstrap GHC, since a package set can bootstrap
# multiple GHC versions (usually two major versions). A bootstrap set would need
# knowledge of the GHC it would eventually bootstrap which would make the logic
# unnecessarily complicated.
#
# Luckily Hadrian is, while annoying to bootstrap, relatively simple. Specifically
# all it requires to build is (relative to the GHC we are trying to build) a
# build->build GHC and build->build Haskell packages. We can get all of this
# from bootPkgs which is already passed to the GHC expression.
#
# The solution is the following: The GHC expression passes its source tree and
# version along with some parameters to this function (./make-hadrian.nix)
# which acts as a common expression builder for all Hadrian version as well as
# related packages that are managed in the GHC source tree. Its main job is to
# expose all possible compile time customization in a common interface and
# take care of all differences between Hadrian versions.
{ bootPkgs
, lib
}:

{ # GHC source tree and version to build hadrian & friends from.
  # These are passed on to the actual package expressions.
  ghcSrc
, ghcVersion
  # Contents of a non-default UserSettings.hs to use when building hadrian, if any.
  # Should be a string or null.
, userSettings ? null
}:

let
  callPackage' = f: args: bootPkgs.callPackage f ({
    inherit ghcSrc ghcVersion;
  } // args);

  ghc-platform = callPackage' ./ghc-platform.nix { };
  ghc-toolchain = callPackage' ./ghc-toolchain.nix {
    inherit ghc-platform;
  };
in

callPackage' ./hadrian.nix ({
  inherit userSettings;
} // lib.optionalAttrs (lib.versionAtLeast ghcVersion "9.9") {
  # Starting with GHC 9.9 development, additional in tree packages are required
  # to build hadrian. (Hackage-released conditional dependencies are handled
  # in ./hadrian.nix without requiring intervention here.)
  inherit ghc-platform ghc-toolchain;
})