summaryrefslogtreecommitdiff
path: root/pkgs/test/haskell/shellFor/default.nix
blob: c6dda7e1696218d6938ee5ab5a3e263fa66c4ee5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{
  lib,
  writeText,
  srcOnly,
  haskellPackages,
  cabal-install,
}:

(haskellPackages.shellFor {
  packages = p: [
    p.constraints
    p.cereal
  ];
  # WARNING: When updating this, make sure that the libraries passed to
  # `extraDependencies` are not actually transitive dependencies of libraries in
  # `packages` above.  We explicitly want to test that it is possible to specify
  # `extraDependencies` that are not in the closure of `packages`.
  extraDependencies = p: { libraryHaskellDepends = [ p.conduit ]; };
  nativeBuildInputs = [ cabal-install ];
  unpackPhase = ''
    sourceRoot=$(pwd)/scratch
    mkdir -p "$sourceRoot"
    cd "$sourceRoot"
    cp -r "${srcOnly haskellPackages.constraints}" constraints
    cp -r "${srcOnly haskellPackages.cereal}" cereal
    cp ${writeText "cabal.project" "packages: constraints cereal"} cabal.project
  '';
  buildPhase = ''
    export HOME=$(mktemp -d)
    mkdir -p $HOME/.cabal
    touch $HOME/.cabal/config

    # Check that the extraDependencies.libraryHaskellDepends arg is correctly
    # picked up. This uses ghci to interpret a small Haskell program that uses
    # a package from extraDependencies.
    ghci <<EOF
    :set -XOverloadedStrings
    :m + Conduit
    runResourceT $ connect (yield "done") (sinkFile "outfile")
    EOF

    if [[ "done" != "$(cat outfile)" ]]; then
      echo "ERROR: extraDependencies appear not to be available in the environment"
      exit 1
    fi

    # Check packages arg
    cabal v2-build --offline --verbose constraints cereal --ghc-options="-O0 -j$NIX_BUILD_CORES"
  '';
  installPhase = ''
    touch $out
  '';
}).overrideAttrs
  (oldAttrs: {
    meta =
      let
        oldMeta = oldAttrs.meta or { };
        oldMaintainers = oldMeta.maintainers or [ ];
        additionalMaintainers = with lib.maintainers; [ cdepillabout ];
        allMaintainers = oldMaintainers ++ additionalMaintainers;
      in
      oldMeta
      // {
        maintainers = allMaintainers;
        inherit (cabal-install.meta) platforms;
      };
    # `shellFor` adds a `buildCommand` (via `envFunc -> runCommandCC`), which
    # overrides custom phases. To ensure this test's phases run, we remove
    # that `buildCommand` from the derivation.
    buildCommand = null;
  })