···1+{ perl
2+, autoconf
3+, automake
4+, python3
5+, gcc
6+, cabal-install
7+, runCommand
8+, lib
9+, stdenv
10+11+, ghc
12+, happy
13+, alex
14+15+, ghcjsSrc
16+, version
17+}:
18+19+runCommand "configured-ghcjs-src" {
20+ nativeBuildInputs = [
21+ perl
22+ autoconf
23+ automake
24+ python3
25+ ghc
26+ happy
27+ alex
28+ cabal-install
29+ ] ++ lib.optionals stdenv.isDarwin [
30+ gcc # https://github.com/ghcjs/ghcjs/issues/663
31+ ];
32+ inherit ghcjsSrc;
33+} ''
34+ export HOME=$(pwd)
35+ mkdir $HOME/.cabal
36+ touch $HOME/.cabal/config
37+ cp -r "$ghcjsSrc" "$out"
38+ chmod -R +w "$out"
39+ cd "$out"
40+41+ # TODO: Find a better way to avoid impure version numbers
42+ sed -i 's/RELEASE=NO/RELEASE=YES/' ghc/configure.ac
43+44+ # These files are needed by ghc-boot package, and these are generated by the
45+ # make/hadrian build system when compiling ghc. Since we dont have access to
46+ # the generated code of the ghc while it got built, here is a little hack to
47+ # generate these again.
48+ runhaskell ${./generate_host_version.hs}
49+ mkdir -p utils/pkg-cache/ghc/libraries/ghc-boot/dist-install/build/GHC/Platform
50+ mv Host.hs utils/pkg-cache/ghc/libraries/ghc-boot/dist-install/build/GHC/Platform/Host.hs
51+ mv Version.hs utils/pkg-cache/ghc/libraries/ghc-boot/dist-install/build/GHC/Version.hs
52+53+ # The ghcjs has the following hardcoded paths of lib dir in its code. Patching
54+ # these to match the path expected by the nixpkgs's generic-builder, etc.
55+ sed -i 's/libSubDir = "lib"/libSubDir = "lib\/ghcjs-${version}"/' src-bin/Boot.hs
56+ sed -i 's@let libDir = takeDirectory haddockPath </> ".." </> "lib"@let libDir = takeDirectory haddockPath </> ".." </> "lib/ghcjs-${version}"@' src-bin/HaddockDriver.hs
57+58+ patchShebangs .
59+ ./utils/makePackages.sh copy
60+''