Skip to content

Commit 1e5f356

Browse files
committed
Build without GHC environment files, instead using wrappers
Lets development shells work.
1 parent 785f226 commit 1e5f356

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

builder/comp-builder.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ stdenv.mkDerivation ({
221221
};
222222

223223
CABAL_CONFIG = configFiles + /cabal.config;
224-
GHC_ENVIRONMENT = configFiles + /ghc-environment;
225224
LANG = "en_US.UTF-8"; # GHC needs the locale configured during the Haddock phase.
226225
LC_ALL = "en_US.UTF-8";
227226

@@ -232,7 +231,7 @@ stdenv.mkDerivation ({
232231
++ component.pkgconfig;
233232

234233
nativeBuildInputs =
235-
[ghc buildPackages.removeReferencesTo]
234+
[shellWrappers buildPackages.removeReferencesTo]
236235
++ lib.optional (component.pkgconfig != []) pkgconfig
237236
++ executableToolDepends;
238237

builder/with-package-wrapper.nix

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let
1818
docDir = "$out/share/doc/ghc/html";
1919
packageCfgDir = "${libDir}/package.conf.d";
2020

21-
in runCommand "${ghc.name}-with-${package.identifier.name}" {
21+
in runCommand "${ghc.name}-for-${package.identifier.name}" {
2222
preferLocalBuild = true;
2323
passthru = {
2424
inherit (ghc) version meta;
@@ -32,49 +32,56 @@ in runCommand "${ghc.name}-with-${package.identifier.name}" {
3232
# Start with a ghc...
3333
mkdir -p $out/bin
3434
${lndir}/bin/lndir -silent ${ghc} $out
35-
36-
# ...and replace package database with the one from target package config.
37-
rm -rf ${libDir}
38-
mkdir -p ${libDir}
39-
# ... yet retain the lib/.../bin directory. This contains `unlit' and friends.
40-
${lndir}/bin/lndir -silent ${ghc}/lib/${ghcCommand}-${ghc.version}/bin ${libDir}
41-
35+
# ... remove all of the package directories
36+
rm -rf ${libDir}/*/
37+
# ... but retain the lib/ghc/bin directory. This contains `unlit' and friends.
38+
ln -s ${ghc}/lib/${ghcCommand}-${ghc.version}/bin ${libDir}
39+
# Replace the package database with the one from target package config.
4240
ln -s ${configFiles}/package.conf.d ${packageCfgDir}
4341
4442
# Wrap compiler executables with correct env variables.
4543
# The NIX_ variables are used by the patched Paths_ghc module.
46-
# The GHC_ENVIRONMENT variable forces ghc to use the build
47-
# dependencies of the component.
4844
49-
for prg in ${ghcCommand} ${ghcCommand}i ${ghcCommand}-${ghc.version} ${ghcCommand}i-${ghc.version} runghc runhaskell; do
45+
for prg in ${ghcCommand} ${ghcCommand}i ${ghcCommand}-${ghc.version} ${ghcCommand}i-${ghc.version}; do
5046
if [[ -x "${ghc}/bin/$prg" ]]; then
5147
rm -f $out/bin/$prg
5248
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
49+
--add-flags '"-B$NIX_${ghcCommandCaps}_LIBDIR"' \
5350
--set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \
5451
--set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \
5552
--set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
56-
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}" \
57-
--set "${ghcCommandCaps}_ENVIRONMENT" "${configFiles}/ghc-environment"
53+
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
5854
fi
5955
done
6056
61-
# Point ghc-pkg to the package database of the component using the
62-
# GHC_PACKAGE_PATH variable.
63-
64-
for prg in ${ghcCommand}-pkg ${ghcCommand}-pkg-${ghc.version}; do
57+
for prg in runghc runhaskell; do
6558
if [[ -x "${ghc}/bin/$prg" ]]; then
6659
rm -f $out/bin/$prg
67-
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
68-
--set "${ghcCommandCaps}_PACKAGE_PATH" "${configFiles}/package.conf.d"
60+
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
61+
--add-flags "-f $out/bin/${ghcCommand}" \
62+
--set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \
63+
--set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \
64+
--set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
65+
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
6966
fi
7067
done
7168
72-
# fixme: check if this is needed
73-
# haddock was referring to the base ghc, https://github.com/NixOS/nixpkgs/issues/36976
69+
# Wrap haddock, if the base GHC provides it.
7470
if [[ -x "${ghc}/bin/haddock" ]]; then
7571
rm -f $out/bin/haddock
7672
makeWrapper ${ghc}/bin/haddock $out/bin/haddock \
73+
--add-flags '"-B$NIX_${ghcCommandCaps}_LIBDIR"' \
7774
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
7875
fi
76+
77+
# Point ghc-pkg to the package database of the component using the
78+
# --global-package-db flag.
79+
80+
for prg in ${ghcCommand}-pkg ${ghcCommand}-pkg-${ghc.version}; do
81+
if [[ -x "${ghc}/bin/$prg" ]]; then
82+
rm -f $out/bin/$prg
83+
makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "--global-package-db=${packageCfgDir}"
84+
fi
85+
done
7986
''
8087
)

0 commit comments

Comments
 (0)