Skip to content

Commit 2d7b6dc

Browse files
committed
Try using GHC_ENVIRONMENT for dev shells
1 parent 30fbdc4 commit 2d7b6dc

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

builder/comp-builder.nix

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ let
6565
fi
6666
'';
6767

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+
6874
configFiles = runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } (''
6975
mkdir -p $out
7076
${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
@@ -91,6 +97,13 @@ let
9197
9298
echo ${lib.concatStringsSep " " (lib.mapAttrsToList (fname: val: "--flags=${lib.optionalString (!val) "-" + fname}") flags)} >> $out/configure-flags
9399
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+
94107
'' + lib.optionalString component.doExactConfig ''
95108
echo "--exact-configuration" >> $out/configure-flags
96109
echo "allow-newer: ${package.identifier.name}:*" >> $out/cabal.config
@@ -185,6 +198,7 @@ in stdenv.mkDerivation ({
185198
};
186199

187200
CABAL_CONFIG = configFiles + /cabal.config;
201+
# GHC_ENVIRONMENT = configFiles + /ghc-environment;
188202
LANG = "en_US.UTF-8"; # GHC needs the locale configured during the Haddock phase.
189203
LC_ALL = "en_US.UTF-8";
190204

@@ -250,6 +264,15 @@ in stdenv.mkDerivation ({
250264
runHook postInstall
251265
'';
252266

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+
'';
253276
}
254277
# patches can (if they like) depend on the version and revision of the package.
255278
// 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 ({
263286
// lib.optionalAttrs (postCheck != "") { inherit postCheck; }
264287
// lib.optionalAttrs (preInstall != "") { inherit preInstall; }
265288
// lib.optionalAttrs (postInstall != "") { inherit postInstall; }
266-
// lib.optionalAttrs (shellHook != "") { inherit shellHook; }
267289
// lib.optionalAttrs (stdenv.buildPlatform.libc == "glibc"){ LOCALE_ARCHIVE = "${buildPackages.glibcLocales}/lib/locale/locale-archive"; }
268290
)

test/with-packages/default.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
with stdenv.lib;
77

88
let
9-
pkgSet = haskell.mkNewPkgSet {
9+
pkgSet = haskell.mkPkgSet {
1010
inherit pkgs;
1111
# generated with:
1212
# cabal new-build
@@ -66,7 +66,9 @@ in
6666

6767
# Used for testing externally with nix-shell (../tests.sh).
6868
# This just adds cabal-install to the existing shell.
69-
test-shell = pkgSet.config.hsPkgs.test-with-packages.components.library.overrideAttrs (oldAttrs: {
69+
test-shell = let
70+
inherit (pkgSet.config.hsPkgs.test-with-packages.components) library;
71+
in library.overrideAttrs (oldAttrs: {
7072
buildInputs = (oldAttrs.buildInputs or []) ++ [ pkgs.cabal-install ];
7173
});
7274
}

0 commit comments

Comments
 (0)