about summary refs log tree commit diff
path: root/pkgs/development/compilers
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/compilers')
-rw-r--r--pkgs/development/compilers/asn1c/default.nix33
-rw-r--r--pkgs/development/compilers/colm/default.nix4
-rw-r--r--pkgs/development/compilers/elm/default.nix4
-rw-r--r--pkgs/development/compilers/elm/packages/elm-compiler.nix9
-rw-r--r--pkgs/development/compilers/elm/packages/elm-format.nix16
-rw-r--r--pkgs/development/compilers/elm/packages/elm-make.nix6
-rw-r--r--pkgs/development/compilers/elm/packages/elm-package.nix6
-rw-r--r--pkgs/development/compilers/elm/packages/elm-reactor-elm.nix20
-rw-r--r--pkgs/development/compilers/elm/packages/elm-reactor.nix6
-rw-r--r--pkgs/development/compilers/elm/packages/elm-repl.nix6
-rw-r--r--pkgs/development/compilers/elm/packages/release.nix2
-rwxr-xr-xpkgs/development/compilers/elm/update-elm.rb12
-rw-r--r--pkgs/development/compilers/ghc/D2710.patch19
-rw-r--r--pkgs/development/compilers/ghc/D2711.patch22
-rw-r--r--pkgs/development/compilers/ghc/D2712.patch158
-rw-r--r--pkgs/development/compilers/ghc/D2713.patch17
-rw-r--r--pkgs/development/compilers/ghc/head.nix81
-rw-r--r--pkgs/development/compilers/ghcjs/base.nix186
-rw-r--r--pkgs/development/compilers/ghcjs/default.nix180
-rw-r--r--pkgs/development/compilers/ghcjs/head.nix208
-rw-r--r--pkgs/development/compilers/ghcjs/head_shims.nix4
-rw-r--r--pkgs/development/compilers/ghcjs/head_stage2.nix345
-rw-r--r--pkgs/development/compilers/kotlin/default.nix4
-rw-r--r--pkgs/development/compilers/llvm/3.8/D17533-1.patch60
-rw-r--r--pkgs/development/compilers/llvm/3.8/llvm.nix6
-rw-r--r--pkgs/development/compilers/rust/bootstrap.nix12
-rw-r--r--pkgs/development/compilers/rust/default.nix14
-rw-r--r--pkgs/development/compilers/rust/rustc.nix4
28 files changed, 1010 insertions, 434 deletions
diff --git a/pkgs/development/compilers/asn1c/default.nix b/pkgs/development/compilers/asn1c/default.nix
new file mode 100644
index 000000000000..d3c4bf19a65b
--- /dev/null
+++ b/pkgs/development/compilers/asn1c/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchurl, perl }:
+
+stdenv.mkDerivation rec {
+  name = "asn1c-${version}";
+  version = "0.9.27";
+
+  src = fetchurl {
+    url = "http://lionet.info/soft/asn1c-${version}.tar.gz";
+    sha256 = "17nvn2kzvlryasr9dzqg6gs27b9lvqpval0k31pb64bjqbhn8pq2";
+  };
+
+  outputs = [ "out" "doc" "man" ];
+
+  buildInputs = [ perl ];
+
+  preConfigure = ''
+    patchShebangs examples/crfc2asn1.pl
+  '';
+
+  postInstall = ''
+    cp -r skeletons/standard-modules $out/share/asn1c
+  '';
+
+  doCheck = true;
+
+  meta = with stdenv.lib; {
+    homepage = http://lionet.info/asn1c/compiler.html;
+    description = "Open Source ASN.1 Compiler";
+    license = licenses.bsd2;
+    platforms = platforms.all;
+    maintainers = [ maintainers.montag451 ];
+  };
+}
diff --git a/pkgs/development/compilers/colm/default.nix b/pkgs/development/compilers/colm/default.nix
index b7773a91d983..8cf8a04f4eb5 100644
--- a/pkgs/development/compilers/colm/default.nix
+++ b/pkgs/development/compilers/colm/default.nix
@@ -2,11 +2,11 @@
 
 stdenv.mkDerivation rec {
   name = "colm-${version}";
-  version = "0.13.0.3";
+  version = "0.13.0.4";
 
   src = fetchurl {
     url = "http://www.colm.net/files/colm/${name}.tar.gz";
-    sha256 = "0dadfsnkbxcrf5kihvncbprb6w64jz2myylfmj952gdmcsim4zj2";
+    sha256 = "04xcb7w82x9i4ygxqla9n39y646n3jw626khdp5297z1dkxx1czx";
   };
 
   buildInputs = [ makeWrapper ];
diff --git a/pkgs/development/compilers/elm/default.nix b/pkgs/development/compilers/elm/default.nix
index 950caeedf53b..e125a050b249 100644
--- a/pkgs/development/compilers/elm/default.nix
+++ b/pkgs/development/compilers/elm/default.nix
@@ -80,9 +80,9 @@ let
       };
   };
 in hsPkgs.elmPkgs // {
-  elm = buildEnv {
+  elm = lib.hiPrio (buildEnv {
     name = "elm-${hsPkgs.elmVersion}";
     paths = lib.mapAttrsToList (name: pkg: pkg) hsPkgs.elmPkgs;
     pathsToLink = [ "/bin" ];
-  };
+  });
 }
