@@ -9,12 +9,17 @@ let
99 target-pkg = "${ghc.targetPrefix}ghc-pkg";
1010
1111 # This is a bit of a hack. So we'll have a slightly longer explaination here:
12+
13+ # Every library component built with `comp-builder.nix` includes an `exactDep`
14+ # and `envDep` directory with precomputed values used here.
15+ # GHC derivations include `exactDep` and `envDep` derivations that have
16+ # the same information for each of the built in packages.
17+
1218 # exactDep will pass --exact-configuration to the `SETUP_HS confiugre` command.
1319 # This requires us to pass --dependency={dep name}={pkg id}. The dependency
14− # name will usually be the name of the package `p`, which we can locate in the
15− # package-db, passed in via `pdbArg`. Thus querying the package-db for the
16− # id field for package `p`, will unsually provide is with the right value. Sublibs
17− # need a bit of special handling:
20+ # name will usually be the name of the package `p`, that will have been located
21+ # in the suitable package db when the dependency (along with `exactDep` and `envDep`)
22+ # was built. Sublibs need a bit of special handling:
1823 #
1924 # - Sublibs: if the dependency is a sublibrary of a package, we need to use
2025 # the sublibrary's name for the dep name, and lookup the sublibraries
@@ -22,52 +27,33 @@ let
2227 # sublib name to exactDep, as we don't have access to it at the call-site,
2328 # we resort to a bit of globbing, which (as pkg db's should contain only
2429 # a single package) work.
25− exactDep = pdbArg: p: nativeBuildInputs: runCommand "${p}-exactdep" { inherit nativeBuildInputs; } ''
26− mkdir -p $out
27− touch $out/configure-flags
28− touch $out/cabal.config
29−
30− if id=$(${target-pkg} ${pdbArg} field ${p} id --simple-output); then
31− echo "--dependency=${p}=$id" >> $out/configure-flags
32− elif id=$(${target-pkg} ${pdbArg} field "z-${p}-z-*" id --simple-output); then
33− name=$(${target-pkg} ${pdbArg} field "z-${p}-z-*" name --simple-output)
34− # so we are dealing with a sublib. As we build sublibs separately, the above
35− # query should be safe.
36− echo "--dependency=''${name#z-${p}-z-}=$id" >> $out/configure-flags
37− fi
38− if ver=$(${target-pkg} ${pdbArg} field ${p} version --simple-output); then
39− echo "constraint: ${p} == $ver" >> $out/cabal.config
40− echo "constraint: ${p} installed" >> $out/cabal.config
41− fi
42− '';
4330
44− catExactDep = dep: ''
45− cat ${dep}/configure-flags >> $out/configure-flags
46− cat ${dep}/cabal.config >> $out/cabal.config
31+ getLibComponent = dep:
32+ dep.components.library # Regular package dependency
33+ or dep; # or a sublib
34+
35+ catPkgExactDep = p: ''
36+ cat ${getLibComponent p}/exactDep/configure-flags >> $out/configure-flags
37+ cat ${getLibComponent p}/exactDep/cabal.config >> $out/cabal.config
4738 '';
4839
49− catPkgExactDep = p:
50− catExactDep (exactDep (packageDb p) p.identifier.name [ghc (p.components.library or p)]);
51−
52− catGhcPkgExactDep = p: catExactDep (exactDep "" p [ghc]);
53−
54− envDep = pdbArg: p: nativeBuildInputs: runCommand "${p}-envdep" { inherit nativeBuildInputs; } ''
55− touch $out
56− if id=$(${target-pkg} ${pdbArg} field ${p} id --simple-output); then
57− echo "package-id $id" >> $out
40+ catGhcPkgExactDep = p: ''
41+ if [ -e ${ghc.exactDeps}/${p} ]; then
42+ cat ${ghc.exactDeps}/${p}/configure-flags >> $out/configure-flags
43+ cat ${ghc.exactDeps}/${p}/cabal.config >> $out/cabal.config
5844 fi
5945 '';
6046
61− catEnvDep = ghcEnv: ''
62− cat ${ghcEnv} >> $out/ghc-environment
47+ catPkgEnvDep = p: ''
48+ cat ${getLibComponent p}/envDep >> $out/ghc-environment
6349 '';
6450
65− catPkgEnvDep = p:
66− catEnvDep (envDep (packageDb p) p.identifier.name [ghc (p.components.library or p)]);
67−
68− catGhcPkgEnvDep = p: catEnvDep (envDep "" p [ghc]);
51+ catGhcPkgEnvDep = p: ''
52+ if [ -e ${ghc.envDeps}/${p} ]; then
53+ cat ${ghc.envDeps}/${p} >> $out/ghc-environment
54+ fi
55+ '';
6956
70− packageDb = p: "--package-db ${p.components.library or p}/package.conf.d";
7157in { identifier, component, fullName, flags ? {} }:
7258 runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } (''
7359 mkdir -p $out
@@ -86,8 +72,9 @@ in { identifier, component, fullName, flags ? {} }:
8672 '') nonReinstallablePkgs}
8773
8874 ${lib.concatMapStringsSep "\n" (p: ''
89− cp -f "${p}/package.conf.d/"*.conf $out/package.conf.d
90− '') (haskellLib.flatLibDepends component)}
75+ cp -f "${(getLibComponent p).configFiles}/package.conf.d/"*.conf $out/package.conf.d
76+ cp -f "${getLibComponent p}/package.conf.d/"*.conf $out/package.conf.d
77+ '') component.depends}
9178
9279 # Note: we pass `clear` first to ensure that we never consult the implicit global package db.
9380 ${flagsAndConfig "package-db" ["clear" "$out/package.conf.d"]}