@@ -0,0 +1,178 @@
1+{ mkDerivation
2+, test-framework
3+, test-framework-hunit
4+, test-framework-quickcheck2
5+, data-default
6+, ghc-paths
7+, haskell-src-exts
8+, haskell-src-meta
9+, optparse-applicative
10+, system-fileio
11+, system-filepath
12+, text-binary
13+, unordered-containers
14+, cabal-install
15+, wl-pprint-text
16+, base16-bytestring
17+, executable-path
18+, transformers-compat
19+, haddock-api
20+, regex-posix
21+, callPackage
22+
23+, bootPkgs, gmp
24+, jailbreak-cabal
25+
26+, runCommand
27+, nodejs, stdenv, filepath, HTTP, HUnit, mtl, network, QuickCheck, random, stm
28+, time
29+, zlib, aeson, attoparsec, bzlib, hashable
30+, lens
31+, parallel, safe, shelly, split, stringsearch, syb
32+, tar, terminfo
33+, vector, yaml, fetchgit, fetchFromGitHub, Cabal
34+, alex, happy, git, gnumake, autoconf, patch
35+, automake, libtool
36+, cryptohash
37+, haddock, hspec, xhtml, primitive, cacert, pkgs
38+, coreutils
39+, libiconv
40+
41+, ghcjsBootSrc ? fetchgit {
42+ url = git://github.com/ghcjs/ghcjs-boot.git;
43+ rev = "b000a4f4619b850bf3f9a45c9058f7a51e7709c8";
44+ sha256 = "164v0xf33r6mnympp6s70v8j6g7ccyg7z95gjp43bq150ppvisbq";
45+ fetchSubmodules = true;
46+ }
47+, ghcjsBoot ? import ./ghcjs-boot.nix {
48+ inherit runCommand;
49+ src = ghcjsBootSrc;
50+ }
51+, shims ? import ./head_shims.nix { inherit fetchFromGitHub; }
52+}:
53+let
54+ inherit (bootPkgs) ghc;
55+ version = "0.2.020161101";
56+
57+in mkDerivation (rec {
58+ pname = "ghcjs";
59+ inherit version;
60+ src = fetchFromGitHub {
61+ owner = "ghcjs";
62+ repo = "ghcjs";
63+ rev = "899c834a36692bbbde9b9d16fe5b92ce55a623c4";
64+ sha256 = "024yj4k0dxy7nvyq19n3xbhh4b4csdrgj19a3l4bmm1zn84gmpl6";
65+ };
66+ isLibrary = true;
67+ isExecutable = true;
68+ jailbreak = true;
69+ doHaddock = false;
70+ doCheck = false;
71+ buildDepends = [
72+ filepath HTTP mtl network random stm time zlib aeson attoparsec
73+ bzlib data-default ghc-paths hashable haskell-src-exts haskell-src-meta
74+ lens optparse-applicative parallel safe shelly split
75+ stringsearch syb system-fileio system-filepath tar terminfo text-binary
76+ unordered-containers vector wl-pprint-text yaml
77+ alex happy git gnumake autoconf automake libtool patch gmp
78+ base16-bytestring cryptohash executable-path haddock-api
79+ transformers-compat QuickCheck haddock hspec xhtml
80+ regex-posix libiconv
81+ ];
82+ buildTools = [ nodejs git ];
83+ testDepends = [
84+ HUnit test-framework test-framework-hunit
85+ ];
86+ patches = [ ./ghcjs.patch ];
87+ postPatch = ''
88+ substituteInPlace Setup.hs \
89+ --replace "/usr/bin/env" "${coreutils}/bin/env"
90+
91+ substituteInPlace src/Compiler/Info.hs \
92+ --replace "@PREFIX@" "$out" \
93+ --replace "@VERSION@" "${version}"
94+
95+ substituteInPlace src-bin/Boot.hs \
96+ --replace "@PREFIX@" "$out" \
97+ --replace "@CC@" "${stdenv.cc}/bin/cc"
98+ '';
99+ preBuild = ''
100+ export HOME="$TMP"
101+
102+ local topDir=$out/lib/ghcjs-${version}
103+ mkdir -p $topDir
104+
105+ cp -r ${ghcjsBoot} $topDir/ghcjs-boot
106+ chmod -R u+w $topDir/ghcjs-boot
107+
108+ cp -r ${shims} $topDir/shims
109+ chmod -R u+w $topDir/shims
110+
111+ # Make the patches be relative their corresponding package's directory.
112+ # See: https://github.com/ghcjs/ghcjs-boot/pull/12
113+ for patch in "$topDir/ghcjs-boot/patches/"*.patch; do
114+ echo "fixing patch: $patch"
115+ sed -i -e 's@ \(a\|b\)/boot/[^/]\+@ \1@g' $patch
116+ done
117+ '';
118+ # We build with --quick so we can build stage 2 packages separately.
119+ # This is necessary due to: https://github.com/haskell/cabal/commit/af19fb2c2d231d8deff1cb24164a2bf7efb8905a
120+ # Cabal otherwise fails to build: http://hydra.nixos.org/build/31824079/nixlog/1/raw
121+ postInstall = ''
122+ PATH=$out/bin:$PATH LD_LIBRARY_PATH=${gmp.out}/lib:${stdenv.cc}/lib64:$LD_LIBRARY_PATH \
123+ env -u GHC_PACKAGE_PATH $out/bin/ghcjs-boot \
124+ --dev \
125+ --quick \
126+ --with-cabal ${cabal-install}/bin/cabal \
127+ --with-gmp-includes ${gmp.dev}/include \
128+ --with-gmp-libraries ${gmp.out}/lib
129+ '';
130+ passthru = let
131+ ghcjsNodePkgs = callPackage ../../../top-level/node-packages.nix {
132+ generated = ./node-packages-generated.nix;
133+ self = ghcjsNodePkgs;
134+ };
135+ in {
136+ inherit bootPkgs;
137+ isCross = true;
138+ isGhcjs = true;
139+ inherit nodejs ghcjsBoot;
140+ inherit (ghcjsNodePkgs) "socket.io";
141+
142+ # This is the list of the Stage 1 packages that are built into a booted ghcjs installation
143+ # It can be generated with the command:
144+ # nix-shell -p haskell.packages.ghcjs.ghc --command "ghcjs-pkg list | sed -n 's/^ \(.*\)-\([0-9.]*\)$/\1_\2/ p' | sed 's/\./_/g' | sed 's/^\([^_]*\)\(.*\)$/ \"\1\"/'"
145+ stage1Packages = [
146+ "array"
147+ "base"
148+ "binary"
149+ "rts"
150+ "bytestring"
151+ "containers"
152+ "deepseq"
153+ "directory"
154+ "filepath"
155+ "ghc-prim"
156+ "ghcjs-prim"
157+ "integer-gmp"
158+ "old-locale"
159+ "pretty"
160+ "primitive"
161+ "process"
162+ "template-haskell"
163+ "time"
164+ "transformers"
165+ "unix"
166+ ];
167+
168+ mkStage2 = import ./stage2.nix {
169+ inherit ghcjsBoot;
170+ };
171+ };
172+
173+ homepage = "https://github.com/ghcjs/ghcjs";
174+ description = "A Haskell to JavaScript compiler that uses the GHC API";
175+ license = stdenv.lib.licenses.bsd3;
176+ platforms = ghc.meta.platforms;
177+ maintainers = with stdenv.lib.maintainers; [ jwiegley cstrahan ];
178+})