diff --git a/pkgs/development/compilers/elm/packages/elm-compiler.nix b/pkgs/development/compilers/elm/packages/elm-compiler.nix
index f6a92b64f6d7..b0943f1ece35 100644
--- a/pkgs/development/compilers/elm/packages/elm-compiler.nix
+++ b/pkgs/development/compilers/elm/packages/elm-compiler.nix
@@ -7,11 +7,11 @@
 }:
 mkDerivation {
   pname = "elm-compiler";
-  version = "0.17.1";
+  version = "0.18";
   src = fetchgit {
     url = "https://github.com/elm-lang/elm-compiler";
-    sha256 = "17y0jlii81mnjywknblcv1nfja51slmwrhz9x8w144b0sblcj0if";
-    rev = "e44deafaf9cbf3749484070f267f03a368711adb";
+    sha256 = "09fmrbfpc1kzc3p9h79w57b9qjhajdswc4jfm9gyjw95vsiwasgh";
+    rev = "eb97f2a5dd5421c708a91b71442e69d02453cc80";
   };
   isLibrary = true;
   isExecutable = true;
@@ -35,4 +35,7 @@ mkDerivation {
   homepage = "http://elm-lang.org";
   description = "Values to help with elm-package, elm-make, and elm-lang.org.";
   license = stdenv.lib.licenses.bsd3;
+  # added manually since tests are not passing
+  # https://travis-ci.org/elm-lang/elm-compiler/builds/176845852
+  doCheck = false;
 }
diff --git a/pkgs/development/compilers/elm/packages/elm-format.nix b/pkgs/development/compilers/elm/packages/elm-format.nix
index 4d30c697abd4..48eafff6f724 100644
--- a/pkgs/development/compilers/elm/packages/elm-format.nix
+++ b/pkgs/development/compilers/elm/packages/elm-format.nix
@@ -7,11 +7,11 @@
 }:
 mkDerivation {
   pname = "elm-format";
-  version = "0.4.0";
+  version = "0.5.2";
   src = fetchgit {
     url = "http://github.com/avh4/elm-format";
-    sha256 = "199xh2w5cwcf79a8fv6j8dpk9h8a4cygrf8cfr9p7bvp2wvczibm";
-    rev = "d9cbe65c5f01d21b5a02c2f963aa4c9d3f0539d0";
+    sha256 = "0lman7h6wr75y90javcc4y1scvwgv125gqqaqvfrd5xrfmm43gg8";
+    rev = "e452ed9342620e7bb0bc822983b96411d57143ef";
   };
   isLibrary = false;
   isExecutable = true;
@@ -32,14 +32,4 @@ mkDerivation {
   homepage = "http://elm-lang.org";
   description = "A source code formatter for Elm";
   license = stdenv.lib.licenses.bsd3;
-
-  # XXX: I've manually disabled tests, only the following test is failing
-  # ...
-  # ElmFormat.Cli
-  #   format a single file in place:                    OK
-  #   usage instructions:                               FAIL
-  # ...
-  # 1 out of 266 tests failed (0.50s)
-  # Test suite elm-format-tests: FAIL
-  doCheck = false;
 }
diff --git a/pkgs/development/compilers/elm/packages/elm-make.nix b/pkgs/development/compilers/elm/packages/elm-make.nix
index bed7698cfe42..dc1760e2958b 100644
--- a/pkgs/development/compilers/elm/packages/elm-make.nix
+++ b/pkgs/development/compilers/elm/packages/elm-make.nix
@@ -5,11 +5,11 @@
 }:
 mkDerivation {
   pname = "elm-make";
-  version = "0.17.1";
+  version = "0.18";
   src = fetchgit {
     url = "https://github.com/elm-lang/elm-make";
-    sha256 = "0k9w5gl48lhhr3n2iflf0vkb3w6al0xcbglgiw4fq1ssz3aa7ijw";
-    rev = "0a0a1f52ab04e2d68d60a5798722e1de30b47335";
+    sha256 = "1yq4w4yqignlc2si5ns53pmz0a99gix5d2qgi6x7finf7i6sxyw2";
+    rev = "1a554833a70694ab142b9179bfac996143f68d9e";
   };
   isLibrary = false;
   isExecutable = true;
diff --git a/pkgs/development/compilers/elm/packages/elm-package.nix b/pkgs/development/compilers/elm/packages/elm-package.nix
index faf46e859c94..f93432dc0a30 100644
--- a/pkgs/development/compilers/elm/packages/elm-package.nix
+++ b/pkgs/development/compilers/elm/packages/elm-package.nix
@@ -7,11 +7,11 @@
 }:
 mkDerivation {
   pname = "elm-package";
-  version = "0.17.1";
+  version = "0.18";
   src = fetchgit {
     url = "https://github.com/elm-lang/elm-package";
-    sha256 = "0dnn871py0pvzxsjjggy5ww2zj9g71c2dcnp38rcr4nbj8yxik85";
-    rev = "9011ccdbced1d06aa60de0e3096e609ef44d26dd";
+    sha256 = "19krnkjvfk02gmmic5h5i1i0lw7s30927bnd5g57cj8nqbigysv7";
+    rev = "8bd150314bacab5b6fc451927aa01deec2276fbf";
   };
   isLibrary = true;
   isExecutable = true;
diff --git a/pkgs/development/compilers/elm/packages/elm-reactor-elm.nix b/pkgs/development/compilers/elm/packages/elm-reactor-elm.nix
index 790430125901..90c8956323b5 100644
--- a/pkgs/development/compilers/elm/packages/elm-reactor-elm.nix
+++ b/pkgs/development/compilers/elm/packages/elm-reactor-elm.nix
@@ -1,22 +1,22 @@
 {
   "elm-lang/virtual-dom" = {
-    version = "1.1.0";
-    sha256 = "16g66cvvh85ddciq0ymaqfyq2bcz11pxn0g0dc1wx7bmlqx7q1jz";
+    version = "2.0.1";
+    sha256 = "19nfjx072m7a7bx8flc50vbmiww172jmscyq9x91cr2kby5hvbw3";
   };
   "evancz/elm-markdown" = {
-    version = "3.0.0";
-    sha256 = "0r3hcim4mpn46ahv1q6sjp6i2viyp7jik6i71xgwmvfb9drns2p6";
+    version = "3.0.1";
+    sha256 = "144lzpcapf2mhqiz90mkllmm4skrcs0iha1daps42qn3xps7hvmj";
   };
   "elm-lang/html" = {
-    version = "1.1.0";
-    sha256 = "1v7pwxxd81qrfywb4rr199p2i9z77vjkbwjwm5gy1nxdpi8mb50y";
+    version = "2.0.0";
+    sha256 = "05sqjd5n8jnq4lv5v0ipcg98b8im1isnnl4wns1zzn4w5nbrjjzi";
   };
   "elm-lang/svg" = {
-    version = "1.1.1";
-    sha256 = "0xzc0fq2kg797km0nq2f52w6xdffrl9l0y5zbkpa72w163zpxkkn";
+    version = "2.0.0";
+    sha256 = "1c7p967n1yhynravqwgh80vprwz7r2r1n0x3icn5wzk9iaqs069l";
   };
   "elm-lang/core" = {
-    version = "4.0.2";
-    sha256 = "1qjhfr3gd1qmfvna7iddspmk26v2nmgmgw9m6yyz10ygy3i9mla6";
+    version = "5.0.0";
+    sha256 = "0gqyc09bh43pi7r2cizyjm5y0zpgarv3is17dl325qvxb9s1y2gn";
   };
 }
diff --git a/pkgs/development/compilers/elm/packages/elm-reactor.nix b/pkgs/development/compilers/elm/packages/elm-reactor.nix
index cf6d33a5acb4..08bf5779b74a 100644
--- a/pkgs/development/compilers/elm/packages/elm-reactor.nix
+++ b/pkgs/development/compilers/elm/packages/elm-reactor.nix
@@ -6,11 +6,11 @@
 }:
 mkDerivation {
   pname = "elm-reactor";
-  version = "0.17.1";
+  version = "0.18";
   src = fetchgit {
     url = "https://github.com/elm-lang/elm-reactor";
-    sha256 = "14kkqskvhkfznpl8cmjlvv3rp6ciqmdbxrmq6f20p3aznvkrdvf8";
-    rev = "7522d7ef379c5a4ffbba11b1be09ed04add08a63";
+    sha256 = "0lpidsckyfcr8d6bln735d98dx7ga7j1vyssw0qsv8ijj18gxx65";
+    rev = "c519d4ec0aaf2f043a416fe858346b0181eca516";
   };
   isLibrary = false;
   isExecutable = true;
diff --git a/pkgs/development/compilers/elm/packages/elm-repl.nix b/pkgs/development/compilers/elm/packages/elm-repl.nix
index e08c295f294c..64e29596099c 100644
--- a/pkgs/development/compilers/elm/packages/elm-repl.nix
+++ b/pkgs/development/compilers/elm/packages/elm-repl.nix
@@ -6,11 +6,11 @@
 }:
 mkDerivation {
   pname = "elm-repl";
-  version = "0.17.1";
+  version = "0.18";
   src = fetchgit {
     url = "https://github.com/elm-lang/elm-repl";
-    sha256 = "0nh2yfr0bi4rg1kak1gjaczpq56y1nii05b5y7hn6n4w651jkm28";
-    rev = "413ac0d4ee43c8542afd3041bbb7b8c903cd3d30";
+    sha256 = "112fzykils4lqz4pc44q4mwvxg0px0zfwx511bfvblrxkwwqlfb5";
+    rev = "85f0bcfc28ea6c8a99a360d55c21ff25a556f9fe";
   };
   isLibrary = false;
   isExecutable = true;
diff --git a/pkgs/development/compilers/elm/packages/release.nix b/pkgs/development/compilers/elm/packages/release.nix
index 6817d8e297f4..fd4e08fff09c 100644
--- a/pkgs/development/compilers/elm/packages/release.nix
+++ b/pkgs/development/compilers/elm/packages/release.nix
@@ -2,7 +2,7 @@
 # Please, do not modify it by hand!
 { callPackage }:
 {
-  version = "0.17.1";
+  version = "0.18.0";
   packages = {
     elm-compiler = callPackage ./elm-compiler.nix { };
     elm-package = callPackage ./elm-package.nix { };
diff --git a/pkgs/development/compilers/elm/update-elm.rb b/pkgs/development/compilers/elm/update-elm.rb
index a1f76945cd2c..5169ff3fd29a 100755
--- a/pkgs/development/compilers/elm/update-elm.rb
+++ b/pkgs/development/compilers/elm/update-elm.rb
@@ -1,12 +1,12 @@
 #!/usr/bin/env ruby
 
 # Take those from https://github.com/elm-lang/elm-platform/blob/master/installers/BuildFromSource.hs
-$elm_version = "0.17.1"
-$elm_packages = { "elm-compiler" => "0.17.1",
-                  "elm-package" => "0.17.1",
-                  "elm-make" => "0.17.1",
-                  "elm-reactor" => "0.17.1",
-                  "elm-repl" => "0.17.1"
+$elm_version = "0.18.0"
+$elm_packages = { "elm-compiler" => "0.18.0",
+                  "elm-package" => "0.18.0",
+                  "elm-make" => "0.18.0",
+                  "elm-reactor" => "0.18.0",
+                  "elm-repl" => "0.18.0"
                 }
 
 for pkg, ver in $elm_packages
diff --git a/pkgs/development/compilers/ghc/D2710.patch b/pkgs/development/compilers/ghc/D2710.patch
new file mode 100644
index 000000000000..0ee1b06c7346
--- /dev/null
+++ b/pkgs/development/compilers/ghc/D2710.patch
@@ -0,0 +1,19 @@
+diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h
+--- a/rts/LinkerInternals.h
++++ b/rts/LinkerInternals.h
+@@ -303,4 +303,14 @@
+ #  define OBJFORMAT_MACHO
+ #endif
+ 
++/* In order to simplify control flow a bit, some references to mmap-related
++   definitions are blocked off by a C-level if statement rather than a CPP-level
++   #if statement. Since those are dead branches when !RTS_LINKER_USE_MMAP, we
++   just stub out the relevant symbols here
++*/
++#if !RTS_LINKER_USE_MMAP
++#define munmap(x,y) /* nothing */
++#define MAP_ANONYMOUS 0
++#endif
++
+ #endif /* LINKERINTERNALS_H */
+
diff --git a/pkgs/development/compilers/ghc/D2711.patch b/pkgs/development/compilers/ghc/D2711.patch
new file mode 100644
index 000000000000..8d229f273999
--- /dev/null
+++ b/pkgs/development/compilers/ghc/D2711.patch
@@ -0,0 +1,22 @@
+diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c
+--- a/rts/sm/Storage.c
++++ b/rts/sm/Storage.c
+@@ -1314,7 +1314,7 @@
+    ------------------------------------------------------------------------- */
+ 
+ #if (defined(arm_HOST_ARCH) || defined(aarch64_HOST_ARCH)) && defined(ios_HOST_OS)
+-void sys_icache_invalidate(void *start, size_t len);
++#include <libkern/OSCacheControl.h>
+ #endif
+ 
+ /* On ARM and other platforms, we need to flush the cache after
+@@ -1327,7 +1327,7 @@
+   (void)exec_addr;
+ #elif (defined(arm_HOST_ARCH) || defined(aarch64_HOST_ARCH)) && defined(ios_HOST_OS)
+   /* On iOS we need to use the special 'sys_icache_invalidate' call. */
+-  sys_icache_invalidate(exec_addr, ((unsigned char*)exec_addr)+len);
++  sys_icache_invalidate(exec_addr, len);
+ #elif defined(__GNUC__)
+   /* For all other platforms, fall back to a libgcc builtin. */
+   unsigned char* begin = (unsigned char*)exec_addr;
+
diff --git a/pkgs/development/compilers/ghc/D2712.patch b/pkgs/development/compilers/ghc/D2712.patch
new file mode 100644
index 000000000000..d938d70bbcfe
--- /dev/null
+++ b/pkgs/development/compilers/ghc/D2712.patch
@@ -0,0 +1,158 @@
+diff --git a/includes/rts/OSThreads.h b/includes/rts/OSThreads.h
+--- a/includes/rts/OSThreads.h
++++ b/includes/rts/OSThreads.h
+@@ -15,7 +15,12 @@
+ #ifndef RTS_OSTHREADS_H
+ #define RTS_OSTHREADS_H
+ 
+-#if defined(THREADED_RTS) /* to near the end */
++#if defined(HAVE_PTHREAD_H) && !defined(mingw32_HOST_OS)
++#define BUILD_OSTHREAD_POSIX
++#endif
++
++
++#if defined(THREADED_RTS) || defined(BUILD_OSTHREAD_POSIX) /* to near end */
+ 
+ #if defined(HAVE_PTHREAD_H) && !defined(mingw32_HOST_OS)
+ 
+@@ -205,13 +210,25 @@
+ void releaseThreadNode (void);
+ #endif // !CMINUSMINUS
+ 
+-#else
++#endif /* defined(THREADED_RTS) || defined(BUILD_OSTHREAD_POSIX) */
++
++#ifndef THREADED_RTS
++
++#ifdef ACQUIRE_LOCK
++// If we have pthreads, we pull in the threading primitives even when the RTS
++// isn't threaded, but we expect these macros to be noops on non-threaded RTS.
++
++#undef ACQUIRE_LOCK
++#undef RELEASE_LOCK
++#undef ASSERT_LOCK_HELD
++
++#endif
+ 
+ #define ACQUIRE_LOCK(l)
+ #define RELEASE_LOCK(l)
+ #define ASSERT_LOCK_HELD(l)
+ 
+-#endif /* defined(THREADED_RTS) */
++#endif
+ 
+ #ifndef CMINUSMINUS
+ //
+diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
+--- a/rts/posix/OSThreads.c
++++ b/rts/posix/OSThreads.c
+@@ -35,7 +35,7 @@
+ #endif
+ #endif
+ 
+-#if defined(THREADED_RTS)
++#if defined(THREADED_RTS) || defined(BUILD_OSTHREAD_POSIX)
+ #include "RtsUtils.h"
+ #include "Task.h"
+ 
+@@ -225,47 +225,6 @@
+     return NULL;
+ }
+ 
+-int
+-forkOS_createThread ( HsStablePtr entry )
+-{
+-    pthread_t tid;
+-    int result = pthread_create(&tid, NULL,
+-                                forkOS_createThreadWrapper, (void*)entry);
+-    if(!result)
+-        pthread_detach(tid);
+-    return result;
+-}
+-
+-void freeThreadingResources (void) { /* nothing */ }
+-
+-uint32_t
+-getNumberOfProcessors (void)
+-{
+-    static uint32_t nproc = 0;
+-
+-    if (nproc == 0) {
+-#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
+-        nproc = sysconf(_SC_NPROCESSORS_ONLN);
+-#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
+-        nproc = sysconf(_SC_NPROCESSORS_CONF);
+-#elif defined(darwin_HOST_OS)
+-        size_t size = sizeof(uint32_t);
+-        if(sysctlbyname("hw.logicalcpu",&nproc,&size,NULL,0) != 0) {
+-            if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
+-                nproc = 1;
+-        }
+-#elif defined(freebsd_HOST_OS)
+-        size_t size = sizeof(uint32_t);
+-        if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
+-            nproc = 1;
+-#else
+-        nproc = 1;
+-#endif
+-    }
+-
+-    return nproc;
+-}
+-
+ #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
+ // Schedules the thread to run on CPU n of m.  m may be less than the
+ // number of physical CPUs, in which case, the thread will be allowed
+@@ -353,6 +312,51 @@
+     pthread_kill(id, SIGPIPE);
+ }
+ 
++#endif /* defined(THREADED_RTS) || defined(BUILD_OSTHREAD_POSIX) */
++
++#if defined(THREADED_RTS)
++
++int
++forkOS_createThread ( HsStablePtr entry )
++{
++    pthread_t tid;
++    int result = pthread_create(&tid, NULL,
++                                forkOS_createThreadWrapper, (void*)entry);
++    if(!result)
++        pthread_detach(tid);
++    return result;
++}
++
++void freeThreadingResources (void) { /* nothing */ }
++
++uint32_t
++getNumberOfProcessors (void)
++{
++    static uint32_t nproc = 0;
++
++    if (nproc == 0) {
++#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
++        nproc = sysconf(_SC_NPROCESSORS_ONLN);
++#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
++        nproc = sysconf(_SC_NPROCESSORS_CONF);
++#elif defined(darwin_HOST_OS)
++        size_t size = sizeof(uint32_t);
++        if(sysctlbyname("hw.logicalcpu",&nproc,&size,NULL,0) != 0) {
++            if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
++                nproc = 1;
++        }
++#elif defined(freebsd_HOST_OS)
++        size_t size = sizeof(uint32_t);
++        if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
++            nproc = 1;
++#else
++        nproc = 1;
++#endif
++    }
++
++    return nproc;
++}
++
+ #else /* !defined(THREADED_RTS) */
+ 
+ int
+
diff --git a/pkgs/development/compilers/ghc/D2713.patch b/pkgs/development/compilers/ghc/D2713.patch
new file mode 100644
index 000000000000..80cf35a52974
--- /dev/null
+++ b/pkgs/development/compilers/ghc/D2713.patch
@@ -0,0 +1,17 @@
+diff --git a/configure.ac b/configure.ac
+--- a/configure.ac
++++ b/configure.ac
+@@ -437,7 +437,11 @@
+ else
+   CrossCompilePrefix=""
+ fi
+-TargetPlatformFull="${TargetPlatform}"
++# Despite its similarity in name to TargetPlatform, TargetPlatformFull is used
++# in calls to subproject configure scripts and thus must be set to the autoconf
++# triple, not the normalized GHC triple that TargetPlatform is set to.
++# It may be better to just do away with the GHC triples all together.
++TargetPlatformFull="${target}"
+ AC_SUBST(CrossCompiling)
+ AC_SUBST(CrossCompilePrefix)
+ AC_SUBST(TargetPlatformFull)
+
diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix
index d57b6e575da5..f46a017c66aa 100644
--- a/pkgs/development/compilers/ghc/head.nix
+++ b/pkgs/development/compilers/ghc/head.nix
@@ -1,48 +1,51 @@
 { stdenv, fetchgit, bootPkgs, perl, gmp, ncurses, libiconv, binutils, coreutils
-, autoconf, automake, happy, alex
+, autoconf, automake, happy, alex, crossSystem, selfPkgs, cross ? null
 }:
 
 let
   inherit (bootPkgs) ghc;
 
-in stdenv.mkDerivation rec {
-  version = "8.1.20161109";
+  commonBuildInputs = [ ghc perl autoconf automake happy alex ];
+
+  version = "8.1.20161115";
+
+  commonPreConfigure =  ''
+    sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
+  '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
+    export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/ghc-${version}"
+  '' + stdenv.lib.optionalString stdenv.isDarwin ''
+    export NIX_LDFLAGS+=" -no_dtrace_dof"
+  '';
+in stdenv.mkDerivation (rec {
+  inherit version;
   name = "ghc-${version}";
-  rev = "2e8463b232054b788b73e6551947a9434aa76009";
+  rev = "017d11e0a36866b05ace32ece1af11adf652a619";
 
   src = fetchgit {
     url = "git://git.haskell.org/ghc.git";
     inherit rev;
-    sha256 = "12nxai5qqnw42syhd0vzl2f9f8z28rc0fsa7g771dyzpqglak90l";
+    sha256 = "1ryggmz961qd0fl50rkjjvi6g9azwla2vx9310a9nzjaj5x6ib4y";
   };
 
-  patches = [
-    ./ghc-HEAD-dont-pass-linker-flags-via-response-files.patch   # https://github.com/NixOS/nixpkgs/issues/10752
-  ];
+  # This shouldn't be necessary since 1ad1edbb32ce01ba8b47d8e8dad357b0edd6a4dc, but
+  # see http://hydra.cryp.to/build/2061608/nixlog/1/raw
+  patches = [ ./ghc-HEAD-dont-pass-linker-flags-via-response-files.patch ];
 
-  postUnpack = ''
-    pushd ghc-${builtins.substring 0 7 rev}
+  postPatch = ''
     echo ${version} >VERSION
     echo ${rev} >GIT_COMMIT_ID
     patchShebangs .
     ./boot
-    popd
   '';
 
-  buildInputs = [ ghc perl autoconf automake happy alex ];
+  buildInputs = commonBuildInputs;
 
   enableParallelBuilding = true;
 
-  preConfigure = ''
-    sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
-  '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
-    export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/ghc-${version}"
-  '' + stdenv.lib.optionalString stdenv.isDarwin ''
-    export NIX_LDFLAGS+=" -no_dtrace_dof"
-  '';
+  preConfigure = commonPreConfigure;
 
   configureFlags = [
-    "--with-cc=${stdenv.cc}/bin/cc"
+    "CC=${stdenv.cc}/bin/cc"
     "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
     "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
   ] ++ stdenv.lib.optional stdenv.isDarwin [
@@ -67,6 +70,11 @@ in stdenv.mkDerivation rec {
 
   passthru = {
     inherit bootPkgs;
+  } // stdenv.lib.optionalAttrs (crossSystem != null) {
+    crossCompiler = selfPkgs.ghc.override {
+      cross = crossSystem;
+      bootPkgs = selfPkgs;
+    };
   };
 
   meta = {
@@ -76,4 +84,35 @@ in stdenv.mkDerivation rec {
     inherit (ghc.meta) license platforms;
   };
 
-}
+} // stdenv.lib.optionalAttrs (cross != null) {
+  name = "${cross.config}-ghc-${version}";
+
+  # Some fixes for cross-compilation to iOS. See https://phabricator.haskell.org/D2710 (D2711,D2712,D2713)
+  patches = [ ./D2710.patch ./D2711.patch ./D2712.patch ./D2713.patch ];
+
+  preConfigure = commonPreConfigure + ''
+    sed 's|#BuildFlavour  = quick-cross|BuildFlavour  = perf-cross|' mk/build.mk.sample > mk/build.mk
+  '';
+
+  configureFlags = [
+    "CC=${stdenv.ccCross}/bin/${cross.config}-cc"
+    "LD=${stdenv.binutilsCross}/bin/${cross.config}-ld"
+    "AR=${stdenv.binutilsCross}/bin/${cross.config}-ar"
+    "NM=${stdenv.binutilsCross}/bin/${cross.config}-nm"
+    "RANLIB=${stdenv.binutilsCross}/bin/${cross.config}-ranlib"
+    "--target=${cross.config}"
+    "--enable-bootstrap-with-devel-snapshot"
+  ];
+
+  buildInputs = commonBuildInputs ++ [ stdenv.ccCross stdenv.binutilsCross ];
+
+  dontSetConfigureCross = true;
+
+  passthru = {
+    inherit bootPkgs cross;
+
+    cc = "${stdenv.ccCross}/bin/${cross.config}-cc";
+
+    ld = "${stdenv.binutilsCross}/bin/${cross.config}-ld";
+  };
+})
diff --git a/pkgs/development/compilers/ghcjs/base.nix b/pkgs/development/compilers/ghcjs/base.nix
new file mode 100644
index 000000000000..f8b861311d60
--- /dev/null
+++ b/pkgs/development/compilers/ghcjs/base.nix
@@ -0,0 +1,186 @@
+{ mkDerivation
+, test-framework
+, test-framework-hunit
+, test-framework-quickcheck2
+, data-default
+, ghc-paths
+, haskell-src-exts
+, haskell-src-meta
+, optparse-applicative
+, system-fileio
+, system-filepath
+, text-binary
+, unordered-containers
+, cabal-install
+, wl-pprint-text
+, base16-bytestring
+, executable-path
+, transformers-compat
+, haddock-api
+, ghcjs-prim
+, regex-posix
+, callPackage
+
+, bootPkgs, gmp
+, jailbreak-cabal
+
+, runCommand
+, nodejs, stdenv, filepath, HTTP, HUnit, mtl, network, QuickCheck, random, stm
+, time
+, zlib, aeson, attoparsec, bzlib, hashable
+, lens
+, parallel, safe, shelly, split, stringsearch, syb
+, tar, terminfo
+, vector, yaml, fetchgit, fetchFromGitHub, Cabal
+, alex, happy, git, gnumake, autoconf, patch
+, automake, libtool
+, cryptohash
+, haddock, hspec, xhtml, primitive, cacert, pkgs
+, coreutils
+, libiconv
+
+, version ? "0.2.0"
+, ghcjsSrc ? fetchFromGitHub {
+    owner = "ghcjs";
+    repo = "ghcjs";
+    rev = "689c7753f50353dd05606ed79c51cd5a94d3922a";
+    sha256 = "076020a9gjv8ldj5ckm43sbzq9s6c5xj6lpd8v28ybpiama3m6b4";
+  }
+, ghcjsBootSrc ? fetchgit {
+    url = git://github.com/ghcjs/ghcjs-boot.git;
+    rev = "8c549931da27ba9e607f77195208ec156c840c8a";
+    sha256 = "0yg9bnabja39qysh9pg1335qbvbc0r2mdw6cky94p7kavacndfdv";
+    fetchSubmodules = true;
+  }
+, ghcjsBoot ? import ./ghcjs-boot.nix {
+    inherit runCommand;
+    src = ghcjsBootSrc;
+  }
+, shims ? import ./shims.nix { inherit fetchFromGitHub; }
+
+# This is the list of the Stage 1 packages that are built into a booted ghcjs installation
+# It can be generated with the command:
+# 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\"/'"
+, stage1Packages ? [
+    "array"
+    "base"
+    "binary"
+    "bytestring"
+    "containers"
+    "deepseq"
+    "directory"
+    "filepath"
+    "ghc-boot"
+    "ghc-boot-th"
+    "ghc-prim"
+    "ghci"
+    "ghcjs-prim"
+    "ghcjs-th"
+    "integer-gmp"
+    "pretty"
+    "primitive"
+    "process"
+    "rts"
+    "template-haskell"
+    "time"
+    "transformers"
+    "unix"
+  ]
+
+, stage2 ? import ./stage2.nix
+}:
+let
+  inherit (bootPkgs) ghc;
+
+in mkDerivation (rec {
+  pname = "ghcjs";
+  inherit version;
+  src = ghcjsSrc;
+  isLibrary = true;
+  isExecutable = true;
+  jailbreak = true;
+  doHaddock = false;
+  doCheck = false;
+  buildDepends = [
+    filepath HTTP mtl network random stm time zlib aeson attoparsec
+    bzlib data-default ghc-paths hashable haskell-src-exts haskell-src-meta
+    lens optparse-applicative parallel safe shelly split
+    stringsearch syb system-fileio system-filepath tar terminfo text-binary
+    unordered-containers vector wl-pprint-text yaml
+    alex happy git gnumake autoconf automake libtool patch gmp
+    base16-bytestring cryptohash executable-path haddock-api
+    transformers-compat QuickCheck haddock hspec xhtml
+    ghcjs-prim regex-posix libiconv
+  ];
+  buildTools = [ nodejs git ];
+  testDepends = [
+    HUnit test-framework test-framework-hunit
+  ];
+  patches = [ ./ghcjs.patch ];
+  postPatch = ''
+    substituteInPlace Setup.hs \
+      --replace "/usr/bin/env" "${coreutils}/bin/env"
+
+    substituteInPlace src/Compiler/Info.hs \
+      --replace "@PREFIX@" "$out"          \
+      --replace "@VERSION@" "${version}"
+
+    substituteInPlace src-bin/Boot.hs \
+      --replace "@PREFIX@" "$out"     \
+      --replace "@CC@"     "${stdenv.cc}/bin/cc"
+  '';
+  preBuild = ''
+    export HOME="$TMP"
+
+    local topDir=$out/lib/ghcjs-${version}
+    mkdir -p $topDir
+
+    cp -r ${ghcjsBoot} $topDir/ghcjs-boot
+    chmod -R u+w $topDir/ghcjs-boot
+
+    cp -r ${shims} $topDir/shims
+    chmod -R u+w $topDir/shims
+
+    # Make the patches be relative their corresponding package's directory.
+    # See: https://github.com/ghcjs/ghcjs-boot/pull/12
+    for patch in "$topDir/ghcjs-boot/patches/"*.patch; do
+      echo "fixing patch: $patch"
+      sed -i -e 's@ \(a\|b\)/boot/[^/]\+@ \1@g' $patch
+    done
+  '';
+  # We build with --quick so we can build stage 2 packages separately.
+  # This is necessary due to: https://github.com/haskell/cabal/commit/af19fb2c2d231d8deff1cb24164a2bf7efb8905a
+  # Cabal otherwise fails to build: http://hydra.nixos.org/build/31824079/nixlog/1/raw
+  postInstall = ''
+    PATH=$out/bin:$PATH LD_LIBRARY_PATH=${gmp.out}/lib:${stdenv.cc}/lib64:$LD_LIBRARY_PATH \
+      env -u GHC_PACKAGE_PATH $out/bin/ghcjs-boot \
+        --dev \
+        --quick \
+        --with-cabal ${cabal-install}/bin/cabal \
+        --with-gmp-includes ${gmp.dev}/include \
+        --with-gmp-libraries ${gmp.out}/lib
+  '';
+  passthru = let
+    ghcjsNodePkgs = callPackage ../../../top-level/node-packages.nix {
+      generated = ./node-packages-generated.nix;
+      self = ghcjsNodePkgs;
+    };
+  in {
+    inherit bootPkgs;
+    isCross = true;
+    isGhcjs = true;
+    inherit nodejs ghcjsBoot;
+    inherit (ghcjsNodePkgs) "socket.io";
+
+    inherit stage1Packages;
+    mkStage2 = stage2 {
+      inherit ghcjsBoot;
+    };
+  };
+
+  homepage = "https://github.com/ghcjs/ghcjs";
+  description = "A Haskell to JavaScript compiler that uses the GHC API";
+  license = stdenv.lib.licenses.bsd3;
+  platforms = ghc.meta.platforms;
+  maintainers = with stdenv.lib.maintainers; [ jwiegley cstrahan ];
+})
diff --git a/pkgs/development/compilers/ghcjs/default.nix b/pkgs/development/compilers/ghcjs/default.nix
index 565215f474ea..7400057b128f 100644
--- a/pkgs/development/compilers/ghcjs/default.nix
+++ b/pkgs/development/compilers/ghcjs/default.nix
@@ -1,179 +1,3 @@
-{ mkDerivation
-, test-framework
-, test-framework-hunit
-, test-framework-quickcheck2
-, data-default
-, ghc-paths
-, haskell-src-exts
-, haskell-src-meta
-, optparse-applicative
-, system-fileio
-, system-filepath
-, text-binary
-, unordered-containers
-, cabal-install
-, wl-pprint-text
-, base16-bytestring
-, executable-path
-, transformers-compat
-, haddock-api
-, ghcjs-prim
-, regex-posix
-, callPackage
+{ bootPkgs }:
 
-, bootPkgs, gmp
-, jailbreak-cabal
-
-, runCommand
-, nodejs, stdenv, filepath, HTTP, HUnit, mtl, network, QuickCheck, random, stm
-, time
-, zlib, aeson, attoparsec, bzlib, hashable
-, lens
-, parallel, safe, shelly, split, stringsearch, syb
-, tar, terminfo
-, vector, yaml, fetchgit, fetchFromGitHub, Cabal
-, alex, happy, git, gnumake, autoconf, patch
-, automake, libtool
-, cryptohash
-, haddock, hspec, xhtml, primitive, cacert, pkgs
-, coreutils
-, libiconv
-
-, ghcjsBootSrc ? fetchgit {
-    url = git://github.com/ghcjs/ghcjs-boot.git;
-    rev = "8c549931da27ba9e607f77195208ec156c840c8a";
-    sha256 = "0yg9bnabja39qysh9pg1335qbvbc0r2mdw6cky94p7kavacndfdv";
-    fetchSubmodules = true;
-  }
-, ghcjsBoot ? import ./ghcjs-boot.nix {
-    inherit runCommand;
-    src = ghcjsBootSrc;
-  }
-, shims ? import ./shims.nix { inherit fetchFromGitHub; }
-}:
-let
-  inherit (bootPkgs) ghc;
-  version = "0.2.0";
-
-in mkDerivation (rec {
-  pname = "ghcjs";
-  inherit version;
-  src = fetchFromGitHub {
-    owner = "ghcjs";
-    repo = "ghcjs";
-    rev = "689c7753f50353dd05606ed79c51cd5a94d3922a";
-    sha256 = "076020a9gjv8ldj5ckm43sbzq9s6c5xj6lpd8v28ybpiama3m6b4";
-  };
-  isLibrary = true;
-  isExecutable = true;
-  jailbreak = true;
-  doHaddock = false;
-  doCheck = false;
-  buildDepends = [
-    filepath HTTP mtl network random stm time zlib aeson attoparsec
-    bzlib data-default ghc-paths hashable haskell-src-exts haskell-src-meta
-    lens optparse-applicative parallel safe shelly split
-    stringsearch syb system-fileio system-filepath tar terminfo text-binary
-    unordered-containers vector wl-pprint-text yaml
-    alex happy git gnumake autoconf automake libtool patch gmp
-    base16-bytestring cryptohash executable-path haddock-api
-    transformers-compat QuickCheck haddock hspec xhtml
-    ghcjs-prim regex-posix libiconv
-  ];
-  buildTools = [ nodejs git ];
-  testDepends = [
-    HUnit test-framework test-framework-hunit
-  ];
-  patches = [ ./ghcjs.patch ];
-  postPatch = ''
-    substituteInPlace Setup.hs \
-      --replace "/usr/bin/env" "${coreutils}/bin/env"
-
-    substituteInPlace src/Compiler/Info.hs \
-      --replace "@PREFIX@" "$out"          \
-      --replace "@VERSION@" "${version}"
-
-    substituteInPlace src-bin/Boot.hs \
-      --replace "@PREFIX@" "$out"     \
-      --replace "@CC@"     "${stdenv.cc}/bin/cc"
-  '';
-  preBuild = ''
-    export HOME="$TMP"
-
-    local topDir=$out/lib/ghcjs-${version}
-    mkdir -p $topDir
-
-    cp -r ${ghcjsBoot} $topDir/ghcjs-boot
-    chmod -R u+w $topDir/ghcjs-boot
-
-    cp -r ${shims} $topDir/shims
-    chmod -R u+w $topDir/shims
-
-    # Make the patches be relative their corresponding package's directory.
-    # See: https://github.com/ghcjs/ghcjs-boot/pull/12
-    for patch in "$topDir/ghcjs-boot/patches/"*.patch; do
-      echo "fixing patch: $patch"
-      sed -i -e 's@ \(a\|b\)/boot/[^/]\+@ \1@g' $patch
-    done
-  '';
-  # We build with --quick so we can build stage 2 packages separately.
-  # This is necessary due to: https://github.com/haskell/cabal/commit/af19fb2c2d231d8deff1cb24164a2bf7efb8905a
-  # Cabal otherwise fails to build: http://hydra.nixos.org/build/31824079/nixlog/1/raw
-  postInstall = ''
-    PATH=$out/bin:$PATH LD_LIBRARY_PATH=${gmp.out}/lib:${stdenv.cc}/lib64:$LD_LIBRARY_PATH \
-      env -u GHC_PACKAGE_PATH $out/bin/ghcjs-boot \
-        --dev \
-        --quick \
-        --with-cabal ${cabal-install}/bin/cabal \
-        --with-gmp-includes ${gmp.dev}/include \
-        --with-gmp-libraries ${gmp.out}/lib
-  '';
-  passthru = let
-    ghcjsNodePkgs = callPackage ../../../top-level/node-packages.nix {
-      generated = ./node-packages-generated.nix;
-      self = ghcjsNodePkgs;
-    };
-  in {
-    inherit bootPkgs;
-    isCross = true;
-    isGhcjs = true;
-    inherit nodejs ghcjsBoot;
-    inherit (ghcjsNodePkgs) "socket.io";
-
-    # This is the list of the Stage 1 packages that are built into a booted ghcjs installation
-    # It can be generated with the command:
-    # 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\"/'"
-    stage1Packages = [
-      "array"
-      "base"
-      "binary"
-      "rts"
-      "bytestring"
-      "containers"
-      "deepseq"
-      "directory"
-      "filepath"
-      "ghc-prim"
-      "ghcjs-prim"
-      "integer-gmp"
-      "old-locale"
-      "pretty"
-      "primitive"
-      "process"
-      "template-haskell"
-      "time"
-      "transformers"
-      "unix"
-    ];
-
-    mkStage2 = import ./stage2.nix {
-      inherit ghcjsBoot;
-    };
-  };
-
-  homepage = "https://github.com/ghcjs/ghcjs";
-  description = "A Haskell to JavaScript compiler that uses the GHC API";
-  license = stdenv.lib.licenses.bsd3;
-  platforms = ghc.meta.platforms;
-  maintainers = with stdenv.lib.maintainers; [ jwiegley cstrahan ];
-})
+bootPkgs.callPackage ./base.nix { inherit bootPkgs; }
diff --git a/pkgs/development/compilers/ghcjs/head.nix b/pkgs/development/compilers/ghcjs/head.nix
index 2bf13cb895f5..b191f9655d2a 100644
--- a/pkgs/development/compilers/ghcjs/head.nix
+++ b/pkgs/development/compilers/ghcjs/head.nix
@@ -1,178 +1,50 @@
-{ mkDerivation
-, test-framework
-, test-framework-hunit
-, test-framework-quickcheck2
-, data-default
-, ghc-paths
-, haskell-src-exts
-, haskell-src-meta
-, optparse-applicative
-, system-fileio
-, system-filepath
-, text-binary
-, unordered-containers
-, cabal-install
-, wl-pprint-text
-, base16-bytestring
-, executable-path
-, transformers-compat
-, haddock-api
-, regex-posix
-, callPackage
+{ fetchgit, fetchFromGitHub, bootPkgs }:
 
-, bootPkgs, gmp
-, jailbreak-cabal
-
-, runCommand
-, nodejs, stdenv, filepath, HTTP, HUnit, mtl, network, QuickCheck, random, stm
-, time
-, zlib, aeson, attoparsec, bzlib, hashable
-, lens
-, parallel, safe, shelly, split, stringsearch, syb
-, tar, terminfo
-, vector, yaml, fetchgit, fetchFromGitHub, Cabal
-, alex, happy, git, gnumake, autoconf, patch
-, automake, libtool
-, cryptohash
-, haddock, hspec, xhtml, primitive, cacert, pkgs
-, coreutils
-, libiconv
-
-, ghcjsBootSrc ? fetchgit {
-    url = git://github.com/ghcjs/ghcjs-boot.git;
-    rev = "b000a4f4619b850bf3f9a45c9058f7a51e7709c8";
-    sha256 = "164v0xf33r6mnympp6s70v8j6g7ccyg7z95gjp43bq150ppvisbq";
-    fetchSubmodules = true;
-  }
-, ghcjsBoot ? import ./ghcjs-boot.nix {
-    inherit runCommand;
-    src = ghcjsBootSrc;
-  }
-, shims ? import ./head_shims.nix { inherit fetchFromGitHub; }
-}:
-let
-  inherit (bootPkgs) ghc;
+bootPkgs.callPackage ./base.nix {
   version = "0.2.020161101";
 
-in mkDerivation (rec {
-  pname = "ghcjs";
-  inherit version;
-  src = fetchFromGitHub {
+  # deprecated on HEAD, directly included in the distribution
+  ghcjs-prim = null;
+  inherit bootPkgs;
+
+  ghcjsSrc = fetchFromGitHub {
     owner = "ghcjs";
     repo = "ghcjs";
     rev = "899c834a36692bbbde9b9d16fe5b92ce55a623c4";
     sha256 = "024yj4k0dxy7nvyq19n3xbhh4b4csdrgj19a3l4bmm1zn84gmpl6";
   };
-  isLibrary = true;
-  isExecutable = true;
-  jailbreak = true;
-  doHaddock = false;
-  doCheck = false;
-  buildDepends = [
-    filepath HTTP mtl network random stm time zlib aeson attoparsec
-    bzlib data-default ghc-paths hashable haskell-src-exts haskell-src-meta
-    lens optparse-applicative parallel safe shelly split
-    stringsearch syb system-fileio system-filepath tar terminfo text-binary
-    unordered-containers vector wl-pprint-text yaml
-    alex happy git gnumake autoconf automake libtool patch gmp
-    base16-bytestring cryptohash executable-path haddock-api
-    transformers-compat QuickCheck haddock hspec xhtml
-    regex-posix libiconv
-  ];
-  buildTools = [ nodejs git ];
-  testDepends = [
-    HUnit test-framework test-framework-hunit
-  ];
-  patches = [ ./ghcjs.patch ];
-  postPatch = ''
-    substituteInPlace Setup.hs \
-      --replace "/usr/bin/env" "${coreutils}/bin/env"
-
-    substituteInPlace src/Compiler/Info.hs \
-      --replace "@PREFIX@" "$out"          \
-      --replace "@VERSION@" "${version}"
-
-    substituteInPlace src-bin/Boot.hs \
-      --replace "@PREFIX@" "$out"     \
-      --replace "@CC@"     "${stdenv.cc}/bin/cc"
-  '';
-  preBuild = ''
-    export HOME="$TMP"
-
-    local topDir=$out/lib/ghcjs-${version}
-    mkdir -p $topDir
-
-    cp -r ${ghcjsBoot} $topDir/ghcjs-boot
-    chmod -R u+w $topDir/ghcjs-boot
-
-    cp -r ${shims} $topDir/shims
-    chmod -R u+w $topDir/shims
-
-    # Make the patches be relative their corresponding package's directory.
-    # See: https://github.com/ghcjs/ghcjs-boot/pull/12
-    for patch in "$topDir/ghcjs-boot/patches/"*.patch; do
-      echo "fixing patch: $patch"
-      sed -i -e 's@ \(a\|b\)/boot/[^/]\+@ \1@g' $patch
-    done
-  '';
-  # We build with --quick so we can build stage 2 packages separately.
-  # This is necessary due to: https://github.com/haskell/cabal/commit/af19fb2c2d231d8deff1cb24164a2bf7efb8905a
-  # Cabal otherwise fails to build: http://hydra.nixos.org/build/31824079/nixlog/1/raw
-  postInstall = ''
-    PATH=$out/bin:$PATH LD_LIBRARY_PATH=${gmp.out}/lib:${stdenv.cc}/lib64:$LD_LIBRARY_PATH \
-      env -u GHC_PACKAGE_PATH $out/bin/ghcjs-boot \
-        --dev \
-        --quick \
-        --with-cabal ${cabal-install}/bin/cabal \
-        --with-gmp-includes ${gmp.dev}/include \
-        --with-gmp-libraries ${gmp.out}/lib
-  '';
-  passthru = let
-    ghcjsNodePkgs = callPackage ../../../top-level/node-packages.nix {
-      generated = ./node-packages-generated.nix;
-      self = ghcjsNodePkgs;
-    };
-  in {
-    inherit bootPkgs;
-    isCross = true;
-    isGhcjs = true;
-    inherit nodejs ghcjsBoot;
-    inherit (ghcjsNodePkgs) "socket.io";
-
-    # This is the list of the Stage 1 packages that are built into a booted ghcjs installation
-    # It can be generated with the command:
-    # 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\"/'"
-    stage1Packages = [
-      "array"
-      "base"
-      "binary"
-      "rts"
-      "bytestring"
-      "containers"
-      "deepseq"
-      "directory"
-      "filepath"
-      "ghc-prim"
-      "ghcjs-prim"
-      "integer-gmp"
-      "old-locale"
-      "pretty"
-      "primitive"
-      "process"
-      "template-haskell"
-      "time"
-      "transformers"
-      "unix"
-    ];
-
-    mkStage2 = import ./stage2.nix {
-      inherit ghcjsBoot;
-    };
+  ghcjsBootSrc = fetchgit {
+    url = git://github.com/ghcjs/ghcjs-boot.git;
+    rev = "b000a4f4619b850bf3f9a45c9058f7a51e7709c8";
+    sha256 = "164v0xf33r6mnympp6s70v8j6g7ccyg7z95gjp43bq150ppvisbq";
+    fetchSubmodules = true;
   };
 
-  homepage = "https://github.com/ghcjs/ghcjs";
-  description = "A Haskell to JavaScript compiler that uses the GHC API";
-  license = stdenv.lib.licenses.bsd3;
-  platforms = ghc.meta.platforms;
-  maintainers = with stdenv.lib.maintainers; [ jwiegley cstrahan ];
-})
+  shims = import ./head_shims.nix { inherit fetchFromGitHub; };
+  stage1Packages = [
+    "array"
+    "base"
+    "binary"
+    "bytestring"
+    "containers"
+    "deepseq"
+    "directory"
+    "filepath"
+    "ghc-boot"
+    "ghc-boot-th"
+    "ghc-prim"
+    "ghci"
+    "ghcjs-prim"
+    "ghcjs-th"
+    "integer-gmp"
+    "pretty"
+    "primitive"
+    "process"
+    "rts"
+    "template-haskell"
+    "time"
+    "transformers"
+    "unix"
+  ];
+  stage2 = import ./head_stage2.nix;
+}
diff --git a/pkgs/development/compilers/ghcjs/head_shims.nix b/pkgs/development/compilers/ghcjs/head_shims.nix
index e321978f0bdc..68b03d057397 100644
--- a/pkgs/development/compilers/ghcjs/head_shims.nix
+++ b/pkgs/development/compilers/ghcjs/head_shims.nix
@@ -2,6 +2,6 @@
 fetchFromGitHub {
   owner = "ghcjs";
   repo = "shims";
-  rev = "1f555d3ca072c61862cc35f92f5ac05f3b938a37";
-  sha256 = "1pciyrlrp5i9s4s8ai4dvhihcahazva6fg0graxxxkjdvnl789ws";
+  rev = "f67394c559ac921a768b12f141499119563b8bf3";
+  sha256 = "1lz86qmkxkfch1yk9a62admw7jsd34sqcrskgpq28hbhjpgzf1lv";
 }
diff --git a/pkgs/development/compilers/ghcjs/head_stage2.nix b/pkgs/development/compilers/ghcjs/head_stage2.nix
new file mode 100644
index 000000000000..765a384bf634
--- /dev/null
+++ b/pkgs/development/compilers/ghcjs/head_stage2.nix
@@ -0,0 +1,345 @@
+{ ghcjsBoot }: { callPackage }:
+
+{
+  async = callPackage
+    ({ mkDerivation, base, HUnit, stdenv, stm, test-framework
+      , test-framework-hunit
+      }:
+      mkDerivation {
+        pname = "async";
+        version = "2.1.0";
+        src = "${ghcjsBoot}/boot/async";
+        doCheck = false;
+        libraryHaskellDepends = [ base stm ];
+        testHaskellDepends = [
+          base HUnit test-framework test-framework-hunit
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/simonmar/async";
+        description = "Run IO operations asynchronously and wait for their results";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  aeson = callPackage
+    ({ mkDerivation, attoparsec, base, bytestring, containers, deepseq
+      , dlist, fail, ghc-prim, hashable, HUnit, mtl, QuickCheck, scientific
+      , stdenv, syb, tagged, template-haskell, test-framework
+      , test-framework-hunit, test-framework-quickcheck2, text, time
+      , transformers, unordered-containers, vector
+      }:
+      mkDerivation {
+        pname = "aeson";
+        version = "0.11.2.0";
+        src = "${ghcjsBoot}/boot/aeson";
+        doCheck = false;
+        libraryHaskellDepends = [
+          attoparsec base bytestring containers deepseq dlist fail ghc-prim
+          hashable mtl scientific syb tagged template-haskell text time transformers
+          unordered-containers vector
+        ];
+        testHaskellDepends = [
+          attoparsec base bytestring containers ghc-prim HUnit QuickCheck
+          template-haskell test-framework test-framework-hunit
+          test-framework-quickcheck2 text time unordered-containers vector
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/bos/aeson";
+        description = "Fast JSON parsing and encoding";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  attoparsec = callPackage
+    ({ mkDerivation, array, base, bytestring, containers, deepseq
+      , QuickCheck, quickcheck-unicode, scientific, stdenv
+      , test-framework, test-framework-quickcheck2, text, transformers
+      , vector
+      }:
+      mkDerivation {
+        pname = "attoparsec";
+        version = "0.13.0.2";
+        src = "${ghcjsBoot}/boot/attoparsec";
+        doCheck = false;
+        libraryHaskellDepends = [
+          array base bytestring containers deepseq scientific text
+          transformers
+        ];
+        testHaskellDepends = [
+          array base bytestring containers deepseq QuickCheck
+          quickcheck-unicode scientific test-framework
+          test-framework-quickcheck2 text transformers vector
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/bos/attoparsec";
+        description = "Fast combinator parsing for bytestrings and text";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  case-insensitive = callPackage
+    ({ mkDerivation, base, bytestring, deepseq, hashable, HUnit, stdenv
+      , test-framework, test-framework-hunit, text
+      }:
+      mkDerivation {
+        pname = "case-insensitive";
+        version = "1.2.0.6";
+        src = "${ghcjsBoot}/boot/case-insensitive";
+        doCheck = false;
+        libraryHaskellDepends = [ base bytestring deepseq hashable text ];
+        testHaskellDepends = [
+          base bytestring HUnit test-framework test-framework-hunit text
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/basvandijk/case-insensitive";
+        description = "Case insensitive string comparison";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  dlist = callPackage
+    ({ mkDerivation, base, Cabal, deepseq, QuickCheck, stdenv }:
+      mkDerivation {
+        pname = "dlist";
+        version = "0.7.1.2";
+        src = "${ghcjsBoot}/boot/dlist";
+        doCheck = false;
+        libraryHaskellDepends = [ base deepseq ];
+        testHaskellDepends = [ base Cabal QuickCheck ];
+        jailbreak = true;
+        homepage = "https://github.com/spl/dlist";
+        description = "Difference lists";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  extensible-exceptions = callPackage
+    ({ mkDerivation, base, stdenv }:
+      mkDerivation {
+        pname = "extensible-exceptions";
+        version = "0.1.1.4";
+        src = "${ghcjsBoot}/boot/extensible-exceptions";
+        doCheck = false;
+        libraryHaskellDepends = [ base ];
+        jailbreak = true;
+        description = "Extensible exceptions";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  hashable = callPackage
+    ({ mkDerivation, base, bytestring, ghc-prim, HUnit, integer-gmp
+      , QuickCheck, random, stdenv, test-framework, test-framework-hunit
+      , test-framework-quickcheck2, text, unix
+      }:
+      mkDerivation {
+        pname = "hashable";
+        version = "1.2.4.0";
+        src = "${ghcjsBoot}/boot/hashable";
+        doCheck = false;
+        libraryHaskellDepends = [
+          base bytestring ghc-prim integer-gmp text
+        ];
+        testHaskellDepends = [
+          base bytestring ghc-prim HUnit QuickCheck random test-framework
+          test-framework-hunit test-framework-quickcheck2 text unix
+        ];
+        jailbreak = true;
+        homepage = "http://github.com/tibbe/hashable";
+        description = "A class for types that can be converted to a hash value";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  mtl = callPackage
+    ({ mkDerivation, base, stdenv, transformers }:
+      mkDerivation {
+        pname = "mtl";
+        version = "2.2.2";
+        src = "${ghcjsBoot}/boot/mtl";
+        doCheck = false;
+        libraryHaskellDepends = [ base transformers ];
+        jailbreak = true;
+        homepage = "http://github.com/ekmett/mtl";
+        description = "Monad classes, using functional dependencies";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  old-time = callPackage
+    ({ mkDerivation, base, old-locale, stdenv }:
+      mkDerivation {
+        pname = "old-time";
+        version = "1.1.0.3";
+        src = "${ghcjsBoot}/boot/old-time";
+        doCheck = false;
+        libraryHaskellDepends = [ base old-locale ];
+        jailbreak = true;
+        description = "Time library";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  parallel = callPackage
+    ({ mkDerivation, array, base, containers, deepseq, stdenv }:
+      mkDerivation {
+        pname = "parallel";
+        version = "3.2.1.0";
+        src = "${ghcjsBoot}/boot/parallel";
+        doCheck = false;
+        libraryHaskellDepends = [ array base containers deepseq ];
+        jailbreak = true;
+        description = "Parallel programming library";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  scientific = callPackage
+    ({ mkDerivation, base, binary, bytestring, containers, deepseq, ghc-prim
+      , hashable, integer-gmp, QuickCheck, smallcheck, stdenv, tasty
+      , tasty-ant-xml, tasty-hunit, tasty-quickcheck, tasty-smallcheck
+      , text, vector
+      }:
+      mkDerivation {
+        pname = "scientific";
+        version = "0.3.4.7";
+        src = "${ghcjsBoot}/boot/scientific";
+        doCheck = false;
+        libraryHaskellDepends = [
+          base binary bytestring containers deepseq ghc-prim hashable
+          integer-gmp text vector
+        ];
+        testHaskellDepends = [
+          base bytestring QuickCheck smallcheck tasty tasty-ant-xml
+          tasty-hunit tasty-quickcheck tasty-smallcheck text
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/basvandijk/scientific";
+        description = "Numbers represented using scientific notation";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  stm = callPackage
+    ({ mkDerivation, array, base, stdenv }:
+      mkDerivation {
+        pname = "stm";
+        version = "2.4.4.1";
+        src = "${ghcjsBoot}/boot/stm";
+        doCheck = false;
+        libraryHaskellDepends = [ array base ];
+        jailbreak = true;
+        description = "Software Transactional Memory";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  syb = callPackage
+    ({ mkDerivation, base, containers, HUnit, mtl, stdenv }:
+      mkDerivation {
+        pname = "syb";
+        version = "0.6";
+        src = "${ghcjsBoot}/boot/syb";
+        doCheck = false;
+        libraryHaskellDepends = [ base ];
+        testHaskellDepends = [ base containers HUnit mtl ];
+        jailbreak = true;
+        homepage = "http://www.cs.uu.nl/wiki/GenericProgramming/SYB";
+        description = "Scrap Your Boilerplate";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  text = callPackage
+    ({ mkDerivation, array, base, binary, bytestring, deepseq, directory
+      , ghc-prim, HUnit, integer-gmp, QuickCheck, quickcheck-unicode
+      , random, stdenv, test-framework, test-framework-hunit
+      , test-framework-quickcheck2
+      }:
+      mkDerivation {
+        pname = "text";
+        version = "1.2.2.1";
+        src = "${ghcjsBoot}/boot/text";
+        doCheck = false;
+        libraryHaskellDepends = [
+          array base binary bytestring deepseq ghc-prim integer-gmp
+        ];
+        testHaskellDepends = [
+          array base binary bytestring deepseq directory ghc-prim HUnit
+          integer-gmp QuickCheck quickcheck-unicode random test-framework
+          test-framework-hunit test-framework-quickcheck2
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/bos/text";
+        description = "An efficient packed Unicode text type";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  unordered-containers = callPackage
+    ({ mkDerivation, base, ChasingBottoms, containers, deepseq, hashable
+      , HUnit, QuickCheck, stdenv, test-framework, test-framework-hunit
+      , test-framework-quickcheck2
+      }:
+      mkDerivation {
+        pname = "unordered-containers";
+        version = "0.2.7.0";
+        src = "${ghcjsBoot}/boot/unordered-containers";
+        doCheck = false;
+        libraryHaskellDepends = [ base deepseq hashable ];
+        testHaskellDepends = [
+          base ChasingBottoms containers hashable HUnit QuickCheck
+          test-framework test-framework-hunit test-framework-quickcheck2
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/tibbe/unordered-containers";
+        description = "Efficient hashing-based container types";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  vector = callPackage
+    ({ mkDerivation, base, deepseq, ghc-prim, primitive, QuickCheck
+      , random, stdenv, template-haskell, test-framework
+      , test-framework-quickcheck2, transformers
+      }:
+      mkDerivation {
+        pname = "vector";
+        version = "0.11.0.0";
+        src = "${ghcjsBoot}/boot/vector";
+        doCheck = false;
+        libraryHaskellDepends = [ base deepseq ghc-prim primitive ];
+        testHaskellDepends = [
+          base QuickCheck random template-haskell test-framework
+          test-framework-quickcheck2 transformers
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/haskell/vector";
+        description = "Efficient Arrays";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  ghcjs-base = callPackage
+    ({ mkDerivation, aeson, array, attoparsec, base, bytestring
+      , containers, deepseq, directory, dlist, ghc-prim, ghcjs-prim
+      , hashable, HUnit, integer-gmp, primitive, QuickCheck
+      , quickcheck-unicode, random, scientific, stdenv, test-framework
+      , test-framework-hunit, test-framework-quickcheck2, text, time
+      , transformers, unordered-containers, vector
+      }:
+      mkDerivation {
+        pname = "ghcjs-base";
+        version = "0.2.0.0";
+        src = "${ghcjsBoot}/ghcjs/ghcjs-base";
+        doCheck = false;
+        libraryHaskellDepends = [
+          aeson attoparsec base bytestring containers deepseq dlist ghc-prim
+          ghcjs-prim hashable integer-gmp primitive scientific text time
+          transformers unordered-containers vector
+        ];
+        testHaskellDepends = [
+          array base bytestring deepseq directory ghc-prim ghcjs-prim HUnit
+          primitive QuickCheck quickcheck-unicode random test-framework
+          test-framework-hunit test-framework-quickcheck2 text
+        ];
+        jailbreak = true;
+        homepage = "http://github.com/ghcjs/ghcjs-base";
+        description = "Base library for GHCJS";
+        license = stdenv.lib.licenses.mit;
+      }) {};
+  Cabal = callPackage
+    ({ mkDerivation, array, base, binary, bytestring, containers
+      , deepseq, directory, extensible-exceptions, filepath, HUnit
+      , old-time, pretty, process, QuickCheck, regex-posix, stdenv
+      , test-framework, test-framework-hunit, test-framework-quickcheck2
+      , time, unix
+      }:
+      mkDerivation {
+        pname = "Cabal";
+        version = "1.24.0.0";
+        src = "${ghcjsBoot}/boot/cabal/Cabal";
+        doCheck = false;
+        libraryHaskellDepends = [
+          array base binary bytestring containers deepseq directory filepath
+          pretty process time unix
+        ];
+        testHaskellDepends = [
+          base bytestring containers directory extensible-exceptions filepath
+          HUnit old-time process QuickCheck regex-posix test-framework
+          test-framework-hunit test-framework-quickcheck2 unix
+        ];
+        jailbreak = true;
+        homepage = "http://www.haskell.org/cabal/";
+        description = "A framework for packaging Haskell software";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+}
diff --git a/pkgs/development/compilers/kotlin/default.nix b/pkgs/development/compilers/kotlin/default.nix
index e1de97e17c40..52a47c50420e 100644
--- a/pkgs/development/compilers/kotlin/default.nix
+++ b/pkgs/development/compilers/kotlin/default.nix
@@ -1,12 +1,12 @@
 { stdenv, fetchurl, makeWrapper, jre, unzip }:
 
 stdenv.mkDerivation rec {
-  version = "1.0.5";
+  version = "1.0.5-2";
   name = "kotlin-${version}";
 
   src = fetchurl {
     url = "https://github.com/JetBrains/kotlin/releases/download/v${version}/kotlin-compiler-${version}.zip";
-    sha512 = "0bkgxr4an1fq890s3bw4izwc8ly29xk28gdibvnp2q9qd15rwrny5dgns697rnbw2gg0nn08q5p33asvbkac001cfabfphamjwndvc9";
+    sha512 = "0z8phc51y8dfjnm95fs2dnmvhp7xm2am5xm71byh598flkpjmagnwah4j8z9fpg4qy94dwmqxf5zs3q8nfra89kmwskzpvp7bbibi0h";
   };
 
   propagatedBuildInputs = [ jre ] ;
diff --git a/pkgs/development/compilers/llvm/3.8/D17533-1.patch b/pkgs/development/compilers/llvm/3.8/D17533-1.patch
new file mode 100644
index 000000000000..79ca953d6e5b
--- /dev/null
+++ b/pkgs/development/compilers/llvm/3.8/D17533-1.patch
@@ -0,0 +1,60 @@
+commit eb92f5a745014532b83abfba04602fce87ca8393
+Author: Chuang-Yu Cheng <cycheng@multicorewareinc.com>
+Date:   Fri Apr 8 12:04:32 2016 +0000
+
+    CXX_FAST_TLS calling convention: performance improvement for PPC64
+    
+    This is the same change on PPC64 as r255821 on AArch64. I have even borrowed
+    his commit message.
+    
+    The access function has a short entry and a short exit, the initialization
+    block is only run the first time. To improve the performance, we want to
+    have a short frame at the entry and exit.
+    
+    We explicitly handle most of the CSRs via copies. Only the CSRs that are not
+    handled via copies will be in CSR_SaveList.
+    
+    Frame lowering and prologue/epilogue insertion will generate a short frame
+    in the entry and exit according to CSR_SaveList. The majority of the CSRs will
+    be handled by register allcoator. Register allocator will try to spill and
+    reload them in the initialization block.
+    
+    We add CSRsViaCopy, it will be explicitly handled during lowering.
+    
+    1> we first set FunctionLoweringInfo->SplitCSR if conditions are met (the target
+       supports it for the given machine function and the function has only return
+       exits). We also call TLI->initializeSplitCSR to perform initialization.
+    2> we call TLI->insertCopiesSplitCSR to insert copies from CSRsViaCopy to
+       virtual registers at beginning of the entry block and copies from virtual
+       registers to CSRsViaCopy at beginning of the exit blocks.
+    3> we also need to make sure the explicit copies will not be eliminated.
+    
+    Author: Tom Jablin (tjablin)
+    Reviewers: hfinkel kbarton cycheng
+    
+    http://reviews.llvm.org/D17533
+    
+    git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265781 91177308-0d34-0410-b5e6-96231b3b80d8
+
+diff --git a/lib/CodeGen/TargetFrameLoweringImpl.cpp b/lib/CodeGen/TargetFrameLoweringImpl.cpp
+index 679ade1..0a0e079 100644
+--- a/lib/CodeGen/TargetFrameLoweringImpl.cpp
++++ b/lib/CodeGen/TargetFrameLoweringImpl.cpp
+@@ -63,12 +63,15 @@ void TargetFrameLowering::determineCalleeSaves(MachineFunction &MF,
+   const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
+   const MCPhysReg *CSRegs = TRI.getCalleeSavedRegs(&MF);
+ 
++  // Resize before the early returns. Some backends expect that
++  // SavedRegs.size() == TRI.getNumRegs() after this call even if there are no
++  // saved registers.
++  SavedRegs.resize(TRI.getNumRegs());
++
+   // Early exit if there are no callee saved registers.
+   if (!CSRegs || CSRegs[0] == 0)
+     return;
+ 
+-  SavedRegs.resize(TRI.getNumRegs());
+-
+   // In Naked functions we aren't going to save any registers.
+   if (MF.getFunction()->hasFnAttribute(Attribute::Naked))
+     return;
diff --git a/pkgs/development/compilers/llvm/3.8/llvm.nix b/pkgs/development/compilers/llvm/3.8/llvm.nix
index 6112228bf4fc..fa647e62ff14 100644
--- a/pkgs/development/compilers/llvm/3.8/llvm.nix
+++ b/pkgs/development/compilers/llvm/3.8/llvm.nix
@@ -35,10 +35,14 @@ in stdenv.mkDerivation rec {
 
   propagatedBuildInputs = [ ncurses zlib ];
 
+  # Fix a segfault in llc
+  # See http://lists.llvm.org/pipermail/llvm-dev/2016-October/106500.html
+  patches = [ ./D17533-1.patch ];
+
   # hacky fix: New LLVM releases require a newer OS X SDK than
   # 10.9. This is a temporary measure until nixpkgs darwin support is
   # updated.
-  patchPhase = stdenv.lib.optionalString stdenv.isDarwin ''
+  postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
         sed -i 's/os_trace(\(.*\)");$/printf(\1\\n");/g' ./projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
   '';
 
diff --git a/pkgs/development/compilers/rust/bootstrap.nix b/pkgs/development/compilers/rust/bootstrap.nix
index 454b67b8151b..b912a9d7933c 100644
--- a/pkgs/development/compilers/rust/bootstrap.nix
+++ b/pkgs/development/compilers/rust/bootstrap.nix
@@ -14,16 +14,16 @@ let
     then "x86_64-apple-darwin"
     else abort "missing boostrap url for platform ${stdenv.system}";
 
-  # fetch hashes by running `print-hashes.sh 1.9.0`
+  # fetch hashes by running `print-hashes.sh 1.12.1`
   bootstrapHash =
     if stdenv.system == "i686-linux"
-    then "f5a3f5d53defe827a71447b1a0e7a656394b87ee23e009d7bf73a0277c1b5ac2"
+    then "ede9b9d14d1ddbc29975d1ead73fcf2758719b4b371363afe1c32eb8d6e96bb3"
     else if stdenv.system == "x86_64-linux"
-    then "f4ebbd6d9494cb8fa6c410cb58954e1913546c2bca8963faebc424591547d83f"
+    then "9e546aec13e389429ba2d86c8f4e67eba5af146c979e4faa16ffb40ddaf9984c"
     else if stdenv.system == "i686-darwin"
-    then "bf07182bc362985fcdd48af905cdb559e20c68518cd71dabec3c30b78ca8a94a"
+    then "2648645c4fe1ecf36beb7de63501dd99e9547a7a6d5683acf2693b919a550b69"
     else if stdenv.system == "x86_64-darwin"
-    then "2cdbc47438dc86ecaf35298317b77d735956eb160862e3f6d0fda0da656ecc35"
+    then "0ac5e58dba3d24bf09dcc90eaac02d2df053122b0def945ec4cfe36ac6d4d011"
     else throw "missing boostrap hash for platform ${stdenv.system}";
 
   needsPatchelf = stdenv.isLinux;
@@ -33,7 +33,7 @@ let
      sha256 = bootstrapHash;
   };
 
-  version = "1.11.0";
+  version = "1.12.1";
 in
 
 rec {
diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix
index 7e29435b7d59..dd2d47e940d1 100644
--- a/pkgs/development/compilers/rust/default.nix
+++ b/pkgs/development/compilers/rust/default.nix
@@ -7,12 +7,12 @@ in
 
 rec {
   rustc = callPackage ./rustc.nix {
-    shortVersion = "1.12.1";
+    shortVersion = "1.13";
     isRelease = true;
     forceBundledLLVM = false;
     configureFlags = [ "--release-channel=stable" ];
-    srcRev = "d4f39402a0c2c2b94ec0375cd7f7f6d7918113cd";
-    srcSha = "1lpykjy96rwz4jy28rf7ijca0q9lvckgnbzvcdsrspd5rs2ywfwr";
+    srcRev = "2c6933acc05c61e041be764cb1331f6281993f3f";
+    srcSha = "1w0alyyc29cy2lczrqvg1kfycjxy0xg8fpzdac80m88fxpv23glp";
 
     patches = [
       ./patches/disable-lockfile-check.patch
@@ -25,10 +25,10 @@ rec {
   };
 
   cargo = callPackage ./cargo.nix rec {
-    version = "0.13.0";
-    srcRev = "109cb7c33d426044d141457049bd0fffaca1327c";
-    srcSha = "0p79m7hpzjh36l4fc6a59h6r8yz6qafjcdg5v1yb7bac9m2wi7vs";
-    depsSha256 = "1cwp4p8b985fj8j2qmgsi2mpp51rdpwzm9qa60760nrry1fy624z";
+    version = "0.14.0";
+    srcRev = "eca9e159b6b0d484788ac757cf23052eba75af55";
+    srcSha = "1zm5rzw1mvixnkzr4775pcxx6k235qqxbysyp179cbxsw3dm045s";
+    depsSha256 = "0gpn0cpwgpzwhc359qn6qplx371ag9pqbwayhqrsydk1zm5bm3zr";
 
     inherit rustc; # the rustc that will be wrapped by cargo
     inherit rustPlatform; # used to build cargo
diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix
index e1bff12f398e..57480974a3f1 100644
--- a/pkgs/development/compilers/rust/rustc.nix
+++ b/pkgs/development/compilers/rust/rustc.nix
@@ -93,6 +93,10 @@ stdenv.mkDerivation {
     # Remove test targeted at LLVM 3.9 - https://github.com/rust-lang/rust/issues/36835
     rm -vr src/test/run-pass/issue-36023.rs
 
+    # Disable test getting stuck on hydra - possible fix:
+    # https://reviews.llvm.org/rL281650
+    rm -vr src/test/run-pass/issue-36474.rs
+
     # Useful debugging parameter
     # export VERBOSE=1
   '' +