summary refs log tree commit diff
path: root/pkgs/development/compilers/ghc/wrapper.nix
blob: 4407f16c9e02806fce371ae3b62147f49b0e0ce3 (plain) (blame)
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
{stdenv, ghc, makeWrapper, coreutils}:

stdenv.mkDerivation {
  name = "ghc-${ghc.version}-wrapper";

  buildInputs = [makeWrapper];
  propagatedBuildInputs = [ghc];

  unpackPhase = "true";
  installPhase = ''
    mkdir -p $out/bin
    cp $GHCGetPackages $out/bin/ghc-get-packages.sh
    chmod 755 $out/bin/ghc-get-packages.sh
    for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
      makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\")"
    done
    for prg in runghc runhaskell; do
      makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\" \" -package-conf --ghc-arg=\")"
    done
    for prg in ghc-pkg ghc-pkg-${ghc.version}; do
      makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\" --package-conf=)"
    done
    for prg in hp2ps hpc hasktags hsc2hs; do
      test -x $ghc/bin/$prg && ln -s $ghc/bin/$prg $out/bin/$prg
    done
    cat >> $out/bin/ghc-packages << EOF
    #! /bin/bash -e
    declare -A GHC_PACKAGES_HASH # using bash4 hashs to get uniq paths

    for arg in \$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\"); do
      case "\$arg" in
        -package-conf) ;;
        *)
          CANONICALIZED="\$(${stdenv.lib.optionalString stdenv.isDarwin "${coreutils}/bin/"}readlink -f "\$arg")"
          GHC_PACKAGES_HASH["\$CANONICALIZED"]= ;;
      esac
    done

    for path in \''${!GHC_PACKAGES_HASH[@]}; do
      echo -n "\$path:"
    done
    EOF
    chmod +x $out/bin/ghc-packages
    mkdir -p $out/nix-support
    ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
  '';

  GHCGetPackages = ./ghc-get-packages.sh;

  inherit ghc;
  inherit (ghc) meta;
  ghcVersion = ghc.version;
}