Skip to content

Commit

Permalink
Try using GHC_ENVIRONMENT for dev shells
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Jan 29, 2019
1 parent 30fbdc4 commit 2d7b6dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 23 additions & 1 deletion builder/comp-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ let
fi
'';

envDep = pdbArg: p: ''
if id=$(${ghc.targetPrefix}ghc-pkg -v0 ${pdbArg} field ${p} id --simple-output); then
echo "package-id $id" >> $out/ghc-environment
fi
'';

configFiles = runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } (''
mkdir -p $out
${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
Expand All @@ -91,6 +97,13 @@ let
echo ${lib.concatStringsSep " " (lib.mapAttrsToList (fname: val: "--flags=${lib.optionalString (!val) "-" + fname}") flags)} >> $out/configure-flags
cat > $out/ghc-environment <<EOF
clear-package-db
package-db $out/package.conf.d
EOF
${lib.concatMapStringsSep "\n" (p: envDep "--package-db ${p.components.library}/package.conf.d" p.identifier.name) componentDepends}
${lib.concatMapStringsSep "\n" (envDep "") (lib.remove "ghc" nonReinstallablePkgs)}
'' + lib.optionalString component.doExactConfig ''
echo "--exact-configuration" >> $out/configure-flags
echo "allow-newer: ${package.identifier.name}:*" >> $out/cabal.config
Expand Down Expand Up @@ -185,6 +198,7 @@ in stdenv.mkDerivation ({
};

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

Expand Down Expand Up @@ -250,6 +264,15 @@ in stdenv.mkDerivation ({
runHook postInstall
'';

shellHook = ''
# don't use this variable for the component build, but do provide it in the shell.
export GHC_ENVIRONMENT=$out/ghc-environment
# provide this variable so that `ghc-pkg` works (cabal doesn't like it though)
export GHC_PACKAGE_PATH=$out/package.conf.d
${toString shellHook}
'';
}
# patches can (if they like) depend on the version and revision of the package.
// lib.optionalAttrs (patches != []) { patches = map (p: if builtins.isFunction p then p { inherit (package.identifier) version; inherit revision; } else p) patches; }
Expand All @@ -263,6 +286,5 @@ in stdenv.mkDerivation ({
// lib.optionalAttrs (postCheck != "") { inherit postCheck; }
// lib.optionalAttrs (preInstall != "") { inherit preInstall; }
// lib.optionalAttrs (postInstall != "") { inherit postInstall; }
// lib.optionalAttrs (shellHook != "") { inherit shellHook; }
// lib.optionalAttrs (stdenv.buildPlatform.libc == "glibc"){ LOCALE_ARCHIVE = "${buildPackages.glibcLocales}/lib/locale/locale-archive"; }
)
6 changes: 4 additions & 2 deletions test/with-packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
with stdenv.lib;

let
pkgSet = haskell.mkNewPkgSet {
pkgSet = haskell.mkPkgSet {
inherit pkgs;
# generated with:
# cabal new-build
Expand Down Expand Up @@ -66,7 +66,9 @@ in

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

0 comments on commit 2d7b6dc

Please sign in to comment.