|
5 | 5 | let
|
6 | 6 | fullName = "${name}-setup";
|
7 | 7 |
|
8 |
| - flagsAndConfig = field: xs: lib.optionalString (xs != []) '' |
9 |
| - echo ${lib.concatStringsSep " " (map (x: "--${field}=${x}") xs)} >> $out/configure-flags |
10 |
| - echo "${field}: ${lib.concatStringsSep " " xs}" >> $out/cabal.config |
11 |
| - ''; |
12 |
| - |
13 |
| - flatDepends = |
14 |
| - let |
15 |
| - makePairs = map (p: rec { key="${val}"; val=(p.components.library or p); }); |
16 |
| - closure = builtins.genericClosure { |
17 |
| - startSet = makePairs setup-depends; |
18 |
| - operator = {val,...}: makePairs val.config.depends; |
19 |
| - }; |
20 |
| - in map ({val,...}: val) closure; |
21 |
| - |
22 | 8 | includeGhcPackage = lib.any (p: p.identifier.name == "ghc") setup-depends;
|
23 | 9 |
|
24 |
| - configFiles = runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } ('' |
25 |
| - mkdir -p $out |
26 |
| -
|
27 |
| - # Calls ghc-pkg for the target platform |
28 |
| - target-pkg() { |
29 |
| - ${ghc.targetPrefix}ghc-pkg "$@" |
30 |
| - } |
31 |
| -
|
32 |
| - target-pkg init $out/package.conf.d |
33 |
| -
|
34 |
| - # Copy over the nonReinstallablePkgs from the global package db. |
35 |
| - # Note: we need to use --global-package-db with ghc-pkg to prevent it |
36 |
| - # from looking into the implicit global package db when registering the package. |
37 |
| - ${lib.concatMapStringsSep "\n" (p: '' |
38 |
| - target-pkg describe ${p} | target-pkg --force --global-package-db $out/package.conf.d register - || true |
39 |
| - '') nonReinstallablePkgs} |
40 |
| -
|
41 |
| - ${lib.concatMapStringsSep "\n" (p: '' |
42 |
| - target-pkg --package-db ${p}/package.conf.d dump | target-pkg --force --package-db $out/package.conf.d register - |
43 |
| - '') flatDepends} |
44 |
| -
|
45 |
| - # Note: we pass `clear` first to ensure that we never consult the implicit global package db. |
46 |
| - ${flagsAndConfig "package-db" ["clear" "$out/package.conf.d"]} |
47 |
| -
|
48 |
| - echo ${lib.concatStringsSep " " (lib.mapAttrsToList (fname: val: "--flags=${lib.optionalString (!val) "-" + fname}") flags)} >> $out/configure-flags |
49 |
| -
|
50 |
| - '' |
51 |
| - # This code originates in the `generic-builder.nix` from nixpkgs. However GHC has been fixed |
52 |
| - # to drop unused libraries referneced from libraries; and this patch is usually included in the |
53 |
| - # nixpkgs's GHC builds. This doesn't sadly make this stupid hack unnecessary. It resurfes in |
54 |
| - # the form of Cabal trying to be smart. Cabal when linking a library figures out that you likely |
55 |
| - # need those `rpath` entries, and passes `-optl-Wl,-rpath,...` for each dynamic library path to |
56 |
| - # GHC, thus subverting the linker and forcing it to insert all those RPATHs weather or not they |
57 |
| - # are needed. We therfore reuse the linker hack here to move all al dynamic lirbaries into a |
58 |
| - # common folder (as links) and thus prevent Cabal from going nuts. |
59 |
| - # |
60 |
| - # TODO: Fix Cabal. |
61 |
| - # TODO: this is only needed if we do dynamic libraries. |
62 |
| - + lib.optionalString stdenv.isDarwin '' |
63 |
| - # Work around a limit in the macOS Sierra linker on the number of paths |
64 |
| - # referenced by any one dynamic library: |
65 |
| - # |
66 |
| - # Create a local directory with symlinks of the *.dylib (macOS shared |
67 |
| - # libraries) from all the dependencies. |
68 |
| - local dynamicLinksDir="$out/lib/links" |
69 |
| - mkdir -p $dynamicLinksDir |
70 |
| - for d in $(grep dynamic-library-dirs "$out/package.conf.d/"*|awk '{print $2}'|sort -u); do |
71 |
| - ln -s "$d/"*.dylib $dynamicLinksDir |
72 |
| - done |
73 |
| - # Edit the local package DB to reference the links directory. |
74 |
| - for f in "$out/package.conf.d/"*.conf; do |
75 |
| - sed -i "s,dynamic-library-dirs: .*,dynamic-library-dirs: $dynamicLinksDir," $f |
76 |
| - done |
77 |
| - '' + '' |
78 |
| - target-pkg --package-db $out/package.conf.d recache |
79 |
| - '' + '' |
80 |
| - target-pkg --package-db $out/package.conf.d check |
81 |
| - ''); |
| 10 | + makeConfigFiles = haskellLib.weakCallPackage buildPackages ./make-config-files.nix { |
| 11 | + inherit ghc haskellLib nonReinstallablePkgs; |
| 12 | + }; |
| 13 | + |
| 14 | + configFiles = makeConfigFiles { |
| 15 | + inherit (package) identifier; |
| 16 | + inherit fullName flags; |
| 17 | + component = { |
| 18 | + depends = setup-depends; |
| 19 | + libs = []; |
| 20 | + frameworks = []; |
| 21 | + doExactConfig = false; |
| 22 | + }; |
| 23 | + }; |
82 | 24 |
|
83 | 25 | in stdenv.lib.fix (drv:
|
84 | 26 |
|
|
0 commit comments