65
65
fi
66
66
'' ;
67
67
68
+ envDep = pdbArg : p : ''
69
+ if id=$(${ ghc . targetPrefix } ghc-pkg -v0 ${ pdbArg } field ${ p } id --simple-output); then
70
+ echo "package-id $id" >> $out/ghc-environment
71
+ fi
72
+ '' ;
73
+
68
74
configFiles = runCommand "${ fullName } -config" { nativeBuildInputs = [ ghc ] ; } ( ''
69
75
mkdir -p $out
70
76
${ ghc . targetPrefix } ghc-pkg -v0 init $out/package.conf.d
91
97
92
98
echo ${ lib . concatStringsSep " " ( lib . mapAttrsToList ( fname : val : "--flags=${ lib . optionalString ( ! val ) "-" + fname } " ) flags ) } >> $out/configure-flags
93
99
100
+ cat > $out/ghc-environment <<EOF
101
+ clear-package-db
102
+ package-db $out/package.conf.d
103
+ EOF
104
+ ${ lib . concatMapStringsSep "\n " ( p : envDep "--package-db ${ p . components . library } /package.conf.d" p . identifier . name ) componentDepends }
105
+ ${ lib . concatMapStringsSep "\n " ( envDep "" ) ( lib . remove "ghc" nonReinstallablePkgs ) }
106
+
94
107
'' + lib . optionalString component . doExactConfig ''
95
108
echo "--exact-configuration" >> $out/configure-flags
96
109
echo "allow-newer: ${ package . identifier . name } :*" >> $out/cabal.config
@@ -185,6 +198,7 @@ in stdenv.mkDerivation ({
185
198
} ;
186
199
187
200
CABAL_CONFIG = configFiles + /cabal.config ;
201
+ # GHC_ENVIRONMENT = configFiles + /ghc-environment;
188
202
LANG = "en_US.UTF-8" ; # GHC needs the locale configured during the Haddock phase.
189
203
LC_ALL = "en_US.UTF-8" ;
190
204
@@ -250,6 +264,15 @@ in stdenv.mkDerivation ({
250
264
runHook postInstall
251
265
'' ;
252
266
267
+ shellHook = ''
268
+ # don't use this variable for the component build, but do provide it in the shell.
269
+ export GHC_ENVIRONMENT=$out/ghc-environment
270
+
271
+ # provide this variable so that `ghc-pkg` works (cabal doesn't like it though)
272
+ export GHC_PACKAGE_PATH=$out/package.conf.d
273
+
274
+ ${ toString shellHook }
275
+ '' ;
253
276
}
254
277
# patches can (if they like) depend on the version and revision of the package.
255
278
// lib . optionalAttrs ( patches != [ ] ) { patches = map ( p : if builtins . isFunction p then p { inherit ( package . identifier ) version ; inherit revision ; } else p ) patches ; }
@@ -263,6 +286,5 @@ in stdenv.mkDerivation ({
263
286
// lib . optionalAttrs ( postCheck != "" ) { inherit postCheck ; }
264
287
// lib . optionalAttrs ( preInstall != "" ) { inherit preInstall ; }
265
288
// lib . optionalAttrs ( postInstall != "" ) { inherit postInstall ; }
266
- // lib . optionalAttrs ( shellHook != "" ) { inherit shellHook ; }
267
289
// lib . optionalAttrs ( stdenv . buildPlatform . libc == "glibc" ) { LOCALE_ARCHIVE = "${ buildPackages . glibcLocales } /lib/locale/locale-archive" ; }
268
290
)
0 commit comments