Skip to content

Commit 0e97cea

Browse files
authored
Allow reinstall of filepath in GHC 9.4.8 (#2224)
* Allow reinstall of filepath in GHC 9.4.8 A cabal flag (`vendor-filepath`) was used to avoid the `template-haskell` dependency on `filepath` in the version of `template-haskell` (2.19.0.0) used by `ghc` 9.4.8. ``` if flag(vendor-filepath) other-modules: System.FilePath System.FilePath.Posix System.FilePath.Windows hs-source-dirs: ./vendored-filepath . default-extensions: ImplicitPrelude else build-depends: filepath hs-source-dirs: . ``` The `dummy-ghc` code in haskell.nix does not evaluate conditionals (instead it just includes all of the dependencies. This leads to issues where the planner is unable to come up with a plan because it thinks `filepath` cannot be reinstalled. This fix works around the by hard coding a rule for `vendor-filepath`. * ifdLevel 3 * Fix test * Fix test * Use pkgsBuildBuild for shell tools * Avoid rerunning `githash` test all the time
1 parent ba17561 commit 0e97cea

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

builder/default.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#
1414
# tl;dr: the builder must not re-introduce any reference to the build plan.
1515

16-
{ pkgs, buildPackages, evalPackages, stdenv, lib, haskellLib, ghc, compiler-nix-name, fetchurl, nonReinstallablePkgs, hsPkgs, compiler }:
16+
{ pkgs, buildPackages, pkgsBuildBuild, evalPackages, stdenv, lib, haskellLib, ghc, compiler-nix-name, fetchurl, nonReinstallablePkgs, hsPkgs, compiler }:
1717

1818
let
1919
# Builds a single component of a package.
@@ -85,7 +85,7 @@ let
8585

8686
# Same as haskellPackages.shellFor in nixpkgs.
8787
shellFor = haskellLib.weakCallPackage pkgs ./shell-for.nix {
88-
inherit hsPkgs ghcForComponent makeConfigFiles hoogleLocal haskellLib buildPackages evalPackages compiler;
88+
inherit hsPkgs ghcForComponent makeConfigFiles hoogleLocal haskellLib pkgsBuildBuild evalPackages compiler;
8989
inherit (buildPackages) glibcLocales;
9090
};
9191

builder/shell-for.nix

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, stdenv, mkShell, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs, hoogleLocal, haskellLib, buildPackages, evalPackages, compiler }:
1+
{ lib, stdenv, mkShell, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs, hoogleLocal, haskellLib, pkgsBuildBuild, evalPackages, compiler }:
22

33
{ # `packages` function selects packages that will be worked on in the shell itself.
44
# These packages will not be built by `shellFor`, but their
@@ -149,7 +149,7 @@ let
149149
# inherit (hsPkgs) hoogle;
150150
} // (
151151
lib.optionalAttrs (args ? tools && args.tools ? hoogle) {
152-
hoogle = buildPackages.haskell-nix.hackage-tool (
152+
hoogle = pkgsBuildBuild.haskell-nix.hackage-tool (
153153
haskellLib.versionOrModToMods args.tools.hoogle ++ [{
154154
name = "hoogle";
155155
compiler-nix-name = compiler.nix-name;
@@ -168,12 +168,12 @@ in
168168
nativeBuildInputs = [ ghcEnv.drv ]
169169
++ nativeBuildInputs
170170
++ mkDrvArgs.nativeBuildInputs or []
171-
++ lib.attrValues (buildPackages.haskell-nix.tools' evalPackages compiler.nix-name tools)
171+
++ lib.attrValues (pkgsBuildBuild.haskell-nix.tools' evalPackages compiler.nix-name tools)
172172
# If this shell is a cross compilation shell include
173173
# wrapper script for running cabal build with appropriate args.
174174
# Includes `--with-compiler` in case the `cabal.project` file has `with-compiler:` in it.
175175
++ lib.optional (ghcEnv.targetPrefix != "") (
176-
buildPackages.writeShellScriptBin "${ghcEnv.targetPrefix}cabal" ''
176+
pkgsBuildBuild.writeShellScriptBin "${ghcEnv.targetPrefix}cabal" ''
177177
exec cabal \
178178
--with-ghc=${ghcEnv.targetPrefix}ghc \
179179
--with-compiler=${ghcEnv.targetPrefix}ghc \

lib/call-cabal-project-to-nix.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ let
455455
''}
456456
457457
EXPOSED_MODULES_${varname name}="$(tr '\n' ' ' <<< "$exposed_modules $reexported_modules")"
458-
DEPS_${varname name}="$(jq -r '.library."build-depends"[]|select(type=="array")[],select(type=="object").then[]' $json_cabal_file | sed 's/^\([A-Za-z0-9-]*\).*$/\1/g' | sort -u | tr '\n' ' ')"
458+
DEPS_${varname name}="$(jq -r '.library."build-depends"[]|select(type=="array")[],select(type=="object" and .if.not.flag != "vendor-filepath").then[]' $json_cabal_file | sed 's/^\([A-Za-z0-9-]*\).*$/\1/g' | sort -u | tr '\n' ' ')"
459459
VER_${varname name}="$(jq -r '.version' $json_cabal_file)"
460460
PKGS+=" ${name}"
461461
LAST_PKG="${name}"

test/githash/default.nix

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ let
1515
project = haskell-nix.cabalProject' {
1616
inherit src;
1717
cabalProjectLocal = builtins.readFile ../cabal.project.local;
18-
# When haskell.nix has come from the store (e.g. on hydra) we need to provide
19-
# a suitable mock of the cleaned source with a .git dir.
20-
modules = (optional (!(src ? origSrc && __pathExists (src.origSrc + "/.git"))) {
18+
# Mock the .git dir to avoid rebuilding on every commit.
19+
modules = [{
2120
packages.githash-test.src =
2221
rec {
2322
origSrc = evalPackages.runCommand "githash-test-src" { nativeBuildInputs = [ evalPackages.gitReallyMinimal ]; } ''
@@ -32,7 +31,6 @@ let
3231
origSrcSubDir = origSrc + origSubDir;
3332
outPath = origSrcSubDir;
3433
};
35-
}) ++ [{
3634
packages.githash-test.components.exes.githash-test.build-tools = mkForce [ git ];
3735
}];
3836
inherit compiler-nix-name evalPackages;

test/tests.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ fi
9696

9797
if [ "$TESTS" == "multi-target" ] || [ "$TESTS" == "all" ]; then
9898
printf "*** Checking that a nix-shell works for a multi-target project...\n" >& 2
99+
TEST_CABAL_DIR=$(mktemp -d)
99100
nix-shell $NIX_BUILD_ARGS \
100101
--pure ./default.nix \
101102
--argstr compiler-nix-name "$GHC" \
102103
-A cabal-simple.test-shell \
103-
--run 'cd cabal-simple && CABAL_DIR=$(mktemp -d) cabal new-build'
104+
--run "cd cabal-simple && CABAL_DIR=$TEST_CABAL_DIR cabal update && CABAL_DIR=$TEST_CABAL_DIR cabal build"
104105
echo >& 2
105106
fi
106107

@@ -123,7 +124,7 @@ if [ "$TESTS" == "shellFor-multiple-package" ] || [ "$TESTS" == "all" ]; then
123124
--pure ./default.nix \
124125
--argstr compiler-nix-name $SHELL_FOR_GHC \
125126
-A shell-for.envPkga \
126-
--run 'cd shell-for && CABAL_DIR=$(mktemp -d) cabal new-build --project=single.project all'
127+
--run 'cd shell-for && CABAL_DIR=$(mktemp -d) cabal new-build --project-file=single.project all'
127128
echo >& 2
128129
fi
129130

0 commit comments

Comments
 (0)