···11+{ perl
22+, autoconf
33+, automake
44+, python3
55+, gcc
66+, cabal-install
77+, runCommand
88+, lib
99+, stdenv
1010+1111+, ghc
1212+, happy
1313+, alex
1414+1515+, ghcjsSrc
1616+, version
1717+}:
1818+1919+runCommand "configured-ghcjs-src" {
2020+ nativeBuildInputs = [
2121+ perl
2222+ autoconf
2323+ automake
2424+ python3
2525+ ghc
2626+ happy
2727+ alex
2828+ cabal-install
2929+ ] ++ lib.optionals stdenv.isDarwin [
3030+ gcc # https://github.com/ghcjs/ghcjs/issues/663
3131+ ];
3232+ inherit ghcjsSrc;
3333+} ''
3434+ export HOME=$(pwd)
3535+ mkdir $HOME/.cabal
3636+ touch $HOME/.cabal/config
3737+ cp -r "$ghcjsSrc" "$out"
3838+ chmod -R +w "$out"
3939+ cd "$out"
4040+4141+ # TODO: Find a better way to avoid impure version numbers
4242+ sed -i 's/RELEASE=NO/RELEASE=YES/' ghc/configure.ac
4343+4444+ # These files are needed by ghc-boot package, and these are generated by the
4545+ # make/hadrian build system when compiling ghc. Since we dont have access to
4646+ # the generated code of the ghc while it got built, here is a little hack to
4747+ # generate these again.
4848+ runhaskell ${./generate_host_version.hs}
4949+ mkdir -p utils/pkg-cache/ghc/libraries/ghc-boot/dist-install/build/GHC/Platform
5050+ mv Host.hs utils/pkg-cache/ghc/libraries/ghc-boot/dist-install/build/GHC/Platform/Host.hs
5151+ mv Version.hs utils/pkg-cache/ghc/libraries/ghc-boot/dist-install/build/GHC/Version.hs
5252+5353+ # The ghcjs has the following hardcoded paths of lib dir in its code. Patching
5454+ # these to match the path expected by the nixpkgs's generic-builder, etc.
5555+ sed -i 's/libSubDir = "lib"/libSubDir = "lib\/ghcjs-${version}"/' src-bin/Boot.hs
5656+ sed -i 's@let libDir = takeDirectory haddockPath </> ".." </> "lib"@let libDir = takeDirectory haddockPath </> ".." </> "lib/ghcjs-${version}"@' src-bin/HaddockDriver.hs
5757+5858+ patchShebangs .
5959+ ./utils/makePackages.sh copy
6060+''