2020 ghc = if enableDWARF then defaults . ghc . dwarf else defaults . ghc ;
2121
2222 inherit ( configFiles ) targetPrefix ghcCommand ghcCommandCaps packageCfgDir ;
23- libDir = "$out /${ configFiles . libDir } " ;
24- docDir = "$out /share/doc/ghc/html" ;
23+ libDir = "$wrappedGhc /${ configFiles . libDir } " ;
24+ docDir = "$wrappedGhc /share/doc/ghc/html" ;
2525 # For musl we can use haddock from the buildGHC
2626 haddock = if stdenv . hostPlatform . isLinux && stdenv . targetPlatform . isMusl && ! haskellLib . isNativeMusl
2727 then ghc . buildGHC
2828 else ghc ;
2929
30- in runCommand "${ componentName } -${ ghc . name } -env" {
31- preferLocalBuild = true ;
32- passthru = {
33- inherit ( ghc ) version meta ;
34- inherit targetPrefix ;
35- baseGhc = ghc ;
36- } ;
37- } (
38- ''
30+ script = ''
3931 . ${ makeWrapper } /nix-support/setup-hook
4032
4133 ''
4234 # Start with a ghc and remove all of the package directories
4335 + ''
44- mkdir -p $out /bin
45- ${ lndir } /bin/lndir -silent ${ ghc } $out
36+ mkdir -p $wrappedGhc /bin
37+ ${ lndir } /bin/lndir -silent $unwrappedGhc $wrappedGhc
4638 rm -rf ${ libDir } /*/
4739 ''
4840 # ... but retain the lib/ghc/bin directory. This contains `unlit' and friends.
4941 + ''
50- ln -s ${ ghc } /lib/${ ghcCommand } -${ ghc . version } /bin ${ libDir }
42+ ln -s $unwrappedGhc /lib/${ ghcCommand } -${ ghc . version } /bin ${ libDir }
5143 ''
5244 # ... and the ghcjs shim's if they are available ...
5345 + ''
54- if [ -d ${ ghc } /lib/${ ghcCommand } -${ ghc . version } /shims ]; then
55- ln -s ${ ghc } /lib/${ ghcCommand } -${ ghc . version } /shims ${ libDir }
46+ if [ -d $unwrappedGhc /lib/${ ghcCommand } -${ ghc . version } /shims ]; then
47+ ln -s $unwrappedGhc /lib/${ ghcCommand } -${ ghc . version } /shims ${ libDir }
5648 fi
5749 ''
5850 # ... and node modules ...
5951 + ''
60- if [ -d ${ ghc } /lib/${ ghcCommand } -${ ghc . version } /ghcjs-node ]; then
61- ln -s ${ ghc } /lib/${ ghcCommand } -${ ghc . version } /ghcjs-node ${ libDir }
52+ if [ -d $unwrappedGhc /lib/${ ghcCommand } -${ ghc . version } /ghcjs-node ]; then
53+ ln -s $unwrappedGhc /lib/${ ghcCommand } -${ ghc . version } /ghcjs-node ${ libDir }
6254 fi
6355 ''
6456 # Replace the package database with the one from target package config.
6557 + ''
66- ln -s ${ configFiles } /${ packageCfgDir } $out /${ packageCfgDir }
58+ ln -s $configFiles/${ packageCfgDir } $wrappedGhc /${ packageCfgDir }
6759
6860 ''
6961 # Set the GHC_PLUGINS environment variable according to the plugins for the component.
@@ -77,9 +69,9 @@ in runCommand "${componentName}-${ghc.name}-env" {
7769 GHC_PLUGINS="["
7870 LIST_PREFIX=""
7971 ${ builtins . concatStringsSep "\n " ( map ( plugin : ''
80- id=$(${ ghc } /bin/ghc-pkg --package-db ${ plugin . library } /package.conf.d field ${ plugin . library . package . identifier . name } id --simple-output)
81- lib_dir=$(${ ghc } /bin/ghc-pkg --package-db ${ plugin . library } /package.conf.d field ${ plugin . library . package . identifier . name } dynamic-library-dirs --simple-output)
82- lib_base=$(${ ghc } /bin/ghc-pkg --package-db ${ plugin . library } /package.conf.d field ${ plugin . library . package . identifier . name } hs-libraries --simple-output)
72+ id=$($unwrappedGhc /bin/ghc-pkg --package-db ${ plugin . library } /package.conf.d field ${ plugin . library . package . identifier . name } id --simple-output)
73+ lib_dir=$($unwrappedGhc /bin/ghc-pkg --package-db ${ plugin . library } /package.conf.d field ${ plugin . library . package . identifier . name } dynamic-library-dirs --simple-output)
74+ lib_base=$($unwrappedGhc /bin/ghc-pkg --package-db ${ plugin . library } /package.conf.d field ${ plugin . library . package . identifier . name } hs-libraries --simple-output)
8375 lib="$(echo '' ${lib_dir}/lib'' ${lib_base}*)"
8476 GHC_PLUGINS="'' ${GHC_PLUGINS}'' ${LIST_PREFIX}(\"'' ${lib}\",\"'' ${id}\",\"${ plugin . moduleName } \",["
8577 LIST_PREFIX=""
@@ -103,25 +95,25 @@ in runCommand "${componentName}-${ghc.name}-env" {
10395 # The NIX_ variables are used by the patched Paths_ghc module.
10496 + ''
10597 for prg in ${ ghcCommand } ${ ghcCommand } i ${ ghcCommand } -${ ghc . version } ${ ghcCommand } i-${ ghc . version } ; do
106- if [[ -x "${ ghc } /bin/$prg" ]]; then
107- rm -f $out /bin/$prg
108- makeWrapper ${ ghc } /bin/$prg $out /bin/$prg \
98+ if [[ -x "$unwrappedGhc /bin/$prg" ]]; then
99+ rm -f $wrappedGhc /bin/$prg
100+ makeWrapper $unwrappedGhc /bin/$prg $wrappedGhc /bin/$prg \
109101 --add-flags '"-B$NIX_${ ghcCommandCaps } _LIBDIR"' \
110- --set "NIX_${ ghcCommandCaps } " "$out /bin/${ ghcCommand } " \
111- --set "NIX_${ ghcCommandCaps } PKG" "$out /bin/${ ghcCommand } -pkg" \
102+ --set "NIX_${ ghcCommandCaps } " "$wrappedGhc /bin/${ ghcCommand } " \
103+ --set "NIX_${ ghcCommandCaps } PKG" "$wrappedGhc /bin/${ ghcCommand } -pkg" \
112104 --set "NIX_${ ghcCommandCaps } _DOCDIR" "${ docDir } " \
113105 --set "GHC_PLUGINS" "$GHC_PLUGINS" \
114106 --set "NIX_${ ghcCommandCaps } _LIBDIR" "${ libDir } "
115107 fi
116108 done
117109
118110 for prg in "${ targetPrefix } runghc" "${ targetPrefix } runhaskell"; do
119- if [[ -x "${ ghc } /bin/$prg" ]]; then
120- rm -f $out /bin/$prg
121- makeWrapper ${ ghc } /bin/$prg $out /bin/$prg \
122- --add-flags "-f $out /bin/${ ghcCommand } " \
123- --set "NIX_${ ghcCommandCaps } " "$out /bin/${ ghcCommand } " \
124- --set "NIX_${ ghcCommandCaps } PKG" "$out /bin/${ ghcCommand } -pkg" \
111+ if [[ -x "$unwrappedGhc /bin/$prg" ]]; then
112+ rm -f $wrappedGhc /bin/$prg
113+ makeWrapper $unwrappedGhc /bin/$prg $wrappedGhc /bin/$prg \
114+ --add-flags "-f $wrappedGhc /bin/${ ghcCommand } " \
115+ --set "NIX_${ ghcCommandCaps } " "$wrappedGhc /bin/${ ghcCommand } " \
116+ --set "NIX_${ ghcCommandCaps } PKG" "$wrappedGhc /bin/${ ghcCommand } -pkg" \
125117 --set "NIX_${ ghcCommandCaps } _DOCDIR" "${ docDir } " \
126118 --set "GHC_PLUGINS" "$GHC_PLUGINS" \
127119 --set "NIX_${ ghcCommandCaps } _LIBDIR" "${ libDir } "
@@ -132,8 +124,8 @@ in runCommand "${componentName}-${ghc.name}-env" {
132124 # Wrap haddock, if the base GHC provides it.
133125 + ''
134126 if [[ -x "${ haddock } /bin/haddock" ]]; then
135- rm -f $out /bin/haddock
136- makeWrapper ${ haddock } /bin/haddock $out /bin/haddock \
127+ rm -f $wrappedGhc /bin/haddock
128+ makeWrapper ${ haddock } /bin/haddock $wrappedGhc /bin/haddock \
137129 --add-flags '"-B$NIX_${ ghcCommandCaps } _LIBDIR"' \
138130 --set "NIX_${ ghcCommandCaps } _LIBDIR" "${ libDir } "
139131 fi
@@ -143,12 +135,31 @@ in runCommand "${componentName}-${ghc.name}-env" {
143135 # --global-package-db flag.
144136 + ''
145137 for prg in ${ ghcCommand } -pkg ${ ghcCommand } -pkg-${ ghc . version } ; do
146- if [[ -x "${ ghc } /bin/$prg" ]]; then
147- rm -f $out /bin/$prg
148- makeWrapper ${ ghc } /bin/$prg $out /bin/$prg --add-flags "--global-package-db=$out /${ packageCfgDir } "
138+ if [[ -x "$unwrappedGhc /bin/$prg" ]]; then
139+ rm -f $wrappedGhc /bin/$prg
140+ makeWrapper $unwrappedGhc /bin/$prg $wrappedGhc /bin/$prg --add-flags "--global-package-db=$wrappedGhc /${ packageCfgDir } "
149141 fi
150142 done
151143
152144 ${ postInstall }
153- ''
154- )
145+ '' ;
146+
147+ drv = runCommand "${ componentName } -${ ghc . name } -env" {
148+ preferLocalBuild = true ;
149+ passthru = {
150+ inherit script targetPrefix ;
151+ inherit ( ghc ) version meta ;
152+ } ;
153+ propagatedBuildInputs = configFiles . libDeps ;
154+ nativeBuildInputs = [ ghc ] ;
155+ } ( ''
156+ mkdir -p $out/configFiles
157+ configFiles=$out/configFiles
158+ ${ configFiles . script }
159+ wrappedGhc=$out
160+ ${ script }
161+ '' ) ;
162+ in {
163+ inherit script drv targetPrefix ;
164+ baseGhc = ghc ;
165+ }
0 commit comments