summary refs log tree commit diff
path: root/pkgs/development/compilers
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2017-12-29 14:28:16 -0500
committerJohn Ericson <John.Ericson@Obsidian.Systems>2017-12-29 15:28:49 -0500
commit5d336d36bb0cb20d8966e9e426f8621629ac6e03 (patch)
tree9513a7b9d1fe0d5b90be6bc973af3fd5164d3036 /pkgs/development/compilers
parent169227bfd248f1bc4175e62d2e3d77658f9b0738 (diff)
parente82bd498d1a2a28fb20249569a6f49fcaab9aca8 (diff)
downloadnixlib-5d336d36bb0cb20d8966e9e426f8621629ac6e03.tar
nixlib-5d336d36bb0cb20d8966e9e426f8621629ac6e03.tar.gz
nixlib-5d336d36bb0cb20d8966e9e426f8621629ac6e03.tar.bz2
nixlib-5d336d36bb0cb20d8966e9e426f8621629ac6e03.tar.lz
nixlib-5d336d36bb0cb20d8966e9e426f8621629ac6e03.tar.xz
nixlib-5d336d36bb0cb20d8966e9e426f8621629ac6e03.tar.zst
nixlib-5d336d36bb0cb20d8966e9e426f8621629ac6e03.zip
Merge commit 'e82bd498d1a2a28fb20249569a6f49fcaab9aca8' into mingw32-w64-fix
Diffstat (limited to 'pkgs/development/compilers')
-rw-r--r--pkgs/development/compilers/abcl/default.nix4
-rw-r--r--pkgs/development/compilers/arachne-pnr/default.nix22
-rw-r--r--pkgs/development/compilers/avian/default.nix1
-rw-r--r--pkgs/development/compilers/avra/default.nix2
-rw-r--r--pkgs/development/compilers/boo/default.nix3
-rw-r--r--pkgs/development/compilers/ccl/default.nix10
-rw-r--r--pkgs/development/compilers/chez/default.nix10
-rw-r--r--pkgs/development/compilers/clasp/default.nix74
-rw-r--r--pkgs/development/compilers/closure/default.nix27
-rw-r--r--pkgs/development/compilers/compcert/default.nix7
-rw-r--r--pkgs/development/compilers/coreclr/default.nix75
-rw-r--r--pkgs/development/compilers/crystal/default.nix89
-rw-r--r--pkgs/development/compilers/cudatoolkit/default.nix81
-rw-r--r--pkgs/development/compilers/dale/default.nix3
-rw-r--r--pkgs/development/compilers/dmd/2.067.1.nix33
-rw-r--r--pkgs/development/compilers/dmd/default.nix32
-rw-r--r--pkgs/development/compilers/dotnet/sdk/default.nix53
-rw-r--r--pkgs/development/compilers/edk2/default.nix11
-rw-r--r--pkgs/development/compilers/elm/packages/elm-format.nix43
-rw-r--r--pkgs/development/compilers/emscripten-fastcomp/default.nix74
-rw-r--r--pkgs/development/compilers/emscripten-fastcomp/emscripten-fastcomp.nix54
-rw-r--r--pkgs/development/compilers/factor-lang/default.nix11
-rw-r--r--pkgs/development/compilers/fsharp/default.nix3
-rw-r--r--pkgs/development/compilers/fsharp41/default.nix2
-rw-r--r--pkgs/development/compilers/fstar/default.nix65
-rw-r--r--pkgs/development/compilers/gambit/bootstrap.nix2
-rw-r--r--pkgs/development/compilers/gambit/default.nix31
-rw-r--r--pkgs/development/compilers/gcc/4.5/default.nix219
-rw-r--r--pkgs/development/compilers/gcc/4.8/default.nix274
-rw-r--r--pkgs/development/compilers/gcc/4.9/default.nix270
-rw-r--r--pkgs/development/compilers/gcc/5/default.nix281
-rw-r--r--pkgs/development/compilers/gcc/6/default.nix294
-rw-r--r--pkgs/development/compilers/gcc/7/default.nix278
-rw-r--r--pkgs/development/compilers/gcc/libstdc++-hook.sh2
-rw-r--r--pkgs/development/compilers/gcc/res_state-not-declared.patch13
-rw-r--r--pkgs/development/compilers/gcc/sigsegv-not-declared.patch13
-rw-r--r--pkgs/development/compilers/gcc/snapshot/default.nix272
-rw-r--r--pkgs/development/compilers/gcc/struct-sigaltstack-4.9.patch78
-rw-r--r--pkgs/development/compilers/gcc/struct-sigaltstack.patch87
-rw-r--r--pkgs/development/compilers/gcc/struct-ucontext-4.5.patch107
-rw-r--r--pkgs/development/compilers/gcc/struct-ucontext-4.8.patch177
-rw-r--r--pkgs/development/compilers/gcc/struct-ucontext-libjava.patch33
-rw-r--r--pkgs/development/compilers/gcc/struct-ucontext.patch190
-rw-r--r--pkgs/development/compilers/gerbil/default.nix14
-rw-r--r--pkgs/development/compilers/ghc/6.10.2-binary.nix95
-rw-r--r--pkgs/development/compilers/ghc/6.10.4.nix1
-rw-r--r--pkgs/development/compilers/ghc/7.0.4-binary.nix111
-rw-r--r--pkgs/development/compilers/ghc/7.10.2.nix4
-rw-r--r--pkgs/development/compilers/ghc/7.10.3.nix4
-rw-r--r--pkgs/development/compilers/ghc/7.2.2.nix1
-rw-r--r--pkgs/development/compilers/ghc/7.4.2-binary.nix90
-rw-r--r--pkgs/development/compilers/ghc/7.6.3.nix2
-rw-r--r--pkgs/development/compilers/ghc/8.0.2.nix4
-rw-r--r--pkgs/development/compilers/ghc/8.2.1.nix24
-rw-r--r--pkgs/development/compilers/ghc/8.2.2.nix (renamed from pkgs/development/compilers/ghc/8.0.1.nix)96
-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.nix4
-rw-r--r--pkgs/development/compilers/ghcjs/base.nix7
-rw-r--r--pkgs/development/compilers/ghcjs/default.nix1
-rw-r--r--pkgs/development/compilers/ghcjs/ghcjs-head.patch86
-rw-r--r--pkgs/development/compilers/ghcjs/head.nix18
-rw-r--r--pkgs/development/compilers/ghcjs/head_shims.nix4
-rw-r--r--pkgs/development/compilers/ghcjs/head_stage2.nix552
-rw-r--r--pkgs/development/compilers/ghcjs/node-packages-generated.nix943
-rw-r--r--pkgs/development/compilers/ghcjs/node-packages.json1
-rw-r--r--pkgs/development/compilers/ghcjs/stage2.nix6
-rw-r--r--pkgs/development/compilers/ghdl/default.nix2
-rw-r--r--pkgs/development/compilers/gnu-smalltalk/default.nix3
-rw-r--r--pkgs/development/compilers/go/1.8.nix4
-rw-r--r--pkgs/development/compilers/go/1.9.nix187
-rw-r--r--pkgs/development/compilers/go/remove-test-pie-1.9.patch26
-rw-r--r--pkgs/development/compilers/go/remove-tools-1.9.patch35
-rw-r--r--pkgs/development/compilers/go/ssl-cert-file-1.9.patch80
-rw-r--r--pkgs/development/compilers/gwt/2.4.0.nix7
-rw-r--r--pkgs/development/compilers/halvm/2.4.0.nix9
-rw-r--r--pkgs/development/compilers/haxe/default.nix4
-rw-r--r--pkgs/development/compilers/hhvm/default.nix31
-rw-r--r--pkgs/development/compilers/hhvm/flexible-array-members-gcc6.patch20
-rw-r--r--pkgs/development/compilers/ispc/default.nix12
-rw-r--r--pkgs/development/compilers/jetbrains-jdk/default.nix80
-rw-r--r--pkgs/development/compilers/jhc/default.nix1
-rw-r--r--pkgs/development/compilers/julia/0.6.nix191
-rw-r--r--pkgs/development/compilers/kotlin/default.nix4
-rw-r--r--pkgs/development/compilers/ldc/default.nix103
-rw-r--r--pkgs/development/compilers/llvm/3.4/llvm.nix21
-rw-r--r--pkgs/development/compilers/llvm/3.5/libc++/default.nix6
-rw-r--r--pkgs/development/compilers/llvm/3.5/libc++/xlocale-glibc-2.26.patch17
-rw-r--r--pkgs/development/compilers/llvm/3.5/llvm.nix27
-rw-r--r--pkgs/development/compilers/llvm/3.7/default.nix30
-rw-r--r--pkgs/development/compilers/llvm/3.7/libc++/default.nix2
-rw-r--r--pkgs/development/compilers/llvm/3.7/libc++/xlocale-glibc-2.26.patch17
-rw-r--r--pkgs/development/compilers/llvm/3.7/llvm.nix17
-rw-r--r--pkgs/development/compilers/llvm/3.8/default.nix29
-rw-r--r--pkgs/development/compilers/llvm/3.8/libc++/default.nix5
-rw-r--r--pkgs/development/compilers/llvm/3.8/llvm.nix24
-rw-r--r--pkgs/development/compilers/llvm/3.9/default.nix29
-rw-r--r--pkgs/development/compilers/llvm/3.9/libc++/default.nix5
-rw-r--r--pkgs/development/compilers/llvm/3.9/libc++/xlocale-glibc-2.26.patch19
-rw-r--r--pkgs/development/compilers/llvm/3.9/llvm.nix27
-rw-r--r--pkgs/development/compilers/llvm/4/default.nix36
-rw-r--r--pkgs/development/compilers/llvm/4/libc++/default.nix8
-rw-r--r--pkgs/development/compilers/llvm/4/libc++/xlocale-glibc-2.26.patch19
-rw-r--r--pkgs/development/compilers/llvm/4/llvm.nix29
-rw-r--r--pkgs/development/compilers/llvm/5/clang/default.nix97
-rw-r--r--pkgs/development/compilers/llvm/5/clang/purity.patch30
-rw-r--r--pkgs/development/compilers/llvm/5/compiler-rt-codesign.patch155
-rw-r--r--pkgs/development/compilers/llvm/5/default.nix81
-rw-r--r--pkgs/development/compilers/llvm/5/libc++/default.nix44
-rw-r--r--pkgs/development/compilers/llvm/5/libc++/setup-hook.sh3
-rw-r--r--pkgs/development/compilers/llvm/5/libc++abi.nix47
-rw-r--r--pkgs/development/compilers/llvm/5/lld.nix33
-rw-r--r--pkgs/development/compilers/llvm/5/lldb.nix51
-rw-r--r--pkgs/development/compilers/llvm/5/llvm-outputs.patch26
-rw-r--r--pkgs/development/compilers/llvm/5/llvm.nix155
-rw-r--r--pkgs/development/compilers/llvm/5/openmp.nix26
-rw-r--r--pkgs/development/compilers/microscheme/default.nix6
-rw-r--r--pkgs/development/compilers/mono/llvm.nix4
-rw-r--r--pkgs/development/compilers/nasm/default.nix16
-rw-r--r--pkgs/development/compilers/neko/default.nix3
-rw-r--r--pkgs/development/compilers/neko/xlocale-fix.patch59
-rw-r--r--pkgs/development/compilers/nim/default.nix4
-rw-r--r--pkgs/development/compilers/obliv-c/default.nix17
-rw-r--r--pkgs/development/compilers/ocaml/4.06.nix9
-rw-r--r--pkgs/development/compilers/opa/default.nix2
-rw-r--r--pkgs/development/compilers/openjdk/8.nix51
-rw-r--r--pkgs/development/compilers/openjdk/9.nix262
-rw-r--r--pkgs/development/compilers/openjdk/fix-java-home-jdk9.patch14
-rw-r--r--pkgs/development/compilers/openjdk/read-truststore-from-env-jdk9.patch20
-rw-r--r--pkgs/development/compilers/openjdk/swing-use-gtk-jdk9.patch26
-rw-r--r--pkgs/development/compilers/oraclejdk/jdk8cpu-linux.nix6
-rw-r--r--pkgs/development/compilers/oraclejdk/jdk8psu-linux.nix6
-rw-r--r--pkgs/development/compilers/oraclejdk/jdk9-linux.nix175
-rw-r--r--pkgs/development/compilers/orc/default.nix6
-rw-r--r--pkgs/development/compilers/picat/default.nix1
-rw-r--r--pkgs/development/compilers/ponyc/default.nix6
-rw-r--r--pkgs/development/compilers/ponyc/pony-stable.nix6
-rw-r--r--pkgs/development/compilers/purescript/psc-package/default.nix4
-rw-r--r--pkgs/development/compilers/rdmd/default.nix28
-rw-r--r--pkgs/development/compilers/reason/default.nix44
-rw-r--r--pkgs/development/compilers/rust/beta.nix39
-rw-r--r--pkgs/development/compilers/rust/bootstrap.nix30
-rw-r--r--pkgs/development/compilers/rust/cargo.nix25
-rw-r--r--pkgs/development/compilers/rust/default.nix15
-rw-r--r--pkgs/development/compilers/rust/nightly.nix36
-rw-r--r--pkgs/development/compilers/rust/nightlyBin.nix23
-rw-r--r--pkgs/development/compilers/rust/patches/0001-Disable-fragile-tests-libstd-net-tcp-on-Darwin-Linux.patch (renamed from pkgs/development/compilers/rust/patches/darwin-disable-fragile-tcp-tests.patch)31
-rw-r--r--pkgs/development/compilers/rust/patches/disable-lockfile-check-beta.patch25
-rw-r--r--pkgs/development/compilers/rust/patches/disable-lockfile-check-nightly.patch25
-rwxr-xr-xpkgs/development/compilers/rust/print-hashes.sh30
-rw-r--r--pkgs/development/compilers/rust/rustc.nix17
-rw-r--r--pkgs/development/compilers/sbcl/1.2.0.nix84
-rw-r--r--pkgs/development/compilers/sbcl/1.3.12.nix104
-rw-r--r--pkgs/development/compilers/sbcl/default.nix17
-rw-r--r--pkgs/development/compilers/scala/default.nix4
-rw-r--r--pkgs/development/compilers/shaderc/default.nix1
-rw-r--r--pkgs/development/compilers/solc/default.nix20
-rw-r--r--pkgs/development/compilers/souffle/default.nix3
-rw-r--r--pkgs/development/compilers/souper/default.nix4
-rw-r--r--pkgs/development/compilers/swift/default.nix7
-rw-r--r--pkgs/development/compilers/teyjus/default.nix4
-rw-r--r--pkgs/development/compilers/tinycc/default.nix6
-rw-r--r--pkgs/development/compilers/urweb/default.nix8
-rw-r--r--pkgs/development/compilers/vala/default.nix18
-rw-r--r--pkgs/development/compilers/yosys/default.nix26
-rw-r--r--pkgs/development/compilers/zig/default.nix34
-rw-r--r--pkgs/development/compilers/zulu/8.nix82
-rw-r--r--pkgs/development/compilers/zulu/default.nix21
170 files changed, 5692 insertions, 3430 deletions
diff --git a/pkgs/development/compilers/abcl/default.nix b/pkgs/development/compilers/abcl/default.nix
index 678cdcc22ccf..c48b36e5aba5 100644
--- a/pkgs/development/compilers/abcl/default.nix
+++ b/pkgs/development/compilers/abcl/default.nix
@@ -2,11 +2,11 @@
 stdenv.mkDerivation rec {
   name = "${pname}-${version}";
   pname = "abcl";
-  version = "1.4.0";
+  version = "1.5.0";
   # or fetchFromGitHub(owner,repo,rev) or fetchgit(rev)
   src = fetchurl {
     url = "https://common-lisp.net/project/armedbear/releases/${version}/${pname}-src-${version}.tar.gz";
-    sha256 = "1y4nixm1459ch6226ikdilcsf91c2rg1d82cqqmcn24kfjl1m62i";
+    sha256 = "1hhvcg050nfpjbdmskc1cv2j38qi6qfl77a61b5cxx576kbff3lj";
   };
   configurePhase = ''
     mkdir nix-tools
diff --git a/pkgs/development/compilers/arachne-pnr/default.nix b/pkgs/development/compilers/arachne-pnr/default.nix
index 52a3b485d91e..7db75d129781 100644
--- a/pkgs/development/compilers/arachne-pnr/default.nix
+++ b/pkgs/development/compilers/arachne-pnr/default.nix
@@ -2,19 +2,19 @@
 
 stdenv.mkDerivation rec {
   name = "arachne-pnr-${version}";
-  version = "2016.08.18";
+  version = "2017.11.05";
 
   src = fetchFromGitHub {
-    owner = "cseed";
-    repo = "arachne-pnr";
-    rev = "52e69ed207342710080d85c7c639480e74a021d7";
-    sha256 = "15bdw5yxj76lxrwksp6liwmr6l1x77isf4bs50ys9rsnmiwh8c3w";
+    owner  = "cseed";
+    repo   = "arachne-pnr";
+    rev    = "1e81432830c75c505c76e419619f605a6c4c7583";
+    sha256 = "0lzblmi1klbsmd32h8nh027npm1z1a199lng13lcrqwr17lhb7my";
   };
 
-  preBuild = ''
-    makeFlags="DESTDIR=$out $makeFlags"
-  '';
-  makeFlags = "ICEBOX=${icestorm}/share/icebox";
+  enableParallelBuilding = true;
+  makeFlags =
+    [ "PREFIX=$(out)" "ICEBOX=${icestorm}/share/icebox"
+    ];
 
   meta = {
     description = "Place and route tool for FPGAs";
@@ -29,8 +29,8 @@ stdenv.mkDerivation rec {
       the IceStorm [2] icepack command.
     '';
     homepage = https://github.com/cseed/arachne-pnr;
-    license = stdenv.lib.licenses.gpl2;
-    maintainers = [ stdenv.lib.maintainers.shell ];
+    license = stdenv.lib.licenses.mit;
+    maintainers = with stdenv.lib.maintainers; [ shell thoughtpolice ];
     platforms = stdenv.lib.platforms.linux;
   };
 }
diff --git a/pkgs/development/compilers/avian/default.nix b/pkgs/development/compilers/avian/default.nix
index c2a2b93fc0c5..3d58e75200c8 100644
--- a/pkgs/development/compilers/avian/default.nix
+++ b/pkgs/development/compilers/avian/default.nix
@@ -32,5 +32,6 @@ stdenv.mkDerivation rec {
     homepage = https://readytalk.github.io/avian/;
     license = stdenv.lib.licenses.isc;
     platforms = stdenv.lib.platforms.all;
+    maintainers = [ stdenv.lib.maintainers.earldouglas ];
   };
 }
diff --git a/pkgs/development/compilers/avra/default.nix b/pkgs/development/compilers/avra/default.nix
index 706659194005..88a34bd6fd6e 100644
--- a/pkgs/development/compilers/avra/default.nix
+++ b/pkgs/development/compilers/avra/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
   '';
 
   meta = with stdenv.lib; {
-    description = "Assember for the Atmel AVR microcontroller family";
+    description = "Assembler for the Atmel AVR microcontroller family";
     homepage = http://avra.sourceforge.net/;
     license = licenses.gpl2Plus;
     platforms = platforms.all;
diff --git a/pkgs/development/compilers/boo/default.nix b/pkgs/development/compilers/boo/default.nix
index 5fa88ab87e9e..d27f498842e3 100644
--- a/pkgs/development/compilers/boo/default.nix
+++ b/pkgs/development/compilers/boo/default.nix
@@ -16,8 +16,9 @@ in stdenv.mkDerivation rec {
     sha256 = "174abdwfpq8i3ijx6bwqll16lx7xwici374rgsbymyk8g8mla094";
   };
 
+  nativeBuildInputs = [ pkgconfig ];
   buildInputs = [
-    pkgconfig mono makeWrapper nant shared_mime_info gtksourceview
+    mono makeWrapper nant shared_mime_info gtksourceview
     gtk2
   ];
 
diff --git a/pkgs/development/compilers/ccl/default.nix b/pkgs/development/compilers/ccl/default.nix
index 7ece0ffda533..ed7e0357d74c 100644
--- a/pkgs/development/compilers/ccl/default.nix
+++ b/pkgs/development/compilers/ccl/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchsvn, gcc, glibc, m4, coreutils }:
+{ stdenv, fetchsvn, fetchpatch, gcc, glibc, m4, coreutils }:
 
 let
   options = rec {
@@ -39,12 +39,18 @@ stdenv.mkDerivation rec {
     sha256 = cfg.sha256;
   };
 
+  patches = fetchpatch {
+    name = "ccl-1.11-glibc-2.26.patch";
+    url = https://patch-diff.githubusercontent.com/raw/Clozure/ccl/pull/80.patch;
+    sha256 = "02v6287w0nppfpvkn9dyd5rvq2zkgd47ia9gs17hrww2hgzr6agd";
+  };
+
   buildInputs = [ gcc glibc m4 ];
 
   CCL_RUNTIME = cfg.runtime;
   CCL_KERNEL = cfg.kernel;
 
-  patchPhase = ''
+  postPatch = ''
     substituteInPlace lisp-kernel/${CCL_KERNEL}/Makefile \
       --replace "svnversion" "echo ${revision}" \
       --replace "/bin/rm"    "${coreutils}/bin/rm" \
diff --git a/pkgs/development/compilers/chez/default.nix b/pkgs/development/compilers/chez/default.nix
index e4ceb40cad6e..b85d32326a1a 100644
--- a/pkgs/development/compilers/chez/default.nix
+++ b/pkgs/development/compilers/chez/default.nix
@@ -2,13 +2,13 @@
 
 stdenv.mkDerivation rec {
   name    = "chez-scheme-${version}";
-  version = "9.4-${dver}";
-  dver    = "20160507";
+  version = "9.5-${dver}";
+  dver    = "20171012";
 
   src = fetchgit {
     url    = "https://github.com/cisco/chezscheme.git";
-    rev    = "65df1d1f7c37f5b5a93cd7e5b475dda9dbafe03c";
-    sha256 = "1b273il3njnn04z55w1hnygvcqllc6p5qg9mcwh10w39fwsd8fbs";
+    rev    = "adb3b7bb22ddaa1ba91b98b6f4a647427c3a4d9b";
+    sha256 = "0hiynf7g0q77ipqxjsqdm2zb0m15bl1hhp615fn3i2hv0qz5a4xr";
     fetchSubmodules = true;
   };
 
@@ -24,7 +24,7 @@ stdenv.mkDerivation rec {
   */
   patchPhase = ''
     substituteInPlace ./configure \
-      --replace "git submodule init && git submodule update || exit 1" ""
+      --replace "git submodule init && git submodule update || exit 1" "true"
 
     substituteInPlace ./workarea \
       --replace "/bin/ln" "${coreutils}/bin/ln" \
diff --git a/pkgs/development/compilers/clasp/default.nix b/pkgs/development/compilers/clasp/default.nix
new file mode 100644
index 000000000000..6bfb71a9627d
--- /dev/null
+++ b/pkgs/development/compilers/clasp/default.nix
@@ -0,0 +1,74 @@
+{stdenv, fetchFromGitHub
+  , llvmPackages
+  , cmake, boehmgc, gmp, zlib, ncurses, boost
+  , waf, python, git, sbcl
+}:
+stdenv.mkDerivation rec {
+  name = "${pname}-${version}";
+  pname = "clasp";
+  version = "0.4.99.20170801";
+
+  src = fetchFromGitHub {
+    owner = "drmeister";
+    repo = "clasp";
+    rev = "525ce1cffff39311e3e7df6d0b71fa267779bdf5";
+    sha256 = "1jqya04wybgxnski341p5sycy2gysxad0s5q8d59z0f6ckj3v8k1";
+    fetchSubmodules = true;
+  };
+
+  nativeBuildInputs = [ cmake python git sbcl ];
+
+  buildInputs = with llvmPackages; (
+    builtins.map (x: stdenv.lib.overrideDerivation x
+         (x: {NIX_CFLAGS_COMPILE= (x.NIX_CFLAGS_COMPILE or "") + " -frtti"; }))
+      [ llvm clang clang-unwrapped clang ]) ++
+  [
+    gmp zlib ncurses
+    boost boehmgc
+    (boost.override {enableStatic = true; enableShared = false;})
+    (stdenv.lib.overrideDerivation boehmgc
+      (x: {configureFlags = (x.configureFlags or []) ++ ["--enable-static"];}))
+  ];
+
+  NIX_CFLAGS_COMPILE = " -frtti ";
+
+  configurePhase = ''
+    runHook preConfigure
+
+    export CXX=clang++
+    export CC=clang
+
+    echo "
+      INSTALL_PATH_PREFIX = '$out'
+    " | sed -e 's/^ *//' > wscript.config
+
+    python ./waf configure update_submodules
+
+    runHook postConfigure
+  '';
+
+  buildPhase = ''
+    runHook preBuild
+
+    python ./waf build_cboehm
+
+    runHook postBuild
+  '';
+
+  installPhase = ''
+    runHook preInstall
+
+    python ./waf install_cboehm
+
+    runHook postInstall
+  '';
+
+  meta = {
+    inherit version;
+    description = ''A Common Lisp implementation based on LLVM with C++ integration'';
+    license = stdenv.lib.licenses.lgpl21Plus ;
+    maintainers = [stdenv.lib.maintainers.raskin];
+    platforms = stdenv.lib.platforms.linux;
+    homepage = "https://github.com/drmeister/clasp";
+  };
+}
diff --git a/pkgs/development/compilers/closure/default.nix b/pkgs/development/compilers/closure/default.nix
index 86e04b491e57..8d1b06f52b70 100644
--- a/pkgs/development/compilers/closure/default.nix
+++ b/pkgs/development/compilers/closure/default.nix
@@ -1,31 +1,30 @@
-{ stdenv, fetchurl, jre, gnutar, bash }:
+{ stdenv, fetchurl, jre, makeWrapper }:
 
 stdenv.mkDerivation rec {
   name = "closure-compiler-${version}";
-  version = "20170218";
+  version = "20170910";
 
   src = fetchurl {
-    url = "http://dl.google.com/closure-compiler/compiler-${version}.tar.gz";
-    sha256 = "06snabmpy07x4xm8d1xgq5dfzbjli10xkxk3nx9jms39zkj493cd";
+    url = "https://dl.google.com/closure-compiler/compiler-${version}.tar.gz";
+    sha256 = "0znzsks8ql9qajhcjzfkhmnpz8zs6b8cji04fhivyq973jpxxrak";
   };
 
-  phases = [ "installPhase" ];
+  sourceRoot = ".";
 
-  buildInputs = [ gnutar ];
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ jre ];
 
   installPhase = ''
     mkdir -p $out/share/java $out/bin
-    tar -xzf $src
-    cp -r closure-compiler-v${version}.jar $out/share/java/
-    echo "#!${bash}/bin/bash" > $out/bin/closure-compiler
-    echo "${jre}/bin/java -jar $out/share/java/closure-compiler-v${version}.jar \"\$@\"" >> $out/bin/closure-compiler
-    chmod +x $out/bin/closure-compiler
+    cp closure-compiler-v${version}.jar $out/share/java
+    makeWrapper ${jre}/bin/java $out/bin/closure-compiler \
+      --add-flags "-jar $out/share/java/closure-compiler-v${version}.jar"
   '';
 
-  meta = {
+  meta = with stdenv.lib; {
     description = "A tool for making JavaScript download and run faster";
     homepage = https://developers.google.com/closure/compiler/;
-    license = stdenv.lib.licenses.asl20;
-    platforms = stdenv.lib.platforms.unix;
+    license = licenses.asl20;
+    platforms = platforms.all;
   };
 }
diff --git a/pkgs/development/compilers/compcert/default.nix b/pkgs/development/compilers/compcert/default.nix
index f519776b6891..a12f1c42ba61 100644
--- a/pkgs/development/compilers/compcert/default.nix
+++ b/pkgs/development/compilers/compcert/default.nix
@@ -7,11 +7,11 @@ assert lib.versionAtLeast ocamlPackages.ocaml.version "4.02";
 
 stdenv.mkDerivation rec {
   name    = "compcert-${version}";
-  version = "3.0.1";
+  version = "3.1";
 
   src = fetchurl {
     url    = "http://compcert.inria.fr/release/${name}.tgz";
-    sha256 = "0dgrj26dzdy4n3s9b5hwc6lm54vans1v4qx9hdp1q8w1qqcdriq9";
+    sha256 = "0irfwlw2chalp0g2gw0makc699hn3z37sha1a239p9d90mzx03cx";
   };
 
   buildInputs = [ coq ]
@@ -20,6 +20,7 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = true;
 
   configurePhase = ''
+    substituteInPlace VERSION --replace '3.0.1' '3.1'
     substituteInPlace ./configure --replace '{toolprefix}gcc' '{toolprefix}cc'
     ./configure -clightgen -prefix $out -toolprefix ${tools}/bin/ '' +
     (if stdenv.isDarwin then "x86_64-macosx" else "x86_64-linux");
@@ -39,7 +40,7 @@ stdenv.mkDerivation rec {
   meta = with stdenv.lib; {
     description = "Formally verified C compiler";
     homepage    = "http://compcert.inria.fr";
-    license     = licenses.inria;
+    license     = licenses.inria-compcert;
     platforms   = platforms.linux ++
                   platforms.darwin;
     maintainers = with maintainers; [ thoughtpolice jwiegley vbgl ];
diff --git a/pkgs/development/compilers/coreclr/default.nix b/pkgs/development/compilers/coreclr/default.nix
index b619bf6ce208..17d91f36875c 100644
--- a/pkgs/development/compilers/coreclr/default.nix
+++ b/pkgs/development/compilers/coreclr/default.nix
@@ -1,5 +1,6 @@
 { stdenv
 , fetchFromGitHub
+, fetchpatch
 , which
 , cmake
 , clang
@@ -12,21 +13,29 @@
 , lttng-ust
 , liburcu
 , libuuid
-, ed
+, libkrb5
 , debug ? false
 }:
 
 stdenv.mkDerivation rec {
   name = "coreclr-${version}";
-  version = "1.0.4";
+  version = "2.0.0";
 
   src = fetchFromGitHub {
     owner  = "dotnet";
     repo   = "coreclr";
     rev    = "v${version}";
-    sha256 = "1wpig71q0kh2yrq162d32x00zlwrrs1wymkgijh49cqkn4cwkh91";
+    sha256 = "16z58ix8kmk8csfy5qsqz8z30czhrap2vb8s8vdflmbcfnq31jcw";
   };
 
+  patches = [
+    (fetchpatch {
+      # glibc 2.26
+      url = https://github.com/dotnet/coreclr/commit/a8f83b615708c529b112898e7d2fbc3f618b26ee.patch;
+      sha256 = "047ph5gip4z2h7liwdxsmpnlaq0sd3hliaw4nyqjp647m80g3ffq";
+    })
+  ];
+
   buildInputs = [
     which
     cmake
@@ -41,67 +50,43 @@ stdenv.mkDerivation rec {
     lttng-ust
     liburcu
     libuuid
-    ed
+    libkrb5
   ];
 
   configurePhase = ''
-    # Prevent clang-3.5 (rather than just clang) from being selected as the compiler as that's
-    # not wrapped
-    # substituteInPlace src/pal/tools/gen-buildsys-clang.sh --replace "which \"clang-\$" "which \"clang-DoNotFindThisOne\$"
-
-    patchShebangs build.sh
-    patchShebangs src/pal/tools/gen-buildsys-clang.sh
-
-    # See https://github.com/dotnet/coreclr/issues/7573#issuecomment-253081323
-    ed -v ./src/pal/src/include/pal/palinternal.h << EOF
-    /^#undef memcpy
-    -1
-    d
-    +1
-    d
-    w
-    EOF
+    # override to avoid cmake running
+    patchShebangs .
   '';
 
   BuildArch = if stdenv.is64bit then "x64" else "x86";
   BuildType = if debug then "Debug" else "Release";
 
-  hardeningDisable = [ "strictoverflow" "format" ];
-  NIX_CFLAGS_COMPILE = [
-    "-Wno-error=unused-result" "-Wno-error=delete-non-virtual-dtor"
-    "-Wno-error=null-dereference"
+  hardeningDisable = [
+    "strictoverflow"
+    "format"
   ];
 
   buildPhase = ''
+    runHook preBuild
     ./build.sh $BuildArch $BuildType
-
-    # Try to make some sensible hierarchy out of the output
-    pushd bin/Product/Linux.$BuildArch.$BuildType
-    mkdir lib2
-    mv *.so *.so.dbg lib2
-    mv bin lib3
-    mkdir lib4
-    mv Loader lib4
-    mv inc include
-    mv gcinfo include
-    mkdir bin
-    mkdir -p share/doc
-    mv sosdocsunix.txt share/doc
-    for f in * ; do test -f $f && mv -v $f bin; done
-    popd
+    runHook postBuild
   '';
 
   installPhase = ''
-    mkdir -p $out
-    cp -rv bin/Product/Linux.$BuildArch.$BuildType/* $out
+    runHook preInstall
+    mkdir -p $out/share/dotnet $out/bin
+    cp -r bin/Product/Linux.$BuildArch.$BuildType/* $out/share/dotnet
+    for cmd in coreconsole corerun createdump crossgen ilasm ildasm mcs superpmi; do
+      ln -s $out/share/dotnet/$cmd $out/bin/$cmd
+    done
+    runHook postInstall
   '';
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://dotnet.github.io/core/;
     description = ".NET is a general purpose development platform";
     platforms = [ "x86_64-linux" ];
-    maintainers = with stdenv.lib.maintainers; [ obadz ];
-    license = stdenv.lib.licenses.mit;
-    broken = true; # CoreCLR has proven to be very difficult to package. PRs welcome if someone wants to shave that yak.
+    maintainers = with maintainers; [ kuznero ];
+    license = licenses.mit;
   };
 }
diff --git a/pkgs/development/compilers/crystal/default.nix b/pkgs/development/compilers/crystal/default.nix
index 62a504ef9668..6b817d06553e 100644
--- a/pkgs/development/compilers/crystal/default.nix
+++ b/pkgs/development/compilers/crystal/default.nix
@@ -1,81 +1,71 @@
-{ stdenv, fetchurl, boehmgc, libatomic_ops, pcre, libevent, libiconv, llvm_4, makeWrapper }:
+{ stdenv, fetchurl, boehmgc, libatomic_ops, pcre, libevent, libiconv, llvm, makeWrapper }:
 
 stdenv.mkDerivation rec {
-  version = "0.23.0";
-  name = "crystal-${version}-1";
-  arch =
-    {
-      "x86_64-linux" = "linux-x86_64";
-      "i686-linux" = "linux-i686";
-      "x86_64-darwin" = "darwin-x86_64";
-    }."${stdenv.system}" or (throw "system ${stdenv.system} not supported");
-
-  prebuiltBinary = fetchurl {
-    url = "https://github.com/crystal-lang/crystal/releases/download/${version}/crystal-${version}-1-${arch}.tar.gz";
-    sha256 =
-      {
-        "x86_64-linux" = "0nhs7swbll8hrk15kmmywngkhij80x62axiskb1gjmiwvzhlh0qx";
-        "i686-linux" = "03xp8d3lqflzzm26lpdn4yavj87qzgd6xyrqxp2pn9ybwrq8fx8a";
-        "x86_64-darwin" = "1prz6c1gs8z7dgpdy2id2mjn1c8f5p2bf9b39985bav448njbyjz";
-      }."${stdenv.system}" or (throw "system ${stdenv.system} not supported");
-  };
+  name = "crystal-${version}";
+  version = "0.23.1";
 
   src = fetchurl {
     url = "https://github.com/crystal-lang/crystal/archive/${version}.tar.gz";
-    sha256 = "05ymwmjkl1b4m888p725kybpiap5ag2vj8l07d59j02inm5r0rcv";
+    sha256 = "8cf1b9a4eab29fca2f779ea186ae18f7ce444ce189c621925fa1a0c61dd5ff55";
+  };
+
+  prebuiltName = "crystal-0.23.0-1";
+  prebuiltSrc = let arch = {
+    "x86_64-linux" = "linux-x86_64";
+    "i686-linux" = "linux-i686";
+    "x86_64-darwin" = "darwin-x86_64";
+  }."${stdenv.system}" or (throw "system ${stdenv.system} not supported");
+  in fetchurl {
+    url = "https://github.com/crystal-lang/crystal/releases/download/0.23.0/${prebuiltName}-${arch}.tar.gz";
+    sha256 = {
+      "x86_64-linux" = "0nhs7swbll8hrk15kmmywngkhij80x62axiskb1gjmiwvzhlh0qx";
+      "i686-linux" = "03xp8d3lqflzzm26lpdn4yavj87qzgd6xyrqxp2pn9ybwrq8fx8a";
+      "x86_64-darwin" = "1prz6c1gs8z7dgpdy2id2mjn1c8f5p2bf9b39985bav448njbyjz";
+    }."${stdenv.system}";
   };
 
+  srcs = [ src prebuiltSrc ];
+
   # crystal on Darwin needs libiconv to build
-  buildInputs = [
-    boehmgc libatomic_ops pcre libevent llvm_4 makeWrapper
+  libs = [
+    boehmgc libatomic_ops pcre libevent
   ] ++ stdenv.lib.optionals stdenv.isDarwin [
     libiconv
   ];
 
-  libPath = stdenv.lib.makeLibraryPath ([
-    boehmgc libatomic_ops pcre libevent
-  ] ++ stdenv.lib.optionals stdenv.isDarwin [
-    libiconv
-  ]);
+  nativeBuildInputs = [ makeWrapper ];
 
-  unpackPhase = ''
-    tar zxf ${src}
-    tar zxf ${prebuiltBinary}
-  '';
+  buildInputs = libs ++ [ llvm ];
+
+  libPath = stdenv.lib.makeLibraryPath libs;
 
-  sourceRoot = ".";
+  sourceRoot = "${name}";
 
   fixPrebuiltBinary = if stdenv.isDarwin then ''
-    wrapProgram $(pwd)/crystal-${version}-1/embedded/bin/crystal \
+    wrapProgram ../${prebuiltName}/embedded/bin/crystal \
         --suffix DYLD_LIBRARY_PATH : $libPath
   ''
   else ''
     patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
-      crystal-${version}-1/embedded/bin/crystal
+      ../${prebuiltName}/embedded/bin/crystal
     patchelf --set-rpath ${ stdenv.lib.makeLibraryPath [ stdenv.cc.cc ] } \
-      crystal-${version}-1/embedded/bin/crystal
+      ../${prebuiltName}/embedded/bin/crystal
   '';
 
-  buildPhase = ''
-    # patch the script which launches the prebuilt compiler
-    substituteInPlace $(pwd)/crystal-${version}-1/bin/crystal --replace \
-      "/usr/bin/env bash" "${stdenv.shell}"
-    substituteInPlace $(pwd)/crystal-${version}/bin/crystal --replace \
-      "/usr/bin/env bash" "${stdenv.shell}"
-
+  preBuild = ''
+    patchShebangs bin/crystal
+    patchShebangs ../${prebuiltName}/bin/crystal
     ${fixPrebuiltBinary}
-
-    cd crystal-${version}
-    make release=1 PATH="../crystal-${version}-1/bin:$PATH"
-    make doc
+    export PATH="$(pwd)/../${prebuiltName}/bin:$PATH"
   '';
 
+  makeFlags = [ "CRYSTAL_CONFIG_VERSION=${version}" "release=1" "all" "doc" ];
+
   installPhase = ''
     install -Dm755 .build/crystal $out/bin/crystal
     wrapProgram $out/bin/crystal \
         --suffix CRYSTAL_PATH : $out/lib/crystal \
         --suffix LIBRARY_PATH : $libPath
-
     install -dm755 $out/lib/crystal
     cp -r src/* $out/lib/crystal/
 
@@ -93,12 +83,13 @@ stdenv.mkDerivation rec {
 
   dontStrip = true;
 
+  enableParallelBuilding = true;
+
   meta = {
     description = "A compiled language with Ruby like syntax and type inference";
     homepage = https://crystal-lang.org/;
     license = stdenv.lib.licenses.asl20;
-    maintainers = with stdenv.lib.maintainers; [ mingchuan ];
+    maintainers = with stdenv.lib.maintainers; [ sifmelcara david50407 ];
     platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" ];
   };
 }
-
diff --git a/pkgs/development/compilers/cudatoolkit/default.nix b/pkgs/development/compilers/cudatoolkit/default.nix
index 0b219b804471..62b2e7c18508 100644
--- a/pkgs/development/compilers/cudatoolkit/default.nix
+++ b/pkgs/development/compilers/cudatoolkit/default.nix
@@ -1,30 +1,44 @@
-{ lib, stdenv, fetchurl, patchelf, perl, ncurses, expat, python27, zlib
+{ lib, stdenv, makeWrapper, fetchurl, requireFile, patchelf, perl, ncurses, expat, python27, zlib
+, gcc48, gcc49, gcc5, gcc6
 , xorg, gtk2, glib, fontconfig, freetype, unixODBC, alsaLib, glibc
 }:
 
 let
 
   common =
-    { version, url, sha256
+    args@{ gcc, version, sha256
+    , url ? ""
+    , name ? ""
+    , developerProgram ? false
     , python ? python27
     }:
 
     stdenv.mkDerivation rec {
       name = "cudatoolkit-${version}";
+      inherit (args) version;
 
       dontPatchELF = true;
       dontStrip = true;
 
       src =
-        if stdenv.system == "x86_64-linux" then
-          fetchurl {
-            inherit url sha256;
+        if developerProgram then
+          requireFile {
+            message = ''
+              This nix expression requires that ${args.name} is already part of the store.
+              Register yourself to NVIDIA Accelerated Computing Developer Program, retrieve the CUDA toolkit
+              at https://developer.nvidia.com/cuda-toolkit, and run the following command in the download directory:
+              nix-prefetch-url file://${args.name}
+            '';
+            inherit (args) name sha256;
           }
-        else throw "cudatoolkit does not support platform ${stdenv.system}";
+        else
+          fetchurl {
+            inherit (args) url sha256;
+          };
 
-      outputs = [ "out" "doc" ];
+      outputs = [ "out" "lib" "doc" ];
 
-      buildInputs = [ perl ];
+      nativeBuildInputs = [ perl makeWrapper ];
 
       runtimeDependencies = [
         ncurses expat python zlib glibc
@@ -37,8 +51,8 @@ let
       unpackPhase = ''
         sh $src --keep --noexec
         cd pkg/run_files
-        sh cuda-linux64-rel-${version}-*.run --keep --noexec
-        sh cuda-samples-linux-${version}-*.run --keep --noexec
+        sh cuda-linux*.run --keep --noexec
+        sh cuda-samples*.run --keep --noexec
         cd pkg
       '';
 
@@ -51,7 +65,11 @@ let
             patchelf \
               --set-interpreter "''$(cat $NIX_CC/nix-support/dynamic-linker)" $i
           fi
-          rpath2=$rpath:$lib/lib:$out/jre/lib/amd64/jli:$out/lib:$out/lib64:$out/nvvm/lib:$out/nvvm/lib64
+          if [[ $i =~ libcudart ]]; then
+            rpath2=
+          else
+            rpath2=$rpath:$lib/lib:$out/jre/lib/amd64/jli:$out/lib:$out/lib64:$out/nvvm/lib:$out/nvvm/lib64
+          fi
           patchelf --set-rpath $rpath2 --force-rpath $i
         done < <(find . -type f -print0)
       '';
@@ -80,18 +98,33 @@ let
         mkdir -p $out/nix-support
         echo "cmakeFlags+=' -DCUDA_TOOLKIT_ROOT_DIR=$out'" >> $out/nix-support/setup-hook
 
+        # Move some libraries to the lib output so that programs that
+        # depend on them don't pull in this entire monstrosity.
+        mkdir -p $lib/lib
+        mv -v $out/lib64/libcudart* $lib/lib/
+
         # Remove OpenCL libraries as they are provided by ocl-icd and driver.
         rm -f $out/lib64/libOpenCL*
 
+        # Set compiler for NVCC.
+        wrapProgram $out/bin/nvcc \
+          --prefix PATH : ${gcc}/bin
       '' + lib.optionalString (lib.versionOlder version "8.0") ''
         # Hack to fix building against recent Glibc/GCC.
         echo "NIX_CFLAGS_COMPILE+=' -D_FORCE_INLINES'" >> $out/nix-support/setup-hook
       '';
 
+      passthru = {
+        cc = gcc;
+        majorVersion =
+          let versionParts = lib.splitString "." version;
+          in "${lib.elemAt versionParts 0}.${lib.elemAt versionParts 1}";
+      };
+
       meta = with stdenv.lib; {
         description = "A compiler for NVIDIA GPUs, math libraries, and tools";
-        homepage = https://developer.nvidia.com/cuda-toolkit;
-        platforms = platforms.linux;
+        homepage = "https://developer.nvidia.com/cuda-toolkit";
+        platforms = [ "x86_64-linux" ];
         license = licenses.unfree;
       };
     };
@@ -100,32 +133,44 @@ in {
 
   cudatoolkit6 = common {
     version = "6.0.37";
-    url = http://developer.download.nvidia.com/compute/cuda/6_0/rel/installers/cuda_6.0.37_linux_64.run;
+    url = "http://developer.download.nvidia.com/compute/cuda/6_0/rel/installers/cuda_6.0.37_linux_64.run";
     sha256 = "991e436c7a6c94ec67cf44204d136adfef87baa3ded270544fa211179779bc40";
+    gcc = gcc48;
   };
 
   cudatoolkit65 = common {
     version = "6.5.19";
-    url = http://developer.download.nvidia.com/compute/cuda/6_5/rel/installers/cuda_6.5.19_linux_64.run;
+    url = "http://developer.download.nvidia.com/compute/cuda/6_5/rel/installers/cuda_6.5.19_linux_64.run";
     sha256 = "1x9zdmk8z784d3d35vr2ak1l4h5v4jfjhpxfi9fl9dvjkcavqyaj";
+    gcc = gcc48;
   };
 
   cudatoolkit7 = common {
     version = "7.0.28";
-    url = http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.28_linux.run;
+    url = "http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.28_linux.run";
     sha256 = "1km5hpiimx11jcazg0h3mjzk220klwahs2vfqhjavpds5ff2wafi";
+    gcc = gcc49;
   };
 
   cudatoolkit75 = common {
     version = "7.5.18";
-    url = http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda_7.5.18_linux.run;
+    url = "http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda_7.5.18_linux.run";
     sha256 = "1v2ylzp34ijyhcxyh5p6i0cwawwbbdhni2l5l4qm21s1cx9ish88";
+    gcc = gcc49;
   };
 
   cudatoolkit8 = common {
     version = "8.0.61";
-    url = https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run;
+    url = "https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run";
     sha256 = "1i4xrsqbad283qffvysn88w2pmxzxbbby41lw0j1113z771akv4w";
+    gcc = gcc5;
+  };
+
+  cudatoolkit9 = common {
+    version = "9.0.176";
+    url = "https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda_9.0.176_384.81_linux-run";
+    sha256 = "0308rmmychxfa4inb1ird9bpgfppgr9yrfg1qp0val5azqik91ln";
+    gcc = gcc6;
   };
 
 }
diff --git a/pkgs/development/compilers/dale/default.nix b/pkgs/development/compilers/dale/default.nix
index fae1c1d1b40d..8bae6e2363f6 100644
--- a/pkgs/development/compilers/dale/default.nix
+++ b/pkgs/development/compilers/dale/default.nix
@@ -20,7 +20,8 @@ in stdenv.mkDerivation {
     sha256 = "0dc5cjahv7lzlp92hidlh83rwgrpgb6xz2pnba2pm5xrv2pnsskl";
   };
 
-  buildInputs = [ cmake pkgconfig libffi llvm_35 ]
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ cmake libffi llvm_35 ]
              ++ stdenv.lib.optional doCheck perl;
 
   patches = [ ./link-llvm.patch ];
diff --git a/pkgs/development/compilers/dmd/2.067.1.nix b/pkgs/development/compilers/dmd/2.067.1.nix
index 3cf530e9e5e8..6a3cddbd2e50 100644
--- a/pkgs/development/compilers/dmd/2.067.1.nix
+++ b/pkgs/development/compilers/dmd/2.067.1.nix
@@ -17,18 +17,21 @@ stdenv.mkDerivation rec {
     repo = "dmd";
     rev = "v${version}";
     sha256 = "0fm29lg8axfmzdaj0y6vg70lhwb5d9rv4aavnvdd15xjschinlcz";
+    name = "dmd-v${version}-src";
   })
   (fetchFromGitHub {
     owner = "dlang";
     repo = "druntime";
     rev = "v${version}";
     sha256 = "1n2qfw9kmnql0fk2nxikispqs7vh85nhvyyr00fk227n9lgnqf02";
+    name = "druntime-v${version}-src";
   })
   (fetchFromGitHub {
     owner = "dlang";
     repo = "phobos";
     rev = "v${version}";
     sha256 = "0fywgds9xvjcgnqxmpwr67p3wi2m535619pvj159cgwv5y0nr3p1";
+    name = "phobos-v${version}-src";
   })
   ];
 
@@ -43,6 +46,7 @@ stdenv.mkDerivation rec {
   # Compile with PIC to prevent colliding modules with binutils 2.28.
   # https://issues.dlang.org/show_bug.cgi?id=17375
   usePIC = "-fPIC";
+  ROOT_HOME_DIR = "$(echo ~root)";
 
   postPatch = ''
       # Ugly hack so the dlopen call has a chance to succeed.
@@ -67,19 +71,23 @@ stdenv.mkDerivation rec {
           --replace g++ $CXX
   ''
 
-    + stdenv.lib.optionalString stdenv.hostPlatform.isLinux ''
-        substituteInPlace dmd/src/root/port.c \
-          --replace "#include <bits/mathdef.h>" "#include <complex.h>"
-    ''
+  + stdenv.lib.optionalString stdenv.hostPlatform.isLinux ''
+      substituteInPlace dmd/src/root/port.c \
+        --replace "#include <bits/mathdef.h>" "#include <complex.h>"
 
-    + stdenv.lib.optionalString stdenv.hostPlatform.isDarwin ''
-        substituteInPlace dmd/src/posix.mak \
-            --replace MACOSX_DEPLOYMENT_TARGET MACOSX_DEPLOYMENT_TARGET_
+      # See https://github.com/NixOS/nixpkgs/issues/29443
+      substituteInPlace phobos/std/path.d \
+          --replace "\"/root" "\"${ROOT_HOME_DIR}"
+  ''
+
+  + stdenv.lib.optionalString stdenv.hostPlatform.isDarwin ''
+      substituteInPlace dmd/src/posix.mak \
+          --replace MACOSX_DEPLOYMENT_TARGET MACOSX_DEPLOYMENT_TARGET_
 
-        # Was not able to compile on darwin due to "__inline_isnanl"
-        # being undefined.
-        substituteInPlace dmd/src/root/port.c --replace __inline_isnanl __inline_isnan
-    '';
+      # Was not able to compile on darwin due to "__inline_isnanl"
+      # being undefined.
+      substituteInPlace dmd/src/root/port.c --replace __inline_isnanl __inline_isnan
+  '';
 
   nativeBuildInputs = [ makeWrapper unzip which ];
   buildInputs = [ curl tzdata ];
@@ -96,7 +104,8 @@ stdenv.mkDerivation rec {
       cd ..
   '';
 
-  doCheck = true;
+  # disable check phase because some tests are not working with sandboxing
+  doCheck = false;
 
   checkPhase = ''
       cd dmd
diff --git a/pkgs/development/compilers/dmd/default.nix b/pkgs/development/compilers/dmd/default.nix
index 278a77f62903..938dd04904bf 100644
--- a/pkgs/development/compilers/dmd/default.nix
+++ b/pkgs/development/compilers/dmd/default.nix
@@ -1,6 +1,6 @@
 { stdenv, fetchFromGitHub
 , makeWrapper, unzip, which
-, curl, tzdata
+, curl, tzdata, gdb, darwin
 # Versions 2.070.2 and up require a working dmd compiler to build:
 , bootstrapDmd }:
 
@@ -14,18 +14,21 @@ stdenv.mkDerivation rec {
     repo = "dmd";
     rev = "v${version}";
     sha256 = "0kq6r8rcghvzk5jcphg89l85rg734s29bssd2rcw3fygx0k9a9k5";
+    name = "dmd-v${version}-src";
   })
   (fetchFromGitHub {
     owner = "dlang";
     repo = "druntime";
     rev = "v${version}";
     sha256 = "0idn2v1lmp7hl637g3i7pdfj9mjk4sclkz4cm77nl8873k2fhk8j";
+    name = "druntime-v${version}-src";
   })
   (fetchFromGitHub {
     owner = "dlang";
     repo = "phobos";
     rev = "v${version}";
     sha256 = "1a7q5fd15yspgs5plxgx54jyrcwgzlyw3rahmz04jd2s5h56dj04";
+    name = "phobos-v${version}-src";
   })
   ];
 
@@ -35,6 +38,10 @@ stdenv.mkDerivation rec {
       mv dmd-v${version}-src dmd
       mv druntime-v${version}-src druntime
       mv phobos-v${version}-src phobos
+
+      # Remove cppa test for now because it doesn't work.
+      rm dmd/test/runnable/cppa.d
+      rm dmd/test/runnable/extra-files/cppb.cpp
   '';
 
   # Compile with PIC to prevent colliding modules with binutils 2.28.
@@ -69,26 +76,32 @@ stdenv.mkDerivation rec {
             --replace MACOSX_DEPLOYMENT_TARGET MACOSX_DEPLOYMENT_TARGET_
     '';
 
-  nativeBuildInputs = [ bootstrapDmd makeWrapper unzip which ];
+  nativeBuildInputs = [ bootstrapDmd makeWrapper unzip which gdb ]
+
+  ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [
+    Foundation
+  ]);
+
   buildInputs = [ curl tzdata ];
 
   # Buid and install are based on http://wiki.dlang.org/Building_DMD
   buildPhase = ''
       cd dmd
-      make -f posix.mak INSTALL_DIR=$out
+      make -j$NIX_BUILD_CORES -f posix.mak INSTALL_DIR=$out
       ${
           let bits = builtins.toString stdenv.hostPlatform.parsed.cpu.bits;
           osname = if stdenv.hostPlatform.isDarwin then "osx" else stdenv.hostPlatform.parsed.kernel.name; in
           "export DMD=$PWD/generated/${osname}/release/${bits}/dmd"
       }
       cd ../druntime
-      make -f posix.mak PIC=${usePIC} INSTALL_DIR=$out DMD=$DMD
+      make -j$NIX_BUILD_CORES -f posix.mak PIC=${usePIC} INSTALL_DIR=$out DMD=$DMD
       cd ../phobos
-      make -f posix.mak PIC=${usePIC} INSTALL_DIR=$out DMD=$DMD
+      make -j$NIX_BUILD_CORES -f posix.mak PIC=${usePIC} INSTALL_DIR=$out DMD=$DMD
       cd ..
   '';
 
-  doCheck = true;
+  # disable check phase because some tests are not working with sandboxing
+  doCheck = false;
 
   checkPhase = ''
       cd dmd
@@ -97,10 +110,11 @@ stdenv.mkDerivation rec {
           osname = if stdenv.hostPlatform.isDarwin then "osx" else stdenv.hostPlatform.parsed.kernel.name; in
           "export DMD=$PWD/generated/${osname}/release/${bits}/dmd"
       }
+      make -j$NIX_BUILD_CORES -C test -f Makefile PIC=${usePIC} DMD=$DMD BUILD=release SHARED=0
       cd ../druntime
-      make -f posix.mak unittest PIC=${usePIC} DMD=$DMD BUILD=release
+      make -j$NIX_BUILD_CORES -f posix.mak unittest PIC=${usePIC} DMD=$DMD BUILD=release
       cd ../phobos
-      make -f posix.mak unittest PIC=${usePIC} DMD=$DMD BUILD=release
+      make -j$NIX_BUILD_CORES -f posix.mak unittest PIC=${usePIC} DMD=$DMD BUILD=release
       cd ..
   '';
 
@@ -153,7 +167,7 @@ stdenv.mkDerivation rec {
     # Everything is now Boost licensed, even the backend.
     # https://github.com/dlang/dmd/pull/6680
     license = licenses.boost;
+    maintainers = with maintainers; [ ThomasMader ];
     platforms = platforms.unix;
   };
 }
-
diff --git a/pkgs/development/compilers/dotnet/sdk/default.nix b/pkgs/development/compilers/dotnet/sdk/default.nix
new file mode 100644
index 000000000000..e7cb7495c90e
--- /dev/null
+++ b/pkgs/development/compilers/dotnet/sdk/default.nix
@@ -0,0 +1,53 @@
+{ stdenv
+, fetchurl
+, libunwind
+, openssl
+, icu
+, libuuid
+, zlib
+, curl
+, patchelf
+}:
+
+let
+  rpath = stdenv.lib.makeLibraryPath [ stdenv.cc.cc libunwind libuuid icu openssl zlib curl ];
+in
+  stdenv.mkDerivation rec {
+    version = "2.0.3";
+    name = "dotnet-sdk-${version}";
+
+    src = fetchurl {
+      url = "https://dotnetcli.azureedge.net/dotnet/Sdk/2.0.3-servicing-007037/dotnet-sdk-2.0.3-servicing-007037-linux-x64.tar.gz";
+      sha256 = "0kqk1f0vfdfyb9mp7d4y83airkxyixmxb7lrx0h0hym2a9661ch8";
+    };
+
+    unpackPhase = "tar xvzf $src";
+
+    buildPhase = ''
+      runHook preBuild
+      patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" ./dotnet
+      patchelf --set-rpath "${rpath}" ./dotnet
+      find -type f -name "*.so" -exec patchelf --set-rpath "${rpath}" {} \;
+      echo -n "dotnet-sdk version: "
+      ./dotnet --version
+      runHook postBuild
+    '';
+
+    dontPatchELF = true;
+
+    installPhase = ''
+      runHook preInstall
+      mkdir -p $out/bin
+      cp -r ./ $out
+      ln -s $out/dotnet $out/bin/dotnet
+      runHook postInstall
+    '';
+
+    meta = with stdenv.lib; {
+      homepage = https://dotnet.github.io/;
+      description = ".NET Core SDK 2.0.2 with .NET Core 2.0.0";
+      platforms = [ "x86_64-linux" ];
+      maintainers = with maintainers; [ kuznero ];
+      license = licenses.mit;
+    };
+  }
diff --git a/pkgs/development/compilers/edk2/default.nix b/pkgs/development/compilers/edk2/default.nix
index 1e6e0e8c1f6b..b3e2ff909b7f 100644
--- a/pkgs/development/compilers/edk2/default.nix
+++ b/pkgs/development/compilers/edk2/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchgit, libuuid, python2, iasl }:
+{ stdenv, fetchFromGitHub, libuuid, python2, iasl }:
 
 let
   pythonEnv = python2.withPackages(ps: [ps.tkinter]);
@@ -13,10 +13,11 @@ else
 edk2 = stdenv.mkDerivation {
   name = "edk2-2014-12-10";
 
-  src = fetchgit {
-    url = git://github.com/tianocore/edk2;
-    rev = "684a565a04";
-    sha256 = "0s9ywb8w7xzlnmm4kwzykxkrdaw53b7pky121cc9wjkllzqwyxrb";
+  src = fetchFromGitHub {
+    owner = "tianocore";
+    repo = "edk2";
+    rev = "vUDK2017";
+    sha256 = "0sswa028644yr8fbl8j6rhrdm717fj29h4dys3ygklmjhss90a2g";
   };
 
   buildInputs = [ libuuid pythonEnv];
diff --git a/pkgs/development/compilers/elm/packages/elm-format.nix b/pkgs/development/compilers/elm/packages/elm-format.nix
index a9340fc94fe4..56db835ac10a 100644
--- a/pkgs/development/compilers/elm/packages/elm-format.nix
+++ b/pkgs/development/compilers/elm/packages/elm-format.nix
@@ -1,37 +1,40 @@
-{ mkDerivation, aeson, ansi-terminal, ansi-wl-pprint, base, binary
-, bytestring, containers, directory, edit-distance, fetchgit
-, filemanip, filepath, HUnit, indents, mtl, optparse-applicative
-, parsec, pretty, process, QuickCheck, quickcheck-io
-, regex-applicative, split, stdenv, tasty, tasty-golden
-, tasty-hunit, tasty-quickcheck, text, union-find, wl-pprint
+{ mkDerivation, ansi-terminal, ansi-wl-pprint, base, binary
+, bytestring, Cabal, cmark, containers, directory, fetchgit
+, filepath, free, HUnit, indents, json, mtl, optparse-applicative
+, parsec, process, QuickCheck, quickcheck-io, split, stdenv, tasty
+, tasty-golden, tasty-hunit, tasty-quickcheck, text
 }:
 mkDerivation {
   pname = "elm-format";
-  version = "0.5.2";
+  version = "0.7.0";
   src = fetchgit {
     url = "http://github.com/avh4/elm-format";
-    sha256 = "0lman7h6wr75y90javcc4y1scvwgv125gqqaqvfrd5xrfmm43gg8";
-    rev = "e452ed9342620e7bb0bc822983b96411d57143ef";
+    sha256 = "1snl2lrrzdwgzi68agi3sdw84aslj04pzzxpm1mam9ic6dzhn3jf";
+    rev = "da4b415c6a2b7e77b7d9f00beca3e45230e603fb";
   };
-  isLibrary = false;
+
+  doHaddock = false;
+  isLibrary = true;
   isExecutable = true;
-  executableHaskellDepends = [
-    aeson ansi-terminal ansi-wl-pprint base binary bytestring
-    containers directory edit-distance filemanip filepath indents mtl
-    optparse-applicative parsec pretty process regex-applicative split
-    text
+  setupHaskellDepends = [ base Cabal directory filepath process ];
+  libraryHaskellDepends = [
+    ansi-terminal ansi-wl-pprint base binary bytestring containers
+    directory filepath free indents json mtl optparse-applicative
+    parsec process split text
   ];
+  executableHaskellDepends = [ base ];
   testHaskellDepends = [
-    aeson ansi-terminal ansi-wl-pprint base binary bytestring
-    containers directory edit-distance filemanip filepath HUnit indents
-    mtl optparse-applicative parsec pretty process QuickCheck
-    quickcheck-io regex-applicative split tasty tasty-golden
-    tasty-hunit tasty-quickcheck text union-find wl-pprint
+    base cmark containers HUnit mtl parsec QuickCheck quickcheck-io
+    split tasty tasty-golden tasty-hunit tasty-quickcheck text
   ];
   jailbreak = true;
   postInstall = ''
     ln -s $out/bin/elm-format-0.18 $out/bin/elm-format
   '';
+  postPatch = ''
+    sed -i "s|desc <-.*||" ./Setup.hs
+    sed -i "s|gitDescribe = .*|gitDescribe = \\\\\"da4b415c\\\\\"\"|" ./Setup.hs
+  '';
   homepage = http://elm-lang.org;
   description = "A source code formatter for Elm";
   license = stdenv.lib.licenses.bsd3;
diff --git a/pkgs/development/compilers/emscripten-fastcomp/default.nix b/pkgs/development/compilers/emscripten-fastcomp/default.nix
index f35ca26584f1..5d952073740e 100644
--- a/pkgs/development/compilers/emscripten-fastcomp/default.nix
+++ b/pkgs/development/compilers/emscripten-fastcomp/default.nix
@@ -1,54 +1,26 @@
-{ stdenv, fetchFromGitHub, cmake, python, ... }:
-
+{ newScope, stdenv, wrapCC, wrapCCWith, symlinkJoin }:
 let
-  rev = "1.37.16";
-  gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
-in
-stdenv.mkDerivation rec {
-  name = "emscripten-fastcomp-${rev}";
-
-  src = fetchFromGitHub {
-    owner = "kripken";
-    repo = "emscripten-fastcomp";
-    sha256 = "0wj9sc0gciaiidcjv6wb0qn6ks06xds7q34351masc7qpvd217by";
-    inherit rev;
-  };
-
-  srcFL = fetchFromGitHub {
-    owner = "kripken";
-    repo = "emscripten-fastcomp-clang";
-    sha256 = "1akdgxzxhzjbhp4d14ajcrp9jrf39x004a726ly2gynqc185l4j7";
-    inherit rev;
-  };
-
-  nativeBuildInputs = [ cmake python ];
-  preConfigure = ''
-    cp -Lr ${srcFL} tools/clang
-    chmod +w -R tools/clang
-  '';
-  cmakeFlags = [
-    "-DCMAKE_BUILD_TYPE=Release"
-    "-DLLVM_TARGETS_TO_BUILD='X86;JSBackend'"
-    "-DLLVM_INCLUDE_EXAMPLES=OFF"
-    "-DLLVM_INCLUDE_TESTS=OFF"
-    # "-DCLANG_INCLUDE_EXAMPLES=OFF"
-    "-DCLANG_INCLUDE_TESTS=OFF"
-  ] ++ (stdenv.lib.optional stdenv.isLinux
-    # necessary for clang to find crtend.o
-    "-DGCC_INSTALL_PREFIX=${gcc}"
-  );
-  enableParallelBuilding = true;
-
-  passthru = {
-    isClang = true;
-    inherit gcc;
-  };
+  callPackage = newScope (self // {inherit stdenv;});
 
-  meta = with stdenv.lib; {
-    homepage = https://github.com/kripken/emscripten-fastcomp;
-    description = "Emscripten LLVM";
-    platforms = platforms.all;
-    maintainers = with maintainers; [ qknight matthewbauer ];
-    license = stdenv.lib.licenses.ncsa;
+  self = {
+    emscriptenfastcomp-unwrapped = callPackage ./emscripten-fastcomp.nix {};
+    emscriptenfastcomp-wrapped = wrapCCWith {
+      cc = self.emscriptenfastcomp-unwrapped;
+      libc = stdenv.cc.libc;
+      extraBuildCommands = ''
+        # hardening flags break WASM support
+        cat > $out/nix-support/add-hardening.sh
+      '';
+    };
+    emscriptenfastcomp = symlinkJoin {
+      name = "emscriptenfastcomp";
+      paths = [ self.emscriptenfastcomp-wrapped self.emscriptenfastcomp-unwrapped ];
+      preferLocalBuild = false;
+      allowSubstitutes = true;
+      postBuild = ''
+        # replace unwrapped clang-3.9 binary by wrapper
+        ln -sf $out/bin/clang $out/bin/clang-[0-9]*
+      '';
+    };
   };
-}
+in self
diff --git a/pkgs/development/compilers/emscripten-fastcomp/emscripten-fastcomp.nix b/pkgs/development/compilers/emscripten-fastcomp/emscripten-fastcomp.nix
new file mode 100644
index 000000000000..f35ca26584f1
--- /dev/null
+++ b/pkgs/development/compilers/emscripten-fastcomp/emscripten-fastcomp.nix
@@ -0,0 +1,54 @@
+{ stdenv, fetchFromGitHub, cmake, python, ... }:
+
+let
+  rev = "1.37.16";
+  gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
+in
+stdenv.mkDerivation rec {
+  name = "emscripten-fastcomp-${rev}";
+
+  src = fetchFromGitHub {
+    owner = "kripken";
+    repo = "emscripten-fastcomp";
+    sha256 = "0wj9sc0gciaiidcjv6wb0qn6ks06xds7q34351masc7qpvd217by";
+    inherit rev;
+  };
+
+  srcFL = fetchFromGitHub {
+    owner = "kripken";
+    repo = "emscripten-fastcomp-clang";
+    sha256 = "1akdgxzxhzjbhp4d14ajcrp9jrf39x004a726ly2gynqc185l4j7";
+    inherit rev;
+  };
+
+  nativeBuildInputs = [ cmake python ];
+  preConfigure = ''
+    cp -Lr ${srcFL} tools/clang
+    chmod +w -R tools/clang
+  '';
+  cmakeFlags = [
+    "-DCMAKE_BUILD_TYPE=Release"
+    "-DLLVM_TARGETS_TO_BUILD='X86;JSBackend'"
+    "-DLLVM_INCLUDE_EXAMPLES=OFF"
+    "-DLLVM_INCLUDE_TESTS=OFF"
+    # "-DCLANG_INCLUDE_EXAMPLES=OFF"
+    "-DCLANG_INCLUDE_TESTS=OFF"
+  ] ++ (stdenv.lib.optional stdenv.isLinux
+    # necessary for clang to find crtend.o
+    "-DGCC_INSTALL_PREFIX=${gcc}"
+  );
+  enableParallelBuilding = true;
+
+  passthru = {
+    isClang = true;
+    inherit gcc;
+  };
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/kripken/emscripten-fastcomp;
+    description = "Emscripten LLVM";
+    platforms = platforms.all;
+    maintainers = with maintainers; [ qknight matthewbauer ];
+    license = stdenv.lib.licenses.ncsa;
+  };
+}
diff --git a/pkgs/development/compilers/factor-lang/default.nix b/pkgs/development/compilers/factor-lang/default.nix
index 85caa82a155c..ae2d39d604a6 100644
--- a/pkgs/development/compilers/factor-lang/default.nix
+++ b/pkgs/development/compilers/factor-lang/default.nix
@@ -1,7 +1,7 @@
 { stdenv, fetchurl, fetchFromGitHub, glib, glibc, git,
   rlwrap, curl, pkgconfig, perl, makeWrapper, tzdata, ncurses,
   libX11, pango, cairo, gtk2, gdk_pixbuf, gtkglext,
-  mesa, libXmu, libXt, libICE, libSM }:
+  mesa_glu, libXmu, libXt, libICE, libSM }:
 
 stdenv.mkDerivation rec {
   name = "factor-lang-${version}";
@@ -21,9 +21,10 @@ stdenv.mkDerivation rec {
     name = "factorimage";
   };
 
-  buildInputs = [ git rlwrap curl pkgconfig perl makeWrapper
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ git rlwrap curl perl makeWrapper
     libX11 pango cairo gtk2 gdk_pixbuf gtkglext
-    mesa libXmu libXt libICE libSM ];
+    mesa_glu libXmu libXt libICE libSM ];
 
   buildPhase = ''
     make $(bash ./build-support/factor.sh make-target) GIT_LABEL=heads/master-${rev}
@@ -50,7 +51,7 @@ stdenv.mkDerivation rec {
     # to be a generic solution here.
     find $(echo ${stdenv.lib.makeLibraryPath [
         glib libX11 pango cairo gtk2 gdk_pixbuf gtkglext
-        mesa libXmu libXt libICE libSM ]} | sed -e 's#:# #g') -name \*.so.\* > $TMPDIR/so.lst
+        mesa_glu libXmu libXt libICE libSM ]} | sed -e 's#:# #g') -name \*.so.\* > $TMPDIR/so.lst
 
     (echo $(cat $TMPDIR/so.lst | wc -l) "libs found in cache \`/etc/ld.so.cache'";
     for l in $(<$TMPDIR/so.lst);
@@ -71,7 +72,7 @@ stdenv.mkDerivation rec {
     wrapProgram $out/bin/factor --prefix LD_LIBRARY_PATH : \
       "${stdenv.lib.makeLibraryPath [ glib
         libX11 pango cairo gtk2 gdk_pixbuf gtkglext
-        mesa libXmu libXt libICE libSM ]}"
+        mesa_glu libXmu libXt libICE libSM ]}"
 
     sed -ie 's#/bin/.factor-wrapped#/lib/factor/factor#g' $out/bin/factor
     mv $out/bin/.factor-wrapped $out/lib/factor/factor
diff --git a/pkgs/development/compilers/fsharp/default.nix b/pkgs/development/compilers/fsharp/default.nix
index 751d44a38a4c..af33039d341a 100644
--- a/pkgs/development/compilers/fsharp/default.nix
+++ b/pkgs/development/compilers/fsharp/default.nix
@@ -11,7 +11,8 @@ stdenv.mkDerivation rec {
     sha256 = "0mvmvwwpl4zq0yvgzdizww8l9azvlrc82xm32nz1fi1nw8x5qfqk";
   };
 
-  buildInputs = [ mono pkgconfig dotnetbuildhelpers autoconf automake which ];
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ mono dotnetbuildhelpers autoconf automake which ];
 
   configurePhase = ''
     sed -i '988d' src/FSharpSource.targets
diff --git a/pkgs/development/compilers/fsharp41/default.nix b/pkgs/development/compilers/fsharp41/default.nix
index 488aaa228dae..354723dfa740 100644
--- a/pkgs/development/compilers/fsharp41/default.nix
+++ b/pkgs/development/compilers/fsharp41/default.nix
@@ -11,8 +11,8 @@ stdenv.mkDerivation rec {
     sha256 = "0rfkrk4mzi4w54mfqilvng9ar5swhmnwhsyjc54rx3fd0np3jiyl";
   };
 
+  nativeBuildInputs = [ pkgconfig ];
   buildInputs = [
-    pkgconfig
     autoconf
     automake
     which
diff --git a/pkgs/development/compilers/fstar/default.nix b/pkgs/development/compilers/fstar/default.nix
index 0887dd992526..3aef4e3ba89d 100644
--- a/pkgs/development/compilers/fstar/default.nix
+++ b/pkgs/development/compilers/fstar/default.nix
@@ -1,78 +1,30 @@
-{ stdenv, fetchFromGitHub, mono, fsharp, dotnetPackages, z3, ocamlPackages, openssl, makeWrapper, pkgconfig, file }:
+{ stdenv, fetchFromGitHub, z3, ocamlPackages, makeWrapper }:
 
 stdenv.mkDerivation rec {
   name = "fstar-${version}";
-  version = "0.9.4.0";
+  version = "0.9.5.0";
 
   src = fetchFromGitHub {
     owner = "FStarLang";
     repo = "FStar";
     rev = "v${version}";
-    sha256 = "130779p5plsgvz0dkcqycns3vwrvyfl138nq2xdhd3rkdsbyyvb7";
+    sha256 = "1pi2ny3kpmvm85x8w98anhjf0hp0wccc51m7v697qypn5cl4ydqk";
   };
 
   nativeBuildInputs = [ makeWrapper ];
 
   buildInputs = with ocamlPackages; [
-    mono fsharp z3 dotnetPackages.FsLexYacc ocaml findlib ocaml_batteries
-    zarith camlp4 yojson pprint openssl pkgconfig file
+    z3 ocaml findlib ocaml_batteries menhir stdint
+    zarith camlp4 yojson pprint
   ];
 
-  preBuild = ''
-    substituteInPlace src/Makefile --replace "\$(RUNTIME) VS/.nuget/NuGet.exe" "true" \
-      --replace Darwin xyz
-    substituteInPlace src/VS/.nuget/NuGet.targets --replace "mono" "true"
+  makeFlags = [ "PREFIX=$(out)" ];
 
-    # Fails with bad interpreter otherwise
+  preBuild = ''
     patchShebangs src/tools
     patchShebangs bin
-
-    export FSharpTargetsPath="$(dirname $(pkg-config FSharp.Core --variable=Libraries))/Microsoft.FSharp.Targets"
-    # remove hardcoded windows paths
-    sed -i '/<FSharpTargetsPath/d' src/*/*.fsproj
-
-    mkdir -p src/VS/packages/FsLexYacc.6.1.0
-    ln -s ${dotnetPackages.FsLexYacc}/lib/dotnet/FsLexYacc src/VS/packages/FsLexYacc.6.1.0/build
-  '';
-
-  makeFlags = [
-    "FSYACC=${dotnetPackages.FsLexYacc}/bin/fsyacc"
-    "FSLEX=${dotnetPackages.FsLexYacc}/bin/fslex"
-    "NUGET=true"
-    "PREFIX=$(out)"
-  ];
-
-  buildFlags = "-C src";
-
-  # Now that the .NET fstar.exe is built, use it to build the native OCaml binary
-  postBuild = ''
-    patchShebangs bin/fstar.exe
-
-    # Workaround for fsharp/fsharp#419
-    cp ${fsharp}/lib/mono/4.5/FSharp.Core.dll bin/
-
-    # Use the built .NET binary to extract the sources of itself from F* to OCaml
-    make ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES} -l''${NIX_BUILD_CORES}} \
-        $makeFlags "''${makeFlagsArray[@]}" \
-        ocaml -C src
-
-    # Build the extracted OCaml sources
-    make ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES} -l''${NIX_BUILD_CORES}} \
-        $makeFlags "''${makeFlagsArray[@]}" \
-        -C src/ocaml-output
   '';
-
-  # https://github.com/FStarLang/FStar/issues/676
-  doCheck = false;
-
-  preCheck = "ulimit -s unlimited";
-
-  # Basic test suite:
-  #checkFlags = "VERBOSE=y -C examples";
-
-  # Complete, but heavyweight test suite:
-  checkTarget = "regressions";
-  checkFlags = "VERBOSE=y -C src";
+  buildFlags = "-C src/ocaml-output";
 
   installFlags = "-C src/ocaml-output";
 
@@ -85,5 +37,6 @@ stdenv.mkDerivation rec {
     homepage = https://www.fstar-lang.org;
     license = licenses.asl20;
     platforms = with platforms; darwin ++ linux;
+    maintainers = with maintainers; [ gebner ];
   };
 }
diff --git a/pkgs/development/compilers/gambit/bootstrap.nix b/pkgs/development/compilers/gambit/bootstrap.nix
index 65fb20aa2603..e645ecb41bd2 100644
--- a/pkgs/development/compilers/gambit/bootstrap.nix
+++ b/pkgs/development/compilers/gambit/bootstrap.nix
@@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ autoconf ];
 
   configurePhase = ''
-    ./configure --prefix=$out --enable-single-host
+    ./configure --prefix=$out
   '';
 
   buildPhase = ''
diff --git a/pkgs/development/compilers/gambit/default.nix b/pkgs/development/compilers/gambit/default.nix
index 58b08ebd4fb7..79f57c42c50d 100644
--- a/pkgs/development/compilers/gambit/default.nix
+++ b/pkgs/development/compilers/gambit/default.nix
@@ -1,19 +1,16 @@
 { stdenv, fetchurl, fetchgit, git, openssl, autoconf, pkgs }:
 
+# TODO: distinct packages for gambit-release and gambit-devel
+
 stdenv.mkDerivation rec {
   name    = "gambit-${version}";
-  version = "4.8.8-f3ffeb6";
+  version = "4.8.8-300db59";
   bootstrap = import ./bootstrap.nix ( pkgs );
 
-#  devver  = "4_8_8";
-#  src = fetchurl {
-#    url    = "http://www.iro.umontreal.ca/~gambit/download/gambit/v4.8/source/gambit-v${version}-devel.tgz";
-#    sha256 = "0j3ka76cfb007rlcc3nv5p1s6vh31cwp87hwwabawf16vs1jb7bl";
-#  };
   src = fetchgit {
     url = "https://github.com/feeley/gambit.git";
-    rev = "f3ffeb695aeea80c18c1b9ef276b57898c780dca";
-    sha256 = "1lqixsrgk9z2gj6z1nkys0pfd3m5zjxrp3gvqn2wpr9h7hjb8x06";
+    rev = "300db59e1d3b66bcd597f617849df0274d2a4472";
+    sha256 = "1mhy49lasakgvdaswkxasdssik11lx3hfx4h1gs2b6881488ssdp";
   };
 
   buildInputs = [ openssl git autoconf bootstrap ];
@@ -28,6 +25,8 @@ stdenv.mkDerivation rec {
       --enable-absolute-shared-libs # Yes, NixOS will want an absolute path, and fix it.
       --enable-poll
       --enable-openssl
+      --enable-default-runtime-options="f8,-8,t8" # Default to UTF-8 for source and all I/O
+      #--enable-debug # Nope: enables plenty of good stuff, but also the costly console.log
 
       #--enable-multiple-versions # Nope, NixOS already does version multiplexing
       #--enable-guide
@@ -49,15 +48,15 @@ stdenv.mkDerivation rec {
 
   buildPhase = ''
     # Make bootstrap compiler, from release bootstrap
-    mkdir -p boot/wip-compiler &&
-    cp -rp ${bootstrap}/. boot/wip-compiler/. &&
+    mkdir -p boot &&
+    cp -rp ${bootstrap}/. boot/. &&
     chmod -R u+w boot &&
-    cd boot/wip-compiler && \
-    cp ../../gsc/makefile.in ../../gsc/*.scm gsc && \
-    (cd gsc && make bootclean ) &&
-    make bootstrap &&
-    cd ../.. &&
-    cp boot/wip-compiler/gsc/gsc gsc-boot &&
+    cd boot &&
+    cp ../gsc/makefile.in ../gsc/*.scm gsc && # */
+    ./configure &&
+    for i in lib gsi gsc ; do (cd $i ; make ) ; done &&
+    cd .. &&
+    cp boot/gsc/gsc gsc-boot &&
 
     # Now use the bootstrap compiler to build the real thing!
     make -j2 from-scratch
diff --git a/pkgs/development/compilers/gcc/4.5/default.nix b/pkgs/development/compilers/gcc/4.5/default.nix
index 9164bc1fc691..c31de725e807 100644
--- a/pkgs/development/compilers/gcc/4.5/default.nix
+++ b/pkgs/development/compilers/gcc/4.5/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, noSysDirs
+{ stdenv, targetPackages, fetchurl, noSysDirs
 , langC ? true, langCC ? true, langFortran ? false
 , langJava ? false
 , langAda ? false
@@ -20,7 +20,7 @@
 , enableMultilib ? false
 , name ? "gcc"
 , libcCross ? null
-, crossStageStatic ? true
+, crossStageStatic ? false
 , gnat ? null
 , libpthread ? null, libpthreadCross ? null  # required for GNU/Hurd
 , stripped ? true
@@ -72,62 +72,60 @@ let version = "4.5.4";
         gccFpu = targetPlatform.platform.gcc.fpu or null;
         gccFloat = targetPlatform.platform.gcc.float or null;
         gccMode = targetPlatform.platform.gcc.mode or null;
-        withArch = if gccArch != null then " --with-arch=${gccArch}" else "";
-        withCpu = if gccCpu != null then " --with-cpu=${gccCpu}" else "";
-        withAbi = if gccAbi != null then " --with-abi=${gccAbi}" else "";
-        withFpu = if gccFpu != null then " --with-fpu=${gccFpu}" else "";
-        withFloat = if gccFloat != null then " --with-float=${gccFloat}" else "";
-        withMode = if gccMode != null then " --with-mode=${gccMode}" else "";
       in
-        withArch +
-        withCpu +
-        withAbi +
-        withFpu +
-        withFloat +
-        withMode;
+        optional (gccArch != null) "--with-arch=${gccArch}" ++
+        optional (gccCpu != null) "--with-cpu=${gccCpu}" ++
+        optional (gccAbi != null) "--with-abi=${gccAbi}" ++
+        optional (gccFpu != null) "--with-fpu=${gccFpu}" ++
+        optional (gccFloat != null) "--with-float=${gccFloat}" ++
+        optional (gccMode != null) "--with-mode=${gccMode}";
+
+    /* Cross-gcc settings */
+    crossMingw = (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt");
 
     crossConfigureFlags =
-      platformFlags +
       # Ensure that -print-prog-name is able to find the correct programs.
-      " --with-as=${binutils}/bin/${targetPlatform.config}-as" +
-      " --with-ld=${binutils}/bin/${targetPlatform.config}-ld" +
-      (if crossMingw && crossStageStatic then
-        " --with-headers=${libcCross}/include" +
-        " --with-gcc" +
-        " --with-gnu-as" +
-        " --with-gnu-ld" +
-        " --with-gnu-ld" +
-        " --disable-shared" +
-        " --disable-nls" +
-        " --disable-debug" +
-        " --enable-sjlj-exceptions" +
-        " --enable-threads=win32" +
-        " --disable-win32-registry"
-        else if crossStageStatic then
-        " --disable-libssp --disable-nls" +
-        " --without-headers" +
-        " --disable-threads " +
-        " --disable-libmudflap " +
-        " --disable-libgomp " +
-        " --disable-shared" +
-        " --disable-decimal-float" # libdecnumber requires libc
-        else
-        " --with-headers=${libcCross}/include" +
-        " --enable-__cxa_atexit" +
-        " --enable-long-long" +
-        (if crossMingw then
-          " --enable-threads=win32" +
-          " --enable-sjlj-exceptions" +
-          " --enable-hash-synchronization" +
-          " --enable-version-specific-runtime-libs" +
-          " --enable-libssp" +
-          " --disable-nls" +
-          " --with-dwarf2"
-          else
-          " --enable-threads=posix" +
-          " --enable-nls" +
-          " --disable-decimal-float") # No final libdecnumber (it may work only in 386)
-        );
+      [ "--with-as=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
+        "--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld" ] ++
+      (if crossMingw && crossStageStatic then [
+        "--with-headers=${libcCross}/include"
+        "--with-gcc"
+        "--with-gnu-as"
+        "--with-gnu-ld"
+        "--with-gnu-ld"
+        "--disable-shared"
+        "--disable-nls"
+        "--disable-debug"
+        "--enable-sjlj-exceptions"
+        "--enable-threads=win32"
+        "--disable-win32-registry"
+      ] else if crossStageStatic then [
+        "--disable-libssp"
+        "--disable-nls"
+        "--without-headers"
+        "--disable-threads"
+        "--disable-libmudflap"
+        "--disable-libgomp"
+        "--disable-shared"
+        "--disable-decimal-float" # libdecnumber requires libc
+      ] else [
+        "--with-headers=${libcCross}/include"
+        "--enable-__cxa_atexit"
+        "--enable-long-long"
+      ] ++
+        (if crossMingw then [
+          "--enable-threads=win32"
+          "--enable-sjlj-exceptions"
+          "--enable-hash-synchronization"
+          "--enable-version-specific-runtime-libs"
+          "--enable-libssp"
+          "--disable-nls"
+          "--with-dwarf2"
+        ] else [
+          "--enable-threads=posix"
+          "--enable-nls"
+          "--disable-decimal-float" # No final libdecnumber (it may work only in 386)
+        ]));
     stageNameAddon = if crossStageStatic then "-stage-static" else
       "-stage-final";
     crossNameAddon = if targetPlatform != hostPlatform then "-${targetPlatform.config}" + stageNameAddon else "";
@@ -149,8 +147,9 @@ stdenv.mkDerivation ({
 
   hardeningDisable = [ "format" ] ++ optional (name != "gnat") "all";
 
-  outputs = if (hostPlatform.is64bit && langAda) then [ "out" "doc" ]
-    else [ "out" "lib" "doc" ];
+  outputs = [ "out" "man" "info" ]
+    ++ optional (!(hostPlatform.is64bit && langAda)) "lib";
+
   setOutputFlags = false;
   NIX_NO_SELF_RPATH = true;
 
@@ -164,6 +163,7 @@ stdenv.mkDerivation ({
     # target libraries and tools.
     ++ optional langAda ../gnat-cflags.patch
     ++ optional langVhdl ./ghdl-ortho-cflags.patch
+    ++ [ ../struct-ucontext-4.5.patch ] # glibc-2.26
     ;
 
   postPatch =
@@ -224,7 +224,9 @@ stdenv.mkDerivation ({
         ''
     else null;
 
-  inherit noSysDirs profiledCompiler staticCompiler langJava crossStageStatic
+  # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild,
+  crossStageStatic = targetPlatform == hostPlatform || crossStageStatic;
+  inherit noSysDirs profiledCompiler staticCompiler langJava
     libcCross crossMingw;
 
   nativeBuildInputs = [ texinfo which gettext ]
@@ -237,57 +239,80 @@ stdenv.mkDerivation ({
     ++ (optional langJava boehmgc)
     ++ (optionals langJava [zip unzip])
     ++ (optionals javaAwtGtk ([gtk2 pkgconfig libart_lgpl] ++ xlibs))
-    ++ (optionals (targetPlatform != hostPlatform) [binutils])
+    ++ (optionals (targetPlatform != hostPlatform) [targetPackages.stdenv.cc.bintools])
     ++ (optionals langAda [gnatboot])
     ++ (optionals langVhdl [gnat])
     ;
 
   # TODO(@Ericson2314): Always pass "--target" and always prefix.
-  configurePlatforms = [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
-  configureFlags = "
-    ${if enableMultilib then "" else "--disable-multilib"}
-    ${if enableShared then "" else "--disable-shared"}
-    ${if ppl != null then "--with-ppl=${ppl}" else ""}
-    ${if cloogppl != null then "--with-cloog=${cloogppl}" else ""}
-    ${if langJava then
-      "--with-ecj-jar=${javaEcj} " +
+  configurePlatforms =
+    # TODO(@Ericson2314): Figure out what's going wrong with Arm
+    if hostPlatform == targetPlatform && targetPlatform.isArm
+    then []
+    else [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
+
+  configureFlags =
+    # Basic dependencies
+    [
+      "--with-gmp=${gmp.dev}"
+      "--with-mpfr=${mpfr.dev}"
+      "--with-mpc=${libmpc}"
+    ] ++
+    optional (libelf != null) "--with-libelf=${libelf}" ++
+    optional (!(crossMingw && crossStageStatic))
+      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include" ++
+
+    # Basic configuration
+    [
+      "--disable-libstdcxx-pch"
+      "--without-included-gettext"
+      "--with-system-zlib"
+      "--enable-languages=${
+        concatStrings (intersperse ","
+          (  optional langC        "c"
+          ++ optional langCC       "c++"
+          ++ optional langFortran  "fortran"
+          ++ optional langJava     "java"
+          ++ optional langAda      "ada"
+          ++ optional langVhdl     "vhdl"
+          )
+        )
+      }"
+    ] ++
+    optional (!enableMultilib) "--disable-multilib" ++
+    optional (!enableShared) "--disable-shared" ++
+
+    # Optional features
+    optional (cloogppl != null) "--with-cloog=${cloogppl}" ++
+    optional (ppl != null) "--with-ppl=${ppl}" ++
+
+    # Java options
+    optionals langJava [
+      "--with-ecj-jar=${javaEcj}"
 
       # Follow Sun's layout for the convenience of IcedTea/OpenJDK.  See
       # <http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2010-April/008888.html>.
-      "--enable-java-home --with-java-home=\${prefix}/lib/jvm/jre "
-      else ""}
-    ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
-    ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr}" else ""}
-    --with-gmp=${gmp.dev}
-    --with-mpfr=${mpfr.dev}
-    --with-mpc=${libmpc}
-    ${if libelf != null then "--with-libelf=${libelf}" else ""}
-    --disable-libstdcxx-pch
-    --without-included-gettext
-    --with-system-zlib
-    --enable-languages=${
-      concatStrings (intersperse ","
-        (  optional langC        "c"
-        ++ optional langCC       "c++"
-        ++ optional langFortran  "fortran"
-        ++ optional langJava     "java"
-        ++ optional langAda      "ada"
-        ++ optional langVhdl     "vhdl"
-        )
-      )
-    }
-    ${optionalString (!(crossMingw && crossStageStatic))
-      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include"}
-    ${ # Trick that should be taken out once we have a mips64el-linux not loongson2f
-      if targetPlatform == hostPlatform && stdenv.system == "mips64el-linux" then "--with-arch=loongson2f" else ""}
-    ${if langAda then " --enable-libada" else ""}
-    ${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
-    ${platformFlags}
-    ${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
-  ";
+      "--enable-java-home"
+      "--with-java-home=\${prefix}/lib/jvm/jre"
+    ] ++
+    optional javaAwtGtk "--enable-java-awt=gtk" ++
+    optional (langJava && javaAntlr != null) "--with-antlr-jar=${javaAntlr}" ++
+
+    # Ada
+    optional langAda "--enable-libada" ++
+
+    platformFlags ++
+    optional (targetPlatform != hostPlatform) crossConfigureFlags ++
+
+    # Platform-specific flags
+    optional (targetPlatform == hostPlatform && targetPlatform.isi686) "--with-arch=i686" ++
+    # Trick that should be taken out once we have a mips64el-linux not loongson2f
+    optional (targetPlatform == hostPlatform && stdenv.system == "mips64el-linux") "--with-arch=loongson2f"
+  ;
 
   targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
 
+  /* For cross-built gcc (build != host == target) */
   crossAttrs = {
     AR_FOR_BUILD = "ar";
     AS_FOR_BUILD = "as";
diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix
index 0b0292d92ee9..b20094249254 100644
--- a/pkgs/development/compilers/gcc/4.8/default.nix
+++ b/pkgs/development/compilers/gcc/4.8/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, fetchpatch, noSysDirs
+{ stdenv, targetPackages, fetchurl, fetchpatch, noSysDirs
 , langC ? true, langCC ? true, langFortran ? false
 , langObjC ? targetPlatform.isDarwin
 , langObjCpp ? targetPlatform.isDarwin
@@ -26,7 +26,7 @@
 , enablePlugin ? hostPlatform == buildPlatform # Whether to support user-supplied plug-ins
 , name ? "gcc"
 , libcCross ? null
-, crossStageStatic ? true
+, crossStageStatic ? false
 , gnat ? null
 , libpthread ? null, libpthreadCross ? null  # required for GNU/Hurd
 , stripped ? true
@@ -79,7 +79,11 @@ let version = "4.8.5";
           sha256 = "01jd7pdarh54ki498g6sz64ijl9a1l5f9v8q2696aaxalvh2vwzl";
           excludes = [ "gcc/cp/ChangeLog" ];
         })]
-      ;
+      ++ [ # glibc-2.26
+        ../struct-ucontext-4.8.patch
+        ../sigsegv-not-declared.patch
+        ../res_state-not-declared.patch
+      ];
 
     javaEcj = fetchurl {
       # The `$(top_srcdir)/ecj.jar' file is automatically picked up at
@@ -112,72 +116,68 @@ let version = "4.8.5";
         gccFpu = targetPlatform.platform.gcc.fpu or null;
         gccFloat = targetPlatform.platform.gcc.float or null;
         gccMode = targetPlatform.platform.gcc.mode or null;
-        withArch = if gccArch != null then " --with-arch=${gccArch}" else "";
-        withCpu = if gccCpu != null then " --with-cpu=${gccCpu}" else "";
-        withAbi = if gccAbi != null then " --with-abi=${gccAbi}" else "";
-        withFpu = if gccFpu != null then " --with-fpu=${gccFpu}" else "";
-        withFloat = if gccFloat != null then " --with-float=${gccFloat}" else "";
-        withMode = if gccMode != null then " --with-mode=${gccMode}" else "";
       in
-        withArch +
-        withCpu +
-        withAbi +
-        withFpu +
-        withFloat +
-        withMode;
-
-    /* Cross-gcc settings */
+        optional (gccArch != null) "--with-arch=${gccArch}" ++
+        optional (gccCpu != null) "--with-cpu=${gccCpu}" ++
+        optional (gccAbi != null) "--with-abi=${gccAbi}" ++
+        optional (gccFpu != null) "--with-fpu=${gccFpu}" ++
+        optional (gccFloat != null) "--with-float=${gccFloat}" ++
+        optional (gccMode != null) "--with-mode=${gccMode}";
+
+    /* Cross-gcc settings (build == host != target) */
     crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt";
     crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem";
     crossConfigureFlags =
-        # Ensure that -print-prog-name is able to find the correct programs.
-        " --with-as=${binutils}/bin/${targetPlatform.config}-as" +
-        " --with-ld=${binutils}/bin/${targetPlatform.config}-ld" +
-        (if crossMingw && crossStageStatic then
-          " --with-headers=${libcCross}/include" +
-          " --with-gcc" +
-          " --with-gnu-as" +
-          " --with-gnu-ld" +
-          " --with-gnu-ld" +
-          " --disable-shared" +
-          " --disable-nls" +
-          " --disable-debug" +
-          " --enable-sjlj-exceptions" +
-          " --enable-threads=win32" +
-          " --disable-win32-registry"
-          else if crossStageStatic then
-          " --disable-libssp --disable-nls" +
-          " --without-headers" +
-          " --disable-threads " +
-          " --disable-libmudflap " +
-          " --disable-libgomp " +
-          " --disable-libquadmath" +
-          " --disable-shared" +
-          " --disable-libatomic " +  # libatomic requires libc
-          " --disable-decimal-float" # libdecnumber requires libc
-          else
-          (if crossDarwin then " --with-sysroot=${libcCross.out}/share/sysroot"
-           else                " --with-headers=${libcCross.dev}/include") +
-          # Ensure that -print-prog-name is able to find the correct programs.
-          " --enable-__cxa_atexit" +
-          " --enable-long-long" +
-          (if crossMingw then
-            " --enable-threads=win32" +
-            " --enable-sjlj-exceptions" +
-            " --enable-hash-synchronization" +
-            " --enable-libssp" +
-            " --disable-nls" +
-            " --with-dwarf2" +
-            # To keep ABI compatibility with upstream mingw-w64
-            " --enable-fully-dynamic-string"
-            else (if targetPlatform.libc == "uclibc" then
-              # In uclibc cases, libgomp needs an additional '-ldl'
-              # and as I don't know how to pass it, I disable libgomp.
-              " --disable-libgomp" else "") +
-            " --enable-threads=posix" +
-            " --enable-nls" +
-            " --disable-decimal-float") # No final libdecnumber (it may work only in 386)
-          );
+      # Ensure that -print-prog-name is able to find the correct programs.
+      [ "--with-as=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
+        "--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld" ] ++
+      (if crossMingw && crossStageStatic then [
+        "--with-headers=${libcCross}/include"
+        "--with-gcc"
+        "--with-gnu-as"
+        "--with-gnu-ld"
+        "--with-gnu-ld"
+        "--disable-shared"
+        "--disable-nls"
+        "--disable-debug"
+        "--enable-sjlj-exceptions"
+        "--enable-threads=win32"
+        "--disable-win32-registry"
+      ] else if crossStageStatic then [
+        "--disable-libssp"
+        "--disable-nls"
+        "--without-headers"
+        "--disable-threads"
+        "--disable-libgomp"
+        "--disable-libquadmath"
+        "--disable-shared"
+        "--disable-libatomic"  # libatomic requires libc
+        "--disable-decimal-float" # libdecnumber requires libc
+      ] else [
+        (if crossDarwin then "--with-sysroot=${getLib libcCross}/share/sysroot"
+         else                "--with-headers=${getDev libcCross}/include")
+        "--enable-__cxa_atexit"
+        "--enable-long-long"
+      ] ++
+        (if crossMingw then [
+          "--enable-threads=win32"
+          "--enable-sjlj-exceptions"
+          "--enable-hash-synchronization"
+          "--enable-libssp"
+          "--disable-nls"
+          "--with-dwarf2"
+          # To keep ABI compatibility with upstream mingw-w64
+          "--enable-fully-dynamic-string"
+        ] else
+          optionals (targetPlatform.libc == "uclibc") [
+            # In uclibc cases, libgomp needs an additional '-ldl'
+            # and as I don't know how to pass it, I disable libgomp.
+            "--disable-libgomp"
+          ] ++ [
+          "--enable-threads=posix"
+          "--enable-nls"
+          "--disable-decimal-float" # No final libdecnumber (it may work only in 386)
+        ]));
     stageNameAddon = if crossStageStatic then "-stage-static" else "-stage-final";
     crossNameAddon = if targetPlatform != hostPlatform then "-${targetPlatform.config}" + stageNameAddon else "";
 
@@ -262,7 +262,9 @@ stdenv.mkDerivation ({
         ''
     else null;
 
-  inherit noSysDirs staticCompiler langJava crossStageStatic
+  # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild,
+  crossStageStatic = targetPlatform == hostPlatform || crossStageStatic;
+  inherit noSysDirs staticCompiler langJava
     libcCross crossMingw;
 
   nativeBuildInputs = [ texinfo which gettext ]
@@ -275,7 +277,7 @@ stdenv.mkDerivation ({
     ++ (optional (zlib != null) zlib)
     ++ (optionals langJava [ boehmgc zip unzip ])
     ++ (optionals javaAwtGtk ([ gtk2 libart_lgpl ] ++ xlibs))
-    ++ (optionals (targetPlatform != hostPlatform) [binutils])
+    ++ (optionals (targetPlatform != hostPlatform) [targetPackages.stdenv.cc.bintools])
     ++ (optionals langAda [gnatboot])
     ++ (optionals langVhdl [gnat])
 
@@ -295,61 +297,92 @@ stdenv.mkDerivation ({
   dontDisableStatic = true;
 
   # TODO(@Ericson2314): Always pass "--target" and always prefix.
-  configurePlatforms = [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
-  configureFlags = "
-    ${if hostPlatform.isSunOS then
-      " --enable-long-long --enable-libssp --enable-threads=posix --disable-nls --enable-__cxa_atexit " +
-      # On Illumos/Solaris GNU as is preferred
-      " --with-gnu-as --without-gnu-ld "
-      else ""}
-    --enable-lto
-    ${if enableMultilib then "--disable-libquadmath" else "--disable-multilib"}
-    ${if enableShared then "" else "--disable-shared"}
-    ${if enablePlugin then "--enable-plugin" else "--disable-plugin"}
-    ${optionalString (isl != null) "--with-isl=${isl}"}
-    ${optionalString (cloog != null) "--with-cloog=${cloog} --disable-cloog-version-check --enable-cloog-backend=isl"}
-    ${if langJava then
-      "--with-ecj-jar=${javaEcj} " +
+  configurePlatforms =
+    # TODO(@Ericson2314): Figure out what's going wrong with Arm
+    if hostPlatform == targetPlatform && targetPlatform.isArm
+    then []
+    else [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
+
+  configureFlags =
+    # Basic dependencies
+    [
+      "--with-gmp-include=${gmp.dev}/include"
+      "--with-gmp-lib=${gmp.out}/lib"
+      "--with-mpfr-include=${mpfr.dev}/include"
+      "--with-mpfr-lib=${mpfr.out}/lib"
+      "--with-mpc=${libmpc}"
+    ] ++
+    optional (libelf != null) "--with-libelf=${libelf}" ++
+    optional (!(crossMingw && crossStageStatic))
+      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include" ++
+
+    # Basic configuration
+    [
+      "--enable-lto"
+      "--disable-libstdcxx-pch"
+      "--without-included-gettext"
+      "--with-system-zlib"
+      "--enable-static"
+      "--enable-languages=${
+        concatStrings (intersperse ","
+          (  optional langC        "c"
+          ++ optional langCC       "c++"
+          ++ optional langFortran  "fortran"
+          ++ optional langJava     "java"
+          ++ optional langAda      "ada"
+          ++ optional langVhdl     "vhdl"
+          ++ optional langGo       "go"
+          ++ optional langObjC     "objc"
+          ++ optional langObjCpp   "obj-c++"
+          ++ optionals crossDarwin [ "objc" "obj-c++" ]
+          )
+        )
+      }"
+    ] ++
+
+    # Optional features
+    optional (isl != null) "--with-isl=${isl}" ++
+    optionals (cloog != null) [
+      "--with-cloog=${cloog}"
+      "--disable-cloog-version-check"
+      "--enable-cloog-backend=isl"
+    ] ++
+
+    (if enableMultilib
+      then ["--enable-multilib" "--disable-libquadmath"]
+      else ["--disable-multilib"]) ++
+    optional (!enableShared) "--disable-shared" ++
+    (if enablePlugin
+      then ["--enable-plugin"]
+      else ["--disable-plugin"]) ++
+
+    # Java options
+    optionals langJava [
+      "--with-ecj-jar=${javaEcj}"
 
       # Follow Sun's layout for the convenience of IcedTea/OpenJDK.  See
       # <http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2010-April/008888.html>.
-      "--enable-java-home --with-java-home=\${prefix}/lib/jvm/jre "
-      else ""}
-    ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
-    ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr}" else ""}
-    --with-gmp-include=${gmp.dev}/include
-    --with-gmp-lib=${gmp.out}/lib
-    --with-mpfr-include=${mpfr.dev}/include
-    --with-mpfr-lib=${mpfr.out}/lib
-    --with-mpc=${libmpc}
-    ${if libelf != null then "--with-libelf=${libelf}" else ""}
-    --disable-libstdcxx-pch
-    --without-included-gettext
-    --with-system-zlib
-    --enable-static
-    --enable-languages=${
-      concatStrings (intersperse ","
-        (  optional langC        "c"
-        ++ optional langCC       "c++"
-        ++ optional langFortran  "fortran"
-        ++ optional langJava     "java"
-        ++ optional langAda      "ada"
-        ++ optional langVhdl     "vhdl"
-        ++ optional langGo       "go"
-        ++ optional langObjC     "objc"
-        ++ optional langObjCpp   "obj-c++"
-        ++ optionals crossDarwin [ "objc" "obj-c++" ]
-        )
-      )
-    }
-    ${optionalString (!(crossMingw && crossStageStatic))
-      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include"}
-    ${if langAda then " --enable-libada" else ""}
-    ${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
-    ${platformFlags}
-    ${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
-    ${if !bootstrap then "--disable-bootstrap" else ""}
-  ";
+      "--enable-java-home"
+      "--with-java-home=\${prefix}/lib/jvm/jre"
+    ] ++
+    optional javaAwtGtk "--enable-java-awt=gtk" ++
+    optional (langJava && javaAntlr != null) "--with-antlr-jar=${javaAntlr}" ++
+
+    # Ada
+    optional langAda "--enable-libada" ++
+
+    platformFlags ++
+    optional (targetPlatform != hostPlatform) crossConfigureFlags ++
+    optional (!bootstrap) "--disable-bootstrap" ++
+
+    # Platform-specific flags
+    optional (targetPlatform == hostPlatform && targetPlatform.isi686) "--with-arch=i686" ++
+    optionals hostPlatform.isSunOS [
+      "--enable-long-long" "--enable-libssp" "--enable-threads=posix" "--disable-nls" "--enable-__cxa_atexit"
+      # On Illumos/Solaris GNU as is preferred
+      "--with-gnu-as" "--without-gnu-ld"
+    ]
+  ;
 
   targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
 
@@ -362,7 +395,8 @@ stdenv.mkDerivation ({
     then "install-strip"
     else "install";
 
-  crossAttrs = {
+  /* For cross-built gcc (build != host == target) */
+  crossAttrs =  {
     AR_FOR_BUILD = "ar";
     AS_FOR_BUILD = "as";
     LD_FOR_BUILD = "ld";
diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix
index 223de92e533c..f28007a6cd14 100644
--- a/pkgs/development/compilers/gcc/4.9/default.nix
+++ b/pkgs/development/compilers/gcc/4.9/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, noSysDirs
+{ stdenv, targetPackages, fetchurl, noSysDirs
 , langC ? true, langCC ? true, langFortran ? false
 , langObjC ? targetPlatform.isDarwin
 , langObjCpp ? targetPlatform.isDarwin
@@ -26,7 +26,7 @@
 , enablePlugin ? hostPlatform == buildPlatform # Whether to support user-supplied plug-ins
 , name ? "gcc"
 , libcCross ? null
-, crossStageStatic ? true
+, crossStageStatic ? false
 , gnat ? null
 , libpthread ? null, libpthreadCross ? null  # required for GNU/Hurd
 , stripped ? true
@@ -73,6 +73,7 @@ let version = "4.9.4";
       # target libraries and tools.
       ++ optional langAda ../gnat-cflags.patch
       ++ optional langFortran ../gfortran-driving.patch
+      ++ [ ../struct-ucontext.patch ../struct-sigaltstack-4.9.patch ] # glibc-2.26
       ;
 
     javaEcj = fetchurl {
@@ -106,77 +107,75 @@ let version = "4.9.4";
         gccFpu = targetPlatform.platform.gcc.fpu or null;
         gccFloat = targetPlatform.platform.gcc.float or null;
         gccMode = targetPlatform.platform.gcc.mode or null;
-        withArch = if gccArch != null then " --with-arch=${gccArch}" else "";
-        withCpu = if gccCpu != null then " --with-cpu=${gccCpu}" else "";
-        withAbi = if gccAbi != null then " --with-abi=${gccAbi}" else "";
-        withFpu = if gccFpu != null then " --with-fpu=${gccFpu}" else "";
-        withFloat = if gccFloat != null then " --with-float=${gccFloat}" else "";
-        withMode = if gccMode != null then " --with-mode=${gccMode}" else "";
       in
-        withArch +
-        withCpu +
-        withAbi +
-        withFpu +
-        withFloat +
-        withMode;
-
-    /* Cross-gcc settings */
+        optional (gccArch != null) "--with-arch=${gccArch}" ++
+        optional (gccCpu != null) "--with-cpu=${gccCpu}" ++
+        optional (gccAbi != null) "--with-abi=${gccAbi}" ++
+        optional (gccFpu != null) "--with-fpu=${gccFpu}" ++
+        optional (gccFloat != null) "--with-float=${gccFloat}" ++
+        optional (gccMode != null) "--with-mode=${gccMode}";
+
+    /* Cross-gcc settings (build == host != target) */
     crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt";
     crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem";
     crossConfigureFlags =
-        # Ensure that -print-prog-name is able to find the correct programs.
-        " --with-as=${binutils}/bin/${targetPlatform.config}-as" +
-        " --with-ld=${binutils}/bin/${targetPlatform.config}-ld" +
-        (if crossMingw && crossStageStatic then
-          " --with-headers=${libcCross}/include" +
-          " --with-gcc" +
-          " --with-gnu-as" +
-          " --with-gnu-ld" +
-          " --with-gnu-ld" +
-          " --disable-shared" +
-          " --disable-nls" +
-          " --disable-debug" +
-          " --enable-sjlj-exceptions" +
-          " --enable-threads=win32" +
-          " --disable-win32-registry"
-          else if crossStageStatic then
-          " --disable-libssp --disable-nls" +
-          " --without-headers" +
-          " --disable-threads " +
-          " --disable-libgomp " +
-          " --disable-libquadmath" +
-          " --disable-shared" +
-          " --disable-libatomic " +  # libatomic requires libc
-          " --disable-decimal-float" # libdecnumber requires libc
-          else
-          (if crossDarwin then " --with-sysroot=${libcCross.out}/share/sysroot"
-           else                " --with-headers=${libcCross.dev}/include") +
-          " --enable-__cxa_atexit" +
-          " --enable-long-long" +
-          (if crossMingw then
-            " --enable-threads=win32" +
-            " --enable-sjlj-exceptions" +
-            " --enable-hash-synchronization" +
-            " --enable-libssp" +
-            " --disable-nls" +
-            " --with-dwarf2" +
-            # To keep ABI compatibility with upstream mingw-w64
-            " --enable-fully-dynamic-string"
-            else (if targetPlatform.libc == "uclibc" then
-              # libsanitizer requires netrom/netrom.h which is not
-              # available in uclibc.
-              " --disable-libsanitizer" +
-              # In uclibc cases, libgomp needs an additional '-ldl'
-              # and as I don't know how to pass it, I disable libgomp.
-              " --disable-libgomp" else "") +
-            " --enable-threads=posix" +
-            " --enable-nls" +
-            " --disable-decimal-float") # No final libdecnumber (it may work only in 386)
-          );
+      # Ensure that -print-prog-name is able to find the correct programs.
+      [ "--with-as=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
+        "--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld" ] ++
+      (if crossMingw && crossStageStatic then [
+        "--with-headers=${libcCross}/include"
+        "--with-gcc"
+        "--with-gnu-as"
+        "--with-gnu-ld"
+        "--with-gnu-ld"
+        "--disable-shared"
+        "--disable-nls"
+        "--disable-debug"
+        "--enable-sjlj-exceptions"
+        "--enable-threads=win32"
+        "--disable-win32-registry"
+      ] else if crossStageStatic then [
+        "--disable-libssp"
+        "--disable-nls"
+        "--without-headers"
+        "--disable-threads"
+        "--disable-libgomp"
+        "--disable-libquadmath"
+        "--disable-shared"
+        "--disable-libatomic"  # libatomic requires libc
+        "--disable-decimal-float" # libdecnumber requires libc
+      ] else [
+        (if crossDarwin then "--with-sysroot=${getLib libcCross}/share/sysroot"
+         else                "--with-headers=${getDev libcCross}/include")
+        "--enable-__cxa_atexit"
+        "--enable-long-long"
+      ] ++
+        (if crossMingw then [
+          "--enable-threads=win32"
+          "--enable-sjlj-exceptions"
+          "--enable-hash-synchronization"
+          "--enable-libssp"
+          "--disable-nls"
+          "--with-dwarf2"
+          # To keep ABI compatibility with upstream mingw-w64
+          "--enable-fully-dynamic-string"
+        ] else
+          optionals (targetPlatform.libc == "uclibc") [
+            # libsanitizer requires netrom/netrom.h which is not
+            # available in uclibc.
+            "--disable-libsanitizer"
+            # In uclibc cases, libgomp needs an additional '-ldl'
+            # and as I don't know how to pass it, I disable libgomp.
+            "--disable-libgomp"
+          ] ++ [
+          "--enable-threads=posix"
+          "--enable-nls"
+          "--disable-decimal-float" # No final libdecnumber (it may work only in 386)
+        ]));
     stageNameAddon = if crossStageStatic then "-stage-static" else "-stage-final";
     crossNameAddon = if targetPlatform != hostPlatform then "-${targetPlatform.config}" + stageNameAddon else "";
 
-  bootstrap = targetPlatform == hostPlatform;
+    bootstrap = targetPlatform == hostPlatform;
 
 in
 
@@ -258,7 +257,9 @@ stdenv.mkDerivation ({
         ''
     else null;
 
-  inherit noSysDirs staticCompiler langJava crossStageStatic
+  # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild,
+  crossStageStatic = targetPlatform == hostPlatform || crossStageStatic;
+  inherit noSysDirs staticCompiler langJava
     libcCross crossMingw;
 
   nativeBuildInputs = [ texinfo which gettext ]
@@ -271,7 +272,7 @@ stdenv.mkDerivation ({
     ++ (optional (zlib != null) zlib)
     ++ (optionals langJava [ boehmgc zip unzip ])
     ++ (optionals javaAwtGtk ([ gtk2 libart_lgpl ] ++ xlibs))
-    ++ (optionals (targetPlatform != hostPlatform) [binutils])
+    ++ (optionals (targetPlatform != hostPlatform) [targetPackages.stdenv.cc.bintools])
     ++ (optionals langAda [gnatboot])
     ++ (optionals langVhdl [gnat])
 
@@ -295,59 +296,91 @@ stdenv.mkDerivation ({
   dontDisableStatic = true;
 
   # TODO(@Ericson2314): Always pass "--target" and always prefix.
-  configurePlatforms = [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
-  configureFlags = "
-    ${if hostPlatform.isSunOS then
-      " --enable-long-long --enable-libssp --enable-threads=posix --disable-nls --enable-__cxa_atexit " +
-      # On Illumos/Solaris GNU as is preferred
-      " --with-gnu-as --without-gnu-ld "
-      else ""}
-    --enable-lto
-    ${if enableMultilib then "--enable-multilib --disable-libquadmath" else "--disable-multilib"}
-    ${if enableShared then "" else "--disable-shared"}
-    ${if enablePlugin then "--enable-plugin" else "--disable-plugin"}
-    ${optionalString (isl != null) "--with-isl=${isl}"}
-    ${optionalString (cloog != null) "--with-cloog=${cloog} --disable-cloog-version-check --enable-cloog-backend=isl"}
-    ${if langJava then
-      "--with-ecj-jar=${javaEcj} " +
+  configurePlatforms =
+    # TODO(@Ericson2314): Figure out what's going wrong with Arm
+    if hostPlatform == targetPlatform && targetPlatform.isArm
+    then []
+    else [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
+
+  configureFlags =
+    # Basic dependencies
+    [
+      "--with-gmp-include=${gmp.dev}/include"
+      "--with-gmp-lib=${gmp.out}/lib"
+      "--with-mpfr=${mpfr.dev}"
+      "--with-mpc=${libmpc}"
+    ] ++
+    optional (libelf != null) "--with-libelf=${libelf}" ++
+    optional (!(crossMingw && crossStageStatic))
+      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include" ++
+
+    # Basic configuration
+    [
+      "--enable-lto"
+      "--disable-libstdcxx-pch"
+      "--without-included-gettext"
+      "--with-system-zlib"
+      "--enable-static"
+      "--enable-languages=${
+        concatStrings (intersperse ","
+          (  optional langC        "c"
+          ++ optional langCC       "c++"
+          ++ optional langFortran  "fortran"
+          ++ optional langJava     "java"
+          ++ optional langAda      "ada"
+          ++ optional langVhdl     "vhdl"
+          ++ optional langGo       "go"
+          ++ optional langObjC     "objc"
+          ++ optional langObjCpp   "obj-c++"
+          ++ optionals crossDarwin [ "objc" "obj-c++" ]
+          )
+        )
+      }"
+    ] ++
+
+    (if enableMultilib
+      then ["--enable-multilib" "--disable-libquadmath"]
+      else ["--disable-multilib"]) ++
+    optional (!enableShared) "--disable-shared" ++
+    (if enablePlugin
+      then ["--enable-plugin"]
+      else ["--disable-plugin"]) ++
+
+    # Optional features
+    optional (isl != null) "--with-isl=${isl}" ++
+    optionals (cloog != null) [
+      "--with-cloog=${cloog}"
+      "--disable-cloog-version-check"
+      "--enable-cloog-backend=isl"
+    ] ++
+
+    # Java options
+    optionals langJava [
+      "--with-ecj-jar=${javaEcj}"
 
       # Follow Sun's layout for the convenience of IcedTea/OpenJDK.  See
       # <http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2010-April/008888.html>.
-      "--enable-java-home --with-java-home=\${prefix}/lib/jvm/jre "
-      else ""}
-    ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
-    ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr}" else ""}
-    --with-gmp=${gmp.dev}
-    --with-mpfr=${mpfr.dev}
-    --with-mpc=${libmpc}
-    ${if libelf != null then "--with-libelf=${libelf}" else ""}
-    --disable-libstdcxx-pch
-    --without-included-gettext
-    --with-system-zlib
-    --enable-static
-    --enable-languages=${
-      concatStrings (intersperse ","
-        (  optional langC        "c"
-        ++ optional langCC       "c++"
-        ++ optional langFortran  "fortran"
-        ++ optional langJava     "java"
-        ++ optional langAda      "ada"
-        ++ optional langVhdl     "vhdl"
-        ++ optional langGo       "go"
-        ++ optional langObjC     "objc"
-        ++ optional langObjCpp   "obj-c++"
-        ++ optionals crossDarwin [ "objc" "obj-c++" ]
-        )
-      )
-    }
-    ${optionalString (!(crossMingw && crossStageStatic))
-      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include"}
-    ${if langAda then " --enable-libada" else ""}
-    ${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
-    ${platformFlags}
-    ${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
-    ${if !bootstrap then "--disable-bootstrap" else ""}
-  ";
+      "--enable-java-home"
+      "--with-java-home=\${prefix}/lib/jvm/jre"
+    ] ++
+    optional javaAwtGtk "--enable-java-awt=gtk" ++
+    optional (langJava && javaAntlr != null) "--with-antlr-jar=${javaAntlr}" ++
+
+    # Ada
+    optional langAda "--enable-libada" ++
+
+    platformFlags ++
+    optional (targetPlatform != hostPlatform) crossConfigureFlags ++
+    optional (!bootstrap) "--disable-bootstrap" ++
+
+    # Platform-specific flags
+    optional (targetPlatform == hostPlatform && targetPlatform.isi686) "--with-arch=i686" ++
+    optionals hostPlatform.isSunOS [
+      "--enable-long-long" "--enable-libssp" "--enable-threads=posix" "--disable-nls" "--enable-__cxa_atexit"
+      # On Illumos/Solaris GNU as is preferred
+      "--with-gnu-as" "--without-gnu-ld"
+    ]
+  ;
 
   targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
 
@@ -360,6 +393,7 @@ stdenv.mkDerivation ({
     then "install-strip"
     else "install";
 
+  /* For cross-built gcc (build != host == target) */
   crossAttrs = {
     AR_FOR_BUILD = "ar";
     AS_FOR_BUILD = "as";
diff --git a/pkgs/development/compilers/gcc/5/default.nix b/pkgs/development/compilers/gcc/5/default.nix
index bb1c12cd4b09..8cd32ae14da7 100644
--- a/pkgs/development/compilers/gcc/5/default.nix
+++ b/pkgs/development/compilers/gcc/5/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, noSysDirs
+{ stdenv, targetPackages, fetchurl, noSysDirs
 , langC ? true, langCC ? true, langFortran ? false
 , langObjC ? targetPlatform.isDarwin
 , langObjCpp ? targetPlatform.isDarwin
@@ -26,12 +26,11 @@
 , enablePlugin ? hostPlatform == buildPlatform # Whether to support user-supplied plug-ins
 , name ? "gcc"
 , libcCross ? null
-, crossStageStatic ? true
+, crossStageStatic ? false
 , gnat ? null
 , libpthread ? null, libpthreadCross ? null  # required for GNU/Hurd
 , stripped ? true
 , gnused ? null
-, binutils ? null
 , cloog # unused; just for compat with gcc4, as we override the parameter on some places
 , darwin ? null
 , buildPlatform, hostPlatform, targetPlatform
@@ -51,7 +50,7 @@ assert libelf != null -> zlib != null;
 assert hostPlatform.isDarwin -> gnused != null;
 
 # Need c++filt on darwin
-assert hostPlatform.isDarwin -> binutils != null;
+assert hostPlatform.isDarwin -> targetPackages.stdenv.cc.bintools or null != null;
 
 # The go frontend is written in c++
 assert langGo -> langCC;
@@ -59,8 +58,8 @@ assert langGo -> langCC;
 with stdenv.lib;
 with builtins;
 
-let version = "5.4.0";
-    sha256 = "0fihlcy5hnksdxk0sn6bvgnyq8gfrgs8m794b1jxwd1dxinzg3b0";
+let version = "5.5.0";
+    sha256 = "11zd1hgzkli3b2v70qsm2hyqppngd4616qc96lmm9zl2kl9yl32k";
 
     # Whether building a cross-compiler for GNU/Hurd.
     crossGNU = targetPlatform != hostPlatform && targetPlatform.config == "i586-pc-gnu";
@@ -111,77 +110,75 @@ let version = "5.4.0";
         gccFpu = targetPlatform.platform.gcc.fpu or null;
         gccFloat = targetPlatform.platform.gcc.float or null;
         gccMode = targetPlatform.platform.gcc.mode or null;
-        withArch = if gccArch != null then " --with-arch=${gccArch}" else "";
-        withCpu = if gccCpu != null then " --with-cpu=${gccCpu}" else "";
-        withAbi = if gccAbi != null then " --with-abi=${gccAbi}" else "";
-        withFpu = if gccFpu != null then " --with-fpu=${gccFpu}" else "";
-        withFloat = if gccFloat != null then " --with-float=${gccFloat}" else "";
-        withMode = if gccMode != null then " --with-mode=${gccMode}" else "";
       in
-        withArch +
-        withCpu +
-        withAbi +
-        withFpu +
-        withFloat +
-        withMode;
-
-    /* Cross-gcc settings */
+        optional (gccArch != null) "--with-arch=${gccArch}" ++
+        optional (gccCpu != null) "--with-cpu=${gccCpu}" ++
+        optional (gccAbi != null) "--with-abi=${gccAbi}" ++
+        optional (gccFpu != null) "--with-fpu=${gccFpu}" ++
+        optional (gccFloat != null) "--with-float=${gccFloat}" ++
+        optional (gccMode != null) "--with-mode=${gccMode}";
+
+    /* Cross-gcc settings (build == host != target) */
     crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt";
     crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem";
     crossConfigureFlags =
-        # Ensure that -print-prog-name is able to find the correct programs.
-        " --with-as=${binutils}/bin/${targetPlatform.config}-as" +
-        " --with-ld=${binutils}/bin/${targetPlatform.config}-ld" +
-        (if crossMingw && crossStageStatic then
-          " --with-headers=${libcCross}/include" +
-          " --with-gcc" +
-          " --with-gnu-as" +
-          " --with-gnu-ld" +
-          " --with-gnu-ld" +
-          " --disable-shared" +
-          " --disable-nls" +
-          " --disable-debug" +
-          " --enable-sjlj-exceptions" +
-          " --enable-threads=win32" +
-          " --disable-win32-registry"
-          else if crossStageStatic then
-          " --disable-libssp --disable-nls" +
-          " --without-headers" +
-          " --disable-threads " +
-          " --disable-libgomp " +
-          " --disable-libquadmath" +
-          " --disable-shared" +
-          " --disable-libatomic " +  # libatomic requires libc
-          " --disable-decimal-float" # libdecnumber requires libc
-          else
-          (if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot"
-           else                " --with-headers=${getDev libcCross}/include") +
-          " --enable-__cxa_atexit" +
-          " --enable-long-long" +
-          (if crossMingw then
-            " --enable-threads=win32" +
-            " --enable-sjlj-exceptions" +
-            " --enable-hash-synchronization" +
-            " --enable-libssp" +
-            " --disable-nls" +
-            " --with-dwarf2" +
-            # To keep ABI compatibility with upstream mingw-w64
-            " --enable-fully-dynamic-string"
-            else (if targetPlatform.libc == "uclibc" then
-              # libsanitizer requires netrom/netrom.h which is not
-              # available in uclibc.
-              " --disable-libsanitizer" +
-              # In uclibc cases, libgomp needs an additional '-ldl'
-              # and as I don't know how to pass it, I disable libgomp.
-              " --disable-libgomp" else "") +
-            " --enable-threads=posix" +
-            " --enable-nls" +
-            " --disable-decimal-float") # No final libdecnumber (it may work only in 386)
-          );
+      # Ensure that -print-prog-name is able to find the correct programs.
+      [ "--with-as=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
+        "--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld" ] ++
+      (if crossMingw && crossStageStatic then [
+        "--with-headers=${libcCross}/include"
+        "--with-gcc"
+        "--with-gnu-as"
+        "--with-gnu-ld"
+        "--with-gnu-ld"
+        "--disable-shared"
+        "--disable-nls"
+        "--disable-debug"
+        "--enable-sjlj-exceptions"
+        "--enable-threads=win32"
+        "--disable-win32-registry"
+      ] else if crossStageStatic then [
+        "--disable-libssp"
+        "--disable-nls"
+        "--without-headers"
+        "--disable-threads"
+        "--disable-libgomp"
+        "--disable-libquadmath"
+        "--disable-shared"
+        "--disable-libatomic"  # libatomic requires libc
+        "--disable-decimal-float" # libdecnumber requires libc
+      ] else [
+        (if crossDarwin then "--with-sysroot=${getLib libcCross}/share/sysroot"
+         else                "--with-headers=${getDev libcCross}/include")
+        "--enable-__cxa_atexit"
+        "--enable-long-long"
+      ] ++
+        (if crossMingw then [
+          "--enable-threads=win32"
+          "--enable-sjlj-exceptions"
+          "--enable-hash-synchronization"
+          "--enable-libssp"
+          "--disable-nls"
+          "--with-dwarf2"
+          # To keep ABI compatibility with upstream mingw-w64
+          "--enable-fully-dynamic-string"
+        ] else
+          optionals (targetPlatform.libc == "uclibc") [
+            # libsanitizer requires netrom/netrom.h which is not
+            # available in uclibc.
+            "--disable-libsanitizer"
+            # In uclibc cases, libgomp needs an additional '-ldl'
+            # and as I don't know how to pass it, I disable libgomp.
+            "--disable-libgomp"
+          ] ++ [
+          "--enable-threads=posix"
+          "--enable-nls"
+          "--disable-decimal-float" # No final libdecnumber (it may work only in 386)
+        ]));
     stageNameAddon = if crossStageStatic then "-stage-static" else "-stage-final";
     crossNameAddon = if targetPlatform != hostPlatform then "-${targetPlatform.config}" + stageNameAddon else "";
 
-  bootstrap = targetPlatform == hostPlatform;
+    bootstrap = targetPlatform == hostPlatform;
 
 in
 
@@ -194,12 +191,11 @@ stdenv.mkDerivation ({
   builder = ../builder.sh;
 
   src = fetchurl {
-    url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2";
+    url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
     inherit sha256;
   };
 
-  # FIXME stackprotector needs gcc 4.9 in bootstrap tools
-  hardeningDisable = [ "stackprotector" "format" ];
+  hardeningDisable = [ "format" ];
 
   inherit patches;
 
@@ -276,7 +272,9 @@ stdenv.mkDerivation ({
         ''
     else null;
 
-  inherit noSysDirs staticCompiler langJava crossStageStatic
+  # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild,
+  crossStageStatic = targetPlatform == hostPlatform || crossStageStatic;
+  inherit noSysDirs staticCompiler langJava
     libcCross crossMingw;
 
   nativeBuildInputs = [ texinfo which gettext ]
@@ -288,14 +286,15 @@ stdenv.mkDerivation ({
     ++ (optional (zlib != null) zlib)
     ++ (optionals langJava [ boehmgc zip unzip ])
     ++ (optionals javaAwtGtk ([ gtk2 libart_lgpl ] ++ xlibs))
-    ++ (optionals (targetPlatform != hostPlatform) [binutils])
+    ++ (optionals (targetPlatform != hostPlatform) [targetPackages.stdenv.cc.bintools])
+    ++ (optionals (buildPlatform != hostPlatform) [buildPackages.stdenv.cc])
     ++ (optionals langAda [gnatboot])
     ++ (optionals langVhdl [gnat])
 
     # The builder relies on GNU sed (for instance, Darwin's `sed' fails with
     # "-i may not be used with stdin"), and `stdenvNative' doesn't provide it.
     ++ (optional hostPlatform.isDarwin gnused)
-    ++ (optional hostPlatform.isDarwin binutils)
+    ++ (optional hostPlatform.isDarwin targetPackages.stdenv.cc.bintools)
     ;
 
   NIX_LDFLAGS = stdenv.lib.optionalString  hostPlatform.isSunOS "-lm -ldl";
@@ -310,60 +309,87 @@ stdenv.mkDerivation ({
   dontDisableStatic = true;
 
   # TODO(@Ericson2314): Always pass "--target" and always prefix.
-  configurePlatforms = [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
-  configureFlags = "
-    ${if hostPlatform.isSunOS then
-      " --enable-long-long --enable-libssp --enable-threads=posix --disable-nls --enable-__cxa_atexit " +
-      # On Illumos/Solaris GNU as is preferred
-      " --with-gnu-as --without-gnu-ld "
-      else ""}
-    --enable-lto
-    ${if enableMultilib then "--enable-multilib --disable-libquadmath" else "--disable-multilib"}
-    ${if enableShared then "" else "--disable-shared"}
-    ${if enablePlugin then "--enable-plugin" else "--disable-plugin"}
-    ${optionalString (isl != null) "--with-isl=${isl}"}
-    ${if langJava then
-      "--with-ecj-jar=${javaEcj} " +
+  configurePlatforms =
+    # TODO(@Ericson2314): Figure out what's going wrong with Arm
+    if hostPlatform == targetPlatform && targetPlatform.isArm
+    then []
+    else [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
+
+  configureFlags =
+    # Basic dependencies
+    [
+      "--with-gmp-include=${gmp.dev}/include"
+      "--with-gmp-lib=${gmp.out}/lib"
+      "--with-mpfr-include=${mpfr.dev}/include"
+      "--with-mpfr-lib=${mpfr.out}/lib"
+      "--with-mpc=${libmpc}"
+    ] ++
+    optional (libelf != null) "--with-libelf=${libelf}" ++
+    optional (!(crossMingw && crossStageStatic))
+      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include" ++ 
+
+    # Basic configuration
+    [
+      "--enable-lto"
+      "--disable-libstdcxx-pch"
+      "--without-included-gettext"
+      "--with-system-zlib"
+      "--enable-static"
+      "--enable-languages=${
+        concatStrings (intersperse ","
+          (  optional langC        "c"
+          ++ optional langCC       "c++"
+          ++ optional langFortran  "fortran"
+          ++ optional langJava     "java"
+          ++ optional langAda      "ada"
+          ++ optional langVhdl     "vhdl"
+          ++ optional langGo       "go"
+          ++ optional langObjC     "objc"
+          ++ optional langObjCpp   "obj-c++"
+          ++ optionals crossDarwin [ "objc" "obj-c++" ]
+          )
+        )
+      }"
+    ] ++
+
+    # Optional features
+    optional (isl != null) "--with-isl=${isl}" ++
+
+    (if enableMultilib
+      then ["--enable-multilib" "--disable-libquadmath"]
+      else ["--disable-multilib"]) ++
+    optional (!enableShared) "--disable-shared" ++
+    (if enablePlugin
+      then ["--enable-plugin"]
+      else ["--disable-plugin"]) ++
+
+    # Java options
+    optionals langJava [
+      "--with-ecj-jar=${javaEcj}"
 
       # Follow Sun's layout for the convenience of IcedTea/OpenJDK.  See
       # <http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2010-April/008888.html>.
-      "--enable-java-home --with-java-home=\${prefix}/lib/jvm/jre "
-      else ""}
-    ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
-    ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr}" else ""}
-    --with-gmp-include=${gmp.dev}/include
-    --with-gmp-lib=${gmp.out}/lib
-    --with-mpfr-include=${mpfr.dev}/include
-    --with-mpfr-lib=${mpfr.out}/lib
-    --with-mpc=${libmpc}
-    ${if libelf != null then "--with-libelf=${libelf}" else ""}
-    --disable-libstdcxx-pch
-    --without-included-gettext
-    --with-system-zlib
-    --enable-static
-    --enable-languages=${
-      concatStrings (intersperse ","
-        (  optional langC        "c"
-        ++ optional langCC       "c++"
-        ++ optional langFortran  "fortran"
-        ++ optional langJava     "java"
-        ++ optional langAda      "ada"
-        ++ optional langVhdl     "vhdl"
-        ++ optional langGo       "go"
-        ++ optional langObjC     "objc"
-        ++ optional langObjCpp   "obj-c++"
-        ++ optionals crossDarwin [ "objc" "obj-c++" ]
-        )
-      )
-    }
-    ${optionalString (!(crossMingw && crossStageStatic))
-      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include"}
-    ${if langAda then " --enable-libada" else ""}
-    ${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
-    ${platformFlags}
-    ${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
-    ${if !bootstrap then "--disable-bootstrap" else ""}
-  ";
+      "--enable-java-home"
+      "--with-java-home=\${prefix}/lib/jvm/jre"
+    ] ++
+    optional javaAwtGtk "--enable-java-awt=gtk" ++
+    optional (langJava && javaAntlr != null) "--with-antlr-jar=${javaAntlr}" ++
+
+    # Ada
+    optional langAda "--enable-libada" ++
+
+    platformFlags ++
+    optional (targetPlatform != hostPlatform) crossConfigureFlags ++
+    optional (!bootstrap) "--disable-bootstrap" ++
+
+    # Platform-specific flags
+    optional (targetPlatform == hostPlatform && targetPlatform.isi686) "--with-arch=i686" ++
+    optionals hostPlatform.isSunOS [
+      "--enable-long-long" "--enable-libssp" "--enable-threads=posix" "--disable-nls" "--enable-__cxa_atexit"
+      # On Illumos/Solaris GNU as is preferred
+      "--with-gnu-as" "--without-gnu-ld"
+    ]
+  ;
 
   targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
 
@@ -376,6 +402,7 @@ stdenv.mkDerivation ({
     then "install-strip"
     else "install";
 
+  /* For cross-built gcc (build != host == target) */
   crossAttrs = {
     AR_FOR_BUILD = "ar";
     AS_FOR_BUILD = "as";
diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix
index 59e37dd50b6c..9fe49d728fa1 100644
--- a/pkgs/development/compilers/gcc/6/default.nix
+++ b/pkgs/development/compilers/gcc/6/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, noSysDirs
+{ stdenv, targetPackages, fetchurl, noSysDirs
 , langC ? true, langCC ? true, langFortran ? false
 , langObjC ? targetPlatform.isDarwin
 , langObjCpp ? targetPlatform.isDarwin
@@ -26,12 +26,11 @@
 , enablePlugin ? hostPlatform == buildPlatform # Whether to support user-supplied plug-ins
 , name ? "gcc"
 , libcCross ? null
-, crossStageStatic ? true
+, crossStageStatic ? false
 , gnat ? null
 , libpthread ? null, libpthreadCross ? null  # required for GNU/Hurd
 , stripped ? true
 , gnused ? null
-, binutils ? null
 , cloog # unused; just for compat with gcc4, as we override the parameter on some places
 , darwin ? null
 , buildPlatform, hostPlatform, targetPlatform
@@ -51,7 +50,7 @@ assert libelf != null -> zlib != null;
 assert hostPlatform.isDarwin -> gnused != null;
 
 # Need c++filt on darwin
-assert hostPlatform.isDarwin -> binutils != null;
+assert hostPlatform.isDarwin -> targetPackages.stdenv.cc.bintools or null != null;
 
 # The go frontend is written in c++
 assert langGo -> langCC;
@@ -73,7 +72,10 @@ let version = "6.4.0";
       # The GNAT Makefiles did not pay attention to CFLAGS_FOR_TARGET for its
       # target libraries and tools.
       ++ optional langAda ../gnat-cflags.patch
-      ++ optional langFortran ../gfortran-driving.patch;
+      ++ optional langFortran ../gfortran-driving.patch
+      ++ [ ../struct-ucontext.patch ../struct-sigaltstack.patch ] # glibc-2.26
+      ++ optional langJava [ ../struct-ucontext-libjava.patch ] # glibc-2.26
+      ;
 
     javaEcj = fetchurl {
       # The `$(top_srcdir)/ecj.jar' file is automatically picked up at
@@ -106,73 +108,71 @@ let version = "6.4.0";
         gccFpu = targetPlatform.platform.gcc.fpu or null;
         gccFloat = targetPlatform.platform.gcc.float or null;
         gccMode = targetPlatform.platform.gcc.mode or null;
-        withArch = if gccArch != null then " --with-arch=${gccArch}" else "";
-        withCpu = if gccCpu != null then " --with-cpu=${gccCpu}" else "";
-        withAbi = if gccAbi != null then " --with-abi=${gccAbi}" else "";
-        withFpu = if gccFpu != null then " --with-fpu=${gccFpu}" else "";
-        withFloat = if gccFloat != null then " --with-float=${gccFloat}" else "";
-        withMode = if gccMode != null then " --with-mode=${gccMode}" else "";
       in
-        withArch +
-        withCpu +
-        withAbi +
-        withFpu +
-        withFloat +
-        withMode;
-
-    /* Cross-gcc settings */
+        optional (gccArch != null) "--with-arch=${gccArch}" ++
+        optional (gccCpu != null) "--with-cpu=${gccCpu}" ++
+        optional (gccAbi != null) "--with-abi=${gccAbi}" ++
+        optional (gccFpu != null) "--with-fpu=${gccFpu}" ++
+        optional (gccFloat != null) "--with-float=${gccFloat}" ++
+        optional (gccMode != null) "--with-mode=${gccMode}";
+
+    /* Cross-gcc settings (build == host != target) */
     crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt";
     crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem";
     crossConfigureFlags =
-        # Ensure that -print-prog-name is able to find the correct programs.
-        " --with-as=${binutils}/bin/${targetPlatform.config}-as" +
-        " --with-ld=${binutils}/bin/${targetPlatform.config}-ld" +
-        (if crossMingw && crossStageStatic then
-          " --with-headers=${libcCross}/include" +
-          " --with-gcc" +
-          " --with-gnu-as" +
-          " --with-gnu-ld" +
-          " --with-gnu-ld" +
-          " --disable-shared" +
-          " --disable-nls" +
-          " --disable-debug" +
-          " --enable-sjlj-exceptions" +
-          " --enable-threads=win32" +
-          " --disable-win32-registry"
-          else if crossStageStatic then
-          " --disable-libssp --disable-nls" +
-          " --without-headers" +
-          " --disable-threads " +
-          " --disable-libgomp " +
-          " --disable-libquadmath" +
-          " --disable-shared" +
-          " --disable-libatomic " +  # libatomic requires libc
-          " --disable-decimal-float" # libdecnumber requires libc
-          else
-          (if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot"
-           else                " --with-headers=${getDev libcCross}/include") +
-          " --enable-__cxa_atexit" +
-          " --enable-long-long" +
-          (if crossMingw then
-            " --enable-threads=win32" +
-            " --enable-sjlj-exceptions" +
-            " --enable-hash-synchronization" +
-            " --enable-libssp" +
-            " --disable-nls" +
-            " --with-dwarf2" +
-            # To keep ABI compatibility with upstream mingw-w64
-            " --enable-fully-dynamic-string"
-            else (if targetPlatform.libc == "uclibc" then
-              # libsanitizer requires netrom/netrom.h which is not
-              # available in uclibc.
-              " --disable-libsanitizer" +
-              # In uclibc cases, libgomp needs an additional '-ldl'
-              # and as I don't know how to pass it, I disable libgomp.
-              " --disable-libgomp" else "") +
-            " --enable-threads=posix" +
-            " --enable-nls" +
-            " --disable-decimal-float") # No final libdecnumber (it may work only in 386)
-          );
+      # Ensure that -print-prog-name is able to find the correct programs.
+      [ "--with-as=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
+        "--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld" ] ++
+      (if crossMingw && crossStageStatic then [
+        "--with-headers=${libcCross}/include"
+        "--with-gcc"
+        "--with-gnu-as"
+        "--with-gnu-ld"
+        "--with-gnu-ld"
+        "--disable-shared"
+        "--disable-nls"
+        "--disable-debug"
+        "--enable-sjlj-exceptions"
+        "--enable-threads=win32"
+        "--disable-win32-registry"
+      ] else if crossStageStatic then [
+        "--disable-libssp"
+        "--disable-nls"
+        "--without-headers"
+        "--disable-threads"
+        "--disable-libgomp"
+        "--disable-libquadmath"
+        "--disable-shared"
+        "--disable-libatomic"  # libatomic requires libc
+        "--disable-decimal-float" # libdecnumber requires libc
+      ] else [
+        (if crossDarwin then "--with-sysroot=${getLib libcCross}/share/sysroot"
+         else                "--with-headers=${getDev libcCross}/include")
+        "--enable-__cxa_atexit"
+        "--enable-long-long"
+      ] ++
+        (if crossMingw then [
+          "--enable-threads=win32"
+          "--enable-sjlj-exceptions"
+          "--enable-hash-synchronization"
+          "--enable-libssp"
+          "--disable-nls"
+          "--with-dwarf2"
+          # To keep ABI compatibility with upstream mingw-w64
+          "--enable-fully-dynamic-string"
+        ] else
+          optionals (targetPlatform.libc == "uclibc") [
+            # libsanitizer requires netrom/netrom.h which is not
+            # available in uclibc.
+            "--disable-libsanitizer"
+            # In uclibc cases, libgomp needs an additional '-ldl'
+            # and as I don't know how to pass it, I disable libgomp.
+            "--disable-libgomp"
+          ] ++ [
+          "--enable-threads=posix"
+          "--enable-nls"
+          "--disable-decimal-float" # No final libdecnumber (it may work only in 386)
+        ]));
     stageNameAddon = if crossStageStatic then "-stage-static" else "-stage-final";
     crossNameAddon = if targetPlatform != hostPlatform then "-${targetPlatform.config}" + stageNameAddon else "";
 
@@ -195,7 +195,8 @@ stdenv.mkDerivation ({
 
   inherit patches;
 
-  outputs = [ "out" "lib" "man" "info" ];
+  outputs = if langJava || langGo then ["out" "man" "info"]
+    else [ "out" "lib" "man" "info" ];
   setOutputFlags = false;
   NIX_NO_SELF_RPATH = true;
 
@@ -270,7 +271,9 @@ stdenv.mkDerivation ({
         ''
     else null;
 
-  inherit noSysDirs staticCompiler langJava crossStageStatic
+  # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild,
+  crossStageStatic = targetPlatform == hostPlatform || crossStageStatic;
+  inherit noSysDirs staticCompiler langJava
     libcCross crossMingw;
 
   nativeBuildInputs = [ texinfo which gettext ]
@@ -282,14 +285,14 @@ stdenv.mkDerivation ({
     ++ (optional (zlib != null) zlib)
     ++ (optionals langJava [ boehmgc zip unzip ])
     ++ (optionals javaAwtGtk ([ gtk2 libart_lgpl ] ++ xlibs))
-    ++ (optionals (targetPlatform != hostPlatform) [binutils])
+    ++ (optionals (targetPlatform != hostPlatform) [targetPackages.stdenv.cc.bintools])
     ++ (optionals langAda [gnatboot])
     ++ (optionals langVhdl [gnat])
 
     # The builder relies on GNU sed (for instance, Darwin's `sed' fails with
     # "-i may not be used with stdin"), and `stdenvNative' doesn't provide it.
     ++ (optional hostPlatform.isDarwin gnused)
-    ++ (optional hostPlatform.isDarwin binutils)
+    ++ (optional hostPlatform.isDarwin targetPackages.stdenv.cc.bintools)
     ;
 
   NIX_LDFLAGS = stdenv.lib.optionalString  hostPlatform.isSunOS "-lm -ldl";
@@ -299,77 +302,108 @@ stdenv.mkDerivation ({
     export LDFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $LDFLAGS_FOR_TARGET"
     export CXXFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CXXFLAGS_FOR_TARGET"
     export CFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CFLAGS_FOR_TARGET"
-  '';
+  ''
+  + stdenv.lib.optionalString (langJava || langGo) ''
+    export lib=$out;
+  ''
+  ;
 
   dontDisableStatic = true;
 
   # TODO(@Ericson2314): Always pass "--target" and always prefix.
-  configurePlatforms = [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
-  configureFlags = "
-    ${if hostPlatform.isSunOS then
-      " --enable-long-long --enable-libssp --enable-threads=posix --disable-nls --enable-__cxa_atexit " +
-      # On Illumos/Solaris GNU as is preferred
-      " --with-gnu-as --without-gnu-ld "
-      else ""}
-    --enable-lto
-    ${if enableMultilib then "--enable-multilib --disable-libquadmath" else "--disable-multilib"}
-    ${if enableShared then "" else "--disable-shared"}
-    ${if enablePlugin then "--enable-plugin" else "--disable-plugin"}
-    ${optionalString (isl != null) "--with-isl=${isl}"}
-    ${if langJava then
-      "--with-ecj-jar=${javaEcj} " +
+  configurePlatforms =
+    # TODO(@Ericson2314): Figure out what's going wrong with Arm
+    if hostPlatform == targetPlatform && targetPlatform.isArm
+    then []
+    else [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
+
+  configureFlags =
+    # Basic dependencies
+    [
+      "--with-gmp-include=${gmp.dev}/include"
+      "--with-gmp-lib=${gmp.out}/lib"
+      "--with-mpfr-include=${mpfr.dev}/include"
+      "--with-mpfr-lib=${mpfr.out}/lib"
+      "--with-mpc=${libmpc}"
+    ] ++
+    optional (libelf != null) "--with-libelf=${libelf}" ++
+    optional (!(crossMingw && crossStageStatic))
+      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include" ++
+
+    # Basic configuration
+    [
+      "--enable-lto"
+      "--disable-libstdcxx-pch"
+      "--without-included-gettext"
+      "--with-system-zlib"
+      "--enable-static"
+      "--enable-languages=${
+        concatStrings (intersperse ","
+          (  optional langC        "c"
+          ++ optional langCC       "c++"
+          ++ optional langFortran  "fortran"
+          ++ optional langJava     "java"
+          ++ optional langAda      "ada"
+          ++ optional langVhdl     "vhdl"
+          ++ optional langGo       "go"
+          ++ optional langObjC     "objc"
+          ++ optional langObjCpp   "obj-c++"
+          ++ optionals crossDarwin [ "objc" "obj-c++" ]
+          )
+        )
+      }"
+    ] ++
+
+    (if enableMultilib
+      then ["--enable-multilib" "--disable-libquadmath"]
+      else ["--disable-multilib"]) ++
+    optional (!enableShared) "--disable-shared" ++
+    (if enablePlugin
+      then ["--enable-plugin"]
+      else ["--disable-plugin"]) ++
+
+    # Optional features
+    optional (isl != null) "--with-isl=${isl}" ++
+
+    # Java options
+    optionals langJava [
+      "--with-ecj-jar=${javaEcj}"
 
       # Follow Sun's layout for the convenience of IcedTea/OpenJDK.  See
       # <http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2010-April/008888.html>.
-      "--enable-java-home --with-java-home=\${prefix}/lib/jvm/jre "
-      else ""}
-    ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
-    ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr}" else ""}
-    --with-gmp-include=${gmp.dev}/include
-    --with-gmp-lib=${gmp.out}/lib
-    --with-mpfr-include=${mpfr.dev}/include
-    --with-mpfr-lib=${mpfr.out}/lib
-    --with-mpc=${libmpc}
-    ${if libelf != null then "--with-libelf=${libelf}" else ""}
-    --disable-libstdcxx-pch
-    --without-included-gettext
-    --with-system-zlib
-    --enable-static
-    --enable-languages=${
-      concatStrings (intersperse ","
-        (  optional langC        "c"
-        ++ optional langCC       "c++"
-        ++ optional langFortran  "fortran"
-        ++ optional langJava     "java"
-        ++ optional langAda      "ada"
-        ++ optional langVhdl     "vhdl"
-        ++ optional langGo       "go"
-        ++ optional langObjC     "objc"
-        ++ optional langObjCpp   "obj-c++"
-        ++ optionals crossDarwin [ "objc" "obj-c++" ]
-        )
-      )
-    }
-    ${optionalString (!(crossMingw && crossStageStatic))
-      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include"}
-    ${if langAda then " --enable-libada" else ""}
-    ${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
-    ${platformFlags}
-    ${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
-    ${if !bootstrap then "--disable-bootstrap" else ""}
-  ";
+      "--enable-java-home"
+      "--with-java-home=\${prefix}/lib/jvm/jre"
+    ] ++
+    optional javaAwtGtk "--enable-java-awt=gtk" ++
+    optional (langJava && javaAntlr != null) "--with-antlr-jar=${javaAntlr}" ++
+
+    # Ada
+    optional langAda "--enable-libada" ++
+
+    platformFlags ++
+    optional (targetPlatform != hostPlatform) crossConfigureFlags ++
+    optional (!bootstrap) "--disable-bootstrap" ++
+
+    # Platform-specific flags
+    optional (targetPlatform == hostPlatform && targetPlatform.isi686) "--with-arch=i686" ++
+    optionals (hostPlatform.isSunOS) [
+      "--enable-long-long" "--enable-libssp" "--enable-threads=posix" "--disable-nls" "--enable-__cxa_atexit"
+      # On Illumos/Solaris GNU as is preferred
+      "--with-gnu-as" "--without-gnu-ld"
+    ]
+  ;
 
   targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
 
-  buildFlags = if bootstrap then
-    (if profiledCompiler then "profiledbootstrap" else "bootstrap")
-    else "";
+  buildFlags =
+    optional bootstrap (if profiledCompiler then "profiledbootstrap" else "bootstrap");
 
   installTargets =
     if stripped
     then "install-strip"
     else "install";
 
+  /* For cross-built gcc (build != host == target) */
   crossAttrs = {
     AR_FOR_BUILD = "ar";
     AS_FOR_BUILD = "as";
@@ -522,4 +556,10 @@ stdenv.mkDerivation ({
 // optionalAttrs (!stripped || targetPlatform != hostPlatform) { dontStrip = true; }
 
 // optionalAttrs (enableMultilib) { dontMoveLib64 = true; }
+
+// optionalAttrs (langJava) {
+     postFixup = ''
+       target="$(echo "$out/libexec/gcc"/*/*/ecj*)"
+       patchelf --set-rpath "$(patchelf --print-rpath "$target"):$out/lib" "$target"
+     '';}
 )
diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix
index 042e5d577b26..dcfbc1c7cd6e 100644
--- a/pkgs/development/compilers/gcc/7/default.nix
+++ b/pkgs/development/compilers/gcc/7/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, noSysDirs
+{ stdenv, targetPackages, fetchurl, noSysDirs
 , langC ? true, langCC ? true, langFortran ? false
 , langObjC ? targetPlatform.isDarwin
 , langObjCpp ? targetPlatform.isDarwin
@@ -26,12 +26,11 @@
 , enablePlugin ? hostPlatform == buildPlatform # Whether to support user-supplied plug-ins
 , name ? "gcc"
 , libcCross ? null
-, crossStageStatic ? true
+, crossStageStatic ? false
 , gnat ? null
 , libpthread ? null, libpthreadCross ? null  # required for GNU/Hurd
 , stripped ? true
 , gnused ? null
-, binutils ? null
 , cloog # unused; just for compat with gcc4, as we override the parameter on some places
 , darwin ? null
 , flex ? null
@@ -52,7 +51,7 @@ assert libelf != null -> zlib != null;
 assert hostPlatform.isDarwin -> gnused != null;
 
 # Need c++filt on darwin
-assert hostPlatform.isDarwin -> binutils != null;
+assert hostPlatform.isDarwin -> targetPackages.stdenv.cc.bintools or null != null;
 
 # The go frontend is written in c++
 assert langGo -> langCC;
@@ -60,7 +59,7 @@ assert langGo -> langCC;
 with stdenv.lib;
 with builtins;
 
-let version = "7.1.0";
+let version = "7.2.0";
 
     # Whether building a cross-compiler for GNU/Hurd.
     crossGNU = targetPlatform != hostPlatform && targetPlatform.config == "i586-pc-gnu";
@@ -107,78 +106,75 @@ let version = "7.1.0";
         gccFpu = targetPlatform.platform.gcc.fpu or null;
         gccFloat = targetPlatform.platform.gcc.float or null;
         gccMode = targetPlatform.platform.gcc.mode or null;
-        withArch = if gccArch != null then " --with-arch=${gccArch}" else "";
-        withCpu = if gccCpu != null then " --with-cpu=${gccCpu}" else "";
-        withAbi = if gccAbi != null then " --with-abi=${gccAbi}" else "";
-        withFpu = if gccFpu != null then " --with-fpu=${gccFpu}" else "";
-        withFloat = if gccFloat != null then " --with-float=${gccFloat}" else "";
-        withMode = if gccMode != null then " --with-mode=${gccMode}" else "";
       in
-        withArch +
-        withCpu +
-        withAbi +
-        withFpu +
-        withFloat +
-        withMode;
-
-    /* Cross-gcc settings */
+        optional (gccArch != null) "--with-arch=${gccArch}" ++
+        optional (gccCpu != null) "--with-cpu=${gccCpu}" ++
+        optional (gccAbi != null) "--with-abi=${gccAbi}" ++
+        optional (gccFpu != null) "--with-fpu=${gccFpu}" ++
+        optional (gccFloat != null) "--with-float=${gccFloat}" ++
+        optional (gccMode != null) "--with-mode=${gccMode}";
+
+    /* Cross-gcc settings (build == host != target) */
     crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt";
     crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem";
     crossConfigureFlags =
-        # Ensure that -print-prog-name is able to find the correct programs.
-        " --with-as=${binutils}/bin/${targetPlatform.config}-as" +
-        " --with-ld=${binutils}/bin/${targetPlatform.config}-ld" +
-        (if crossMingw && crossStageStatic then
-          " --with-headers=${libcCross}/include" +
-          " --with-gcc" +
-          " --with-gnu-as" +
-          " --with-gnu-ld" +
-          " --with-gnu-ld" +
-          " --disable-shared" +
-          " --disable-nls" +
-          " --disable-debug" +
-          " --enable-sjlj-exceptions" +
-          " --enable-threads=win32" +
-          " --disable-win32-registry"
-          else if crossStageStatic then
-          " --disable-libssp --disable-nls" +
-          " --without-headers" +
-          " --disable-threads " +
-          " --disable-libgomp " +
-          " --disable-libquadmath" +
-          " --disable-shared" +
-          " --disable-libatomic " +  # libatomic requires libc
-          " --disable-decimal-float" # libdecnumber requires libc
-          else
-          (if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot"
-           else                " --with-headers=${getDev libcCross}/include") +
-          # Ensure that -print-prog-name is able to find the correct programs.
-          " --enable-__cxa_atexit" +
-          " --enable-long-long" +
-          (if crossMingw then
-            " --enable-threads=win32" +
-            " --enable-sjlj-exceptions" +
-            " --enable-hash-synchronization" +
-            " --enable-libssp" +
-            " --disable-nls" +
-            " --with-dwarf2" +
-            # To keep ABI compatibility with upstream mingw-w64
-            " --enable-fully-dynamic-string"
-            else (if targetPlatform.libc == "uclibc" then
-              # libsanitizer requires netrom/netrom.h which is not
-              # available in uclibc.
-              " --disable-libsanitizer" +
-              # In uclibc cases, libgomp needs an additional '-ldl'
-              # and as I don't know how to pass it, I disable libgomp.
-              " --disable-libgomp" else "") +
-            " --enable-threads=posix" +
-            " --enable-nls" +
-            " --disable-decimal-float") # No final libdecnumber (it may work only in 386)
-          );
+      # Ensure that -print-prog-name is able to find the correct programs.
+      [ "--with-as=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
+        "--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld" ] ++
+      (if crossMingw && crossStageStatic then [
+        "--with-headers=${libcCross}/include"
+        "--with-gcc"
+        "--with-gnu-as"
+        "--with-gnu-ld"
+        "--with-gnu-ld"
+        "--disable-shared"
+        "--disable-nls"
+        "--disable-debug"
+        "--enable-sjlj-exceptions"
+        "--enable-threads=win32"
+        "--disable-win32-registry"
+      ] else if crossStageStatic then [
+        "--disable-libssp"
+        "--disable-nls"
+        "--without-headers"
+        "--disable-threads"
+        "--disable-libgomp"
+        "--disable-libquadmath"
+        "--disable-shared"
+        "--disable-libatomic"  # libatomic requires libc
+        "--disable-decimal-float" # libdecnumber requires libc
+      ] else [
+        (if crossDarwin then "--with-sysroot=${getLib libcCross}/share/sysroot"
+         else                "--with-headers=${getDev libcCross}/include")
+        "--enable-__cxa_atexit"
+        "--enable-long-long"
+      ] ++
+        (if crossMingw then [
+          "--enable-threads=win32"
+          "--enable-sjlj-exceptions"
+          "--enable-hash-synchronization"
+          "--enable-libssp"
+          "--disable-nls"
+          "--with-dwarf2"
+          # To keep ABI compatibility with upstream mingw-w64
+          "--enable-fully-dynamic-string"
+        ] else
+          optionals (targetPlatform.libc == "uclibc") [
+            # libsanitizer requires netrom/netrom.h which is not
+            # available in uclibc.
+            "--disable-libsanitizer"
+            # In uclibc cases, libgomp needs an additional '-ldl'
+            # and as I don't know how to pass it, I disable libgomp.
+            "--disable-libgomp"
+          ] ++ [
+          "--enable-threads=posix"
+          "--enable-nls"
+          "--disable-decimal-float" # No final libdecnumber (it may work only in 386)
+        ]));
     stageNameAddon = if crossStageStatic then "-stage-static" else "-stage-final";
     crossNameAddon = if targetPlatform != hostPlatform then "-${targetPlatform.config}" + stageNameAddon else "";
 
-  bootstrap = targetPlatform == hostPlatform;
+    bootstrap = targetPlatform == hostPlatform;
 
 in
 
@@ -191,8 +187,8 @@ stdenv.mkDerivation ({
   builder = ../builder.sh;
 
   src = fetchurl {
-    url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.bz2";
-    sha256 = "05xwps0ci7wgxh50askpa2r9p8518qxdgh6ad7pnyk7n6p13d0ca";
+    url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz";
+    sha256 = "16j7i0888j2f1yp9l0nhji6cq65dy6y4nwy8868a8njbzzwavxqw";
   };
 
   inherit patches;
@@ -272,7 +268,9 @@ stdenv.mkDerivation ({
         ''
     else null;
 
-  inherit noSysDirs staticCompiler langJava crossStageStatic
+  # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild,
+  crossStageStatic = targetPlatform == hostPlatform || crossStageStatic;
+  inherit noSysDirs staticCompiler langJava
     libcCross crossMingw;
 
   nativeBuildInputs = [ texinfo which gettext ]
@@ -284,14 +282,14 @@ stdenv.mkDerivation ({
     ++ (optional (zlib != null) zlib)
     ++ (optionals langJava [ boehmgc zip unzip ])
     ++ (optionals javaAwtGtk ([ gtk2 libart_lgpl ] ++ xlibs))
-    ++ (optionals (targetPlatform != hostPlatform) [binutils])
+    ++ (optionals (targetPlatform != hostPlatform) [targetPackages.stdenv.cc.bintools])
     ++ (optionals langAda [gnatboot])
     ++ (optionals langVhdl [gnat])
 
     # The builder relies on GNU sed (for instance, Darwin's `sed' fails with
     # "-i may not be used with stdin"), and `stdenvNative' doesn't provide it.
     ++ (optional hostPlatform.isDarwin gnused)
-    ++ (optional hostPlatform.isDarwin binutils)
+    ++ (optional hostPlatform.isDarwin targetPackages.stdenv.cc.bintools)
     ;
 
   NIX_LDFLAGS = stdenv.lib.optionalString  hostPlatform.isSunOS "-lm -ldl";
@@ -306,60 +304,87 @@ stdenv.mkDerivation ({
   dontDisableStatic = true;
 
   # TODO(@Ericson2314): Always pass "--target" and always prefix.
-  configurePlatforms = [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
-  configureFlags = "
-    ${if hostPlatform.isSunOS then
-      " --enable-long-long --enable-libssp --enable-threads=posix --disable-nls --enable-__cxa_atexit " +
-      # On Illumos/Solaris GNU as is preferred
-      " --with-gnu-as --without-gnu-ld "
-      else ""}
-    --enable-lto
-    ${if enableMultilib then "--enable-multilib --disable-libquadmath" else "--disable-multilib"}
-    ${if enableShared then "" else "--disable-shared"}
-    ${if enablePlugin then "--enable-plugin" else "--disable-plugin"}
-    ${optionalString (isl != null) "--with-isl=${isl}"}
-    ${if langJava then
-      "--with-ecj-jar=${javaEcj} " +
+  configurePlatforms =
+    # TODO(@Ericson2314): Figure out what's going wrong with Arm
+    if hostPlatform == targetPlatform && targetPlatform.isArm
+    then []
+    else [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
+
+  configureFlags =
+    # Basic dependencies
+    [
+      "--with-gmp-include=${gmp.dev}/include"
+      "--with-gmp-lib=${gmp.out}/lib"
+      "--with-mpfr-include=${mpfr.dev}/include"
+      "--with-mpfr-lib=${mpfr.out}/lib"
+      "--with-mpc=${libmpc}"
+    ] ++
+    optional (libelf != null) "--with-libelf=${libelf}" ++
+    optional (!(crossMingw && crossStageStatic))
+      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include" ++
+
+    # Basic configuration
+    [
+      "--enable-lto"
+      "--disable-libstdcxx-pch"
+      "--without-included-gettext"
+      "--with-system-zlib"
+      "--enable-static"
+      "--enable-languages=${
+        concatStrings (intersperse ","
+          (  optional langC        "c"
+          ++ optional langCC       "c++"
+          ++ optional langFortran  "fortran"
+          ++ optional langJava     "java"
+          ++ optional langAda      "ada"
+          ++ optional langVhdl     "vhdl"
+          ++ optional langGo       "go"
+          ++ optional langObjC     "objc"
+          ++ optional langObjCpp   "obj-c++"
+          ++ optionals crossDarwin [ "objc" "obj-c++" ]
+          )
+        )
+      }"
+    ] ++
+
+    (if enableMultilib
+      then ["--enable-multilib" "--disable-libquadmath"]
+      else ["--disable-multilib"]) ++
+    optional (!enableShared) "--disable-shared" ++
+    (if enablePlugin
+      then ["--enable-plugin"]
+      else ["--disable-plugin"]) ++
+
+    # Optional features
+    optional (isl != null) "--with-isl=${isl}" ++
+
+    # Java options
+    optionals langJava [
+      "--with-ecj-jar=${javaEcj}"
 
       # Follow Sun's layout for the convenience of IcedTea/OpenJDK.  See
       # <http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2010-April/008888.html>.
-      "--enable-java-home --with-java-home=\${prefix}/lib/jvm/jre "
-      else ""}
-    ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
-    ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr}" else ""}
-    --with-gmp-include=${gmp.dev}/include
-    --with-gmp-lib=${gmp.out}/lib
-    --with-mpfr-include=${mpfr.dev}/include
-    --with-mpfr-lib=${mpfr.out}/lib
-    --with-mpc=${libmpc}
-    ${if libelf != null then "--with-libelf=${libelf}" else ""}
-    --disable-libstdcxx-pch
-    --without-included-gettext
-    --with-system-zlib
-    --enable-static
-    --enable-languages=${
-      concatStrings (intersperse ","
-        (  optional langC        "c"
-        ++ optional langCC       "c++"
-        ++ optional langFortran  "fortran"
-        ++ optional langJava     "java"
-        ++ optional langAda      "ada"
-        ++ optional langVhdl     "vhdl"
-        ++ optional langGo       "go"
-        ++ optional langObjC     "objc"
-        ++ optional langObjCpp   "obj-c++"
-        ++ optionals crossDarwin [ "objc" "obj-c++" ]
-        )
-      )
-    }
-    ${optionalString (!(crossMingw && crossStageStatic))
-      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include"}
-    ${if langAda then " --enable-libada" else ""}
-    ${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
-    ${platformFlags}
-    ${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
-    ${if !bootstrap then "--disable-bootstrap" else ""}
-  ";
+      "--enable-java-home"
+      "--with-java-home=\${prefix}/lib/jvm/jre"
+    ] ++
+    optional javaAwtGtk "--enable-java-awt=gtk" ++
+    optional (langJava && javaAntlr != null) "--with-antlr-jar=${javaAntlr}" ++
+
+    # Ada
+    optional langAda "--enable-libada" ++
+
+    platformFlags ++
+    optional (targetPlatform != hostPlatform) crossConfigureFlags ++
+    optional (!bootstrap) "--disable-bootstrap" ++
+
+    # Platform-specific flags
+    optional (targetPlatform == hostPlatform && targetPlatform.isi686) "--with-arch=i686" ++
+    optionals hostPlatform.isSunOS [
+      "--enable-long-long" "--enable-libssp" "--enable-threads=posix" "--disable-nls" "--enable-__cxa_atexit"
+      # On Illumos/Solaris GNU as is preferred
+      "--with-gnu-as" "--without-gnu-ld"
+    ]
+  ;
 
   targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
 
@@ -372,6 +397,7 @@ stdenv.mkDerivation ({
     then "install-strip"
     else "install";
 
+  /* For cross-built gcc (build != host == target) */
   crossAttrs = {
     AR_FOR_BUILD = "ar";
     AS_FOR_BUILD = "as";
diff --git a/pkgs/development/compilers/gcc/libstdc++-hook.sh b/pkgs/development/compilers/gcc/libstdc++-hook.sh
new file mode 100644
index 000000000000..2d30c845b5a3
--- /dev/null
+++ b/pkgs/development/compilers/gcc/libstdc++-hook.sh
@@ -0,0 +1,2 @@
+export NIX_CXXSTDLIB_COMPILE+="-isystem $(echo -n @gcc@/include/c++/*) -isystem $(echo -n @gcc@/include/c++/*)/$(@gcc@/bin/gcc -dumpmachine)"
+export NIX_CXXSTDLIB_LINK=" -stdlib=libstdc++"
diff --git a/pkgs/development/compilers/gcc/res_state-not-declared.patch b/pkgs/development/compilers/gcc/res_state-not-declared.patch
new file mode 100644
index 000000000000..e970487786d0
--- /dev/null
+++ b/pkgs/development/compilers/gcc/res_state-not-declared.patch
@@ -0,0 +1,13 @@
+diff --git a/libsanitizer/tsan/tsan_platform_linux.cc b/libsanitizer/tsan/tsan_platform_linux.cc
+index fe69430..49f5270 100644
+--- a/libsanitizer/tsan/tsan_platform_linux.cc
++++ b/libsanitizer/tsan/tsan_platform_linux.cc
+@@ -351,7 +351,7 @@ bool IsGlobalVar(uptr addr) {
+ // closes within glibc. The code is a pure hack.
+ int ExtractResolvFDs(void *state, int *fds, int nfd) {
+   int cnt = 0;
+-  __res_state *statp = (__res_state*)state;
++  struct __res_state *statp = (struct __res_state*)state;
+   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
+     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
+       fds[cnt++] = statp->_u._ext.nssocks[i];
diff --git a/pkgs/development/compilers/gcc/sigsegv-not-declared.patch b/pkgs/development/compilers/gcc/sigsegv-not-declared.patch
new file mode 100644
index 000000000000..f9cfaec82026
--- /dev/null
+++ b/pkgs/development/compilers/gcc/sigsegv-not-declared.patch
@@ -0,0 +1,13 @@
+error: 'SIGSEGV' was not declared in this scope
+diff --git a/libsanitizer/asan/asan_linux.cc b/libsanitizer/asan/asan_linux.cc
+index 0692eb1..472f734 100644
+--- a/libsanitizer/asan/asan_linux.cc
++++ b/libsanitizer/asan/asan_linux.cc
+@@ -26,6 +26,7 @@
+ #include <sys/types.h>
+ #include <fcntl.h>
+ #include <pthread.h>
++#include <signal.h>
+ #include <stdio.h>
+ #include <unistd.h>
+ #include <unwind.h>
diff --git a/pkgs/development/compilers/gcc/snapshot/default.nix b/pkgs/development/compilers/gcc/snapshot/default.nix
index 8ecc13cbede4..7389eaecfd6a 100644
--- a/pkgs/development/compilers/gcc/snapshot/default.nix
+++ b/pkgs/development/compilers/gcc/snapshot/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, noSysDirs
+{ stdenv, targetPackages, fetchurl, noSysDirs
 , langC ? true, langCC ? true, langFortran ? false
 , langObjC ? targetPlatform.isDarwin
 , langObjCpp ? targetPlatform.isDarwin
@@ -26,12 +26,11 @@
 , enablePlugin ? hostPlatform == buildPlatform # Whether to support user-supplied plug-ins
 , name ? "gcc"
 , libcCross ? null
-, crossStageStatic ? true
+, crossStageStatic ? false
 , gnat ? null
 , libpthread ? null, libpthreadCross ? null  # required for GNU/Hurd
 , stripped ? true
 , gnused ? null
-, binutils ? null
 , cloog # unused; just for compat with gcc4, as we override the parameter on some places
 , darwin ? null
 , flex ? null
@@ -52,7 +51,7 @@ assert libelf != null -> zlib != null;
 assert hostPlatform.isDarwin -> gnused != null;
 
 # Need c++filt on darwin
-assert hostPlatform.isDarwin -> binutils != null;
+assert hostPlatform.isDarwin -> targetPackages.stdenv.cc.bintools or null != null;
 
 # The go frontend is written in c++
 assert langGo -> langCC;
@@ -107,78 +106,75 @@ let version = "7-20170409";
         gccFpu = targetPlatform.platform.gcc.fpu or null;
         gccFloat = targetPlatform.platform.gcc.float or null;
         gccMode = targetPlatform.platform.gcc.mode or null;
-        withArch = if gccArch != null then " --with-arch=${gccArch}" else "";
-        withCpu = if gccCpu != null then " --with-cpu=${gccCpu}" else "";
-        withAbi = if gccAbi != null then " --with-abi=${gccAbi}" else "";
-        withFpu = if gccFpu != null then " --with-fpu=${gccFpu}" else "";
-        withFloat = if gccFloat != null then " --with-float=${gccFloat}" else "";
-        withMode = if gccMode != null then " --with-mode=${gccMode}" else "";
       in
-        withArch +
-        withCpu +
-        withAbi +
-        withFpu +
-        withFloat +
-        withMode;
-
-    /* Cross-gcc settings */
+        optional (gccArch != null) "--with-arch=${gccArch}" ++
+        optional (gccCpu != null) "--with-cpu=${gccCpu}" ++
+        optional (gccAbi != null) "--with-abi=${gccAbi}" ++
+        optional (gccFpu != null) "--with-fpu=${gccFpu}" ++
+        optional (gccFloat != null) "--with-float=${gccFloat}" ++
+        optional (gccMode != null) "--with-mode=${gccMode}";
+
+    /* Cross-gcc settings (build == host != target) */
     crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt";
     crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem";
     crossConfigureFlags =
-        # Ensure that -print-prog-name is able to find the correct programs.
-        " --with-as=${binutils}/bin/${targetPlatform.config}-as" +
-        " --with-ld=${binutils}/bin/${targetPlatform.config}-ld" +
-        (if crossMingw && crossStageStatic then
-          " --with-headers=${libcCross}/include" +
-          " --with-gcc" +
-          " --with-gnu-as" +
-          " --with-gnu-ld" +
-          " --with-gnu-ld" +
-          " --disable-shared" +
-          " --disable-nls" +
-          " --disable-debug" +
-          " --enable-sjlj-exceptions" +
-          " --enable-threads=win32" +
-          " --disable-win32-registry"
-          else if crossStageStatic then
-          " --disable-libssp --disable-nls" +
-          " --without-headers" +
-          " --disable-threads " +
-          " --disable-libgomp " +
-          " --disable-libquadmath" +
-          " --disable-shared" +
-          " --disable-libatomic " +  # libatomic requires libc
-          " --disable-decimal-float" # libdecnumber requires libc
-          else
-          (if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot"
-           else                " --with-headers=${getDev libcCross}/include") +
-          # Ensure that -print-prog-name is able to find the correct programs.
-          " --enable-__cxa_atexit" +
-          " --enable-long-long" +
-          (if crossMingw then
-            " --enable-threads=win32" +
-            " --enable-sjlj-exceptions" +
-            " --enable-hash-synchronization" +
-            " --enable-libssp" +
-            " --disable-nls" +
-            " --with-dwarf2" +
-            # To keep ABI compatibility with upstream mingw-w64
-            " --enable-fully-dynamic-string"
-            else (if targetPlatform.libc == "uclibc" then
-              # libsanitizer requires netrom/netrom.h which is not
-              # available in uclibc.
-              " --disable-libsanitizer" +
-              # In uclibc cases, libgomp needs an additional '-ldl'
-              # and as I don't know how to pass it, I disable libgomp.
-              " --disable-libgomp" else "") +
-            " --enable-threads=posix" +
-            " --enable-nls" +
-            " --disable-decimal-float") # No final libdecnumber (it may work only in 386)
-          );
+      # Ensure that -print-prog-name is able to find the correct programs.
+      [ "--with-as=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
+        "--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld" ] ++
+      (if crossMingw && crossStageStatic then [
+        "--with-headers=${libcCross}/include"
+        "--with-gcc"
+        "--with-gnu-as"
+        "--with-gnu-ld"
+        "--with-gnu-ld"
+        "--disable-shared"
+        "--disable-nls"
+        "--disable-debug"
+        "--enable-sjlj-exceptions"
+        "--enable-threads=win32"
+        "--disable-win32-registry"
+      ] else if crossStageStatic then [
+        "--disable-libssp"
+        "--disable-nls"
+        "--without-headers"
+        "--disable-threads"
+        "--disable-libgomp"
+        "--disable-libquadmath"
+        "--disable-shared"
+        "--disable-libatomic"  # libatomic requires libc
+        "--disable-decimal-float" # libdecnumber requires libc
+      ] else [
+        (if crossDarwin then "--with-sysroot=${getLib libcCross}/share/sysroot"
+         else                "--with-headers=${getDev libcCross}/include")
+        "--enable-__cxa_atexit"
+        "--enable-long-long"
+      ] ++
+        (if crossMingw then [
+          "--enable-threads=win32"
+          "--enable-sjlj-exceptions"
+          "--enable-hash-synchronization"
+          "--enable-libssp"
+          "--disable-nls"
+          "--with-dwarf2"
+          # To keep ABI compatibility with upstream mingw-w64
+          "--enable-fully-dynamic-string"
+        ] else
+          optionals (targetPlatform.libc == "uclibc") [
+            # libsanitizer requires netrom/netrom.h which is not
+            # available in uclibc.
+            "--disable-libsanitizer"
+            # In uclibc cases, libgomp needs an additional '-ldl'
+            # and as I don't know how to pass it, I disable libgomp.
+            "--disable-libgomp"
+          ] ++ [
+          "--enable-threads=posix"
+          "--enable-nls"
+          "--disable-decimal-float" # No final libdecnumber (it may work only in 386)
+        ]));
     stageNameAddon = if crossStageStatic then "-stage-static" else "-stage-final";
     crossNameAddon = if targetPlatform != hostPlatform then "-${targetPlatform.config}" + stageNameAddon else "";
 
-  bootstrap = targetPlatform == hostPlatform;
+    bootstrap = targetPlatform == hostPlatform;
 
 in
 
@@ -259,7 +255,9 @@ stdenv.mkDerivation ({
         ''
     else null;
 
-  inherit noSysDirs staticCompiler langJava crossStageStatic
+  # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild,
+  crossStageStatic = targetPlatform == hostPlatform || crossStageStatic;
+  inherit noSysDirs staticCompiler langJava
     libcCross crossMingw;
 
   nativeBuildInputs = [ texinfo which gettext ]
@@ -271,14 +269,14 @@ stdenv.mkDerivation ({
     ++ (optional (zlib != null) zlib)
     ++ (optionals langJava [ boehmgc zip unzip ])
     ++ (optionals javaAwtGtk ([ gtk2 libart_lgpl ] ++ xlibs))
-    ++ (optionals (targetPlatform != hostPlatform) [binutils])
+    ++ (optionals (targetPlatform != hostPlatform) [targetPackages.stdenv.cc.bintools])
     ++ (optionals langAda [gnatboot])
     ++ (optionals langVhdl [gnat])
 
     # The builder relies on GNU sed (for instance, Darwin's `sed' fails with
     # "-i may not be used with stdin"), and `stdenvNative' doesn't provide it.
     ++ (optional hostPlatform.isDarwin gnused)
-    ++ (optional hostPlatform.isDarwin binutils)
+    ++ (optional hostPlatform.isDarwin targetPackages.stdenv.cc.bintools)
     ;
 
   NIX_LDFLAGS = stdenv.lib.optionalString  hostPlatform.isSunOS "-lm -ldl";
@@ -293,60 +291,87 @@ stdenv.mkDerivation ({
   dontDisableStatic = true;
 
   # TODO(@Ericson2314): Always pass "--target" and always prefix.
-  configurePlatforms = [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
-  configureFlags = "
-    ${if hostPlatform.isSunOS then
-      " --enable-long-long --enable-libssp --enable-threads=posix --disable-nls --enable-__cxa_atexit " +
-      # On Illumos/Solaris GNU as is preferred
-      " --with-gnu-as --without-gnu-ld "
-      else ""}
-    --enable-lto
-    ${if enableMultilib then "--enable-multilib --disable-libquadmath" else "--disable-multilib"}
-    ${if enableShared then "" else "--disable-shared"}
-    ${if enablePlugin then "--enable-plugin" else "--disable-plugin"}
-    ${optionalString (isl != null) "--with-isl=${isl}"}
-    ${if langJava then
-      "--with-ecj-jar=${javaEcj} " +
+  configurePlatforms =
+    # TODO(@Ericson2314): Figure out what's going wrong with Arm
+    if hostPlatform == targetPlatform && targetPlatform.isArm
+    then []
+    else [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
+
+  configureFlags =
+    # Basic dependencies
+    [
+      "--with-gmp-include=${gmp.dev}/include"
+      "--with-gmp-lib=${gmp.out}/lib"
+      "--with-mpfr-include=${mpfr.dev}/include"
+      "--with-mpfr-lib=${mpfr.out}/lib"
+      "--with-mpc=${libmpc}"
+    ] ++
+    optional (libelf != null) "--with-libelf=${libelf}" ++
+    optional (!(crossMingw && crossStageStatic))
+      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include" ++
+
+    # Basic configuration
+    [
+      "--enable-lto"
+      "--disable-libstdcxx-pch"
+      "--without-included-gettext"
+      "--with-system-zlib"
+      "--enable-static"
+      "--enable-languages=${
+        concatStrings (intersperse ","
+          (  optional langC        "c"
+          ++ optional langCC       "c++"
+          ++ optional langFortran  "fortran"
+          ++ optional langJava     "java"
+          ++ optional langAda      "ada"
+          ++ optional langVhdl     "vhdl"
+          ++ optional langGo       "go"
+          ++ optional langObjC     "objc"
+          ++ optional langObjCpp   "obj-c++"
+          ++ optionals crossDarwin [ "objc" "obj-c++" ]
+          )
+        )
+      }"
+    ] ++
+
+    (if enableMultilib
+      then ["--enable-multilib" "--disable-libquadmath"]
+      else ["--disable-multilib"]) ++
+    optional (!enableShared) "--disable-shared" ++
+    (if enablePlugin
+      then ["--enable-plugin"]
+      else ["--disable-plugin"]) ++
+
+    # Optional features
+    optional (isl != null) "--with-isl=${isl}" ++
+
+    # Java options
+    optionals langJava [
+      "--with-ecj-jar=${javaEcj}"
 
       # Follow Sun's layout for the convenience of IcedTea/OpenJDK.  See
       # <http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2010-April/008888.html>.
-      "--enable-java-home --with-java-home=\${prefix}/lib/jvm/jre "
-      else ""}
-    ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
-    ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr}" else ""}
-    --with-gmp-include=${gmp.dev}/include
-    --with-gmp-lib=${gmp.out}/lib
-    --with-mpfr-include=${mpfr.dev}/include
-    --with-mpfr-lib=${mpfr.out}/lib
-    --with-mpc=${libmpc}
-    ${if libelf != null then "--with-libelf=${libelf}" else ""}
-    --disable-libstdcxx-pch
-    --without-included-gettext
-    --with-system-zlib
-    --enable-static
-    --enable-languages=${
-      concatStrings (intersperse ","
-        (  optional langC        "c"
-        ++ optional langCC       "c++"
-        ++ optional langFortran  "fortran"
-        ++ optional langJava     "java"
-        ++ optional langAda      "ada"
-        ++ optional langVhdl     "vhdl"
-        ++ optional langGo       "go"
-        ++ optional langObjC     "objc"
-        ++ optional langObjCpp   "obj-c++"
-        ++ optionals crossDarwin [ "objc" "obj-c++" ]
-        )
-      )
-    }
-    ${optionalString (!(crossMingw && crossStageStatic))
-      "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include"}
-    ${if langAda then " --enable-libada" else ""}
-    ${if targetPlatform == hostPlatform && targetPlatform.isi686 then "--with-arch=i686" else ""}
-    ${platformFlags}
-    ${if targetPlatform != hostPlatform then crossConfigureFlags else ""}
-    ${if !bootstrap then "--disable-bootstrap" else ""}
-  ";
+      "--enable-java-home"
+      "--with-java-home=\${prefix}/lib/jvm/jre"
+    ] ++
+    optional javaAwtGtk "--enable-java-awt=gtk" ++
+    optional (langJava && javaAntlr != null) "--with-antlr-jar=${javaAntlr}" ++
+
+    # Ada
+    optional langAda "--enable-libada" ++
+
+    platformFlags ++
+    optional (targetPlatform != hostPlatform) crossConfigureFlags ++
+    optional (!bootstrap) "--disable-bootstrap" ++
+
+    # Platform-specific flags
+    optional (targetPlatform == hostPlatform && targetPlatform.isi686) "--with-arch=i686" ++
+    optionals hostPlatform.isSunOS [
+      "--enable-long-long" "--enable-libssp" "--enable-threads=posix" "--disable-nls" "--enable-__cxa_atexit"
+      # On Illumos/Solaris GNU as is preferred
+      "--with-gnu-as" "--without-gnu-ld"
+    ]
+  ;
 
   targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
 
@@ -359,6 +384,7 @@ stdenv.mkDerivation ({
     then "install-strip"
     else "install";
 
+  /* For cross-built gcc (build != host == target) */
   crossAttrs = {
     AR_FOR_BUILD = "ar";
     AS_FOR_BUILD = "as";
diff --git a/pkgs/development/compilers/gcc/struct-sigaltstack-4.9.patch b/pkgs/development/compilers/gcc/struct-sigaltstack-4.9.patch
new file mode 100644
index 000000000000..fc126b4813d6
--- /dev/null
+++ b/pkgs/development/compilers/gcc/struct-sigaltstack-4.9.patch
@@ -0,0 +1,78 @@
+hand-resolved trivial conflicts for 4.9 from the upstream patch
+72edc2c02f8b4768ad660f46a1c7e2400c0a8e06
+diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cc b/libsanitizer/sanitizer_common/sanitizer_linux.cc
+index 69c9c10..8e53673 100644
+--- a/libsanitizer/sanitizer_common/sanitizer_linux.cc
++++ b/libsanitizer/sanitizer_common/sanitizer_linux.cc
+@@ -599,8 +599,7 @@ uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5) {
+   return internal_syscall(__NR_prctl, option, arg2, arg3, arg4, arg5);
+ }
+ 
+-uptr internal_sigaltstack(const struct sigaltstack *ss,
+-                         struct sigaltstack *oss) {
++uptr internal_sigaltstack(const void *ss, void *oss) {
+   return internal_syscall(__NR_sigaltstack, (uptr)ss, (uptr)oss);
+ }
+ 
+diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.h b/libsanitizer/sanitizer_common/sanitizer_linux.h
+index 6422df1..8e111d1 100644
+--- a/libsanitizer/sanitizer_common/sanitizer_linux.h
++++ b/libsanitizer/sanitizer_common/sanitizer_linux.h
+@@ -18,7 +18,6 @@
+ #include "sanitizer_platform_limits_posix.h"
+ 
+ struct link_map;  // Opaque type returned by dlopen().
+-struct sigaltstack;
+ 
+ namespace __sanitizer {
+ // Dirent structure for getdents(). Note that this structure is different from
+@@ -28,8 +27,7 @@ struct linux_dirent;
+ // Syscall wrappers.
+ uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
+ uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5);
+-uptr internal_sigaltstack(const struct sigaltstack* ss,
+-                          struct sigaltstack* oss);
++uptr internal_sigaltstack(const void* ss, void* oss);
+ uptr internal_sigaction(int signum, const __sanitizer_kernel_sigaction_t *act,
+     __sanitizer_kernel_sigaction_t *oldact);
+ uptr internal_sigprocmask(int how, __sanitizer_kernel_sigset_t *set,
+diff --git a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+index 891386dc..234e8c6 100644
+--- a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
++++ b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+@@ -273,7 +273,7 @@ static int TracerThread(void* argument) {
+ 
+   // Alternate stack for signal handling.
+   InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
+-  struct sigaltstack handler_stack;
++  stack_t handler_stack;
+   internal_memset(&handler_stack, 0, sizeof(handler_stack));
+   handler_stack.ss_sp = handler_stack_memory.data();
+   handler_stack.ss_size = kHandlerStackSize;
+diff --git a/libsanitizer/tsan/tsan_platform_linux.cc b/libsanitizer/tsan/tsan_platform_linux.cc
+index 2ed5718..6f972ab 100644
+--- a/libsanitizer/tsan/tsan_platform_linux.cc
++++ b/libsanitizer/tsan/tsan_platform_linux.cc
+@@ -287,7 +287,7 @@ void InitializePlatform() {
+ int ExtractResolvFDs(void *state, int *fds, int nfd) {
+ #if SANITIZER_LINUX && !SANITIZER_ANDROID
+   int cnt = 0;
+-  __res_state *statp = (__res_state*)state;
++  struct __res_state *statp = (struct __res_state*)state;
+   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
+     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
+       fds[cnt++] = statp->_u._ext.nssocks[i];
+
+error: 'SIGSEGV' was not declared in this scope
+diff --git a/libsanitizer/asan/asan_linux.cc b/libsanitizer/asan/asan_linux.cc
+index 0692eb1..472f734 100644
+--- a/libsanitizer/asan/asan_linux.cc
++++ b/libsanitizer/asan/asan_linux.cc
+@@ -26,6 +26,7 @@
+ #include <sys/types.h>
+ #include <fcntl.h>
+ #include <pthread.h>
++#include <signal.h>
+ #include <stdio.h>
+ #include <unistd.h>
+ #include <unwind.h>
diff --git a/pkgs/development/compilers/gcc/struct-sigaltstack.patch b/pkgs/development/compilers/gcc/struct-sigaltstack.patch
new file mode 100644
index 000000000000..6e1ddb252c24
--- /dev/null
+++ b/pkgs/development/compilers/gcc/struct-sigaltstack.patch
@@ -0,0 +1,87 @@
+From 72edc2c02f8b4768ad660f46a1c7e2400c0a8e06 Mon Sep 17 00:00:00 2001
+From: jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Mon, 17 Jul 2017 19:41:08 +0000
+Subject: [PATCH] 	Backported from mainline 	2017-07-14  Jakub
+ Jelinek  <jakub@redhat.com>
+
+	PR sanitizer/81066
+	* sanitizer_common/sanitizer_linux.h: Cherry-pick upstream r307969.
+	* sanitizer_common/sanitizer_linux.cc: Likewise.
+	* sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc: Likewise.
+	* tsan/tsan_platform_linux.cc: Likewise.
+
+
+git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@250287 138bc75d-0d04-0410-961f-82ee72b054a4
+---
+ libsanitizer/ChangeLog  (REMOVED)                             | 11 +++++++++++
+ libsanitizer/sanitizer_common/sanitizer_linux.cc              |  3 +--
+ libsanitizer/sanitizer_common/sanitizer_linux.h               |  4 +---
+ .../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc  |  2 +-
+ libsanitizer/tsan/tsan_platform_linux.cc                      |  2 +-
+ 5 files changed, 15 insertions(+), 7 deletions(-)
+
+diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cc b/libsanitizer/sanitizer_common/sanitizer_linux.cc
+index 806fcd5..5b6f186 100644
+--- a/libsanitizer/sanitizer_common/sanitizer_linux.cc
++++ b/libsanitizer/sanitizer_common/sanitizer_linux.cc
+@@ -605,8 +605,7 @@ uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5) {
+ }
+ #endif
+ 
+-uptr internal_sigaltstack(const struct sigaltstack *ss,
+-                         struct sigaltstack *oss) {
++uptr internal_sigaltstack(const void *ss, void *oss) {
+   return internal_syscall(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
+ }
+ 
+diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.h b/libsanitizer/sanitizer_common/sanitizer_linux.h
+index 895bfc1..a42df57 100644
+--- a/libsanitizer/sanitizer_common/sanitizer_linux.h
++++ b/libsanitizer/sanitizer_common/sanitizer_linux.h
+@@ -19,7 +19,6 @@
+ #include "sanitizer_platform_limits_posix.h"
+ 
+ struct link_map;  // Opaque type returned by dlopen().
+-struct sigaltstack;
+ 
+ namespace __sanitizer {
+ // Dirent structure for getdents(). Note that this structure is different from
+@@ -28,8 +27,7 @@ struct linux_dirent;
+ 
+ // Syscall wrappers.
+ uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
+-uptr internal_sigaltstack(const struct sigaltstack* ss,
+-                          struct sigaltstack* oss);
++uptr internal_sigaltstack(const void* ss, void* oss);
+ uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
+     __sanitizer_sigset_t *oldset);
+ 
+diff --git a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+index 891386dc..234e8c6 100644
+--- a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
++++ b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+@@ -273,7 +273,7 @@ static int TracerThread(void* argument) {
+ 
+   // Alternate stack for signal handling.
+   InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
+-  struct sigaltstack handler_stack;
++  stack_t handler_stack;
+   internal_memset(&handler_stack, 0, sizeof(handler_stack));
+   handler_stack.ss_sp = handler_stack_memory.data();
+   handler_stack.ss_size = kHandlerStackSize;
+diff --git a/libsanitizer/tsan/tsan_platform_linux.cc b/libsanitizer/tsan/tsan_platform_linux.cc
+index 2ed5718..6f972ab 100644
+--- a/libsanitizer/tsan/tsan_platform_linux.cc
++++ b/libsanitizer/tsan/tsan_platform_linux.cc
+@@ -287,7 +287,7 @@ void InitializePlatform() {
+ int ExtractResolvFDs(void *state, int *fds, int nfd) {
+ #if SANITIZER_LINUX && !SANITIZER_ANDROID
+   int cnt = 0;
+-  __res_state *statp = (__res_state*)state;
++  struct __res_state *statp = (struct __res_state*)state;
+   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
+     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
+       fds[cnt++] = statp->_u._ext.nssocks[i];
+-- 
+2.9.3
+
diff --git a/pkgs/development/compilers/gcc/struct-ucontext-4.5.patch b/pkgs/development/compilers/gcc/struct-ucontext-4.5.patch
new file mode 100644
index 000000000000..a84e9ffe2681
--- /dev/null
+++ b/pkgs/development/compilers/gcc/struct-ucontext-4.5.patch
@@ -0,0 +1,107 @@
+Trivally backported the upstream commit
+b685411208e0aaa79190d54faf945763514706b8
+(different directory, some files not present, etc.)
+We only really use x86* from those, probably, so I didn't bother much.
+diff --git a/gcc/config/alpha/linux-unwind.h b/gcc/config/alpha/linux-unwind.h
+index bdbba4a..e84812e 100644
+--- a/gcc/config/alpha/linux-unwind.h
++++ b/gcc/config/alpha/linux-unwind.h
+@@ -51,7 +51,7 @@ alpha_fallback_frame_state (struct _Unwind_Context *context,
+     {
+       struct rt_sigframe {
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       sc = &rt_->uc.uc_mcontext;
+     }
+diff --git a/gcc/config/bfin/linux-unwind.h b/gcc/config/bfin/linux-unwind.h
+index 77b7c23..8bf5e82 100644
+--- a/gcc/config/bfin/linux-unwind.h
++++ b/gcc/config/bfin/linux-unwind.h
+@@ -52,7 +52,7 @@ bfin_fallback_frame_state (struct _Unwind_Context *context,
+ 	void *puc;
+ 	char retcode[8];
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+ 
+       /* The void * cast is necessary to avoid an aliasing warning.
+diff --git a/gcc/config/i386/linux-unwind.h b/gcc/config/i386/linux-unwind.h
+index 540a0a2..29efbe3 100644
+--- a/gcc/config/i386/linux-unwind.h
++++ b/gcc/config/i386/linux-unwind.h
+@@ -58,7 +58,7 @@ x86_64_fallback_frame_state (struct _Unwind_Context *context,
+   if (*(unsigned char *)(pc+0) == 0x48
+       && *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL)
+     {
+-      struct ucontext *uc_ = context->cfa;
++      ucontext_t *uc_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+          because it does not alias anything.  */
+@@ -138,7 +138,7 @@ x86_fallback_frame_state (struct _Unwind_Context *context,
+ 	siginfo_t *pinfo;
+ 	void *puc;
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+diff --git a/gcc/config/m68k/linux-unwind.h b/gcc/config/m68k/linux-unwind.h
+index 75b7cf7..f964e24 100644
+--- a/gcc/config/m68k/linux-unwind.h
++++ b/gcc/config/m68k/linux-unwind.h
+@@ -33,7 +33,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+ /* <sys/ucontext.h> is unfortunately broken right now.  */
+ struct uw_ucontext {
+ 	unsigned long	  uc_flags;
+-	struct ucontext  *uc_link;
++	ucontext_t	 *uc_link;
+ 	stack_t		  uc_stack;
+ 	mcontext_t	  uc_mcontext;
+ 	unsigned long	  uc_filler[80];
+diff --git a/gcc/config/pa/linux-unwind.h b/gcc/config/pa/linux-unwind.h
+index 9a2657f..e47493d 100644
+--- a/gcc/config/pa/linux-unwind.h
++++ b/gcc/config/pa/linux-unwind.h
+@@ -80,7 +80,7 @@ pa32_fallback_frame_state (struct _Unwind_Context *context,
+   struct sigcontext *sc;
+   struct rt_sigframe {
+     siginfo_t info;
+-    struct ucontext uc;
++    ucontext_t uc;
+   } *frame;
+ 
+   /* rt_sigreturn trampoline:
+diff --git a/gcc/config/sh/linux-unwind.h b/gcc/config/sh/linux-unwind.h
+index e389cac..0bf43ba 100644
+--- a/gcc/config/sh/linux-unwind.h
++++ b/gcc/config/sh/linux-unwind.h
+@@ -180,7 +180,7 @@ sh_fallback_frame_state (struct _Unwind_Context *context,
+     {
+       struct rt_sigframe {
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+diff --git a/gcc/config/xtensa/linux-unwind.h b/gcc/config/xtensa/linux-unwind.h
+index 9872492..586a9d4 100644
+--- a/gcc/config/xtensa/linux-unwind.h
++++ b/gcc/config/xtensa/linux-unwind.h
+@@ -67,7 +67,7 @@ xtensa_fallback_frame_state (struct _Unwind_Context *context,
+ 
+   struct rt_sigframe {
+     siginfo_t info;
+-    struct ucontext uc;
++    ucontext_t uc;
+   } *rt_;
+ 
+   /* movi a2, __NR_rt_sigreturn; syscall */
+-- 
+2.9.3
+
diff --git a/pkgs/development/compilers/gcc/struct-ucontext-4.8.patch b/pkgs/development/compilers/gcc/struct-ucontext-4.8.patch
new file mode 100644
index 000000000000..630ef6586e45
--- /dev/null
+++ b/pkgs/development/compilers/gcc/struct-ucontext-4.8.patch
@@ -0,0 +1,177 @@
+From b685411208e0aaa79190d54faf945763514706b8 Mon Sep 17 00:00:00 2001
+From: jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Tue, 4 Jul 2017 10:23:57 +0000
+Subject: [PATCH] Use ucontext_t not struct ucontext in linux-unwind.h files.
+
+Current glibc no longer gives the ucontext_t type the tag struct
+ucontext, to conform with POSIX namespace rules.  This requires
+various linux-unwind.h files in libgcc, that were previously using
+struct ucontext, to be fixed to use ucontext_t instead.  This is
+similar to the removal of the struct siginfo tag from siginfo_t some
+years ago.
+
+This patch changes those files to use ucontext_t instead.  As the
+standard name that should be unconditionally safe, so this is not
+restricted to architectures supported by glibc, or conditioned on the
+glibc version.
+
+Tested compilation together with current glibc with glibc's
+build-many-glibcs.py.
+
+	* config/aarch64/linux-unwind.h (aarch64_fallback_frame_state),
+	config/alpha/linux-unwind.h (alpha_fallback_frame_state),
+	config/bfin/linux-unwind.h (bfin_fallback_frame_state),
+	config/i386/linux-unwind.h (x86_64_fallback_frame_state,
+	x86_fallback_frame_state), config/m68k/linux-unwind.h (struct
+	uw_ucontext), config/nios2/linux-unwind.h (struct nios2_ucontext),
+	config/pa/linux-unwind.h (pa32_fallback_frame_state),
+	config/sh/linux-unwind.h (sh_fallback_frame_state),
+	config/tilepro/linux-unwind.h (tile_fallback_frame_state),
+	config/xtensa/linux-unwind.h (xtensa_fallback_frame_state): Use
+	ucontext_t instead of struct ucontext.
+
+
+git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-6-branch@249957 138bc75d-0d04-0410-961f-82ee72b054a4
+---
+ libgcc/ChangeLog     (REMOVED)       | 14 ++++++++++++++
+ libgcc/config/aarch64/linux-unwind.h |  2 +-
+ libgcc/config/alpha/linux-unwind.h   |  2 +-
+ libgcc/config/bfin/linux-unwind.h    |  2 +-
+ libgcc/config/i386/linux-unwind.h    |  4 ++--
+ libgcc/config/m68k/linux-unwind.h    |  2 +-
+ libgcc/config/nios2/linux-unwind.h   |  2 +-
+ libgcc/config/pa/linux-unwind.h      |  2 +-
+ libgcc/config/sh/linux-unwind.h      |  2 +-
+ libgcc/config/tilepro/linux-unwind.h |  2 +-
+ libgcc/config/xtensa/linux-unwind.h  |  2 +-
+ 11 files changed, 25 insertions(+), 11 deletions(-)
+
+diff --git a/libgcc/config/aarch64/linux-unwind.h b/libgcc/config/aarch64/linux-unwind.h
+index 4512efb..06de45a 100644
+--- a/libgcc/config/aarch64/linux-unwind.h
++++ b/libgcc/config/aarch64/linux-unwind.h
+@@ -52,7 +52,7 @@ aarch64_fallback_frame_state (struct _Unwind_Context *context,
+   struct rt_sigframe
+   {
+     siginfo_t info;
+-    struct ucontext uc;
++    ucontext_t uc;
+   };
+ 
+   struct rt_sigframe *rt_;
+diff --git a/libgcc/config/alpha/linux-unwind.h b/libgcc/config/alpha/linux-unwind.h
+index bdbba4a..e84812e 100644
+--- a/libgcc/config/alpha/linux-unwind.h
++++ b/libgcc/config/alpha/linux-unwind.h
+@@ -51,7 +51,7 @@ alpha_fallback_frame_state (struct _Unwind_Context *context,
+     {
+       struct rt_sigframe {
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       sc = &rt_->uc.uc_mcontext;
+     }
+diff --git a/libgcc/config/bfin/linux-unwind.h b/libgcc/config/bfin/linux-unwind.h
+index 77b7c23..8bf5e82 100644
+--- a/libgcc/config/bfin/linux-unwind.h
++++ b/libgcc/config/bfin/linux-unwind.h
+@@ -52,7 +52,7 @@ bfin_fallback_frame_state (struct _Unwind_Context *context,
+ 	void *puc;
+ 	char retcode[8];
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+ 
+       /* The void * cast is necessary to avoid an aliasing warning.
+diff --git a/libgcc/config/i386/linux-unwind.h b/libgcc/config/i386/linux-unwind.h
+index 540a0a2..29efbe3 100644
+--- a/libgcc/config/i386/linux-unwind.h
++++ b/libgcc/config/i386/linux-unwind.h
+@@ -58,7 +58,7 @@ x86_64_fallback_frame_state (struct _Unwind_Context *context,
+   if (*(unsigned char *)(pc+0) == 0x48
+       && *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL)
+     {
+-      struct ucontext *uc_ = context->cfa;
++      ucontext_t *uc_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+          because it does not alias anything.  */
+@@ -138,7 +138,7 @@ x86_fallback_frame_state (struct _Unwind_Context *context,
+ 	siginfo_t *pinfo;
+ 	void *puc;
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+diff --git a/libgcc/config/m68k/linux-unwind.h b/libgcc/config/m68k/linux-unwind.h
+index 75b7cf7..f964e24 100644
+--- a/libgcc/config/m68k/linux-unwind.h
++++ b/libgcc/config/m68k/linux-unwind.h
+@@ -33,7 +33,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+ /* <sys/ucontext.h> is unfortunately broken right now.  */
+ struct uw_ucontext {
+ 	unsigned long	  uc_flags;
+-	struct ucontext  *uc_link;
++	ucontext_t	 *uc_link;
+ 	stack_t		  uc_stack;
+ 	mcontext_t	  uc_mcontext;
+ 	unsigned long	  uc_filler[80];
+diff --git a/libgcc/config/pa/linux-unwind.h b/libgcc/config/pa/linux-unwind.h
+index 9a2657f..e47493d 100644
+--- a/libgcc/config/pa/linux-unwind.h
++++ b/libgcc/config/pa/linux-unwind.h
+@@ -80,7 +80,7 @@ pa32_fallback_frame_state (struct _Unwind_Context *context,
+   struct sigcontext *sc;
+   struct rt_sigframe {
+     siginfo_t info;
+-    struct ucontext uc;
++    ucontext_t uc;
+   } *frame;
+ 
+   /* rt_sigreturn trampoline:
+diff --git a/libgcc/config/sh/linux-unwind.h b/libgcc/config/sh/linux-unwind.h
+index e389cac..0bf43ba 100644
+--- a/libgcc/config/sh/linux-unwind.h
++++ b/libgcc/config/sh/linux-unwind.h
+@@ -180,7 +180,7 @@ sh_fallback_frame_state (struct _Unwind_Context *context,
+     {
+       struct rt_sigframe {
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+diff --git a/libgcc/config/tilepro/linux-unwind.h b/libgcc/config/tilepro/linux-unwind.h
+index 796e976..75f8890 100644
+--- a/libgcc/config/tilepro/linux-unwind.h
++++ b/libgcc/config/tilepro/linux-unwind.h
+@@ -61,7 +61,7 @@ tile_fallback_frame_state (struct _Unwind_Context *context,
+   struct rt_sigframe {
+     unsigned char save_area[C_ABI_SAVE_AREA_SIZE];
+     siginfo_t info;
+-    struct ucontext uc;
++    ucontext_t uc;
+   } *rt_;
+ 
+   /* Return if this is not a signal handler.  */
+diff --git a/libgcc/config/xtensa/linux-unwind.h b/libgcc/config/xtensa/linux-unwind.h
+index 9872492..586a9d4 100644
+--- a/libgcc/config/xtensa/linux-unwind.h
++++ b/libgcc/config/xtensa/linux-unwind.h
+@@ -67,7 +67,7 @@ xtensa_fallback_frame_state (struct _Unwind_Context *context,
+ 
+   struct rt_sigframe {
+     siginfo_t info;
+-    struct ucontext uc;
++    ucontext_t uc;
+   } *rt_;
+ 
+   /* movi a2, __NR_rt_sigreturn; syscall */
+-- 
+2.9.3
+
diff --git a/pkgs/development/compilers/gcc/struct-ucontext-libjava.patch b/pkgs/development/compilers/gcc/struct-ucontext-libjava.patch
new file mode 100644
index 000000000000..3892a56954e0
--- /dev/null
+++ b/pkgs/development/compilers/gcc/struct-ucontext-libjava.patch
@@ -0,0 +1,33 @@
+--- a/libjava/include/x86_64-signal.h
++++ a/libjava/include/x86_64-signal.h
+@@ -28,7 +28,7 @@
+ #define HANDLE_DIVIDE_OVERFLOW						\
+ do									\
+ {									\
+-  struct ucontext *_uc = (struct ucontext *)_p;				\
++  ucontext_t *_uc = (ucontext_t *)_p;					\
+   gregset_t &_gregs = _uc->uc_mcontext.gregs;				\
+   unsigned char *_rip = (unsigned char *)_gregs[REG_RIP];		\
+ 									\
+--- a/libjava/include/i386-signal.h
++++ a/libjava/include/i386-signal.h
+@@ -29,7 +29,7 @@
+ #define HANDLE_DIVIDE_OVERFLOW						\
+ do									\
+ {									\
+-  struct ucontext *_uc = (struct ucontext *)_p;				\
++  ucontext_t *_uc = (ucontext_t *)_p;					\
+   gregset_t &_gregs = _uc->uc_mcontext.gregs;				\
+   unsigned char *_eip = (unsigned char *)_gregs[REG_EIP];		\
+ 									\
+--- a/libjava/include/s390-signal.h
++++ a/libjava/include/s390-signal.h
+@@ -51,7 +51,7 @@
+   struct                                                                \
+   {                                                                     \
+     unsigned long int uc_flags;                                         \
+-    struct ucontext *uc_link;                                           \
++    ucontext_t *uc_link;                                                \
+     stack_t uc_stack;                                                   \
+     mcontext_t uc_mcontext;                                             \
+     unsigned long sigmask[2];                                           \
diff --git a/pkgs/development/compilers/gcc/struct-ucontext.patch b/pkgs/development/compilers/gcc/struct-ucontext.patch
new file mode 100644
index 000000000000..c7fb6d1f71cf
--- /dev/null
+++ b/pkgs/development/compilers/gcc/struct-ucontext.patch
@@ -0,0 +1,190 @@
+From b685411208e0aaa79190d54faf945763514706b8 Mon Sep 17 00:00:00 2001
+From: jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Tue, 4 Jul 2017 10:23:57 +0000
+Subject: [PATCH] Use ucontext_t not struct ucontext in linux-unwind.h files.
+
+Current glibc no longer gives the ucontext_t type the tag struct
+ucontext, to conform with POSIX namespace rules.  This requires
+various linux-unwind.h files in libgcc, that were previously using
+struct ucontext, to be fixed to use ucontext_t instead.  This is
+similar to the removal of the struct siginfo tag from siginfo_t some
+years ago.
+
+This patch changes those files to use ucontext_t instead.  As the
+standard name that should be unconditionally safe, so this is not
+restricted to architectures supported by glibc, or conditioned on the
+glibc version.
+
+Tested compilation together with current glibc with glibc's
+build-many-glibcs.py.
+
+	* config/aarch64/linux-unwind.h (aarch64_fallback_frame_state),
+	config/alpha/linux-unwind.h (alpha_fallback_frame_state),
+	config/bfin/linux-unwind.h (bfin_fallback_frame_state),
+	config/i386/linux-unwind.h (x86_64_fallback_frame_state,
+	x86_fallback_frame_state), config/m68k/linux-unwind.h (struct
+	uw_ucontext), config/nios2/linux-unwind.h (struct nios2_ucontext),
+	config/pa/linux-unwind.h (pa32_fallback_frame_state),
+	config/sh/linux-unwind.h (sh_fallback_frame_state),
+	config/tilepro/linux-unwind.h (tile_fallback_frame_state),
+	config/xtensa/linux-unwind.h (xtensa_fallback_frame_state): Use
+	ucontext_t instead of struct ucontext.
+
+
+git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-6-branch@249957 138bc75d-0d04-0410-961f-82ee72b054a4
+---
+ libgcc/ChangeLog     (REMOVED)       | 14 ++++++++++++++
+ libgcc/config/aarch64/linux-unwind.h |  2 +-
+ libgcc/config/alpha/linux-unwind.h   |  2 +-
+ libgcc/config/bfin/linux-unwind.h    |  2 +-
+ libgcc/config/i386/linux-unwind.h    |  4 ++--
+ libgcc/config/m68k/linux-unwind.h    |  2 +-
+ libgcc/config/nios2/linux-unwind.h   |  2 +-
+ libgcc/config/pa/linux-unwind.h      |  2 +-
+ libgcc/config/sh/linux-unwind.h      |  2 +-
+ libgcc/config/tilepro/linux-unwind.h |  2 +-
+ libgcc/config/xtensa/linux-unwind.h  |  2 +-
+ 11 files changed, 25 insertions(+), 11 deletions(-)
+
+diff --git a/libgcc/config/aarch64/linux-unwind.h b/libgcc/config/aarch64/linux-unwind.h
+index 4512efb..06de45a 100644
+--- a/libgcc/config/aarch64/linux-unwind.h
++++ b/libgcc/config/aarch64/linux-unwind.h
+@@ -52,7 +52,7 @@ aarch64_fallback_frame_state (struct _Unwind_Context *context,
+   struct rt_sigframe
+   {
+     siginfo_t info;
+-    struct ucontext uc;
++    ucontext_t uc;
+   };
+ 
+   struct rt_sigframe *rt_;
+diff --git a/libgcc/config/alpha/linux-unwind.h b/libgcc/config/alpha/linux-unwind.h
+index bdbba4a..e84812e 100644
+--- a/libgcc/config/alpha/linux-unwind.h
++++ b/libgcc/config/alpha/linux-unwind.h
+@@ -51,7 +51,7 @@ alpha_fallback_frame_state (struct _Unwind_Context *context,
+     {
+       struct rt_sigframe {
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       sc = &rt_->uc.uc_mcontext;
+     }
+diff --git a/libgcc/config/bfin/linux-unwind.h b/libgcc/config/bfin/linux-unwind.h
+index 77b7c23..8bf5e82 100644
+--- a/libgcc/config/bfin/linux-unwind.h
++++ b/libgcc/config/bfin/linux-unwind.h
+@@ -52,7 +52,7 @@ bfin_fallback_frame_state (struct _Unwind_Context *context,
+ 	void *puc;
+ 	char retcode[8];
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+ 
+       /* The void * cast is necessary to avoid an aliasing warning.
+diff --git a/libgcc/config/i386/linux-unwind.h b/libgcc/config/i386/linux-unwind.h
+index 540a0a2..29efbe3 100644
+--- a/libgcc/config/i386/linux-unwind.h
++++ b/libgcc/config/i386/linux-unwind.h
+@@ -58,7 +58,7 @@ x86_64_fallback_frame_state (struct _Unwind_Context *context,
+   if (*(unsigned char *)(pc+0) == 0x48
+       && *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL)
+     {
+-      struct ucontext *uc_ = context->cfa;
++      ucontext_t *uc_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+          because it does not alias anything.  */
+@@ -138,7 +138,7 @@ x86_fallback_frame_state (struct _Unwind_Context *context,
+ 	siginfo_t *pinfo;
+ 	void *puc;
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+diff --git a/libgcc/config/m68k/linux-unwind.h b/libgcc/config/m68k/linux-unwind.h
+index 75b7cf7..f964e24 100644
+--- a/libgcc/config/m68k/linux-unwind.h
++++ b/libgcc/config/m68k/linux-unwind.h
+@@ -33,7 +33,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+ /* <sys/ucontext.h> is unfortunately broken right now.  */
+ struct uw_ucontext {
+ 	unsigned long	  uc_flags;
+-	struct ucontext  *uc_link;
++	ucontext_t	 *uc_link;
+ 	stack_t		  uc_stack;
+ 	mcontext_t	  uc_mcontext;
+ 	unsigned long	  uc_filler[80];
+diff --git a/libgcc/config/nios2/linux-unwind.h b/libgcc/config/nios2/linux-unwind.h
+index 2304142..30f25ea 100644
+--- a/libgcc/config/nios2/linux-unwind.h
++++ b/libgcc/config/nios2/linux-unwind.h
+@@ -38,7 +38,7 @@ struct nios2_mcontext {
+ 
+ struct nios2_ucontext {
+   unsigned long uc_flags;
+-  struct ucontext *uc_link;
++  ucontext_t *uc_link;
+   stack_t uc_stack;
+   struct nios2_mcontext uc_mcontext;
+   sigset_t uc_sigmask;	/* mask last for extensibility */
+diff --git a/libgcc/config/pa/linux-unwind.h b/libgcc/config/pa/linux-unwind.h
+index 9a2657f..e47493d 100644
+--- a/libgcc/config/pa/linux-unwind.h
++++ b/libgcc/config/pa/linux-unwind.h
+@@ -80,7 +80,7 @@ pa32_fallback_frame_state (struct _Unwind_Context *context,
+   struct sigcontext *sc;
+   struct rt_sigframe {
+     siginfo_t info;
+-    struct ucontext uc;
++    ucontext_t uc;
+   } *frame;
+ 
+   /* rt_sigreturn trampoline:
+diff --git a/libgcc/config/sh/linux-unwind.h b/libgcc/config/sh/linux-unwind.h
+index e389cac..0bf43ba 100644
+--- a/libgcc/config/sh/linux-unwind.h
++++ b/libgcc/config/sh/linux-unwind.h
+@@ -180,7 +180,7 @@ sh_fallback_frame_state (struct _Unwind_Context *context,
+     {
+       struct rt_sigframe {
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+diff --git a/libgcc/config/tilepro/linux-unwind.h b/libgcc/config/tilepro/linux-unwind.h
+index 796e976..75f8890 100644
+--- a/libgcc/config/tilepro/linux-unwind.h
++++ b/libgcc/config/tilepro/linux-unwind.h
+@@ -61,7 +61,7 @@ tile_fallback_frame_state (struct _Unwind_Context *context,
+   struct rt_sigframe {
+     unsigned char save_area[C_ABI_SAVE_AREA_SIZE];
+     siginfo_t info;
+-    struct ucontext uc;
++    ucontext_t uc;
+   } *rt_;
+ 
+   /* Return if this is not a signal handler.  */
+diff --git a/libgcc/config/xtensa/linux-unwind.h b/libgcc/config/xtensa/linux-unwind.h
+index 9872492..586a9d4 100644
+--- a/libgcc/config/xtensa/linux-unwind.h
++++ b/libgcc/config/xtensa/linux-unwind.h
+@@ -67,7 +67,7 @@ xtensa_fallback_frame_state (struct _Unwind_Context *context,
+ 
+   struct rt_sigframe {
+     siginfo_t info;
+-    struct ucontext uc;
++    ucontext_t uc;
+   } *rt_;
+ 
+   /* movi a2, __NR_rt_sigreturn; syscall */
+-- 
+2.9.3
+
diff --git a/pkgs/development/compilers/gerbil/default.nix b/pkgs/development/compilers/gerbil/default.nix
index 22047b663d04..59cafee3b3a9 100644
--- a/pkgs/development/compilers/gerbil/default.nix
+++ b/pkgs/development/compilers/gerbil/default.nix
@@ -2,23 +2,27 @@
   coreutils, rsync, bash,
   openssl, zlib, sqlite, libxml2, libyaml, libmysql, lmdb, leveldb }:
 
+# TODO: distinct packages for gerbil-release and gerbil-devel
+
 stdenv.mkDerivation rec {
   name    = "gerbil-${version}";
 
-  version = "0.12-DEV";
+  version = "0.12-DEV-777-gd855915";
   src = fetchgit {
     url = "https://github.com/vyzo/gerbil.git";
-    rev = "3657b6e940ea248e0b312f276590e38ff68997e7";
-    sha256 = "11ys7082ghkm4yikz4qxmv3jpxcr42jfi0jhjw1mpzbqdg6004w2";
+    rev = "9db6187dc996eec4087f83b86339e7b17bb69bad";
+    sha256 = "1hqmsy77d62dvil3az4vdr0rmwvxhinjl1dbcxzamz2c2kcjv1jg";
   };
 
   buildInputs = [
-    gambit openssl
+    gambit
     coreutils rsync bash
-    zlib openssl zlib sqlite libxml2 libyaml libmysql lmdb leveldb
+    openssl zlib sqlite libxml2 libyaml libmysql lmdb leveldb
   ];
 
   postPatch = ''
+    echo '(define (gerbil-version-string) "v${version}")' > src/gerbil/runtime/gx-version.scm
+
     patchShebangs .
 
     find . -type f -executable -print0 | while IFS= read -r -d ''$'\0' f; do
diff --git a/pkgs/development/compilers/ghc/6.10.2-binary.nix b/pkgs/development/compilers/ghc/6.10.2-binary.nix
index 60749a29b58b..84250c1a6d33 100644
--- a/pkgs/development/compilers/ghc/6.10.2-binary.nix
+++ b/pkgs/development/compilers/ghc/6.10.2-binary.nix
@@ -1,24 +1,26 @@
-{stdenv, lib, fetchurl, perl, libedit, ncurses5, gmp}:
+{ stdenv
+, fetchurl, perl
+, libedit, ncurses5, gmp
+}:
 
 stdenv.mkDerivation rec {
   version = "6.10.2";
 
   name = "ghc-${version}-binary";
 
-  src =
-    if stdenv.system == "i686-linux" then
-      fetchurl {
-        # This binary requires libedit.so.0 (rather than libedit.so.2).
-        url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-unknown-linux.tar.bz2";
-        sha256 = "1fw0zr2qshlpk8s0d16k27zcv5263nqdg2xds5ymw8ff6qz9rz9b";
-      }
-    else if stdenv.system == "x86_64-linux" then
-      fetchurl {
-        # Idem.
-        url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-unknown-linux.tar.bz2";
-        sha256 = "1rd2j7lmcfsm2rdfb5g6q0l8dz3sxadk5m3d2f69d4a6g4p4h7jj";
-      }
-    else throw "cannot bootstrap GHC on this platform";
+  src = fetchurl ({
+    "i686-linux" = {
+      # This binary requires libedit.so.0 (rather than libedit.so.2).
+      url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-unknown-linux.tar.bz2";
+      sha256 = "1fw0zr2qshlpk8s0d16k27zcv5263nqdg2xds5ymw8ff6qz9rz9b";
+    };
+    "x86_64-linux" = {
+      # Idem.
+      url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-unknown-linux.tar.bz2";
+      sha256 = "1rd2j7lmcfsm2rdfb5g6q0l8dz3sxadk5m3d2f69d4a6g4p4h7jj";
+    };
+  }.${stdenv.hostPlatform.system}
+    or (throw "cannot bootstrap GHC on this platform"));
 
   buildInputs = [perl];
 
@@ -27,27 +29,27 @@ stdenv.mkDerivation rec {
     # first. The GHC Cabal build system makes use of strip by default and
     # has hardcoded paths to /usr/bin/strip in many places. We replace
     # those below, making them point to our dummy script.
-     ''
+    ''
       mkdir "$TMP/bin"
       for i in strip; do
         echo '#! ${stdenv.shell}' > "$TMP/bin/$i"
         chmod +x "$TMP/bin/$i"
       done
       PATH="$TMP/bin:$PATH"
-     '' +
+    '' +
     # On Linux, use patchelf to modify the executables so that they can
     # find editline/gmp.
-    (if stdenv.isLinux then ''
+    stdenv.lib.optionalString stdenv.hostPlatform.isLinux ''
       find . -type f -perm -0100 \
           -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-          --set-rpath "${lib.makeLibraryPath [ libedit ncurses5 gmp ]}" {} \;
+          --set-rpath "${stdenv.lib.makeLibraryPath [ libedit ncurses5 gmp ]}" {} \;
       for prog in ld ar gcc strip ranlib; do
         find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
       done
-     '' else "");
+    '';
 
   configurePhase = ''
-    ./configure --prefix=$out --with-gmp-libraries=${lib.getLib gmp}/lib --with-gmp-includes=${lib.getDev gmp}/include
+    ./configure --prefix=$out --with-gmp-libraries=${stdenv.lib.getLib gmp}/lib --with-gmp-includes=${stdenv.lib.getDev gmp}/include
   '';
 
   # Stripping combined with patchelf breaks the executables (they die
@@ -58,44 +60,21 @@ stdenv.mkDerivation rec {
   # calls install-strip ...
   dontBuild = true;
 
-  # The binaries for Darwin use frameworks, so fake those frameworks,
-  # and create some wrapper scripts that set DYLD_FRAMEWORK_PATH so
-  # that the executables work with no special setup.
-  postInstall =
-    (if stdenv.isDarwin then
-      ''
-        mkdir -p $out/frameworks/GMP.framework/Versions/A
-        ln -s ${gmp.out}/lib/libgmp.dylib $out/frameworks/GMP.framework/GMP
-        ln -s ${gmp.out}/lib/libgmp.dylib $out/frameworks/GMP.framework/Versions/A/GMP
-        # !!! fix this
-        mkdir -p $out/frameworks/GNUeditline.framework/Versions/A
-        ln -s ${libedit}/lib/libeditline.dylib $out/frameworks/GNUeditline.framework/GNUeditline
-        ln -s ${libedit}/lib/libeditline.dylib $out/frameworks/GNUeditline.framework/Versions/A/GNUeditline
+  postInstall = ''
+    # bah, the passing gmp doesn't work, so let's add it to the final package.conf in a quick but dirty way
+    sed -i "s@^\(.*pkgName = PackageName \"rts\".*\libraryDirs = \\[\)\(.*\)@\\1\"${gmp.out}/lib\",\2@" $out/lib/ghc-${version}/package.conf
 
-        mv $out/bin $out/bin-orig
-        mkdir $out/bin
-        for i in $(cd $out/bin-orig && ls); do
-            echo \"#! $SHELL -e\" >> $out/bin/$i
-            echo \"DYLD_FRAMEWORK_PATH=$out/frameworks exec $out/bin-orig/$i -framework-path $out/frameworks \\\"\\$@\\\"\" >> $out/bin/$i
-            chmod +x $out/bin/$i
-        done
-      '' else "")
-    +
-      ''
-        # bah, the passing gmp doesn't work, so let's add it to the final package.conf in a quick but dirty way
-        sed -i "s@^\(.*pkgName = PackageName \"rts\".*\libraryDirs = \\[\)\(.*\)@\\1\"${gmp.out}/lib\",\2@" $out/lib/ghc-${version}/package.conf
-
-        # Sanity check, can ghc create executables?
-        cd $TMP
-        mkdir test-ghc; cd test-ghc
-        cat > main.hs << EOF
-          module Main where
-          main = putStrLn "yes"
-        EOF
-        $out/bin/ghc --make main.hs
-        echo compilation ok
-        [ $(./main) == "yes" ]
-      '';
+    # Sanity check, can ghc create executables?
+    cd $TMP
+    mkdir test-ghc; cd test-ghc
+    cat > main.hs << EOF
+      module Main where
+      main = putStrLn "yes"
+    EOF
+    $out/bin/ghc --make main.hs
+    echo compilation ok
+    [ $(./main) == "yes" ]
+  '';
 
   meta = {
     homepage = http://haskell.org/ghc;
diff --git a/pkgs/development/compilers/ghc/6.10.4.nix b/pkgs/development/compilers/ghc/6.10.4.nix
index d2552b027ac1..c56762edd24e 100644
--- a/pkgs/development/compilers/ghc/6.10.4.nix
+++ b/pkgs/development/compilers/ghc/6.10.4.nix
@@ -27,5 +27,6 @@ stdenv.mkDerivation rec {
     description = "The Glasgow Haskell Compiler";
     platforms = ["x86_64-linux" "i686-linux"];  # Darwin is unsupported.
     inherit (ghc.meta) license;
+    broken = true;  # https://nix-cache.s3.amazonaws.com/log/6ys7lzckf2c0532kzhmss73mmz504can-ghc-6.10.4.drv
   };
 }
diff --git a/pkgs/development/compilers/ghc/7.0.4-binary.nix b/pkgs/development/compilers/ghc/7.0.4-binary.nix
index 6140cde4a9ef..394e4239e9a0 100644
--- a/pkgs/development/compilers/ghc/7.0.4-binary.nix
+++ b/pkgs/development/compilers/ghc/7.0.4-binary.nix
@@ -1,32 +1,32 @@
-{stdenv, fetchurl, perl, ncurses5, gmp, libiconv}:
+{ stdenv
+, fetchurl, perl
+, ncurses5, gmp, libiconv
+}:
 
 stdenv.mkDerivation rec {
   version = "7.0.4";
 
   name = "ghc-${version}-binary";
 
-  src =
-    if stdenv.system == "i686-linux" then
-      fetchurl {
-        url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-unknown-linux.tar.bz2";
-        sha256 = "0mfnihiyjl06f5w1yrjp36sw9g67g2ymg5sdl0g23h1pab99jx63";
-      }
-    else if stdenv.system == "x86_64-linux" then
-      fetchurl {
-        url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-unknown-linux.tar.bz2";
-        sha256 = "0mc4rhqcxz427wq4zgffmnn0d2yjqvy6af4x9mha283p1gdj5q99";
-      }
-    else if stdenv.system == "i686-darwin" then
-      fetchurl {
-        url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-apple-darwin.tar.bz2";
-        sha256 = "0qj45hslrrr8zfks8m1jcb3awwx9rh35ndnpfmb0gwb6j7azq5n3";
-      }
-    else if stdenv.system == "x86_64-darwin" then
-      fetchurl {
-        url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-apple-darwin.tar.bz2";
-        sha256 = "1m2ml88p1swf4dnv2vq8hz4drcp46n3ahpfi05wh01ajkf8hnn3l";
-      }
-    else throw "cannot bootstrap GHC on this platform";
+  src = fetchurl ({
+    "i686-linux" = {
+      url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-unknown-linux.tar.bz2";
+      sha256 = "0mfnihiyjl06f5w1yrjp36sw9g67g2ymg5sdl0g23h1pab99jx63";
+    };
+    "x86_64-linux" = {
+      url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-unknown-linux.tar.bz2";
+      sha256 = "0mc4rhqcxz427wq4zgffmnn0d2yjqvy6af4x9mha283p1gdj5q99";
+    };
+    "i686-darwin" = {
+      url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-apple-darwin.tar.bz2";
+      sha256 = "0qj45hslrrr8zfks8m1jcb3awwx9rh35ndnpfmb0gwb6j7azq5n3";
+    };
+    "x86_64-darwin" = {
+      url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-apple-darwin.tar.bz2";
+      sha256 = "1m2ml88p1swf4dnv2vq8hz4drcp46n3ahpfi05wh01ajkf8hnn3l";
+    };
+  }.${stdenv.hostPlatform.system}
+    or (throw "cannot bootstrap GHC on this platform"));
 
   buildInputs = [perl];
 
@@ -41,22 +41,22 @@ stdenv.mkDerivation rec {
     # first. The GHC Cabal build system makes use of strip by default and
     # has hardcoded paths to /usr/bin/strip in many places. We replace
     # those below, making them point to our dummy script.
-     ''
+    ''
       mkdir "$TMP/bin"
       for i in strip; do
         echo '#! ${stdenv.shell}' > "$TMP/bin/$i"
         chmod +x "$TMP/bin/$i"
       done
       PATH="$TMP/bin:$PATH"
-     '' +
+    '' +
     # We have to patch the GMP paths for the integer-gmp package.
-     ''
+    ''
       find . -name integer-gmp.buildinfo \
           -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${gmp.out}/lib@" {} \;
-     '' + stdenv.lib.optionalString stdenv.isDarwin ''
+    '' + stdenv.lib.optionalString stdenv.isDarwin ''
       find . -name base.buildinfo \
           -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${libiconv}/lib@" {} \;
-     '' +
+    '' +
     # On Linux, use patchelf to modify the executables so that they can
     # find editline/gmp.
     stdenv.lib.optionalString stdenv.isLinux ''
@@ -68,24 +68,24 @@ stdenv.mkDerivation rec {
       for prog in ld ar gcc strip ranlib; do
         find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
       done
-     '' + stdenv.lib.optionalString stdenv.isDarwin ''
-       # not enough room in the object files for the full path to libiconv :(
-       fix () {
-         install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
-       }
+    '' + stdenv.lib.optionalString stdenv.isDarwin ''
+      # not enough room in the object files for the full path to libiconv :(
+      fix () {
+        install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
+      }
 
-       ln -s ${libiconv}/lib/libiconv.dylib ghc-7.0.4/utils/ghc-pwd/dist/build/tmp
-       ln -s ${libiconv}/lib/libiconv.dylib ghc-7.0.4/utils/hpc/dist/build/tmp
-       ln -s ${libiconv}/lib/libiconv.dylib ghc-7.0.4/ghc/stage2/build/tmp
+      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/ghc-pwd/dist/build/tmp
+      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/hpc/dist/build/tmp
+      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/ghc/stage2/build/tmp
 
-       for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
-         fix $(find . -type f -name $file)
-       done
+      for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
+        fix $(find . -type f -name $file)
+      done
 
-       for file in $(find . -name setup-config); do
-         substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
-       done
-     '';
+      for file in $(find . -name setup-config); do
+        substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
+      done
+    '';
 
   configurePhase = ''
     ./configure --prefix=$out \
@@ -101,19 +101,18 @@ stdenv.mkDerivation rec {
   # calls install-strip ...
   dontBuild = true;
 
-  postInstall =
-      ''
-        # Sanity check, can ghc create executables?
-        cd $TMP
-        mkdir test-ghc; cd test-ghc
-        cat > main.hs << EOF
-          module Main where
-          main = putStrLn "yes"
-        EOF
-        $out/bin/ghc --make main.hs
-        echo compilation ok
-        [ $(./main) == "yes" ]
-      '';
+  postInstall = ''
+    # Sanity check, can ghc create executables?
+    cd $TMP
+    mkdir test-ghc; cd test-ghc
+    cat > main.hs << EOF
+      module Main where
+      main = putStrLn "yes"
+    EOF
+    $out/bin/ghc --make main.hs
+    echo compilation ok
+    [ $(./main) == "yes" ]
+  '';
 
   meta.license = stdenv.lib.licenses.bsd3;
   meta.platforms = ["x86_64-linux" "i686-linux" "x86_64-darwin"];
diff --git a/pkgs/development/compilers/ghc/7.10.2.nix b/pkgs/development/compilers/ghc/7.10.2.nix
index 863f904e4e96..51274dd60598 100644
--- a/pkgs/development/compilers/ghc/7.10.2.nix
+++ b/pkgs/development/compilers/ghc/7.10.2.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
+{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, targetPackages, coreutils
 , libxml2, libxslt, docbook_xsl, docbook_xml_dtd_45, docbook_xml_dtd_42, hscolour
 
   # If enabled GHC will be build with the GPL-free but slower integer-simple
@@ -70,7 +70,7 @@ stdenv.mkDerivation rec {
     for i in "$out/bin/"*; do
       test ! -h $i || continue
       egrep --quiet '^#!' <(head -n 1 $i) || continue
-      sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ binutils coreutils ]}"' $i
+      sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' $i
     done
   '';
 
diff --git a/pkgs/development/compilers/ghc/7.10.3.nix b/pkgs/development/compilers/ghc/7.10.3.nix
index eb8f1dddd19b..d573a22e0ae8 100644
--- a/pkgs/development/compilers/ghc/7.10.3.nix
+++ b/pkgs/development/compilers/ghc/7.10.3.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
+{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, targetPackages, coreutils
 , libxml2, libxslt, docbook_xsl, docbook_xml_dtd_45, docbook_xml_dtd_42, hscolour
 
   # If enabled GHC will be build with the GPL-free but slower integer-simple
@@ -68,7 +68,7 @@ stdenv.mkDerivation rec {
     for i in "$out/bin/"*; do
       test ! -h $i || continue
       egrep --quiet '^#!' <(head -n 1 $i) || continue
-      sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ binutils coreutils ]}"' $i
+      sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' $i
     done
   '';
 
diff --git a/pkgs/development/compilers/ghc/7.2.2.nix b/pkgs/development/compilers/ghc/7.2.2.nix
index 156ff56bd663..dd3b5cb2ebcb 100644
--- a/pkgs/development/compilers/ghc/7.2.2.nix
+++ b/pkgs/development/compilers/ghc/7.2.2.nix
@@ -61,6 +61,7 @@ stdenv.mkDerivation rec {
     ];
     platforms = ["x86_64-linux" "i686-linux"];  # Darwin is unsupported.
     inherit (ghc.meta) license;
+    broken = true;   # broken by 51cf42ad0d3ccb55af182f1f0ee5eb5094ea5995: https://hydra.nixos.org/build/60616815
   };
 
 }
diff --git a/pkgs/development/compilers/ghc/7.4.2-binary.nix b/pkgs/development/compilers/ghc/7.4.2-binary.nix
index 100bb87768b5..9d85253f6309 100644
--- a/pkgs/development/compilers/ghc/7.4.2-binary.nix
+++ b/pkgs/development/compilers/ghc/7.4.2-binary.nix
@@ -1,32 +1,32 @@
-{stdenv, fetchurl, perl, ncurses5, gmp, libiconv, makeWrapper}:
+{ stdenv
+, fetchurl, perl, makeWrapper
+, ncurses5, gmp, libiconv
+}:
 
 stdenv.mkDerivation rec {
   version = "7.4.2";
 
   name = "ghc-${version}-binary";
 
-  src =
-    if stdenv.system == "i686-linux" then
-      fetchurl {
-        url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-unknown-linux.tar.bz2";
-        sha256 = "0gny7knhss0w0d9r6jm1gghrcb8kqjvj94bb7hxf9syrk4fxlcxi";
-      }
-    else if stdenv.system == "x86_64-linux" then
-      fetchurl {
-        url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-unknown-linux.tar.bz2";
-        sha256 = "043jabd0lh6n1zlqhysngbpvlsdznsa2mmsj08jyqgahw9sjb5ns";
-      }
-    else if stdenv.system == "i686-darwin" then
-      fetchurl {
-        url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-apple-darwin.tar.bz2";
-        sha256 = "1vrbs3pzki37hzym1f1nh07lrqh066z3ypvm81fwlikfsvk4djc0";
-      }
-    else if stdenv.system == "x86_64-darwin" then
-      fetchurl {
-        url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-apple-darwin.tar.bz2";
-        sha256 = "1imzqc0slpg0r6p40n5a9m18cbcm0m86z8dgyhfxcckksw54mzwf";
-      }
-    else throw "cannot bootstrap GHC on this platform";
+  src = fetchurl ({
+    "i686-linux" = {
+      url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-unknown-linux.tar.bz2";
+      sha256 = "0gny7knhss0w0d9r6jm1gghrcb8kqjvj94bb7hxf9syrk4fxlcxi";
+    };
+    "x86_64-linux" = {
+      url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-unknown-linux.tar.bz2";
+      sha256 = "043jabd0lh6n1zlqhysngbpvlsdznsa2mmsj08jyqgahw9sjb5ns";
+    };
+    "i686-darwin" = {
+      url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-apple-darwin.tar.bz2";
+      sha256 = "1vrbs3pzki37hzym1f1nh07lrqh066z3ypvm81fwlikfsvk4djc0";
+    };
+    "x86_64-darwin" = {
+      url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-apple-darwin.tar.bz2";
+      sha256 = "1imzqc0slpg0r6p40n5a9m18cbcm0m86z8dgyhfxcckksw54mzwf";
+    };
+  }.${stdenv.hostPlatform.system}
+    or (throw "cannot bootstrap GHC on this platform"));
 
   buildInputs = [perl];
 
@@ -41,22 +41,22 @@ stdenv.mkDerivation rec {
     # first. The GHC Cabal build system makes use of strip by default and
     # has hardcoded paths to /usr/bin/strip in many places. We replace
     # those below, making them point to our dummy script.
-     ''
+    ''
       mkdir "$TMP/bin"
       for i in strip; do
         echo '#! ${stdenv.shell}' > "$TMP/bin/$i"
         chmod +x "$TMP/bin/$i"
       done
       PATH="$TMP/bin:$PATH"
-     '' +
+    '' +
     # We have to patch the GMP paths for the integer-gmp package.
-     ''
+    ''
       find . -name integer-gmp.buildinfo \
           -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${gmp.out}/lib@" {} \;
-     '' + stdenv.lib.optionalString stdenv.isDarwin ''
+    '' + stdenv.lib.optionalString stdenv.isDarwin ''
       find . -name base.buildinfo \
           -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${libiconv}/lib@" {} \;
-     '' +
+    '' +
     # On Linux, use patchelf to modify the executables so that they can
     # find editline/gmp.
     stdenv.lib.optionalString stdenv.isLinux ''
@@ -73,24 +73,24 @@ stdenv.mkDerivation rec {
       for prog in ld ar gcc strip ranlib; do
         find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
       done
-     '' + stdenv.lib.optionalString stdenv.isDarwin ''
-       # not enough room in the object files for the full path to libiconv :(
-       fix () {
-         install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
-       }
+    '' + stdenv.lib.optionalString stdenv.isDarwin ''
+      # not enough room in the object files for the full path to libiconv :(
+      fix () {
+        install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
+      }
 
-       ln -s ${libiconv}/lib/libiconv.dylib ghc-7.4.2/utils/ghc-pwd/dist-install/build/tmp
-       ln -s ${libiconv}/lib/libiconv.dylib ghc-7.4.2/utils/hpc/dist-install/build/tmp
-       ln -s ${libiconv}/lib/libiconv.dylib ghc-7.4.2/ghc/stage2/build/tmp
+      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/ghc-pwd/dist-install/build/tmp
+      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/hpc/dist-install/build/tmp
+      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/ghc/stage2/build/tmp
 
-       for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
-         fix $(find . -type f -name $file)
-       done
+      for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
+        fix $(find . -type f -name $file)
+      done
 
-       for file in $(find . -name setup-config); do
-         substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
-       done
-     '';
+      for file in $(find . -name setup-config); do
+        substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
+      done
+    '';
 
   configurePhase = ''
     ./configure --prefix=$out \
@@ -107,10 +107,10 @@ stdenv.mkDerivation rec {
   dontBuild = true;
 
   preInstall = stdenv.lib.optionalString stdenv.isDarwin ''
-    mkdir -p $out/lib/ghc-7.4.2
+    mkdir -p $out/lib/ghc-${version}
     mkdir -p $out/bin
     ln -s ${libiconv}/lib/libiconv.dylib $out/bin
-    ln -s ${libiconv}/lib/libiconv.dylib $out/lib/ghc-7.4.2/libiconv.dylib
+    ln -s ${libiconv}/lib/libiconv.dylib $out/lib/ghc-${version}/libiconv.dylib
     ln -s ${libiconv}/lib/libiconv.dylib utils/ghc-cabal/dist-install/build/tmp
   '';
 
diff --git a/pkgs/development/compilers/ghc/7.6.3.nix b/pkgs/development/compilers/ghc/7.6.3.nix
index 5f951936046f..fde4ca2aa37d 100644
--- a/pkgs/development/compilers/ghc/7.6.3.nix
+++ b/pkgs/development/compilers/ghc/7.6.3.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, ghc, perl, ncurses, binutils, libiconv
+{ stdenv, fetchurl, ghc, perl, ncurses, libiconv
 
   # If enabled GHC will be build with the GPL-free but slower integer-simple
   # library instead of the faster but GPLed integer-gmp library.
diff --git a/pkgs/development/compilers/ghc/8.0.2.nix b/pkgs/development/compilers/ghc/8.0.2.nix
index e50a8df7352d..d475e3438b4b 100644
--- a/pkgs/development/compilers/ghc/8.0.2.nix
+++ b/pkgs/development/compilers/ghc/8.0.2.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
+{ stdenv, lib, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, targetPackages, coreutils
 , hscolour, patchutils, sphinx
 
   # If enabled GHC will be build with the GPL-free but slower integer-simple
@@ -65,7 +65,7 @@ stdenv.mkDerivation rec {
     for i in "$out/bin/"*; do
       test ! -h $i || continue
       egrep --quiet '^#!' <(head -n 1 $i) || continue
-      sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ binutils coreutils ]}"' $i
+      sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' $i
     done
   '';
 
diff --git a/pkgs/development/compilers/ghc/8.2.1.nix b/pkgs/development/compilers/ghc/8.2.1.nix
index bce51f92c0bc..bcc801c98ea5 100644
--- a/pkgs/development/compilers/ghc/8.2.1.nix
+++ b/pkgs/development/compilers/ghc/8.2.1.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, fetchurl, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
+{ stdenv, lib, fetchurl, bootPkgs, perl, ncurses, libiconv, targetPackages, coreutils
 , autoconf, automake, happy, alex, python3, sphinx, hscolour
 , buildPlatform, targetPlatform , selfPkgs, cross ? null
 
@@ -10,12 +10,12 @@
 let
   inherit (bootPkgs) ghc;
   version = "8.2.1";
-  preReleaseName = "ghc-8.2.1";
+
   commonBuildInputs = [ alex autoconf automake ghc happy hscolour perl python3 sphinx ];
   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/${preReleaseName}"
+    export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/ghc-${version}"
   '' + stdenv.lib.optionalString stdenv.isDarwin ''
     export NIX_LDFLAGS+=" -no_dtrace_dof"
   '' + stdenv.lib.optionalString enableIntegerSimple ''
@@ -26,7 +26,7 @@ in stdenv.mkDerivation (rec {
   name = "ghc-${version}";
 
   src = fetchurl {
-    url = "https://downloads.haskell.org/~ghc/${version}/${preReleaseName}-src.tar.xz";
+    url = "https://downloads.haskell.org/~ghc/${version}/${name}-src.tar.xz";
     sha256 = "1w4k0n23b9fg8kmarqhfamzpmf91p6jcdr6xlwzfmb4df2bd9hng";
   };
 
@@ -57,7 +57,7 @@ in stdenv.mkDerivation (rec {
   checkTarget = "test";
 
   postInstall = ''
-    paxmark m $out/lib/${preReleaseName}/bin/{ghc,haddock}
+    paxmark m $out/lib/${name}/bin/{ghc,haddock}
 
     # Install the bash completion file.
     install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/ghc
@@ -66,7 +66,7 @@ in stdenv.mkDerivation (rec {
     for i in "$out/bin/"*; do
       test ! -h $i || continue
       egrep --quiet '^#!' <(head -n 1 $i) || continue
-      sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ binutils coreutils ]}"' $i
+      sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' $i
     done
   '';
 
@@ -97,23 +97,23 @@ in stdenv.mkDerivation (rec {
 
   configureFlags = [
     "CC=${stdenv.ccCross}/bin/${cross.config}-cc"
-    "LD=${stdenv.binutils}/bin/${cross.config}-ld"
-    "AR=${stdenv.binutils}/bin/${cross.config}-ar"
-    "NM=${stdenv.binutils}/bin/${cross.config}-nm"
-    "RANLIB=${stdenv.binutils}/bin/${cross.config}-ranlib"
+    "LD=${targetPackages.stdenv.cc.bintools}/bin/${cross.config}-ld"
+    "AR=${targetPackages.stdenv.cc.bintools}/bin/${cross.config}-ar"
+    "NM=${targetPackages.stdenv.cc.bintools}/bin/${cross.config}-nm"
+    "RANLIB=${targetPackages.stdenv.cc.bintools}/bin/${cross.config}-ranlib"
     "--target=${cross.config}"
     "--enable-bootstrap-with-devel-snapshot"
   ] ++
     # fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
     lib.optional (cross.config or null == "aarch64-apple-darwin14") "--disable-large-address-space";
 
-  buildInputs = commonBuildInputs ++ [ stdenv.ccCross stdenv.binutils ];
+  buildInputs = commonBuildInputs ++ [ stdenv.ccCross stdenv.targetPackages.stdenv.cc.bintools ];
 
   dontSetConfigureCross = true;
 
   passthru = {
     inherit bootPkgs cross;
     cc = "${stdenv.ccCross}/bin/${cross.config}-cc";
-    ld = "${stdenv.binutils}/bin/${cross.config}-ld";
+    ld = "${stdenv.targetPackages.stdenv.cc.bintools}/bin/${cross.config}-ld";
   };
 })
diff --git a/pkgs/development/compilers/ghc/8.0.1.nix b/pkgs/development/compilers/ghc/8.2.2.nix
index 6e47ee92630a..cd15a6680c26 100644
--- a/pkgs/development/compilers/ghc/8.0.1.nix
+++ b/pkgs/development/compilers/ghc/8.2.2.nix
@@ -1,5 +1,6 @@
-{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
-, hscolour, patchutils, sphinx
+{ stdenv, lib, fetchurl, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
+, autoconf, automake, happy, alex, python3, sphinx, hscolour
+, buildPlatform, targetPlatform , selfPkgs, cross ? null
 
   # If enabled GHC will be build with the GPL-free but slower integer-simple
   # library instead of the faster but GPLed integer-gmp library.
@@ -8,49 +9,39 @@
 
 let
   inherit (bootPkgs) ghc;
+  version = "8.2.1.20171108";
 
-  fetchFilteredPatch = args: fetchurl (args // {
-    downloadToTemp = true;
-    postFetch = ''
-      ${patchutils}/bin/filterdiff --clean --strip-match=1 -x 'testsuite/*' "$downloadedFile" > "$out"
-    '';
-  });
-in
-stdenv.mkDerivation rec {
-  version = "8.0.1";
+  commonBuildInputs = [ alex autoconf automake ghc happy hscolour perl python3 sphinx ];
+  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"
+  '' + stdenv.lib.optionalString enableIntegerSimple ''
+    echo "INTEGER_LIBRARY=integer-simple" > mk/build.mk
+  '';
+in stdenv.mkDerivation (rec {
+  inherit version;
   name = "ghc-${version}";
 
   src = fetchurl {
-    url = "https://downloads.haskell.org/~ghc/8.0.1/${name}-src.tar.xz";
-    sha256 = "1lniqy29djhjkddnailpaqhlqh4ld2mqvb1fxgxw1qqjhz6j1ywh";
+    url = "https://downloads.haskell.org/~ghc/8.2.2-rc3/${name}-src.tar.xz";
+    sha256 = "13h55vcrs243bv4hv8i4jq80rsx5hvhi09r3rcs562d8zk7k665w";
   };
 
-  patches = [
-    ./relocation.patch
+  postPatch = "patchShebangs .";
 
-    # Fix https://ghc.haskell.org/trac/ghc/ticket/12130
-    (fetchFilteredPatch { url = https://git.haskell.org/ghc.git/patch/4d71cc89b4e9648f3fbb29c8fcd25d725616e265; sha256 = "0syaxb4y4s2dc440qmrggb4vagvqqhb55m6mx12rip4i9qhxl8k0"; })
-    (fetchFilteredPatch { url = https://git.haskell.org/ghc.git/patch/2f8cd14fe909a377b3e084a4f2ded83a0e6d44dd; sha256 = "06zvlgcf50ab58bw6yw3krn45dsmhg4cmlz4nqff8k4z1f1bj01v"; })
-  ] ++ stdenv.lib.optional stdenv.isLinux ./ghc-no-madv-free.patch;
+  patches = [ ./ghc-gold-linker.patch ];
 
-  buildInputs = [ ghc perl hscolour sphinx];
+  preConfigure = commonPreConfigure;
 
-  enableParallelBuilding = true;
-
-  outputs = [ "out" "doc" ];
+  buildInputs = commonBuildInputs;
 
-  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"
-  '' + stdenv.lib.optionalString enableIntegerSimple ''
-    echo "INTEGER_LIBRARY=integer-simple" > mk/build.mk
-  '';
+  enableParallelBuilding = true;
 
   configureFlags = [
-    "--with-gcc=${stdenv.cc}/bin/cc"
+    "CC=${stdenv.cc}/bin/cc"
     "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
     "--datadir=$doc/share/doc/ghc"
   ] ++ stdenv.lib.optional (! enableIntegerSimple) [
@@ -63,6 +54,8 @@ stdenv.mkDerivation rec {
   # that in turn causes GHCi to abort
   stripDebugFlags = [ "-S" ] ++ stdenv.lib.optional (!stdenv.isDarwin) "--keep-file-symbols";
 
+  checkTarget = "test";
+
   postInstall = ''
     paxmark m $out/lib/${name}/bin/{ghc,haddock}
 
@@ -77,8 +70,15 @@ stdenv.mkDerivation rec {
     done
   '';
 
+  outputs = [ "out" "doc" ];
+
   passthru = {
     inherit bootPkgs;
+  } // stdenv.lib.optionalAttrs (targetPlatform != buildPlatform) {
+    crossCompiler = selfPkgs.ghc.override {
+      cross = targetPlatform;
+      bootPkgs = selfPkgs;
+    };
   };
 
   meta = {
@@ -88,4 +88,32 @@ stdenv.mkDerivation rec {
     inherit (ghc.meta) license platforms;
   };
 
-}
+} // stdenv.lib.optionalAttrs (cross != null) {
+  name = "${cross.config}-ghc-${version}";
+
+  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.binutils}/bin/${cross.config}-ld"
+    "AR=${stdenv.binutils}/bin/${cross.config}-ar"
+    "NM=${stdenv.binutils}/bin/${cross.config}-nm"
+    "RANLIB=${stdenv.binutils}/bin/${cross.config}-ranlib"
+    "--target=${cross.config}"
+    "--enable-bootstrap-with-devel-snapshot"
+  ] ++
+    # fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
+    lib.optional (cross.config or null == "aarch64-apple-darwin14") "--disable-large-address-space";
+
+  buildInputs = commonBuildInputs ++ [ stdenv.ccCross stdenv.binutils ];
+
+  dontSetConfigureCross = true;
+
+  passthru = {
+    inherit bootPkgs cross;
+    cc = "${stdenv.ccCross}/bin/${cross.config}-cc";
+    ld = "${stdenv.binutils}/bin/${cross.config}-ld";
+  };
+})
diff --git a/pkgs/development/compilers/ghc/D2710.patch b/pkgs/development/compilers/ghc/D2710.patch
deleted file mode 100644
index 0ee1b06c7346..000000000000
--- a/pkgs/development/compilers/ghc/D2710.patch
+++ /dev/null
@@ -1,19 +0,0 @@
-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
deleted file mode 100644
index 8d229f273999..000000000000
--- a/pkgs/development/compilers/ghc/D2711.patch
+++ /dev/null
@@ -1,22 +0,0 @@
-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
deleted file mode 100644
index d938d70bbcfe..000000000000
--- a/pkgs/development/compilers/ghc/D2712.patch
+++ /dev/null
@@ -1,158 +0,0 @@
-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
deleted file mode 100644
index 80cf35a52974..000000000000
--- a/pkgs/development/compilers/ghc/D2713.patch
+++ /dev/null
@@ -1,17 +0,0 @@
-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 362b4895b7e3..92ba3f6a46ed 100644
--- a/pkgs/development/compilers/ghc/head.nix
+++ b/pkgs/development/compilers/ghc/head.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, fetchgit, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
+{ stdenv, lib, fetchgit, bootPkgs, perl, ncurses, libiconv, targetPackages, coreutils
 , autoconf, automake, happy, alex, python3, buildPlatform, targetPlatform
 , selfPkgs, cross ? null
 
@@ -71,7 +71,7 @@ in stdenv.mkDerivation (rec {
     for i in "$out/bin/"*; do
       test ! -h $i || continue
       egrep --quiet '^#!' <(head -n 1 $i) || continue
-      sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ binutils coreutils ]}"' $i
+      sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' $i
     done
   '';
 
diff --git a/pkgs/development/compilers/ghcjs/base.nix b/pkgs/development/compilers/ghcjs/base.nix
index a7381fa1a146..d4418b058d92 100644
--- a/pkgs/development/compilers/ghcjs/base.nix
+++ b/pkgs/development/compilers/ghcjs/base.nix
@@ -40,11 +40,6 @@
 , coreutils
 , libiconv
 
-, ghcjsNodePkgs ? callPackage ../../../top-level/node-packages.nix {
-    generated = ./node-packages-generated.nix;
-    self = ghcjsNodePkgs;
-  }
-
 , version ? "0.2.0"
 , ghcjsSrc ? fetchFromGitHub {
     owner = "ghcjs";
@@ -178,7 +173,7 @@ in mkDerivation (rec {
     isCross = true;
     isGhcjs = true;
     inherit nodejs ghcjsBoot;
-    inherit (ghcjsNodePkgs) "socket.io";
+    socket-io = pkgs.nodePackages."socket.io";
 
     inherit stage1Packages;
     mkStage2 = stage2 {
diff --git a/pkgs/development/compilers/ghcjs/default.nix b/pkgs/development/compilers/ghcjs/default.nix
index f23da1149c51..ff989ea22c40 100644
--- a/pkgs/development/compilers/ghcjs/default.nix
+++ b/pkgs/development/compilers/ghcjs/default.nix
@@ -2,5 +2,4 @@
 
 bootPkgs.callPackage ./base.nix {
   inherit bootPkgs;
-  broken = false;
 }
diff --git a/pkgs/development/compilers/ghcjs/ghcjs-head.patch b/pkgs/development/compilers/ghcjs/ghcjs-head.patch
new file mode 100644
index 000000000000..bbb5b30468cb
--- /dev/null
+++ b/pkgs/development/compilers/ghcjs/ghcjs-head.patch
@@ -0,0 +1,86 @@
+diff --git a/src-bin/Boot.hs b/src-bin/Boot.hs
+index db8b12e..7b815c5 100644
+--- a/src-bin/Boot.hs
++++ b/src-bin/Boot.hs
+@@ -540,9 +540,7 @@ initPackageDB :: B ()
+ initPackageDB = do
+   msg info "creating package databases"
+   initDB "--global" <^> beLocations . blGlobalDB
+-  traverseOf_ _Just initUser <^> beLocations . blUserDBDir
+   where
+-    initUser dir = rm_f (dir </> "package.conf") >> initDB "--user" (dir </> "package.conf.d")
+     initDB dbName db = do
+       rm_rf db >> mkdir_p db
+       ghcjs_pkg_ ["init", toTextI db] `catchAny_` return ()
+@@ -566,29 +564,22 @@ installDevelopmentTree = subTop $ do
+   msgD info $ "preparing development boot tree"
+   checkpoint' "ghcjs-boot-git" "ghcjs-boot repository already cloned and prepared" $ do
+     testGit "ghcjs-boot" >>= \case
+-      Just False -> failWith "ghcjs-boot already exists and is not a git repository"
+-      Just True  -> do
+-        msg info "ghcjs-boot repository already exists but checkpoint not reached, cleaning first, then cloning"
+-        rm_rf "ghcjs-boot"
++      Just _ -> do
++        msg info "ghcjs-boot repository already exists; initializing ghcjs-boot"
+         initGhcjsBoot
+       Nothing    -> do
+         msgD info "cloning ghcjs-boot git repository"
+         initGhcjsBoot
+   checkpoint' "shims-git" "shims repository already cloned" $ do
+     testGit "shims" >>= \case
+-      Just False -> failWith "shims already exists and is not a git repository"
+-      Just True  -> do
+-        msgD info "shims repository already exists but checkpoint not reached, cleaning first, then cloning"
+-        rm_rf "shims"
+-        cloneGit shimsDescr "shims" bsrcShimsDevBranch bsrcShimsDev
++      Just _ -> do
++        msgD info "shims repository already exists; moving on"
+       Nothing    -> do
+         msgD info "cloning shims git repository"
+         cloneGit shimsDescr "shims" bsrcShimsDevBranch bsrcShimsDev
+   where
+     initGhcjsBoot = sub $ do
+-      cloneGit bootDescr "ghcjs-boot"  bsrcBootDevBranch bsrcBootDev
+       cd "ghcjs-boot"
+-      git_ ["submodule", "update", "--init", "--recursive"]
+       mapM_ patchPackage =<< allPackages
+       preparePrimops
+       buildGenPrim
+@@ -1201,14 +1192,14 @@ cabalInstallFlags parmakeGhcjs = do
+            , "--avoid-reinstalls"
+            , "--builddir",      "dist"
+            , "--with-compiler", ghcjs ^. pgmLocText
++           , "--with-gcc",      "@CC@"
+            , "--with-hc-pkg",   ghcjsPkg ^. pgmLocText
+-           , "--prefix",        toTextI instDir
++           , "--prefix",        "@PREFIX@"
++           , "--libdir",        "$prefix/lib/$compiler"
++           , "--libsubdir",     "$pkgid"
+            , bool haddock "--enable-documentation" "--disable-documentation"
+            , "--haddock-html"
+--- workaround for hoogle support being broken in haddock for GHC 7.10RC1
+-#if !(__GLASGOW_HASKELL__ >= 709)
+            , "--haddock-hoogle"
+-#endif
+            , "--haddock-hyperlink-source"
+ -- don't slow down Windows builds too much, on other platforms we get this more
+ -- or less for free, thanks to dynamic-too
+diff --git a/src/Compiler/Info.hs b/src/Compiler/Info.hs
+index 33a401f..e2405a7 100644
+--- a/src/Compiler/Info.hs
++++ b/src/Compiler/Info.hs
+@@ -48,13 +48,7 @@ compilerInfo nativeToo dflags = do
+ 
+ -- | the directory to use if started without -B flag
+ getDefaultTopDir :: IO FilePath
+-getDefaultTopDir = do
+-  appdir <- getAppUserDataDirectory "ghcjs"
+-  return (appdir </> subdir </> "ghcjs")
+-      where
+-        targetARCH = arch
+-        targetOS   = os
+-        subdir     = targetARCH ++ '-':targetOS ++ '-':getFullCompilerVersion
++getDefaultTopDir = return "@PREFIX@/lib/ghcjs-@VERSION@"
+ 
+ getDefaultLibDir :: IO FilePath
+ getDefaultLibDir = getDefaultTopDir
diff --git a/pkgs/development/compilers/ghcjs/head.nix b/pkgs/development/compilers/ghcjs/head.nix
index 01b13262ef0c..2cf6c8b39c24 100644
--- a/pkgs/development/compilers/ghcjs/head.nix
+++ b/pkgs/development/compilers/ghcjs/head.nix
@@ -6,19 +6,15 @@ bootPkgs.callPackage ./base.nix {
   inherit bootPkgs;
 
   ghcjsSrc = fetchFromGitHub {
-    # TODO: switch back to the regular ghcjs repo
-    # when https://github.com/ghcjs/ghcjs/pull/573 is merged.
-    owner = "k0001";
+    owner = "ghcjs";
     repo = "ghcjs";
-    rev = "600015e085a28da601b65a41c513d4a458fcd184";
-    sha256 = "01kirrg0fnfwhllvwgfqjiwzwj4yv4lyig87x61n9jp6y5shzjdx";
+    rev = "2b3759942fb5b2fc1a58d314d9b098d4622fa6b6";
+    sha256 = "15asapg0va8dvcdycsx8dgk4xcpdnhml4h31wka6vvxf5anzz8aw";
   };
   ghcjsBootSrc = fetchgit {
-    # TODO: switch back to git://github.com/ghcjs/ghcjs-boot.git
-    # when https://github.com/ghcjs/ghcjs-boot/pull/41 is merged.
-    url = git://github.com/basvandijk/ghcjs-boot.git;
-    rev = "19a3b157ecb807c2224daffda5baecc92b76af35";
-    sha256 = "16sgr8vfr1nx5ljnk8gckgjk70zpa67ix4dbr9aizkwyz41ilfrb";
+    url = git://github.com/ghcjs/ghcjs-boot.git;
+    rev = "106e144cca6529a1b9612c11aea5d6ef65b96745";
+    sha256 = "0gxg8iiwvm93x1dwhxypczn9qiz4m1xvj8i7cf4snfdy2jdyhi5l";
     fetchSubmodules = true;
   };
 
@@ -49,4 +45,6 @@ bootPkgs.callPackage ./base.nix {
     "unix"
   ];
   stage2 = import ./head_stage2.nix;
+
+  patches = [ ./ghcjs-head.patch ];
 }
diff --git a/pkgs/development/compilers/ghcjs/head_shims.nix b/pkgs/development/compilers/ghcjs/head_shims.nix
index 68b03d057397..a9a7f8d45e27 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 = "f67394c559ac921a768b12f141499119563b8bf3";
-  sha256 = "1lz86qmkxkfch1yk9a62admw7jsd34sqcrskgpq28hbhjpgzf1lv";
+  rev = "85395dce971e23a39e5f93af4ed139ca36d4e448";
+  sha256 = "1kqgik75jx681s1kjx1s7dryigr3m940c3zb9vy0r3psxrw6sf2g";
 }
diff --git a/pkgs/development/compilers/ghcjs/head_stage2.nix b/pkgs/development/compilers/ghcjs/head_stage2.nix
index aa19cfea9718..18c7a76dd3af 100644
--- a/pkgs/development/compilers/ghcjs/head_stage2.nix
+++ b/pkgs/development/compilers/ghcjs/head_stage2.nix
@@ -2,117 +2,145 @@
 
 {
   async = callPackage
-    ({ mkDerivation, base, HUnit, stm, test-framework
-     , test-framework-hunit, stdenv
-     }:
-     mkDerivation {
-       pname = "async";
-       version = "2.1.1";
-       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;
-     }) {};
+    ({ mkDerivation, base, HUnit, stdenv, stm, test-framework
+      , test-framework-hunit
+      }:
+      mkDerivation {
+        pname = "async";
+        version = "2.1.1";
+        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, base-compat, base-orphans
-     , base16-bytestring, bytestring, containers, deepseq, directory
-     , dlist, fetchgit, filepath, generic-deriving, ghc-prim, hashable
-     , hashable-time, HUnit, integer-logarithms, QuickCheck
-     , quickcheck-instances, scientific, stdenv, tagged
-     , template-haskell, test-framework, test-framework-hunit
-     , test-framework-quickcheck2, text, time, time-locale-compat
-     , unordered-containers, uuid-types, vector
-     }:
-     mkDerivation {
-       pname = "aeson";
-       version = "1.1.1.0";
-       src = "${ghcjsBoot}/boot/aeson";
-       libraryHaskellDepends = [
-         attoparsec base base-compat bytestring containers deepseq dlist
-         ghc-prim hashable scientific tagged template-haskell text time
-         time-locale-compat unordered-containers uuid-types vector
-       ];
-       testHaskellDepends = [
-         attoparsec base base-compat base-orphans base16-bytestring
-         bytestring containers directory dlist filepath generic-deriving
-         ghc-prim hashable hashable-time HUnit integer-logarithms QuickCheck
-         quickcheck-instances scientific tagged template-haskell
-         test-framework test-framework-hunit test-framework-quickcheck2 text
-         time time-locale-compat unordered-containers uuid-types vector
-       ];
-       jailbreak = true;
-       homepage = https://github.com/bos/aeson;
-       description = "Fast JSON parsing and encoding";
-       license = stdenv.lib.licenses.bsd3;
-     }) {};
+      , base16-bytestring, bytestring, containers, deepseq, directory
+      , dlist, filepath, generic-deriving, ghc-prim, hashable
+      , hashable-time, HUnit, integer-logarithms, QuickCheck
+      , quickcheck-instances, scientific, stdenv, tagged
+      , template-haskell, test-framework, test-framework-hunit
+      , test-framework-quickcheck2, text, th-abstraction, time
+      , time-locale-compat, unordered-containers, uuid-types, vector
+      }:
+      mkDerivation {
+        pname = "aeson";
+        version = "1.2.2.0";
+        src = "${ghcjsBoot}/boot/aeson";
+        doCheck = false;
+        libraryHaskellDepends = [
+          attoparsec base base-compat bytestring containers deepseq dlist
+          ghc-prim hashable scientific tagged template-haskell text
+          th-abstraction time time-locale-compat unordered-containers
+          uuid-types vector
+        ];
+        testHaskellDepends = [
+          attoparsec base base-compat base-orphans base16-bytestring
+          bytestring containers directory dlist filepath generic-deriving
+          ghc-prim hashable hashable-time HUnit integer-logarithms QuickCheck
+          quickcheck-instances scientific tagged template-haskell
+          test-framework test-framework-hunit test-framework-quickcheck2 text
+          time time-locale-compat unordered-containers uuid-types 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, case-insensitive
-     , containers, criterion, deepseq, directory, filepath, ghc-prim
-     , http-types, parsec, QuickCheck, quickcheck-unicode, scientific
-     , tasty, tasty-quickcheck, text, transformers, unordered-containers
-     , vector, stdenv
-     }:
-     mkDerivation {
-       pname = "attoparsec";
-       version = "0.13.1.0";
-       src = "${ghcjsBoot}/boot/attoparsec";
-       libraryHaskellDepends = [
-         array base bytestring containers deepseq scientific text
-         transformers
-       ];
-       testHaskellDepends = [
-         array base bytestring deepseq QuickCheck quickcheck-unicode
-         scientific tasty tasty-quickcheck text transformers vector
-       ];
-       benchmarkHaskellDepends = [
-         array base bytestring case-insensitive containers criterion deepseq
-         directory filepath ghc-prim http-types parsec scientific text
-         transformers unordered-containers vector
-       ];
-       jailbreak = true;
-       homepage = https://github.com/bos/attoparsec;
-       description = "Fast combinator parsing for bytestrings and text";
-       license = stdenv.lib.licenses.bsd3;
-     }) {};
+      , containers, criterion, deepseq, directory, filepath, ghc-prim
+      , http-types, parsec, QuickCheck, quickcheck-unicode, scientific
+      , stdenv, tasty, tasty-quickcheck, text, transformers
+      , unordered-containers, vector
+      }:
+      mkDerivation {
+        pname = "attoparsec";
+        version = "0.13.1.0";
+        src = "${ghcjsBoot}/boot/attoparsec";
+        doCheck = false;
+        libraryHaskellDepends = [
+          array base bytestring containers deepseq scientific text
+          transformers
+        ];
+        testHaskellDepends = [
+          array base bytestring deepseq QuickCheck quickcheck-unicode
+          scientific tasty tasty-quickcheck text transformers vector
+        ];
+        benchmarkHaskellDepends = [
+          array base bytestring case-insensitive containers criterion deepseq
+          directory filepath ghc-prim http-types parsec scientific text
+          transformers unordered-containers vector
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/bos/attoparsec";
+        description = "Fast combinator parsing for bytestrings and text";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  base-compat = callPackage
+    ({ mkDerivation, base, hspec, QuickCheck, stdenv, unix }:
+      mkDerivation {
+        pname = "base-compat";
+        version = "0.9.3";
+        src = "${ghcjsBoot}/boot/base-compat";
+        doCheck = false;
+        libraryHaskellDepends = [ base unix ];
+        testHaskellDepends = [ base hspec QuickCheck ];
+        jailbreak = true;
+        description = "A compatibility layer for base";
+        license = stdenv.lib.licenses.mit;
+      }) {};
+  bytestring-builder = callPackage
+    ({ mkDerivation, base, bytestring, deepseq, stdenv }:
+      mkDerivation {
+        pname = "bytestring-builder";
+        version = "0.10.8.1.0";
+        src = "${ghcjsBoot}/boot/bytestring-builder";
+        doCheck = false;
+        libraryHaskellDepends = [ base bytestring deepseq ];
+        jailbreak = true;
+        description = "The new bytestring builder, packaged outside of GHC";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
   case-insensitive = callPackage
     ({ mkDerivation, base, bytestring, criterion, deepseq, hashable
-     , HUnit, test-framework, test-framework-hunit, text, stdenv
-     }:
-     mkDerivation {
-       pname = "case-insensitive";
-       version = "1.2.0.8";
-       src = "${ghcjsBoot}/boot/case-insensitive";
-       doCheck = false;
-       libraryHaskellDepends = [ base bytestring deepseq hashable text ];
-       testHaskellDepends = [
-         base bytestring HUnit test-framework test-framework-hunit text
-       ];
-       benchmarkHaskellDepends = [ base bytestring criterion deepseq ];
-       jailbreak = true;
-       homepage = https://github.com/basvandijk/case-insensitive;
-       description = "Case insensitive string comparison";
-       license = stdenv.lib.licenses.bsd3;
-     }) {};
+      , HUnit, stdenv, test-framework, test-framework-hunit, text
+      }:
+      mkDerivation {
+        pname = "case-insensitive";
+        version = "1.2.0.8";
+        src = "${ghcjsBoot}/boot/case-insensitive";
+        doCheck = false;
+        libraryHaskellDepends = [ base bytestring deepseq hashable text ];
+        testHaskellDepends = [
+          base bytestring HUnit test-framework test-framework-hunit text
+        ];
+        benchmarkHaskellDepends = [ base bytestring criterion deepseq ];
+        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.8.0.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;
-     }) {};
+      mkDerivation {
+        pname = "dlist";
+        version = "0.8.0.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 {
@@ -125,10 +153,21 @@
         description = "Extensible exceptions";
         license = stdenv.lib.licenses.bsd3;
       }) {};
+  fail = callPackage
+    ({ mkDerivation, stdenv }:
+      mkDerivation {
+        pname = "fail";
+        version = "4.9.0.0";
+        src = "${ghcjsBoot}/boot/fail";
+        jailbreak = true;
+        homepage = "https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail";
+        description = "Forward-compatible MonadFail class";
+        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, base, bytestring, criterion, ghc-prim, HUnit
+      , integer-gmp, QuickCheck, random, siphash, stdenv, test-framework
+      , test-framework-hunit, test-framework-quickcheck2, text, unix
       }:
       mkDerivation {
         pname = "hashable";
@@ -142,24 +181,58 @@
           base bytestring ghc-prim HUnit QuickCheck random test-framework
           test-framework-hunit test-framework-quickcheck2 text unix
         ];
+        benchmarkHaskellDepends = [
+          base bytestring criterion ghc-prim integer-gmp siphash text
+        ];
         jailbreak = true;
-        homepage = http://github.com/tibbe/hashable;
+        homepage = "http://github.com/tibbe/hashable";
         description = "A class for types that can be converted to a hash value";
         license = stdenv.lib.licenses.bsd3;
       }) {};
+  integer-logarithms = callPackage
+    ({ mkDerivation, array, base, ghc-prim, integer-gmp, QuickCheck
+      , smallcheck, stdenv, tasty, tasty-hunit, tasty-quickcheck
+      , tasty-smallcheck
+      }:
+      mkDerivation {
+        pname = "integer-logarithms";
+        version = "1.0.2";
+        src = "${ghcjsBoot}/boot/integer-logarithms";
+        doCheck = false;
+        libraryHaskellDepends = [ array base ghc-prim integer-gmp ];
+        testHaskellDepends = [
+          base QuickCheck smallcheck tasty tasty-hunit tasty-quickcheck
+          tasty-smallcheck
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/phadej/integer-logarithms";
+        description = "Integer logarithms";
+        license = stdenv.lib.licenses.mit;
+      }) {};
   mtl = callPackage
     ({ mkDerivation, base, stdenv, transformers }:
       mkDerivation {
         pname = "mtl";
-        version = "2.2.2";
+        version = "2.2.1";
         src = "${ghcjsBoot}/boot/mtl";
         doCheck = false;
         libraryHaskellDepends = [ base transformers ];
         jailbreak = true;
-        homepage = http://github.com/ekmett/mtl;
+        homepage = "http://github.com/ekmett/mtl";
         description = "Monad classes, using functional dependencies";
         license = stdenv.lib.licenses.bsd3;
       }) {};
+  nats = callPackage
+    ({ mkDerivation, stdenv }:
+      mkDerivation {
+        pname = "nats";
+        version = "1.1.1";
+        src = "${ghcjsBoot}/boot/nats";
+        jailbreak = true;
+        homepage = "http://github.com/ekmett/nats/";
+        description = "Natural numbers";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
   old-time = callPackage
     ({ mkDerivation, base, old-locale, stdenv }:
       mkDerivation {
@@ -184,30 +257,57 @@
         description = "Parallel programming library";
         license = stdenv.lib.licenses.bsd3;
       }) {};
+  random = callPackage
+    ({ mkDerivation, base, stdenv, time }:
+      mkDerivation {
+        pname = "random";
+        version = "1.1";
+        src = "${ghcjsBoot}/boot/random";
+        doCheck = false;
+        libraryHaskellDepends = [ base time ];
+        testHaskellDepends = [ base ];
+        jailbreak = true;
+        description = "random number library";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
   scientific = callPackage
     ({ mkDerivation, base, binary, bytestring, containers, criterion
-     , deepseq, ghc-prim, hashable, integer-gmp, integer-logarithms
-     , QuickCheck, smallcheck, tasty, tasty-ant-xml, tasty-hunit
-     , tasty-quickcheck, tasty-smallcheck, text, vector, stdenv
-     }:
-     mkDerivation {
-       pname = "scientific";
-       version = "0.3.4.10";
-       src = "${ghcjsBoot}/boot/scientific";
-       libraryHaskellDepends = [
-         base binary bytestring containers deepseq ghc-prim hashable
-         integer-gmp integer-logarithms text vector
-       ];
-       testHaskellDepends = [
-         base binary bytestring QuickCheck smallcheck tasty tasty-ant-xml
-         tasty-hunit tasty-quickcheck tasty-smallcheck text
-       ];
-       benchmarkHaskellDepends = [ base criterion ];
-       jailbreak = true;
-       homepage = https://github.com/basvandijk/scientific;
-       description = "Numbers represented using scientific notation";
-       license = stdenv.lib.licenses.bsd3;
-     }) {};
+      , deepseq, ghc-prim, hashable, integer-gmp, integer-logarithms
+      , QuickCheck, smallcheck, stdenv, tasty, tasty-ant-xml, tasty-hunit
+      , tasty-quickcheck, tasty-smallcheck, text, vector
+      }:
+      mkDerivation {
+        pname = "scientific";
+        version = "0.3.4.10";
+        src = "${ghcjsBoot}/boot/scientific";
+        doCheck = false;
+        libraryHaskellDepends = [
+          base binary bytestring containers deepseq ghc-prim hashable
+          integer-gmp integer-logarithms text vector
+        ];
+        testHaskellDepends = [
+          base binary bytestring QuickCheck smallcheck tasty tasty-ant-xml
+          tasty-hunit tasty-quickcheck tasty-smallcheck text
+        ];
+        benchmarkHaskellDepends = [ base criterion ];
+        jailbreak = true;
+        homepage = "https://github.com/basvandijk/scientific";
+        description = "Numbers represented using scientific notation";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  semigroups = callPackage
+    ({ mkDerivation, base, stdenv }:
+      mkDerivation {
+        pname = "semigroups";
+        version = "0.18.3";
+        src = "${ghcjsBoot}/boot/semigroups";
+        doCheck = false;
+        libraryHaskellDepends = [ base ];
+        jailbreak = true;
+        homepage = "http://github.com/ekmett/semigroups/";
+        description = "Anything that associates";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
   stm = callPackage
     ({ mkDerivation, array, base, stdenv }:
       mkDerivation {
@@ -230,27 +330,27 @@
         libraryHaskellDepends = [ base ];
         testHaskellDepends = [ base containers HUnit mtl ];
         jailbreak = true;
-        homepage = http://www.cs.uu.nl/wiki/GenericProgramming/SYB;
+        homepage = "http://www.cs.uu.nl/wiki/GenericProgramming/SYB";
         description = "Scrap Your Boilerplate";
         license = stdenv.lib.licenses.bsd3;
       }) {};
   tagged = callPackage
-    ({ mkDerivation, base, deepseq, template-haskell, transformers
-     , transformers-compat, stdenv
-     }:
-     mkDerivation {
-       pname = "tagged";
-       version = "0.8.5";
-       src = "${ghcjsBoot}/boot/tagged";
-       doCheck = false;
-       libraryHaskellDepends = [
-         base deepseq template-haskell transformers transformers-compat
-       ];
-       jailbreak = true;
-       homepage = http://github.com/ekmett/tagged;
-       description = "Haskell 98 phantom types to avoid unsafely passing dummy arguments";
-       license = stdenv.lib.licenses.bsd3;
-     }) {};
+    ({ mkDerivation, base, deepseq, stdenv, template-haskell
+      , transformers, transformers-compat
+      }:
+      mkDerivation {
+        pname = "tagged";
+        version = "0.8.5";
+        src = "${ghcjsBoot}/boot/tagged";
+        doCheck = false;
+        libraryHaskellDepends = [
+          base deepseq template-haskell transformers transformers-compat
+        ];
+        jailbreak = true;
+        homepage = "http://github.com/ekmett/tagged";
+        description = "Haskell 98 phantom types to avoid unsafely passing dummy arguments";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
   text = callPackage
     ({ mkDerivation, array, base, binary, bytestring, deepseq, directory
       , ghc-prim, HUnit, integer-gmp, QuickCheck, quickcheck-unicode
@@ -271,57 +371,104 @@
           test-framework-hunit test-framework-quickcheck2
         ];
         jailbreak = true;
-        homepage = https://github.com/bos/text;
+        homepage = "https://github.com/bos/text";
         description = "An efficient packed Unicode text type";
         license = stdenv.lib.licenses.bsd3;
       }) {};
+  th-abstraction = callPackage
+    ({ mkDerivation, base, containers, ghc-prim, stdenv
+      , template-haskell
+      }:
+      mkDerivation {
+        pname = "th-abstraction";
+        version = "0.2.6.0";
+        src = "${ghcjsBoot}/boot/th-abstraction";
+        doCheck = false;
+        libraryHaskellDepends = [
+          base containers ghc-prim template-haskell
+        ];
+        testHaskellDepends = [ base containers template-haskell ];
+        jailbreak = true;
+        homepage = "https://github.com/glguy/th-abstraction";
+        description = "Nicer interface for reified information about data types";
+        license = stdenv.lib.licenses.isc;
+      }) {};
+  time-locale-compat = callPackage
+    ({ mkDerivation, base, old-locale, stdenv, time }:
+      mkDerivation {
+        pname = "time-locale-compat";
+        version = "0.1.1.3";
+        src = "${ghcjsBoot}/boot/time-locale-compat";
+        doCheck = false;
+        libraryHaskellDepends = [ base old-locale time ];
+        jailbreak = true;
+        homepage = "https://github.com/khibino/haskell-time-locale-compat";
+        description = "Compatibility of TimeLocale between old-locale and time-1.5";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
+  transformers-compat = callPackage
+    ({ mkDerivation, base, ghc-prim, stdenv, transformers }:
+      mkDerivation {
+        pname = "transformers-compat";
+        version = "0.5.1.4";
+        src = "${ghcjsBoot}/boot/transformers-compat";
+        doCheck = false;
+        libraryHaskellDepends = [ base ghc-prim transformers ];
+        jailbreak = true;
+        homepage = "http://github.com/ekmett/transformers-compat/";
+        description = "A small compatibility shim exposing the new types from transformers 0.3 and 0.4 to older Haskell platforms.";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
   unordered-containers = callPackage
     ({ mkDerivation, base, bytestring, ChasingBottoms, containers
-     , criterion, deepseq, deepseq-generics, hashable, hashmap, HUnit
-     , mtl, QuickCheck, random, test-framework, test-framework-hunit
-     , test-framework-quickcheck2, stdenv
-     }:
-     mkDerivation {
-       pname = "unordered-containers";
-       version = "0.2.7.2";
-       src = "${ghcjsBoot}/boot/unordered-containers";
-       libraryHaskellDepends = [ base deepseq hashable ];
-       testHaskellDepends = [
-         base ChasingBottoms containers hashable HUnit QuickCheck
-         test-framework test-framework-hunit test-framework-quickcheck2
-       ];
-       benchmarkHaskellDepends = [
-         base bytestring containers criterion deepseq deepseq-generics
-         hashable hashmap mtl random
-       ];
-       jailbreak = true;
-       homepage = https://github.com/tibbe/unordered-containers;
-       description = "Efficient hashing-based container types";
-       license = stdenv.lib.licenses.bsd3;
-     }) {};
+      , criterion, deepseq, deepseq-generics, hashable, hashmap, HUnit
+      , mtl, QuickCheck, random, stdenv, test-framework
+      , test-framework-hunit, test-framework-quickcheck2
+      }:
+      mkDerivation {
+        pname = "unordered-containers";
+        version = "0.2.7.2";
+        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
+        ];
+        benchmarkHaskellDepends = [
+          base bytestring containers criterion deepseq deepseq-generics
+          hashable hashmap mtl random
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/tibbe/unordered-containers";
+        description = "Efficient hashing-based container types";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
   uuid-types = callPackage
     ({ mkDerivation, base, binary, bytestring, containers, criterion
-     , deepseq, hashable, HUnit, QuickCheck, random, stdenv, tasty
-     , tasty-hunit, tasty-quickcheck, text
-     }:
-     mkDerivation {
-       pname = "uuid-types";
-       version = "1.0.3";
-       src = "${ghcjsBoot}/boot/uuid/uuid-types";
-       libraryHaskellDepends = [
-         base binary bytestring deepseq hashable random text
-       ];
-       testHaskellDepends = [
-         base bytestring HUnit QuickCheck tasty tasty-hunit tasty-quickcheck
-       ];
-       benchmarkHaskellDepends = [
-         base bytestring containers criterion deepseq random
-       ];
-       jailbreak = true;
-       homepage = https://github.com/aslatter/uuid;
-       description = "Type definitions for Universally Unique Identifiers";
-       license = stdenv.lib.licenses.bsd3;
-     }) {};
+      , deepseq, hashable, HUnit, QuickCheck, random, stdenv, tasty
+      , tasty-hunit, tasty-quickcheck, text, unordered-containers
+      }:
+      mkDerivation {
+        pname = "uuid-types";
+        version = "1.0.3";
+        src = "${ghcjsBoot}/boot/uuid/uuid-types";
+        doCheck = false;
+        libraryHaskellDepends = [
+          base binary bytestring deepseq hashable random text
+        ];
+        testHaskellDepends = [
+          base bytestring HUnit QuickCheck tasty tasty-hunit tasty-quickcheck
+        ];
+        benchmarkHaskellDepends = [
+          base bytestring containers criterion deepseq random
+          unordered-containers
+        ];
+        jailbreak = true;
+        homepage = "https://github.com/hvr/uuid";
+        description = "Type definitions for Universally Unique Identifiers";
+        license = stdenv.lib.licenses.bsd3;
+      }) {};
   vector = callPackage
     ({ mkDerivation, base, deepseq, ghc-prim, primitive, QuickCheck
       , random, stdenv, template-haskell, test-framework
@@ -338,7 +485,7 @@
           test-framework-quickcheck2 transformers
         ];
         jailbreak = true;
-        homepage = https://github.com/haskell/vector;
+        homepage = "https://github.com/haskell/vector";
         description = "Efficient Arrays";
         license = stdenv.lib.licenses.bsd3;
       }) {};
@@ -366,16 +513,15 @@
           test-framework-hunit test-framework-quickcheck2 text
         ];
         jailbreak = true;
-        homepage = http://github.com/ghcjs/ghcjs-base;
-        description = "Base library for GHCJS";
+        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
+      , deepseq, directory, exceptions, filepath, old-time, pretty
+      , process, QuickCheck, regex-posix, stdenv, tagged, tasty
+      , tasty-hunit, tasty-quickcheck, time, transformers, unix
       }:
       mkDerivation {
         pname = "Cabal";
@@ -387,12 +533,12 @@
           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
+          base bytestring containers directory exceptions filepath old-time
+          pretty process QuickCheck regex-posix tagged tasty tasty-hunit
+          tasty-quickcheck transformers unix
         ];
         jailbreak = true;
-        homepage = http://www.haskell.org/cabal/;
+        homepage = "http://www.haskell.org/cabal/";
         description = "A framework for packaging Haskell software";
         license = stdenv.lib.licenses.bsd3;
       }) {};
diff --git a/pkgs/development/compilers/ghcjs/node-packages-generated.nix b/pkgs/development/compilers/ghcjs/node-packages-generated.nix
deleted file mode 100644
index a3c882ff76c8..000000000000
--- a/pkgs/development/compilers/ghcjs/node-packages-generated.nix
+++ /dev/null
@@ -1,943 +0,0 @@
-{ self, fetchurl, fetchgit ? null, lib }:
-
-{
-  by-spec."accepts"."1.1.4" =
-    self.by-version."accepts"."1.1.4";
-  by-version."accepts"."1.1.4" = self.buildNodePackage {
-    name = "accepts-1.1.4";
-    version = "1.1.4";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/accepts/-/accepts-1.1.4.tgz";
-      name = "accepts-1.1.4.tgz";
-      sha1 = "d71c96f7d41d0feda2c38cd14e8a27c04158df4a";
-    };
-    deps = {
-      "mime-types-2.0.14" = self.by-version."mime-types"."2.0.14";
-      "negotiator-0.4.9" = self.by-version."negotiator"."0.4.9";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."after"."0.8.1" =
-    self.by-version."after"."0.8.1";
-  by-version."after"."0.8.1" = self.buildNodePackage {
-    name = "after-0.8.1";
-    version = "0.8.1";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/after/-/after-0.8.1.tgz";
-      name = "after-0.8.1.tgz";
-      sha1 = "ab5d4fb883f596816d3515f8f791c0af486dd627";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."arraybuffer.slice"."0.0.6" =
-    self.by-version."arraybuffer.slice"."0.0.6";
-  by-version."arraybuffer.slice"."0.0.6" = self.buildNodePackage {
-    name = "arraybuffer.slice-0.0.6";
-    version = "0.0.6";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.6.tgz";
-      name = "arraybuffer.slice-0.0.6.tgz";
-      sha1 = "f33b2159f0532a3f3107a272c0ccfbd1ad2979ca";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."backo2"."1.0.2" =
-    self.by-version."backo2"."1.0.2";
-  by-version."backo2"."1.0.2" = self.buildNodePackage {
-    name = "backo2-1.0.2";
-    version = "1.0.2";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz";
-      name = "backo2-1.0.2.tgz";
-      sha1 = "31ab1ac8b129363463e35b3ebb69f4dfcfba7947";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."base64-arraybuffer"."0.1.2" =
-    self.by-version."base64-arraybuffer"."0.1.2";
-  by-version."base64-arraybuffer"."0.1.2" = self.buildNodePackage {
-    name = "base64-arraybuffer-0.1.2";
-    version = "0.1.2";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.2.tgz";
-      name = "base64-arraybuffer-0.1.2.tgz";
-      sha1 = "474df4a9f2da24e05df3158c3b1db3c3cd46a154";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."base64id"."0.1.0" =
-    self.by-version."base64id"."0.1.0";
-  by-version."base64id"."0.1.0" = self.buildNodePackage {
-    name = "base64id-0.1.0";
-    version = "0.1.0";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/base64id/-/base64id-0.1.0.tgz";
-      name = "base64id-0.1.0.tgz";
-      sha1 = "02ce0fdeee0cef4f40080e1e73e834f0b1bfce3f";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."benchmark"."1.0.0" =
-    self.by-version."benchmark"."1.0.0";
-  by-version."benchmark"."1.0.0" = self.buildNodePackage {
-    name = "benchmark-1.0.0";
-    version = "1.0.0";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/benchmark/-/benchmark-1.0.0.tgz";
-      name = "benchmark-1.0.0.tgz";
-      sha1 = "2f1e2fa4c359f11122aa183082218e957e390c73";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."better-assert"."~1.0.0" =
-    self.by-version."better-assert"."1.0.2";
-  by-version."better-assert"."1.0.2" = self.buildNodePackage {
-    name = "better-assert-1.0.2";
-    version = "1.0.2";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz";
-      name = "better-assert-1.0.2.tgz";
-      sha1 = "40866b9e1b9e0b55b481894311e68faffaebc522";
-    };
-    deps = {
-      "callsite-1.0.0" = self.by-version."callsite"."1.0.0";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."blob"."0.0.4" =
-    self.by-version."blob"."0.0.4";
-  by-version."blob"."0.0.4" = self.buildNodePackage {
-    name = "blob-0.0.4";
-    version = "0.0.4";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/blob/-/blob-0.0.4.tgz";
-      name = "blob-0.0.4.tgz";
-      sha1 = "bcf13052ca54463f30f9fc7e95b9a47630a94921";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."callsite"."1.0.0" =
-    self.by-version."callsite"."1.0.0";
-  by-version."callsite"."1.0.0" = self.buildNodePackage {
-    name = "callsite-1.0.0";
-    version = "1.0.0";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz";
-      name = "callsite-1.0.0.tgz";
-      sha1 = "280398e5d664bd74038b6f0905153e6e8af1bc20";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."component-bind"."1.0.0" =
-    self.by-version."component-bind"."1.0.0";
-  by-version."component-bind"."1.0.0" = self.buildNodePackage {
-    name = "component-bind-1.0.0";
-    version = "1.0.0";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz";
-      name = "component-bind-1.0.0.tgz";
-      sha1 = "00c608ab7dcd93897c0009651b1d3a8e1e73bbd1";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."component-emitter"."1.1.2" =
-    self.by-version."component-emitter"."1.1.2";
-  by-version."component-emitter"."1.1.2" = self.buildNodePackage {
-    name = "component-emitter-1.1.2";
-    version = "1.1.2";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/component-emitter/-/component-emitter-1.1.2.tgz";
-      name = "component-emitter-1.1.2.tgz";
-      sha1 = "296594f2753daa63996d2af08d15a95116c9aec3";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."component-emitter"."1.2.0" =
-    self.by-version."component-emitter"."1.2.0";
-  by-version."component-emitter"."1.2.0" = self.buildNodePackage {
-    name = "component-emitter-1.2.0";
-    version = "1.2.0";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/component-emitter/-/component-emitter-1.2.0.tgz";
-      name = "component-emitter-1.2.0.tgz";
-      sha1 = "ccd113a86388d06482d03de3fc7df98526ba8efe";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."component-inherit"."0.0.3" =
-    self.by-version."component-inherit"."0.0.3";
-  by-version."component-inherit"."0.0.3" = self.buildNodePackage {
-    name = "component-inherit-0.0.3";
-    version = "0.0.3";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz";
-      name = "component-inherit-0.0.3.tgz";
-      sha1 = "645fc4adf58b72b649d5cae65135619db26ff143";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."debug"."0.7.4" =
-    self.by-version."debug"."0.7.4";
-  by-version."debug"."0.7.4" = self.buildNodePackage {
-    name = "debug-0.7.4";
-    version = "0.7.4";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/debug/-/debug-0.7.4.tgz";
-      name = "debug-0.7.4.tgz";
-      sha1 = "06e1ea8082c2cb14e39806e22e2f6f757f92af39";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."debug"."2.2.0" =
-    self.by-version."debug"."2.2.0";
-  by-version."debug"."2.2.0" = self.buildNodePackage {
-    name = "debug-2.2.0";
-    version = "2.2.0";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/debug/-/debug-2.2.0.tgz";
-      name = "debug-2.2.0.tgz";
-      sha1 = "f87057e995b1a1f6ae6a4960664137bc56f039da";
-    };
-    deps = {
-      "ms-0.7.1" = self.by-version."ms"."0.7.1";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."engine.io"."1.6.8" =
-    self.by-version."engine.io"."1.6.8";
-  by-version."engine.io"."1.6.8" = self.buildNodePackage {
-    name = "engine.io-1.6.8";
-    version = "1.6.8";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/engine.io/-/engine.io-1.6.8.tgz";
-      name = "engine.io-1.6.8.tgz";
-      sha1 = "de05a06b757e7517695e088c7b051c47819f511b";
-    };
-    deps = {
-      "base64id-0.1.0" = self.by-version."base64id"."0.1.0";
-      "debug-2.2.0" = self.by-version."debug"."2.2.0";
-      "ws-1.0.1" = self.by-version."ws"."1.0.1";
-      "engine.io-parser-1.2.4" = self.by-version."engine.io-parser"."1.2.4";
-      "accepts-1.1.4" = self.by-version."accepts"."1.1.4";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."engine.io-client"."1.6.8" =
-    self.by-version."engine.io-client"."1.6.8";
-  by-version."engine.io-client"."1.6.8" = self.buildNodePackage {
-    name = "engine.io-client-1.6.8";
-    version = "1.6.8";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/engine.io-client/-/engine.io-client-1.6.8.tgz";
-      name = "engine.io-client-1.6.8.tgz";
-      sha1 = "6e2db11648b45e405c46b172ea3e3dac37cc0ceb";
-    };
-    deps = {
-      "has-cors-1.1.0" = self.by-version."has-cors"."1.1.0";
-      "ws-1.0.1" = self.by-version."ws"."1.0.1";
-      "xmlhttprequest-ssl-1.5.1" = self.by-version."xmlhttprequest-ssl"."1.5.1";
-      "component-emitter-1.1.2" = self.by-version."component-emitter"."1.1.2";
-      "indexof-0.0.1" = self.by-version."indexof"."0.0.1";
-      "engine.io-parser-1.2.4" = self.by-version."engine.io-parser"."1.2.4";
-      "debug-2.2.0" = self.by-version."debug"."2.2.0";
-      "parseuri-0.0.4" = self.by-version."parseuri"."0.0.4";
-      "parsejson-0.0.1" = self.by-version."parsejson"."0.0.1";
-      "parseqs-0.0.2" = self.by-version."parseqs"."0.0.2";
-      "component-inherit-0.0.3" = self.by-version."component-inherit"."0.0.3";
-      "yeast-0.1.2" = self.by-version."yeast"."0.1.2";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."engine.io-parser"."1.2.4" =
-    self.by-version."engine.io-parser"."1.2.4";
-  by-version."engine.io-parser"."1.2.4" = self.buildNodePackage {
-    name = "engine.io-parser-1.2.4";
-    version = "1.2.4";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/engine.io-parser/-/engine.io-parser-1.2.4.tgz";
-      name = "engine.io-parser-1.2.4.tgz";
-      sha1 = "e0897b0bf14e792d4cd2a5950553919c56948c42";
-    };
-    deps = {
-      "after-0.8.1" = self.by-version."after"."0.8.1";
-      "arraybuffer.slice-0.0.6" = self.by-version."arraybuffer.slice"."0.0.6";
-      "base64-arraybuffer-0.1.2" = self.by-version."base64-arraybuffer"."0.1.2";
-      "blob-0.0.4" = self.by-version."blob"."0.0.4";
-      "has-binary-0.1.6" = self.by-version."has-binary"."0.1.6";
-      "utf8-2.1.0" = self.by-version."utf8"."2.1.0";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."has-binary"."0.1.6" =
-    self.by-version."has-binary"."0.1.6";
-  by-version."has-binary"."0.1.6" = self.buildNodePackage {
-    name = "has-binary-0.1.6";
-    version = "0.1.6";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/has-binary/-/has-binary-0.1.6.tgz";
-      name = "has-binary-0.1.6.tgz";
-      sha1 = "25326f39cfa4f616ad8787894e3af2cfbc7b6e10";
-    };
-    deps = {
-      "isarray-0.0.1" = self.by-version."isarray"."0.0.1";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."has-binary"."0.1.7" =
-    self.by-version."has-binary"."0.1.7";
-  by-version."has-binary"."0.1.7" = self.buildNodePackage {
-    name = "has-binary-0.1.7";
-    version = "0.1.7";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/has-binary/-/has-binary-0.1.7.tgz";
-      name = "has-binary-0.1.7.tgz";
-      sha1 = "68e61eb16210c9545a0a5cce06a873912fe1e68c";
-    };
-    deps = {
-      "isarray-0.0.1" = self.by-version."isarray"."0.0.1";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."has-cors"."1.1.0" =
-    self.by-version."has-cors"."1.1.0";
-  by-version."has-cors"."1.1.0" = self.buildNodePackage {
-    name = "has-cors-1.1.0";
-    version = "1.1.0";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz";
-      name = "has-cors-1.1.0.tgz";
-      sha1 = "5e474793f7ea9843d1bb99c23eef49ff126fff39";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."indexof"."0.0.1" =
-    self.by-version."indexof"."0.0.1";
-  by-version."indexof"."0.0.1" = self.buildNodePackage {
-    name = "indexof-0.0.1";
-    version = "0.0.1";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz";
-      name = "indexof-0.0.1.tgz";
-      sha1 = "82dc336d232b9062179d05ab3293a66059fd435d";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."isarray"."0.0.1" =
-    self.by-version."isarray"."0.0.1";
-  by-version."isarray"."0.0.1" = self.buildNodePackage {
-    name = "isarray-0.0.1";
-    version = "0.0.1";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz";
-      name = "isarray-0.0.1.tgz";
-      sha1 = "8a18acfca9a8f4177e09abfc6038939b05d1eedf";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."json3"."3.2.6" =
-    self.by-version."json3"."3.2.6";
-  by-version."json3"."3.2.6" = self.buildNodePackage {
-    name = "json3-3.2.6";
-    version = "3.2.6";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/json3/-/json3-3.2.6.tgz";
-      name = "json3-3.2.6.tgz";
-      sha1 = "f6efc93c06a04de9aec53053df2559bb19e2038b";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."json3"."3.3.2" =
-    self.by-version."json3"."3.3.2";
-  by-version."json3"."3.3.2" = self.buildNodePackage {
-    name = "json3-3.3.2";
-    version = "3.3.2";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/json3/-/json3-3.3.2.tgz";
-      name = "json3-3.3.2.tgz";
-      sha1 = "3c0434743df93e2f5c42aee7b19bcb483575f4e1";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."mime-db"."~1.12.0" =
-    self.by-version."mime-db"."1.12.0";
-  by-version."mime-db"."1.12.0" = self.buildNodePackage {
-    name = "mime-db-1.12.0";
-    version = "1.12.0";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/mime-db/-/mime-db-1.12.0.tgz";
-      name = "mime-db-1.12.0.tgz";
-      sha1 = "3d0c63180f458eb10d325aaa37d7c58ae312e9d7";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."mime-types"."~2.0.4" =
-    self.by-version."mime-types"."2.0.14";
-  by-version."mime-types"."2.0.14" = self.buildNodePackage {
-    name = "mime-types-2.0.14";
-    version = "2.0.14";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/mime-types/-/mime-types-2.0.14.tgz";
-      name = "mime-types-2.0.14.tgz";
-      sha1 = "310e159db23e077f8bb22b748dabfa4957140aa6";
-    };
-    deps = {
-      "mime-db-1.12.0" = self.by-version."mime-db"."1.12.0";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."ms"."0.7.1" =
-    self.by-version."ms"."0.7.1";
-  by-version."ms"."0.7.1" = self.buildNodePackage {
-    name = "ms-0.7.1";
-    version = "0.7.1";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/ms/-/ms-0.7.1.tgz";
-      name = "ms-0.7.1.tgz";
-      sha1 = "9cd13c03adbff25b65effde7ce864ee952017098";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."negotiator"."0.4.9" =
-    self.by-version."negotiator"."0.4.9";
-  by-version."negotiator"."0.4.9" = self.buildNodePackage {
-    name = "negotiator-0.4.9";
-    version = "0.4.9";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/negotiator/-/negotiator-0.4.9.tgz";
-      name = "negotiator-0.4.9.tgz";
-      sha1 = "92e46b6db53c7e421ed64a2bc94f08be7630df3f";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."object-component"."0.0.3" =
-    self.by-version."object-component"."0.0.3";
-  by-version."object-component"."0.0.3" = self.buildNodePackage {
-    name = "object-component-0.0.3";
-    version = "0.0.3";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz";
-      name = "object-component-0.0.3.tgz";
-      sha1 = "f0c69aa50efc95b866c186f400a33769cb2f1291";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."options".">=0.0.5" =
-    self.by-version."options"."0.0.6";
-  by-version."options"."0.0.6" = self.buildNodePackage {
-    name = "options-0.0.6";
-    version = "0.0.6";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/options/-/options-0.0.6.tgz";
-      name = "options-0.0.6.tgz";
-      sha1 = "ec22d312806bb53e731773e7cdaefcf1c643128f";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."parsejson"."0.0.1" =
-    self.by-version."parsejson"."0.0.1";
-  by-version."parsejson"."0.0.1" = self.buildNodePackage {
-    name = "parsejson-0.0.1";
-    version = "0.0.1";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/parsejson/-/parsejson-0.0.1.tgz";
-      name = "parsejson-0.0.1.tgz";
-      sha1 = "9b10c6c0d825ab589e685153826de0a3ba278bcc";
-    };
-    deps = {
-      "better-assert-1.0.2" = self.by-version."better-assert"."1.0.2";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."parseqs"."0.0.2" =
-    self.by-version."parseqs"."0.0.2";
-  by-version."parseqs"."0.0.2" = self.buildNodePackage {
-    name = "parseqs-0.0.2";
-    version = "0.0.2";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/parseqs/-/parseqs-0.0.2.tgz";
-      name = "parseqs-0.0.2.tgz";
-      sha1 = "9dfe70b2cddac388bde4f35b1f240fa58adbe6c7";
-    };
-    deps = {
-      "better-assert-1.0.2" = self.by-version."better-assert"."1.0.2";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."parseuri"."0.0.4" =
-    self.by-version."parseuri"."0.0.4";
-  by-version."parseuri"."0.0.4" = self.buildNodePackage {
-    name = "parseuri-0.0.4";
-    version = "0.0.4";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/parseuri/-/parseuri-0.0.4.tgz";
-      name = "parseuri-0.0.4.tgz";
-      sha1 = "806582a39887e1ea18dd5e2fe0e01902268e9350";
-    };
-    deps = {
-      "better-assert-1.0.2" = self.by-version."better-assert"."1.0.2";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."socket.io"."*" =
-    self.by-version."socket.io"."1.4.5";
-  by-version."socket.io"."1.4.5" = self.buildNodePackage {
-    name = "socket.io-1.4.5";
-    version = "1.4.5";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/socket.io/-/socket.io-1.4.5.tgz";
-      name = "socket.io-1.4.5.tgz";
-      sha1 = "f202f49eeb9cf7cf6c0971ad75d8d96d451ea4f7";
-    };
-    deps = {
-      "engine.io-1.6.8" = self.by-version."engine.io"."1.6.8";
-      "socket.io-parser-2.2.6" = self.by-version."socket.io-parser"."2.2.6";
-      "socket.io-client-1.4.5" = self.by-version."socket.io-client"."1.4.5";
-      "socket.io-adapter-0.4.0" = self.by-version."socket.io-adapter"."0.4.0";
-      "has-binary-0.1.7" = self.by-version."has-binary"."0.1.7";
-      "debug-2.2.0" = self.by-version."debug"."2.2.0";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  "socket.io" = self.by-version."socket.io"."1.4.5";
-  by-spec."socket.io-adapter"."0.4.0" =
-    self.by-version."socket.io-adapter"."0.4.0";
-  by-version."socket.io-adapter"."0.4.0" = self.buildNodePackage {
-    name = "socket.io-adapter-0.4.0";
-    version = "0.4.0";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-0.4.0.tgz";
-      name = "socket.io-adapter-0.4.0.tgz";
-      sha1 = "fb9f82ab1aa65290bf72c3657955b930a991a24f";
-    };
-    deps = {
-      "debug-2.2.0" = self.by-version."debug"."2.2.0";
-      "socket.io-parser-2.2.2" = self.by-version."socket.io-parser"."2.2.2";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."socket.io-client"."1.4.5" =
-    self.by-version."socket.io-client"."1.4.5";
-  by-version."socket.io-client"."1.4.5" = self.buildNodePackage {
-    name = "socket.io-client-1.4.5";
-    version = "1.4.5";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/socket.io-client/-/socket.io-client-1.4.5.tgz";
-      name = "socket.io-client-1.4.5.tgz";
-      sha1 = "400d630c31e7c9579e45173f977e4f5bd8dc7d2e";
-    };
-    deps = {
-      "debug-2.2.0" = self.by-version."debug"."2.2.0";
-      "engine.io-client-1.6.8" = self.by-version."engine.io-client"."1.6.8";
-      "component-bind-1.0.0" = self.by-version."component-bind"."1.0.0";
-      "component-emitter-1.2.0" = self.by-version."component-emitter"."1.2.0";
-      "object-component-0.0.3" = self.by-version."object-component"."0.0.3";
-      "socket.io-parser-2.2.6" = self.by-version."socket.io-parser"."2.2.6";
-      "has-binary-0.1.7" = self.by-version."has-binary"."0.1.7";
-      "indexof-0.0.1" = self.by-version."indexof"."0.0.1";
-      "parseuri-0.0.4" = self.by-version."parseuri"."0.0.4";
-      "to-array-0.1.4" = self.by-version."to-array"."0.1.4";
-      "backo2-1.0.2" = self.by-version."backo2"."1.0.2";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."socket.io-parser"."2.2.2" =
-    self.by-version."socket.io-parser"."2.2.2";
-  by-version."socket.io-parser"."2.2.2" = self.buildNodePackage {
-    name = "socket.io-parser-2.2.2";
-    version = "2.2.2";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/socket.io-parser/-/socket.io-parser-2.2.2.tgz";
-      name = "socket.io-parser-2.2.2.tgz";
-      sha1 = "3d7af6b64497e956b7d9fe775f999716027f9417";
-    };
-    deps = {
-      "debug-0.7.4" = self.by-version."debug"."0.7.4";
-      "json3-3.2.6" = self.by-version."json3"."3.2.6";
-      "component-emitter-1.1.2" = self.by-version."component-emitter"."1.1.2";
-      "isarray-0.0.1" = self.by-version."isarray"."0.0.1";
-      "benchmark-1.0.0" = self.by-version."benchmark"."1.0.0";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."socket.io-parser"."2.2.6" =
-    self.by-version."socket.io-parser"."2.2.6";
-  by-version."socket.io-parser"."2.2.6" = self.buildNodePackage {
-    name = "socket.io-parser-2.2.6";
-    version = "2.2.6";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/socket.io-parser/-/socket.io-parser-2.2.6.tgz";
-      name = "socket.io-parser-2.2.6.tgz";
-      sha1 = "38dfd61df50dcf8ab1d9e2091322bf902ba28b99";
-    };
-    deps = {
-      "debug-2.2.0" = self.by-version."debug"."2.2.0";
-      "json3-3.3.2" = self.by-version."json3"."3.3.2";
-      "component-emitter-1.1.2" = self.by-version."component-emitter"."1.1.2";
-      "isarray-0.0.1" = self.by-version."isarray"."0.0.1";
-      "benchmark-1.0.0" = self.by-version."benchmark"."1.0.0";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."to-array"."0.1.4" =
-    self.by-version."to-array"."0.1.4";
-  by-version."to-array"."0.1.4" = self.buildNodePackage {
-    name = "to-array-0.1.4";
-    version = "0.1.4";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz";
-      name = "to-array-0.1.4.tgz";
-      sha1 = "17e6c11f73dd4f3d74cda7a4ff3238e9ad9bf890";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."ultron"."1.0.x" =
-    self.by-version."ultron"."1.0.2";
-  by-version."ultron"."1.0.2" = self.buildNodePackage {
-    name = "ultron-1.0.2";
-    version = "1.0.2";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/ultron/-/ultron-1.0.2.tgz";
-      name = "ultron-1.0.2.tgz";
-      sha1 = "ace116ab557cd197386a4e88f4685378c8b2e4fa";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."utf8"."2.1.0" =
-    self.by-version."utf8"."2.1.0";
-  by-version."utf8"."2.1.0" = self.buildNodePackage {
-    name = "utf8-2.1.0";
-    version = "2.1.0";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/utf8/-/utf8-2.1.0.tgz";
-      name = "utf8-2.1.0.tgz";
-      sha1 = "0cfec5c8052d44a23e3aaa908104e8075f95dfd5";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."ws"."1.0.1" =
-    self.by-version."ws"."1.0.1";
-  by-version."ws"."1.0.1" = self.buildNodePackage {
-    name = "ws-1.0.1";
-    version = "1.0.1";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/ws/-/ws-1.0.1.tgz";
-      name = "ws-1.0.1.tgz";
-      sha1 = "7d0b2a2e58cddd819039c29c9de65045e1b310e9";
-    };
-    deps = {
-      "options-0.0.6" = self.by-version."options"."0.0.6";
-      "ultron-1.0.2" = self.by-version."ultron"."1.0.2";
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."xmlhttprequest-ssl"."1.5.1" =
-    self.by-version."xmlhttprequest-ssl"."1.5.1";
-  by-version."xmlhttprequest-ssl"."1.5.1" = self.buildNodePackage {
-    name = "xmlhttprequest-ssl-1.5.1";
-    version = "1.5.1";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.1.tgz";
-      name = "xmlhttprequest-ssl-1.5.1.tgz";
-      sha1 = "3b7741fea4a86675976e908d296d4445961faa67";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-  by-spec."yeast"."0.1.2" =
-    self.by-version."yeast"."0.1.2";
-  by-version."yeast"."0.1.2" = self.buildNodePackage {
-    name = "yeast-0.1.2";
-    version = "0.1.2";
-    bin = false;
-    src = fetchurl {
-      url = "http://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz";
-      name = "yeast-0.1.2.tgz";
-      sha1 = "008e06d8094320c372dbc2f8ed76a0ca6c8ac419";
-    };
-    deps = {
-    };
-    optionalDependencies = {
-    };
-    peerDependencies = [];
-    os = [ ];
-    cpu = [ ];
-  };
-}
diff --git a/pkgs/development/compilers/ghcjs/node-packages.json b/pkgs/development/compilers/ghcjs/node-packages.json
deleted file mode 100644
index 55fa86675e7a..000000000000
--- a/pkgs/development/compilers/ghcjs/node-packages.json
+++ /dev/null
@@ -1 +0,0 @@
-[ "socket.io" ]
diff --git a/pkgs/development/compilers/ghcjs/stage2.nix b/pkgs/development/compilers/ghcjs/stage2.nix
index 4c4d9f4ff389..3483afc99ef0 100644
--- a/pkgs/development/compilers/ghcjs/stage2.nix
+++ b/pkgs/development/compilers/ghcjs/stage2.nix
@@ -133,7 +133,7 @@
           test-framework-hunit test-framework-quickcheck2 text unix
         ];
         jailbreak = true;
-        homepage = http://github.com/tibbe/hashable;
+        homepage = https://github.com/tibbe/hashable;
         description = "A class for types that can be converted to a hash value";
         license = stdenv.lib.licenses.bsd3;
       }) {};
@@ -146,7 +146,7 @@
         doCheck = false;
         libraryHaskellDepends = [ base transformers ];
         jailbreak = true;
-        homepage = http://github.com/ekmett/mtl;
+        homepage = https://github.com/ekmett/mtl;
         description = "Monad classes, using functional dependencies";
         license = stdenv.lib.licenses.bsd3;
       }) {};
@@ -311,7 +311,7 @@
           test-framework-hunit test-framework-quickcheck2 text
         ];
         jailbreak = true;
-        homepage = http://github.com/ghcjs/ghcjs-base;
+        homepage = https://github.com/ghcjs/ghcjs-base;
         description = "Base library for GHCJS";
         license = stdenv.lib.licenses.mit;
       }) {};
diff --git a/pkgs/development/compilers/ghdl/default.nix b/pkgs/development/compilers/ghdl/default.nix
index 7d3b6860c6ed..eaf9949b52da 100644
--- a/pkgs/development/compilers/ghdl/default.nix
+++ b/pkgs/development/compilers/ghdl/default.nix
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = true;
 
   meta = {
-    homepage = http://sourceforge.net/p/ghdl-updates/wiki/Home/;
+    homepage = https://sourceforge.net/p/ghdl-updates/wiki/Home/;
     description = "Free VHDL simulator";
     maintainers = with stdenv.lib.maintainers; [viric];
     platforms = with stdenv.lib.platforms; (if flavour == "llvm" then [ "i686-linux" "x86_64-linux" ]
diff --git a/pkgs/development/compilers/gnu-smalltalk/default.nix b/pkgs/development/compilers/gnu-smalltalk/default.nix
index b75b57d0f476..21c0a5ede91b 100644
--- a/pkgs/development/compilers/gnu-smalltalk/default.nix
+++ b/pkgs/development/compilers/gnu-smalltalk/default.nix
@@ -25,8 +25,9 @@ in stdenv.mkDerivation rec {
 
   # The dependencies and their justification are explained at
   # http://smalltalk.gnu.org/download
+  nativeBuildInputs = [ pkgconfig ];
   buildInputs = [
-    pkgconfig libtool zip libffi libsigsegv-shared readline gmp gnutls gnome2.gtk
+    libtool zip libffi libsigsegv-shared readline gmp gnutls gnome2.gtk
     cairo SDL sqlite
   ]
   ++ stdenv.lib.optional emacsSupport emacs;
diff --git a/pkgs/development/compilers/go/1.8.nix b/pkgs/development/compilers/go/1.8.nix
index 8a675b1b7761..538c20bac72a 100644
--- a/pkgs/development/compilers/go/1.8.nix
+++ b/pkgs/development/compilers/go/1.8.nix
@@ -25,13 +25,13 @@ in
 
 stdenv.mkDerivation rec {
   name = "go-${version}";
-  version = "1.8.3";
+  version = "1.8.5";
 
   src = fetchFromGitHub {
     owner = "golang";
     repo = "go";
     rev = "go${version}";
-    sha256 = "0g83xm9gb872rsqzwqr1zw5szq69xhynljj2nglg4yyfi7dm2r1c";
+    sha256 = "1ab021l3v29ciaxp738cjpbkh1chlsl6928672q3i82anmdzn5m5";
   };
 
   # perl is used for testing go vet
diff --git a/pkgs/development/compilers/go/1.9.nix b/pkgs/development/compilers/go/1.9.nix
new file mode 100644
index 000000000000..50fa2d976273
--- /dev/null
+++ b/pkgs/development/compilers/go/1.9.nix
@@ -0,0 +1,187 @@
+{ stdenv, fetchFromGitHub, tzdata, iana-etc, go_bootstrap, runCommand, writeScriptBin
+, perl, which, pkgconfig, patch, fetchpatch
+, pcre, cacert, llvm
+, Security, Foundation, bash
+, makeWrapper, git, subversion, mercurial, bazaar }:
+
+let
+
+  inherit (stdenv.lib) optional optionals optionalString;
+
+  clangHack = writeScriptBin "clang" ''
+    #!${stdenv.shell}
+    exec ${stdenv.cc}/bin/clang "$@" 2> >(sed '/ld: warning:.*ignoring unexpected dylib file/ d' 1>&2)
+  '';
+
+  goBootstrap = runCommand "go-bootstrap" {} ''
+    mkdir $out
+    cp -rf ${go_bootstrap}/* $out/
+    chmod -R u+w $out
+    find $out -name "*.c" -delete
+    cp -rf $out/bin/* $out/share/go/bin/
+  '';
+
+in
+
+stdenv.mkDerivation rec {
+  name = "go-${version}";
+  version = "1.9.2";
+
+  src = fetchFromGitHub {
+    owner = "golang";
+    repo = "go";
+    rev = "go${version}";
+    sha256 = "07p4ld07r2nml2bsbfb8h51hqilbqyhhdlia99y1gk7ibvhybv8i";
+  };
+
+  # perl is used for testing go vet
+  nativeBuildInputs = [ perl which pkgconfig patch makeWrapper ];
+  buildInputs = [ pcre ]
+    ++ optionals stdenv.isLinux [ stdenv.glibc.out stdenv.glibc.static ];
+  propagatedBuildInputs = optionals stdenv.isDarwin [ Security Foundation ];
+
+  hardeningDisable = [ "all" ];
+
+  prePatch = ''
+    patchShebangs ./ # replace /bin/bash
+
+    # This source produces shell script at run time,
+    # and thus it is not corrected by patchShebangs.
+    substituteInPlace misc/cgo/testcarchive/carchive_test.go \
+      --replace '#!/usr/bin/env bash' '#!${stdenv.shell}'
+
+    # Disabling the 'os/http/net' tests (they want files not available in
+    # chroot builds)
+    rm src/net/{listen,parse}_test.go
+    rm src/syscall/exec_linux_test.go
+
+    # !!! substituteInPlace does not seems to be effective.
+    # The os test wants to read files in an existing path. Just don't let it be /usr/bin.
+    sed -i 's,/usr/bin,'"`pwd`", src/os/os_test.go
+    sed -i 's,/bin/pwd,'"`type -P pwd`", src/os/os_test.go
+    # Disable the unix socket test
+    sed -i '/TestShutdownUnix/areturn' src/net/net_test.go
+    # Disable the hostname test
+    sed -i '/TestHostname/areturn' src/os/os_test.go
+    # ParseInLocation fails the test
+    sed -i '/TestParseInSydney/areturn' src/time/format_test.go
+    # Remove the api check as it never worked
+    sed -i '/src\/cmd\/api\/run.go/ireturn nil' src/cmd/dist/test.go
+    # Remove the coverage test as we have removed this utility
+    sed -i '/TestCoverageWithCgo/areturn' src/cmd/go/go_test.go
+    # Remove the timezone naming test
+    sed -i '/TestLoadFixed/areturn' src/time/time_test.go
+    # Remove disable setgid test
+    sed -i '/TestRespectSetgidDir/areturn' src/cmd/go/internal/work/build_test.go
+    # Remove cert tests that conflict with NixOS's cert resolution
+    sed -i '/TestEnvVars/areturn' src/crypto/x509/root_unix_test.go
+
+    sed -i 's,/etc/protocols,${iana-etc}/etc/protocols,' src/net/lookup_unix.go
+    sed -i 's,/etc/services,${iana-etc}/etc/services,' src/net/port_unix.go
+
+    # Disable cgo lookup tests not works, they depend on resolver
+    rm src/net/cgo_unix_test.go
+
+  '' + optionalString stdenv.isLinux ''
+    sed -i 's,/usr/share/zoneinfo/,${tzdata}/share/zoneinfo/,' src/time/zoneinfo_unix.go
+  '' + optionalString stdenv.isArm ''
+    sed -i '/TestCurrent/areturn' src/os/user/user_test.go
+    echo '#!/usr/bin/env bash' > misc/cgo/testplugin/test.bash
+  '' + optionalString stdenv.isDarwin ''
+    substituteInPlace src/race.bash --replace \
+      "sysctl machdep.cpu.extfeatures | grep -qv EM64T" true
+    sed -i 's,strings.Contains(.*sysctl.*,true {,' src/cmd/dist/util.go
+    sed -i 's,"/etc","'"$TMPDIR"'",' src/os/os_test.go
+    sed -i 's,/_go_os_test,'"$TMPDIR"'/_go_os_test,' src/os/path_test.go
+
+    sed -i '/TestChdirAndGetwd/areturn' src/os/os_test.go
+    sed -i '/TestCredentialNoSetGroups/areturn' src/os/exec/exec_posix_test.go
+    sed -i '/TestCurrent/areturn' src/os/user/user_test.go
+    sed -i '/TestNohup/areturn' src/os/signal/signal_test.go
+    sed -i '/TestRead0/areturn' src/os/os_test.go
+    sed -i '/TestSystemRoots/areturn' src/crypto/x509/root_darwin_test.go
+
+    sed -i '/TestGoInstallRebuildsStalePackagesInOtherGOPATH/areturn' src/cmd/go/go_test.go
+    sed -i '/TestBuildDashIInstallsDependencies/areturn' src/cmd/go/go_test.go
+
+    sed -i '/TestDisasmExtld/areturn' src/cmd/objdump/objdump_test.go
+
+    sed -i 's/unrecognized/unknown/' src/cmd/link/internal/ld/lib.go
+
+    touch $TMPDIR/group $TMPDIR/hosts $TMPDIR/passwd
+
+    sed -i '1 a\exit 0' misc/cgo/errors/test.bash
+  '';
+
+  patches =
+    [ ./remove-tools-1.9.patch
+      ./ssl-cert-file-1.9.patch
+      ./creds-test.patch
+      ./remove-test-pie-1.9.patch
+
+      (fetchpatch {
+        url = "https://github.com/golang/go/commit/29415eb2b92e78481897c4161ba99f5b09fa6102.patch";
+        sha256 = "01jkm4b2dazzjnfla7rdd0w2clzplga3zza6ybpmkjkk3i4bp73d";
+      })
+    ];
+
+  postPatch = optionalString stdenv.isDarwin ''
+    echo "substitute hardcoded dsymutil with ${llvm}/bin/llvm-dsymutil"
+    substituteInPlace "src/cmd/link/internal/ld/lib.go" --replace dsymutil ${llvm}/bin/llvm-dsymutil
+  '';
+
+  NIX_SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
+
+  GOOS = if stdenv.isDarwin then "darwin" else "linux";
+  GOARCH = if stdenv.isDarwin then "amd64"
+           else if stdenv.system == "i686-linux" then "386"
+           else if stdenv.system == "x86_64-linux" then "amd64"
+           else if stdenv.isArm then "arm"
+           else if stdenv.isAarch64 then "arm64"
+           else throw "Unsupported system";
+  GOARM = optionalString (stdenv.system == "armv5tel-linux") "5";
+  GO386 = 387; # from Arch: don't assume sse2 on i686
+  CGO_ENABLED = 1;
+  GOROOT_BOOTSTRAP = "${goBootstrap}/share/go";
+
+  # The go build actually checks for CC=*/clang and does something different, so we don't
+  # just want the generic `cc` here.
+  CC = if stdenv.isDarwin then "clang" else "cc";
+
+  configurePhase = ''
+    mkdir -p $out/share/go/bin
+    export GOROOT=$out/share/go
+    export GOBIN=$GOROOT/bin
+    export PATH=$GOBIN:$PATH
+  '';
+
+  postConfigure = optionalString stdenv.isDarwin ''
+    export PATH=${clangHack}/bin:$PATH
+  '';
+
+  installPhase = ''
+    cp -r . $GOROOT
+    ( cd $GOROOT/src && ./all.bash )
+
+    # (https://github.com/golang/go/wiki/GoGetTools)
+    wrapProgram $out/share/go/bin/go --prefix PATH ":" "${stdenv.lib.makeBinPath [ git subversion mercurial bazaar ]}"
+  '';
+
+  preFixup = ''
+    rm -r $out/share/go/pkg/bootstrap
+    ln -s $out/share/go/bin $out/bin
+  '';
+
+  setupHook = ./setup-hook.sh;
+
+  disallowedReferences = [ go_bootstrap ];
+
+  meta = with stdenv.lib; {
+    branch = "1.9";
+    homepage = http://golang.org/;
+    description = "The Go Programming language";
+    license = licenses.bsd3;
+    maintainers = with maintainers; [ cstrahan orivej wkennington ];
+    platforms = platforms.linux ++ platforms.darwin;
+  };
+}
diff --git a/pkgs/development/compilers/go/remove-test-pie-1.9.patch b/pkgs/development/compilers/go/remove-test-pie-1.9.patch
new file mode 100644
index 000000000000..46f94f29df20
--- /dev/null
+++ b/pkgs/development/compilers/go/remove-test-pie-1.9.patch
@@ -0,0 +1,26 @@
+diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go
+index 73432d31ea..3310f5298d 100644
+--- a/src/cmd/dist/test.go
++++ b/src/cmd/dist/test.go
+@@ -510,21 +510,6 @@ func (t *tester) registerTests() {
+ 		})
+ 	}
+ 
+-	// Test internal linking of PIE binaries where it is supported.
+-	if t.goos == "linux" && t.goarch == "amd64" && !isAlpineLinux() {
+-		// Issue 18243: We don't have a way to set the default
+-		// dynamic linker used in internal linking mode. So
+-		// this test is skipped on Alpine.
+-		t.tests = append(t.tests, distTest{
+-			name:    "pie_internal",
+-			heading: "internal linking of -buildmode=pie",
+-			fn: func(dt *distTest) error {
+-				t.addCmd(dt, "src", "go", "test", "reflect", "-short", "-buildmode=pie", "-ldflags=-linkmode=internal", t.timeout(60), t.tags(), t.runFlag(""))
+-				return nil
+-			},
+-		})
+-	}
+-
+ 	// sync tests
+ 	t.tests = append(t.tests, distTest{
+ 		name:    "sync_cpu",
diff --git a/pkgs/development/compilers/go/remove-tools-1.9.patch b/pkgs/development/compilers/go/remove-tools-1.9.patch
new file mode 100644
index 000000000000..e76ed61693a8
--- /dev/null
+++ b/pkgs/development/compilers/go/remove-tools-1.9.patch
@@ -0,0 +1,35 @@
+diff --git a/src/go/build/build.go b/src/go/build/build.go
+index d8163d0172..dd80a70473 100644
+--- a/src/go/build/build.go
++++ b/src/go/build/build.go
+@@ -1592,7 +1592,7 @@ func init() {
+ }
+ 
+ // ToolDir is the directory containing build tools.
+-var ToolDir = filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
++var ToolDir = runtime.GOTOOLDIR()
+ 
+ // IsLocalImport reports whether the import path is
+ // a local import path, like ".", "..", "./foo", or "../foo".
+diff --git a/src/runtime/extern.go b/src/runtime/extern.go
+index 6e6c674d96..e9f62f96dc 100644
+--- a/src/runtime/extern.go
++++ b/src/runtime/extern.go
+@@ -223,6 +223,17 @@ func GOROOT() string {
+ 	return sys.DefaultGoroot
+ }
+ 
++// GOTOOLDIR returns the root of the Go tree.
++// It uses the GOTOOLDIR environment variable, if set,
++// or else the root used during the Go build.
++func GOTOOLDIR() string {
++	s := gogetenv("GOTOOLDIR")
++	if s != "" {
++		return s
++	}
++	return GOROOT() + "/pkg/tool/" + GOOS + "_" + GOARCH
++}
++
+ // Version returns the Go tree's version string.
+ // It is either the commit hash and date at the time of the build or,
+ // when possible, a release tag like "go1.3".
diff --git a/pkgs/development/compilers/go/ssl-cert-file-1.9.patch b/pkgs/development/compilers/go/ssl-cert-file-1.9.patch
new file mode 100644
index 000000000000..3f27bc138c10
--- /dev/null
+++ b/pkgs/development/compilers/go/ssl-cert-file-1.9.patch
@@ -0,0 +1,80 @@
+diff --git a/src/crypto/x509/root_cgo_darwin.go b/src/crypto/x509/root_cgo_darwin.go
+index 8e80533590..31c0c666ec 100644
+--- a/src/crypto/x509/root_cgo_darwin.go
++++ b/src/crypto/x509/root_cgo_darwin.go
+@@ -201,11 +201,20 @@ int FetchPEMRoots(CFDataRef *pemRoots, CFDataRef *untrustedPemRoots) {
+ import "C"
+ import (
+ 	"errors"
++	"io/ioutil"
++	"os"
+ 	"unsafe"
+ )
+ 
+ func loadSystemRoots() (*CertPool, error) {
+ 	roots := NewCertPool()
++	if file := os.Getenv("NIX_SSL_CERT_FILE"); file != "" {
++		data, err := ioutil.ReadFile(file)
++		if err == nil {
++			roots.AppendCertsFromPEM(data)
++			return roots, nil
++		}
++	}
+ 
+ 	var data C.CFDataRef = nil
+ 	var untrustedData C.CFDataRef = nil
+diff --git a/src/crypto/x509/root_darwin.go b/src/crypto/x509/root_darwin.go
+index bc35a1cf21..21e52bec51 100644
+--- a/src/crypto/x509/root_darwin.go
++++ b/src/crypto/x509/root_darwin.go
+@@ -81,18 +81,26 @@ func execSecurityRoots() (*CertPool, error) {
+ 		)
+ 	}
+ 
+-	cmd := exec.Command("/usr/bin/security", args...)
+-	data, err := cmd.Output()
+-	if err != nil {
+-		return nil, err
+-	}
+-
+ 	var (
+ 		mu          sync.Mutex
+ 		roots       = NewCertPool()
+ 		numVerified int // number of execs of 'security verify-cert', for debug stats
+ 	)
+ 
++	if file := os.Getenv("NIX_SSL_CERT_FILE"); file != "" {
++		data, err := ioutil.ReadFile(file)
++		if err == nil {
++			roots.AppendCertsFromPEM(data)
++			return roots, nil
++		}
++	}
++
++	cmd := exec.Command("/usr/bin/security", args...)
++	data, err := cmd.Output()
++	if err != nil {
++		return nil, err
++	}
++
+ 	blockCh := make(chan *pem.Block)
+ 	var wg sync.WaitGroup
+ 
+diff --git a/src/crypto/x509/root_unix.go b/src/crypto/x509/root_unix.go
+index 65b5a5fdbc..c9c7ac6a74 100644
+--- a/src/crypto/x509/root_unix.go
++++ b/src/crypto/x509/root_unix.go
+@@ -37,6 +37,13 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
+ 
+ func loadSystemRoots() (*CertPool, error) {
+ 	roots := NewCertPool()
++	if file := os.Getenv("NIX_SSL_CERT_FILE"); file != "" {
++		data, err := ioutil.ReadFile(file)
++		if err == nil {
++			roots.AppendCertsFromPEM(data)
++			return roots, nil
++		}
++	}
+ 
+ 	files := certFiles
+ 	if f := os.Getenv(certFileEnv); f != "" {
diff --git a/pkgs/development/compilers/gwt/2.4.0.nix b/pkgs/development/compilers/gwt/2.4.0.nix
index 4705c327b425..f15e1060203b 100644
--- a/pkgs/development/compilers/gwt/2.4.0.nix
+++ b/pkgs/development/compilers/gwt/2.4.0.nix
@@ -4,8 +4,8 @@ stdenv.mkDerivation {
   name = "gwt-java-2.4.0";
 
   src = fetchurl {
-    url=http://google-web-toolkit.googlecode.com/files/gwt-2.4.0.zip;
-    sha1 = "a91ac20db0ddd5994ac3cbfb0e8061d5bbf66f88";
+    url = "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/google-web-toolkit/gwt-2.4.0.zip";
+    sha256 = "1gvyg00vx7fdqgfl2w7nhql78clg3abs6fxxy7m03pprdm5qmm17";
   };
 
   buildInputs = [ unzip ];
@@ -17,8 +17,9 @@ stdenv.mkDerivation {
   '';
 
   meta = {
-    homepage = http://code.google.com/webtoolkit/;
+    homepage = http://www.gwtproject.org/;
     description = "A development toolkit for building and optimizing complex browser-based applications";
+    license = stdenv.lib.licenses.asl20;
     platforms = stdenv.lib.platforms.unix;
   };
 }
diff --git a/pkgs/development/compilers/halvm/2.4.0.nix b/pkgs/development/compilers/halvm/2.4.0.nix
index b88ac73c7e40..0c4cef653d86 100644
--- a/pkgs/development/compilers/halvm/2.4.0.nix
+++ b/pkgs/development/compilers/halvm/2.4.0.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchgit, bootPkgs, perl, gmp, ncurses, binutils, autoconf, alex, happy, makeStaticLibraries
+{ stdenv, fetchgit, bootPkgs, perl, gmp, ncurses, targetPackages, autoconf, alex, happy, makeStaticLibraries
 , hscolour, xen, automake, gcc, git, zlib, libtool, enableIntegerSimple ? false
 }:
 
@@ -17,14 +17,14 @@ stdenv.mkDerivation rec {
     sed -i '305 d' Makefile
     sed -i '309,439 d' Makefile # Removes RPM packaging
     sed -i '20 d' src/scripts/halvm-cabal.in
-    sed -ie 's|ld |${binutils}/bin/ld |g' src/scripts/ldkernel.in
+    sed -ie 's|ld |${targetPackages.stdenv.cc.bintools}/bin/ld |g' src/scripts/ldkernel.in
   '';
   configureFlags = stdenv.lib.optional (!enableIntegerSimple) [ "--enable-gmp" ];
   propagatedNativeBuildInputs = [ alex happy ];
   buildInputs =
    let haskellPkgs = [ alex happy bootPkgs.hscolour bootPkgs.cabal-install bootPkgs.haddock bootPkgs.hpc
     ]; in [ bootPkgs.ghc
-            automake perl git binutils
+            automake perl git targetPackages.stdenv.cc.bintools
             autoconf xen zlib ncurses.dev
             libtool gmp ] ++ haskellPkgs;
   preConfigure = ''
@@ -40,7 +40,7 @@ stdenv.mkDerivation rec {
     inherit bootPkgs;
     cross.config = "halvm";
     cc = "${gcc}/bin/gcc";
-    ld = "${binutils}/bin/ld";
+    ld = "${targetPackages.stdenv.cc.bintools}/bin/ld";
   };
 
   meta = {
@@ -49,5 +49,6 @@ stdenv.mkDerivation rec {
     platforms = ["x86_64-linux"];       # other platforms don't have Xen
     maintainers = with stdenv.lib.maintainers; [ dmjio ];
     inherit (bootPkgs.ghc.meta) license;
+    broken = true;  # https://nix-cache.s3.amazonaws.com/log/6i98mhbq9nzzhwr4svlivm4gz91l2w0f-HaLVM-2.4.0.drv
   };
 }
diff --git a/pkgs/development/compilers/haxe/default.nix b/pkgs/development/compilers/haxe/default.nix
index ca41545eb451..c6b4913c6236 100644
--- a/pkgs/development/compilers/haxe/default.nix
+++ b/pkgs/development/compilers/haxe/default.nix
@@ -72,8 +72,8 @@ in {
     '';
   };
   haxe_3_4 = generic {
-    version = "3.4.2";
-    sha256 = "1m5fp183agqv8h3ynhxw4kndkpq2d6arysmirv3zl3vz5crmpwqd";
+    version = "3.4.4";
+    sha256 = "057psarsmz8q2y9pqv5221vpdya241gcy8xnl2wg9wyscn6z1lx6";
     prePatch = ''
       sed -i -e 's|"/usr/lib/haxe/std/";|"'"$out/lib/haxe/std/"'";\n&|g' src/main.ml
       sed -i -e 's|"neko"|"${neko}/bin/neko"|g' extra/haxelib_src/src/haxelib/client/Main.hx
diff --git a/pkgs/development/compilers/hhvm/default.nix b/pkgs/development/compilers/hhvm/default.nix
index f0f3a130ef68..3a37ec137580 100644
--- a/pkgs/development/compilers/hhvm/default.nix
+++ b/pkgs/development/compilers/hhvm/default.nix
@@ -1,20 +1,20 @@
-{ stdenv, fetchgit, cmake, pkgconfig, boost, libunwind, libmemcached, pcre
-, libevent, gd, curl, libxml2, icu, flex, bison, openssl, zlib, php
+{ stdenv, fetchgit, fetchurl, cmake, pkgconfig, boost, libunwind, libmemcached
+, pcre, libevent, gd, curl, libxml2, icu, flex, bison, openssl, zlib, php
 , expat, libcap, oniguruma, libdwarf, libmcrypt, tbb, gperftools, glog, libkrb5
 , bzip2, openldap, readline, libelf, uwimap, binutils, cyrus_sasl, pam, libpng
-, libxslt, ocaml, freetype, gdb, git, perl, mariadb, gmp, libyaml, libedit
-, libvpx, imagemagick, fribidi, gperf
+, libxslt, freetype, gdb, git, perl, mariadb, gmp, libyaml, libedit
+, libvpx, imagemagick, fribidi, gperf, which, ocamlPackages
 }:
 
 stdenv.mkDerivation rec {
   name    = "hhvm-${version}";
-  version = "3.15.0";
+  version = "3.21";
 
   # use git version since we need submodules
   src = fetchgit {
     url    = "https://github.com/facebook/hhvm.git";
-    rev    = "92a682ebaa3c85b84857852d8621f528607fe27d";
-    sha256 = "0mn3bfvhdf6b4lflyjfjyr7nppkq505xkaaagk111fqy91rdzd3b";
+    rev    = "56483773e2edd9e61782f1901ce40e47959e71b8";
+    sha256 = "0dmdk98nv04m0fv6909gfbsxqlkckn369yi7kadhir0r7vxsj7wa";
     fetchSubmodules = true;
   };
 
@@ -22,10 +22,19 @@ stdenv.mkDerivation rec {
     [ cmake pkgconfig boost libunwind mariadb.client libmemcached pcre gdb git perl
       libevent gd curl libxml2 icu flex bison openssl zlib php expat libcap
       oniguruma libdwarf libmcrypt tbb gperftools bzip2 openldap readline
-      libelf uwimap binutils cyrus_sasl pam glog libpng libxslt ocaml libkrb5
-      gmp libyaml libedit libvpx imagemagick fribidi gperf
+      libelf uwimap binutils cyrus_sasl pam glog libpng libxslt libkrb5
+      gmp libyaml libedit libvpx imagemagick fribidi gperf which
+      ocamlPackages.ocaml ocamlPackages.ocamlbuild
     ];
 
+  patches = [
+    ./flexible-array-members-gcc6.patch
+    (fetchurl {
+      url = https://github.com/facebook/hhvm/commit/b506902af2b7c53de6d6c92491c2086472292004.patch;
+      sha256 = "1br7diczqks6b1xjrdsac599fc62m9l17gcx7dvkc0qj54lq7ys4";
+    })
+  ];
+
   enableParallelBuilding = false; # occasional build problems;
   dontUseCmakeBuildDir = true;
   NIX_LDFLAGS = "-lpam -L${pam}/lib";
@@ -39,10 +48,10 @@ stdenv.mkDerivation rec {
   cmakeFlags = "-DCMAKE_INSTALL_INCLUDEDIR=include";
 
   prePatch = ''
-    substituteInPlace hphp/util/generate-buildinfo.sh \
-      --replace /bin/bash ${stdenv.shell}
     substituteInPlace ./configure \
       --replace "/usr/bin/env bash" ${stdenv.shell}
+    substituteInPlace ./third-party/ocaml/CMakeLists.txt \
+      --replace "/bin/bash" ${stdenv.shell}
     perl -pi -e 's/([ \t(])(isnan|isinf)\(/$1std::$2(/g' \
       hphp/runtime/base/*.cpp \
       hphp/runtime/ext/std/*.cpp \
diff --git a/pkgs/development/compilers/hhvm/flexible-array-members-gcc6.patch b/pkgs/development/compilers/hhvm/flexible-array-members-gcc6.patch
new file mode 100644
index 000000000000..61b6e5e8d8c3
--- /dev/null
+++ b/pkgs/development/compilers/hhvm/flexible-array-members-gcc6.patch
@@ -0,0 +1,20 @@
+diff --git a/third-party/re2/src/re2/dfa.cc b/third-party/re2/src/re2/dfa.cc
+index 483f678..3aa3610 100644
+--- a/third-party/re2/src/re2/dfa.cc
++++ b/third-party/re2/src/re2/dfa.cc
+@@ -101,8 +101,13 @@ class DFA {
+     uint flag_;         // Empty string bitfield flags in effect on the way
+                         // into this state, along with kFlagMatch if this
+                         // is a matching state.
+-    std::atomic<State*> next_[];    // Outgoing arrows from State,
+-                        // one per input byte class
++// Work around the bug affecting flexible array members in GCC 6.1 and 6.2.
++// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70932)
++#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ == 6 && __GNUC_MINOR__ >= 1
++    std::atomic<State*> next_[0];   // Outgoing arrows from State, one per input byte class
++#else
++    std::atomic<State*> next_[];    // Outgoing arrows from State, one per input byte class
++#endif
+   };
+
+   enum {
diff --git a/pkgs/development/compilers/ispc/default.nix b/pkgs/development/compilers/ispc/default.nix
index 6bc7f66ca299..0e4bc420241d 100644
--- a/pkgs/development/compilers/ispc/default.nix
+++ b/pkgs/development/compilers/ispc/default.nix
@@ -2,11 +2,9 @@
 testedTargets ? ["sse2" "host"] # the default test target is sse4, but that is not supported by all Hydra agents
 }:
 
-# TODO: patch LLVM so Skylake-EX works better (patch included in ispc github) - needed for LLVM 3.9?
-
 stdenv.mkDerivation rec {
-  version = "1.9.1";
-  rev = "v${version}";
+  version = "20170807";
+  rev = "6e0fc2f148e95afad998a7c7f4d7908d29fd8e44";
 
   inherit testedTargets;
 
@@ -16,7 +14,7 @@ stdenv.mkDerivation rec {
     owner = "ispc";
     repo = "ispc";
     inherit rev;
-    sha256 = "1wwsyvn44hd5iyi5779l5378x096307slpyl29wrsmfp66796693";
+    sha256 = "17fwnfm8a329lgfhjwcvji4h1fm4iqmc28wz23hvgqbpj8lk6qgh";
   };
 
   # there are missing dependencies in the Makefile, causing sporadic build failures
@@ -60,8 +58,8 @@ stdenv.mkDerivation rec {
   '';
 
   makeFlags = [
-    "CXX=${llvmPackages.clang}/bin/clang++"
-    "CLANG=${llvmPackages.clang}/bin/clang"
+    "CXX=${stdenv.cc}/bin/clang++"
+    "CLANG=${stdenv.cc}/bin/clang"
     "CLANG_INCLUDE=${llvmPackages.clang-unwrapped}/include"
     ];
 
diff --git a/pkgs/development/compilers/jetbrains-jdk/default.nix b/pkgs/development/compilers/jetbrains-jdk/default.nix
new file mode 100644
index 000000000000..aa3f49ca4d9f
--- /dev/null
+++ b/pkgs/development/compilers/jetbrains-jdk/default.nix
@@ -0,0 +1,80 @@
+{ stdenv, lib, fetchurl, file, glib, libxml2, libav_0_8, ffmpeg, libxslt
+, mesa_noglu , xorg, alsaLib, fontconfig, freetype, pango, gtk2, cairo
+, gdk_pixbuf, atk }:
+
+# TODO: Investigate building from source instead of patching binaries.
+# TODO: Binary patching for not just x86_64-linux but also x86_64-darwin i686-linux
+
+let drv = stdenv.mkDerivation rec {
+  pname = "jetbrainsjdk";
+  version = "152b1036.1";
+  name = pname + "-" + version;
+
+  src = if stdenv.system == "x86_64-linux" then
+    fetchurl {
+      url = "https://bintray.com/jetbrains/intellij-jdk/download_file?file_path=jbsdk8u${version}_linux_x64.tar.gz";
+      sha256 = "1768f02i3dxdbxn8n29d522h8v0mkgnhpb8ixzq5p54vwjmfl6md";
+    }
+  else
+    abort "unsupported system: ${stdenv.system}";
+
+  nativeBuildInputs = [ file ];
+
+  unpackCmd = "mkdir jdk; pushd jdk; tar -xzf $src; popd";
+
+  installPhase = ''
+    cd ..
+
+    exes=$(file $sourceRoot/bin/* $sourceRoot/jre/bin/* 2> /dev/null | grep -E 'ELF.*(executable|shared object)' | sed -e 's/: .*$//')
+    for file in $exes; do
+      paxmark m "$file"
+    done
+
+    mv $sourceRoot $out
+    jrePath=$out/jre
+  '';
+
+  postFixup = let
+    arch = "amd64";
+    rSubPaths = [
+      "lib/${arch}/jli"
+      "lib/${arch}/server"
+      "lib/${arch}/xawt"
+      "lib/${arch}"
+    ];
+    in ''
+    rpath+="''${rpath:+:}${stdenv.lib.concatStringsSep ":" (map (a: "$jrePath/${a}") rSubPaths)}"
+    find $out -type f -perm -0100 \
+        -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
+        --set-rpath "$rpath" {} \;
+    find $out -name "*.so" -exec patchelf --set-rpath "$rpath" {} \;
+  '';
+
+  rpath = lib.makeLibraryPath ([
+    stdenv.cc.cc stdenv.cc.libc glib libxml2 libav_0_8 ffmpeg libxslt mesa_noglu
+    alsaLib fontconfig freetype pango gtk2 cairo gdk_pixbuf atk
+  ] ++ (with xorg; [
+    libX11 libXext libXtst libXi libXp libXt libXrender libXxf86vm
+  ]));
+
+  passthru.home = drv;
+
+  meta = with stdenv.lib; {
+    description = "An OpenJDK fork to better support Jetbrains's products.";
+    longDescription = ''
+     JetBrains Runtime is a runtime environment for running IntelliJ Platform
+     based products on Windows, Mac OS X, and Linux. JetBrains Runtime is
+     based on OpenJDK project with some modifications. These modifications
+     include: Subpixel Anti-Aliasing, enhanced font rendering on Linux, HiDPI
+     support, ligatures, some fixes for native crashes not presented in
+     official build, and other small enhancements.
+
+     JetBrains Runtime is not a certified build of OpenJDK. Please, use at
+     your own risk.
+    '';
+    homepage = "https://bintray.com/jetbrains/intellij-jdk/";
+    licenses = licenses.gpl2;
+    maintainers = with maintainers; [ edwtjo ];
+    platforms = with platforms; [ "x86_64-linux" ];
+  };
+}; in drv
diff --git a/pkgs/development/compilers/jhc/default.nix b/pkgs/development/compilers/jhc/default.nix
index cfeff329fb56..6b8c6599062e 100644
--- a/pkgs/development/compilers/jhc/default.nix
+++ b/pkgs/development/compilers/jhc/default.nix
@@ -27,5 +27,6 @@ stdenv.mkDerivation rec {
     license = stdenv.lib.licenses.bsd3;
     platforms = ["x86_64-linux"]; # 32 bit builds are broken
     maintainers = with stdenv.lib.maintainers; [ aforemny thoughtpolice ];
+    broken = true; # https://hydra.nixos.org/build/61700723
   };
 }
diff --git a/pkgs/development/compilers/julia/0.6.nix b/pkgs/development/compilers/julia/0.6.nix
new file mode 100644
index 000000000000..99e6f8efff10
--- /dev/null
+++ b/pkgs/development/compilers/julia/0.6.nix
@@ -0,0 +1,191 @@
+{ stdenv, fetchgit, fetchurl, fetchzip
+# build tools
+, gfortran, m4, makeWrapper, patchelf, perl, which, python2
+, runCommand
+, paxctl
+# libjulia dependencies
+, libunwind, readline, utf8proc, zlib
+, llvm, libffi, ncurses
+# standard library dependencies
+, curl, fftwSinglePrec, fftw, gmp, libgit2, mpfr, openlibm, openspecfun, pcre2
+# linear algebra
+, openblas, arpack, suitesparse
+# Darwin frameworks
+, CoreServices, ApplicationServices
+}:
+
+with stdenv.lib;
+
+# All dependencies must use the same OpenBLAS.
+let
+  arpack_ = arpack;
+  suitesparse_ = suitesparse;
+in
+let
+  arpack = arpack_.override { inherit openblas; };
+  suitesparse = suitesparse_.override { inherit openblas; };
+in
+
+let
+  dsfmtVersion = "2.2.3";
+  dsfmt = fetchurl {
+    url = "http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/dSFMT-src-${dsfmtVersion}.tar.gz";
+    sha256 = "03kaqbjbi6viz0n33dk5jlf6ayxqlsq4804n7kwkndiga9s4hd42";
+  };
+
+  libuvVersion = "52d72a52cc7ccd570929990f010ed16e2ec604c8";
+  libuv = fetchurl {
+    url = "https://api.github.com/repos/JuliaLang/libuv/tarball/${libuvVersion}";
+    sha256 = "1vldy94sfmlfqmi14126g590wi61fv78rzh7afk82zkipaixvak8";
+  };
+
+  rmathVersion = "0.1";
+  rmath-julia = fetchurl {
+    url = "https://api.github.com/repos/JuliaLang/Rmath-julia/tarball/v${rmathVersion}";
+    sha256 = "0ai5dhjc43zcvangz123ryxmlbm51s21rg13bllwyn98w67arhb4";
+  };
+  
+  virtualenvVersion = "15.0.0";
+  virtualenv = fetchurl {
+    url = "mirror://pypi/v/virtualenv/virtualenv-${virtualenvVersion}.tar.gz";
+    sha256 = "06fw4liazpx5vf3am45q2pdiwrv0id7ckv7n6zmpml29x6vkzmkh";
+  };
+in
+
+stdenv.mkDerivation rec {
+  pname = "julia";
+  version = "0.6.0";
+  name = "${pname}-${version}";
+
+  src = fetchzip {
+    url = "https://github.com/JuliaLang/${pname}/releases/download/v${version}/${name}.tar.gz";
+    sha256 = "19xk2cs43lnsy9y0d8wmxj7ich908ipb40vkf7xg9031x272brxw";
+  };
+  prePatch = ''
+    mkdir deps/srccache
+    cp "${dsfmt}" "./deps/srccache/dsfmt-${dsfmtVersion}.tar.gz"
+    cp "${rmath-julia}" "./deps/srccache/Rmath-julia-${rmathVersion}.tar.gz"
+    cp "${libuv}" "./deps/srccache/libuv-${libuvVersion}.tar.gz"
+    cp "${virtualenv}" "./deps/srccache/virtualenv-${virtualenvVersion}.tar.gz"
+  '';
+
+  patches = [
+    ./0001.1-use-system-utf8proc.patch
+    ./0002-use-system-suitesparse.patch
+  ] ++ stdenv.lib.optional stdenv.needsPax ./0004-hardened.patch;
+
+  postPatch = ''
+    patchShebangs . contrib
+    for i in backtrace replutil cmdlineargs compile; do
+      mv test/$i.jl{,.off}
+      touch test/$i.jl
+    done
+
+    sed -e 's/Invalid Content-Type:/invalid Content-Type:/g' -i test/libgit2.jl
+    sed -e 's/Failed to resolve /failed to resolve /g' -i test/libgit2.jl
+  '';
+
+  buildInputs = [
+    arpack fftw fftwSinglePrec gmp libgit2 libunwind mpfr
+    pcre2.dev openblas openlibm openspecfun readline suitesparse utf8proc
+    zlib llvm
+  ]
+  ++ stdenv.lib.optionals stdenv.isDarwin [CoreServices ApplicationServices]
+  ;
+
+  nativeBuildInputs = [ curl gfortran m4 makeWrapper patchelf perl python2 which ]
+    ++ stdenv.lib.optional stdenv.needsPax paxctl;
+
+  makeFlags =
+    let
+      arch = head (splitString "-" stdenv.system);
+      march = { "x86_64" = "x86-64"; "i686" = "pentium4"; }."${arch}"
+              or (throw "unsupported architecture: ${arch}");
+      # Julia requires Pentium 4 (SSE2) or better
+      cpuTarget = { "x86_64" = "x86-64"; "i686" = "pentium4"; }."${arch}"
+                  or (throw "unsupported architecture: ${arch}");
+    in [
+      "ARCH=${arch}"
+      "MARCH=${march}"
+      "JULIA_CPU_TARGET=${cpuTarget}"
+      "PREFIX=$(out)"
+      "prefix=$(out)"
+      "SHELL=${stdenv.shell}"
+
+      "USE_SYSTEM_BLAS=1"
+      "USE_BLAS64=${if openblas.blas64 then "1" else "0"}"
+      "LIBBLAS=-lopenblas"
+      "LIBBLASNAME=libopenblas"
+
+      "USE_SYSTEM_LAPACK=1"
+      "LIBLAPACK=-lopenblas"
+      "LIBLAPACKNAME=libopenblas"
+
+      "USE_SYSTEM_SUITESPARSE=1"
+      "SUITESPARSE_LIB=-lsuitesparse"
+      "SUITESPARSE_INC=-I${suitesparse}/include"
+
+      "USE_SYSTEM_ARPACK=1"
+      "USE_SYSTEM_FFTW=1"
+      "USE_SYSTEM_GMP=1"
+      "USE_SYSTEM_LIBGIT2=1"
+      "USE_SYSTEM_LIBUNWIND=1"
+      
+      "USE_SYSTEM_LLVM=1"
+      "LLVM_VER=3.9.1"
+
+      "USE_SYSTEM_MPFR=1"
+      "USE_SYSTEM_OPENLIBM=1"
+      "USE_SYSTEM_OPENSPECFUN=1"
+      "USE_SYSTEM_PATCHELF=1"
+      "USE_SYSTEM_PCRE=1"
+      "PCRE_CONFIG=${pcre2.dev}/bin/pcre2-config"
+      "PCRE_INCL_PATH=${pcre2.dev}/include/pcre2.h"
+      "USE_SYSTEM_READLINE=1"
+      "USE_SYSTEM_UTF8PROC=1"
+      "USE_SYSTEM_ZLIB=1"
+    ];
+
+  NIX_CFLAGS_COMPILE = [ "-fPIC" ];
+
+  LD_LIBRARY_PATH = makeLibraryPath [
+    arpack fftw fftwSinglePrec gmp libgit2 mpfr openblas openlibm
+    openspecfun pcre2 suitesparse llvm
+  ];
+
+  dontStrip = true;
+  dontPatchELF = true;
+
+  enableParallelBuilding = true;
+
+  doCheck = !stdenv.isDarwin;
+  checkTarget = "testall";
+  # Julia's tests require read/write access to $HOME
+  preCheck = ''
+    export HOME="$NIX_BUILD_TOP"
+    set
+  '';
+
+  preBuild = ''
+    sed -e '/^install:/s@[^ ]*/doc/[^ ]*@@' -i Makefile
+    sed -e '/[$](DESTDIR)[$](docdir)/d' -i Makefile
+    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
+  '';
+
+  postInstall = ''
+    for prog in "$out/bin/julia" "$out/bin/julia-debug"; do
+        wrapProgram "$prog" \
+            --prefix LD_LIBRARY_PATH : "$LD_LIBRARY_PATH:$out/lib/julia" \
+            --prefix PATH : "${stdenv.lib.makeBinPath [ curl ]}"
+    done
+  '';
+
+  meta = {
+    description = "High-level performance-oriented dynamical language for technical computing";
+    homepage = https://julialang.org/;
+    license = stdenv.lib.licenses.mit;
+    maintainers = with stdenv.lib.maintainers; [ raskin ];
+    platforms = [ "i686-linux" "x86_64-linux" "x86_64-darwin" ];
+    broken = stdenv.isi686;
+  };
+}
diff --git a/pkgs/development/compilers/kotlin/default.nix b/pkgs/development/compilers/kotlin/default.nix
index 65c2125dfbca..37093530a3ca 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.1.4-2";
+  version = "1.1.51";
   name = "kotlin-${version}";
 
   src = fetchurl {
     url = "https://github.com/JetBrains/kotlin/releases/download/v${version}/kotlin-compiler-${version}.zip";
-    sha256 = "09sikwk5xxn4b30icbq28mjs4lm9xbj0bv5yjx75r165iz65g2cv";
+    sha256 = "1kbwyldfyyd20rnrl5yvyvqiqj9b3v6543vhlqsh5swhhc9nnd0b";
   };
 
   propagatedBuildInputs = [ jre ] ;
diff --git a/pkgs/development/compilers/ldc/default.nix b/pkgs/development/compilers/ldc/default.nix
new file mode 100644
index 000000000000..5c283dd4380c
--- /dev/null
+++ b/pkgs/development/compilers/ldc/default.nix
@@ -0,0 +1,103 @@
+{ stdenv, fetchFromGitHub, cmake, llvm, dmd, curl, tzdata, python,
+  lit, gdb, unzip, darwin }:
+
+stdenv.mkDerivation rec {
+  name = "ldc-${version}";
+  version = "1.3.0";
+
+  srcs = [
+  (fetchFromGitHub {
+    owner = "ldc-developers";
+    repo = "ldc";
+    rev = "v${version}";
+    sha256 = "1ac3j4cwwgjpayhijxx4d6478bc3iqksjxkd7xp7byx7k8w1ppdl";
+    name = "ldc-v${version}-src";
+  })
+  (fetchFromGitHub {
+    owner = "ldc-developers";
+    repo = "druntime";
+    rev = "ldc-v${version}";
+    sha256 = "1m13370wnj3sizqk3sdpzi9am5d24srf27d613qblhqa9n8vwz30";
+    name = "druntime-ldc-v${version}-src";
+  })
+  (fetchFromGitHub {
+    owner = "ldc-developers";
+    repo = "phobos";
+    rev = "ldc-v${version}";
+    sha256 = "0fhcdfi7a00plwj27ysfyv783nhk0kspq7hawf6vbsl3s1nyvn8g";
+    name = "phobos-ldc-v${version}-src";
+  })
+  (fetchFromGitHub {
+    owner = "ldc-developers";
+    repo = "dmd-testsuite";
+    rev = "ldc-v${version}";
+    sha256 = "0dmdkp220gqhxjrmrjfkf0vsvylwfaj70hswavq4q3v4dg17pzmj";
+    name = "dmd-testsuite-ldc-v${version}-src";
+  })
+  ];
+
+  sourceRoot = ".";
+
+  postUnpack = ''
+      mv ldc-v${version}-src/* .
+
+      mv druntime-ldc-v${version}-src/* runtime/druntime
+
+      mv phobos-ldc-v${version}-src/* runtime/phobos
+
+      mv dmd-testsuite-ldc-v${version}-src/* tests/d2/dmd-testsuite
+
+      # Remove cppa test for now because it doesn't work.
+      rm tests/d2/dmd-testsuite/runnable/cppa.d
+      rm tests/d2/dmd-testsuite/runnable/extra-files/cppb.cpp
+  '';
+
+  postPatch = ''
+      substituteInPlace runtime/phobos/std/net/curl.d \
+          --replace libcurl.so ${curl.out}/lib/libcurl.so
+
+      # Ugly hack to fix the hardcoded path to zoneinfo in the source file.
+      # https://issues.dlang.org/show_bug.cgi?id=15391
+      substituteInPlace runtime/phobos/std/datetime.d \
+          --replace /usr/share/zoneinfo/ ${tzdata}/share/zoneinfo/
+  ''
+
+  + stdenv.lib.optionalString stdenv.hostPlatform.isDarwin ''
+      substituteInPlace driver/tool.cpp \
+          --replace "gcc" "clang"
+  '';
+
+  nativeBuildInputs = [ cmake llvm dmd python lit gdb unzip ]
+
+  ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [
+    Foundation
+  ]);
+
+  buildInputs = [ curl tzdata stdenv.cc ];
+
+  preConfigure = ''
+    cmakeFlagsArray=("-DINCLUDE_INSTALL_DIR=$out/include/dlang/ldc")
+  '';
+
+  postConfigure = ''
+    export DMD=$PWD/bin/ldc2
+  '';
+
+  makeFlags = [ "DMD=$DMD" ];
+
+  # disable check phase because some tests are not working with sandboxing
+  doCheck = false;
+
+  checkPhase = ''
+      ctest -j $NIX_BUILD_CORES -V DMD=$DMD
+  '';
+
+  meta = with stdenv.lib; {
+    description = "The LLVM-based D compiler";
+    homepage = https://github.com/ldc-developers/ldc;
+    # from https://github.com/ldc-developers/ldc/blob/master/LICENSE
+    license = with licenses; [ bsd3 boost mit ncsa gpl2Plus ];
+    maintainers = with maintainers; [ ThomasMader ];
+    platforms = platforms.unix;
+  };
+}
diff --git a/pkgs/development/compilers/llvm/3.4/llvm.nix b/pkgs/development/compilers/llvm/3.4/llvm.nix
index 79b0c9ff898d..27047e7d941c 100644
--- a/pkgs/development/compilers/llvm/3.4/llvm.nix
+++ b/pkgs/development/compilers/llvm/3.4/llvm.nix
@@ -1,11 +1,12 @@
 { stdenv
 , fetch
+, fetchpatch
 , perl
 , groff
 , cmake
 , python2
 , libffi
-, binutils
+, libbfd
 , libxml2
 , valgrind
 , ncurses
@@ -39,6 +40,22 @@ in stdenv.mkDerivation rec {
     ../fix-llvm-config.patch
   ];
 
+  postPatch = stdenv.lib.optionalString (stdenv ? glibc) ''
+    (
+     cd projects/compiler-rt
+      patch -p1 -F3 < ${
+        fetchpatch {
+          name = "sigaltstack.patch"; # for glibc-2.26
+          url = https://github.com/llvm-mirror/compiler-rt/commit/8a5e425a68d.diff;
+          sha256 = "0h4y5vl74qaa7dl54b1fcyqalvlpd8zban2d1jxfkxpzyi7m8ifi";
+        }
+      }
+
+      sed -i "s,#include <pthread.h>,&\n#include <signal.h>,g" \
+        lib/asan/asan_linux.cc
+    )
+  '';
+
   # hacky fix: created binaries need to be run before installation
   preBuild = ''
     mkdir -p $out/
@@ -50,7 +67,7 @@ in stdenv.mkDerivation rec {
     "-DLLVM_BUILD_TESTS=ON"
     "-DLLVM_ENABLE_FFI=ON"
     "-DLLVM_REQUIRES_RTTI=1"
-    "-DLLVM_BINUTILS_INCDIR=${binutils.dev or binutils}/include"
+    "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
     "-DCMAKE_CXX_FLAGS=-std=c++11"
   ] ++ stdenv.lib.optional (!stdenv.isDarwin) "-DBUILD_SHARED_LIBS=ON";
 
diff --git a/pkgs/development/compilers/llvm/3.5/libc++/default.nix b/pkgs/development/compilers/llvm/3.5/libc++/default.nix
index abc198b06864..1f1129f578f4 100644
--- a/pkgs/development/compilers/llvm/3.5/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/3.5/libc++/default.nix
@@ -20,7 +20,11 @@ stdenv.mkDerivation rec {
                 '"${libcxxabi}/lib/libc++abi.dylib"'
   '';
 
-  patches = [ ./darwin.patch ];
+  patches = [
+    ./darwin.patch
+    # glibc 2.26 fix
+    ./xlocale-glibc-2.26.patch
+  ];
 
   buildInputs = [ cmake libcxxabi ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
 
diff --git a/pkgs/development/compilers/llvm/3.5/libc++/xlocale-glibc-2.26.patch b/pkgs/development/compilers/llvm/3.5/libc++/xlocale-glibc-2.26.patch
new file mode 100644
index 000000000000..250bb49fc231
--- /dev/null
+++ b/pkgs/development/compilers/llvm/3.5/libc++/xlocale-glibc-2.26.patch
@@ -0,0 +1,17 @@
+diff --git a/include/__locale b/include/__locale
+index 3daa1f1..cb8e151 100644
+--- a/include/__locale
++++ b/include/__locale
+@@ -29,10 +29,10 @@
+ # if __ANDROID_API__ <= 20
+ #  include <support/android/locale_bionic.h>
+ # endif
+-#elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
++#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
+     || defined(__sun__)   || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
+ # include <xlocale.h>
+-#endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
++#endif // __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #pragma GCC system_header
diff --git a/pkgs/development/compilers/llvm/3.5/llvm.nix b/pkgs/development/compilers/llvm/3.5/llvm.nix
index c5503da9b838..00b2548d56e6 100644
--- a/pkgs/development/compilers/llvm/3.5/llvm.nix
+++ b/pkgs/development/compilers/llvm/3.5/llvm.nix
@@ -1,11 +1,12 @@
 { stdenv
 , fetch
+, fetchpatch
 , perl
 , groff
 , cmake
 , python
 , libffi
-, binutils
+, libbfd
 , libxml2
 , valgrind
 , ncurses
@@ -33,6 +34,28 @@ in stdenv.mkDerivation rec {
 
   propagatedBuildInputs = [ ncurses zlib ];
 
+  prePatch = ''
+    substituteInPlace CMakeLists.txt \
+      --replace 'set(CMAKE_INSTALL_NAME_DIR "@rpath")' "set(CMAKE_INSTALL_NAME_DIR "$out/lib")" \
+      --replace 'set(CMAKE_INSTALL_RPATH "@executable_path/../lib")' ""
+  '';
+
+  postPatch = stdenv.lib.optionalString (stdenv ? glibc) ''
+    (
+      cd projects/compiler-rt
+      patch -p1 < ${
+        fetchpatch {
+          name = "sigaltstack.patch"; # for glibc-2.26
+          url = https://github.com/llvm-mirror/compiler-rt/commit/8a5e425a68d.diff;
+          sha256 = "0h4y5vl74qaa7dl54b1fcyqalvlpd8zban2d1jxfkxpzyi7m8ifi";
+        }
+      }
+
+      sed -i "s,#include <pthread.h>,&\n#include <signal.h>,g" \
+        lib/asan/asan_linux.cc
+    )
+  '';
+
   # hacky fix: created binaries need to be run before installation
   preBuild = ''
     mkdir -p $out/
@@ -47,7 +70,7 @@ in stdenv.mkDerivation rec {
   ] ++ stdenv.lib.optional enableSharedLibraries
     "-DBUILD_SHARED_LIBS=ON"
     ++ stdenv.lib.optional (!isDarwin)
-    "-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include"
+    "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
     ++ stdenv.lib.optionals ( isDarwin) [
     "-DCMAKE_CXX_FLAGS=-stdlib=libc++"
     "-DCAN_TARGET_i386=false"
diff --git a/pkgs/development/compilers/llvm/3.7/default.nix b/pkgs/development/compilers/llvm/3.7/default.nix
index b7155defb437..432443e1a89a 100644
--- a/pkgs/development/compilers/llvm/3.7/default.nix
+++ b/pkgs/development/compilers/llvm/3.7/default.nix
@@ -1,4 +1,7 @@
-{ newScope, stdenv, cmake, libxml2, python2, isl, fetchurl, overrideCC, wrapCC, ccWrapperFun }:
+{ newScope, stdenv, libstdcxxHook, cmake, libxml2, python2, isl, fetchurl
+, overrideCC, wrapCC, ccWrapperFun, darwin
+}:
+
 let
   callPackage = newScope (self // { inherit stdenv cmake libxml2 python2 isl version fetch; });
 
@@ -22,20 +25,35 @@ let
       inherit clang-tools-extra_src stdenv;
     };
 
-    clang = wrapCC self.clang-unwrapped;
+    clang = if stdenv.cc.isGNU then self.libstdcxxClang else self.libcxxClang;
+
+    libstdcxxClang = ccWrapperFun {
+      cc = self.clang-unwrapped;
+      /* FIXME is this right? */
+      inherit (stdenv.cc) libc nativeTools nativeLibc;
+      extraPackages = [ libstdcxxHook ];
+    };
 
     libcxxClang = ccWrapperFun {
       cc = self.clang-unwrapped;
-      isClang = true;
-      inherit (self) stdenv;
       /* FIXME is this right? */
       inherit (stdenv.cc) libc nativeTools nativeLibc;
       extraPackages = [ self.libcxx self.libcxxabi ];
     };
 
-    stdenv = overrideCC stdenv self.clang;
+    stdenv = stdenv.override (drv: {
+      allowedRequisites = null;
+      cc = self.clang;
+      # Don't include the libc++ and libc++abi from the original stdenv.
+      extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF;
+    });
 
-    libcxxStdenv = overrideCC stdenv self.libcxxClang;
+    libcxxStdenv = stdenv.override (drv: {
+      allowedRequisites = null;
+      cc = self.libcxxClang;
+      # Don't include the libc++ and libc++abi from the original stdenv.
+      extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF;
+    });
 
     lldb = callPackage ./lldb.nix {};
 
diff --git a/pkgs/development/compilers/llvm/3.7/libc++/default.nix b/pkgs/development/compilers/llvm/3.7/libc++/default.nix
index 69ce87bcbf30..4296c0fd192c 100644
--- a/pkgs/development/compilers/llvm/3.7/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/3.7/libc++/default.nix
@@ -17,6 +17,8 @@ stdenv.mkDerivation rec {
   patches = [
     ./darwin.patch
     ./r242056.patch
+    # glibc 2.26 fix
+    ./xlocale-glibc-2.26.patch
   ];
 
   buildInputs = [ cmake libcxxabi ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
diff --git a/pkgs/development/compilers/llvm/3.7/libc++/xlocale-glibc-2.26.patch b/pkgs/development/compilers/llvm/3.7/libc++/xlocale-glibc-2.26.patch
new file mode 100644
index 000000000000..5ee8f6b82305
--- /dev/null
+++ b/pkgs/development/compilers/llvm/3.7/libc++/xlocale-glibc-2.26.patch
@@ -0,0 +1,17 @@
+diff --git a/include/__locale b/include/__locale
+index 1989558..1e42905 100644
+--- a/include/__locale
++++ b/include/__locale
+@@ -34,10 +34,10 @@
+ # include <support/solaris/xlocale.h>
+ #elif defined(_NEWLIB_VERSION)
+ # include <support/newlib/xlocale.h>
+-#elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
++#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
+     || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
+ # include <xlocale.h>
+-#endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
++#endif // __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #pragma GCC system_header
diff --git a/pkgs/development/compilers/llvm/3.7/llvm.nix b/pkgs/development/compilers/llvm/3.7/llvm.nix
index 81aaa7cd65c2..1654914ff8c4 100644
--- a/pkgs/development/compilers/llvm/3.7/llvm.nix
+++ b/pkgs/development/compilers/llvm/3.7/llvm.nix
@@ -1,11 +1,12 @@
 { stdenv
 , fetch
+, fetchpatch
 , perl
 , groff
 , cmake
 , python2
 , libffi
-, binutils
+, libbfd
 , libxml2
 , valgrind
 , ncurses
@@ -45,6 +46,18 @@ in stdenv.mkDerivation rec {
   # those always succeed has the net effect of disabling all bindings.
   prePatch = ''
     substituteInPlace cmake/config-ix.cmake --replace "if(WIN32)" "if(1)"
+  ''
+  + stdenv.lib.optionalString (stdenv ? glibc) ''
+    (
+      cd projects/compiler-rt
+      patch -p1 < ${
+        fetchpatch {
+          name = "sigaltstack.patch"; # for glibc-2.26
+          url = https://github.com/llvm-mirror/compiler-rt/commit/8a5e425a68d.diff;
+          sha256 = "0h4y5vl74qaa7dl54b1fcyqalvlpd8zban2d1jxfkxpzyi7m8ifi";
+        }
+      }
+    )
   '';
 
   # hacky fix: created binaries need to be run before installation
@@ -67,7 +80,7 @@ in stdenv.mkDerivation rec {
   ] ++ stdenv.lib.optional enableSharedLibraries
     "-DBUILD_SHARED_LIBS=ON"
     ++ stdenv.lib.optional (!isDarwin)
-    "-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include"
+    "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
     ++ stdenv.lib.optionals ( isDarwin) [
     "-DLLVM_ENABLE_LIBCXX=ON"
     "-DCAN_TARGET_i386=false"
diff --git a/pkgs/development/compilers/llvm/3.8/default.nix b/pkgs/development/compilers/llvm/3.8/default.nix
index 04cd9f791e62..453d2c1f04b4 100644
--- a/pkgs/development/compilers/llvm/3.8/default.nix
+++ b/pkgs/development/compilers/llvm/3.8/default.nix
@@ -1,4 +1,4 @@
-{ newScope, stdenv, isl, fetchurl, overrideCC, wrapCC, ccWrapperFun }:
+{ newScope, stdenv, libstdcxxHook, isl, fetchurl, overrideCC, wrapCC, ccWrapperFun, darwin }:
 let
   callPackage = newScope (self // { inherit stdenv isl version fetch; });
 
@@ -22,20 +22,35 @@ let
       inherit clang-tools-extra_src stdenv;
     };
 
-    clang = wrapCC self.clang-unwrapped;
+    clang = if stdenv.cc.isGNU then self.libstdcxxClang else self.libcxxClang;
+
+    libstdcxxClang = ccWrapperFun {
+      cc = self.clang-unwrapped;
+      /* FIXME is this right? */
+      inherit (stdenv.cc) libc nativeTools nativeLibc;
+      extraPackages = [ libstdcxxHook ];
+    };
 
     libcxxClang = ccWrapperFun {
       cc = self.clang-unwrapped;
-      isClang = true;
-      inherit (self) stdenv;
       /* FIXME is this right? */
       inherit (stdenv.cc) libc nativeTools nativeLibc;
       extraPackages = [ self.libcxx self.libcxxabi ];
     };
 
-    stdenv = overrideCC stdenv self.clang;
-
-    libcxxStdenv = overrideCC stdenv self.libcxxClang;
+    stdenv = stdenv.override (drv: {
+      allowedRequisites = null;
+      cc = self.clang;
+      # Don't include the libc++ and libc++abi from the original stdenv.
+      extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF;
+    });
+
+    libcxxStdenv = stdenv.override (drv: {
+      allowedRequisites = null;
+      cc = self.libcxxClang;
+      # Don't include the libc++ and libc++abi from the original stdenv.
+      extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF;
+    });
 
     lldb = callPackage ./lldb.nix {};
 
diff --git a/pkgs/development/compilers/llvm/3.8/libc++/default.nix b/pkgs/development/compilers/llvm/3.8/libc++/default.nix
index e4198599904c..ea468b3772e0 100644
--- a/pkgs/development/compilers/llvm/3.8/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/3.8/libc++/default.nix
@@ -14,7 +14,10 @@ stdenv.mkDerivation rec {
     cmakeFlagsArray=($cmakeFlagsArray -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$NIX_BUILD_TOP/libcxxabi-${version}.src/include")
   '';
 
-  patches = lib.optional stdenv.isDarwin ./darwin.patch;
+  patches = [
+    # glibc 2.26 fix
+    ../../3.9/libc++/xlocale-glibc-2.26.patch
+  ] ++ lib.optional stdenv.isDarwin ./darwin.patch;
 
   buildInputs = [ cmake libcxxabi ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
 
diff --git a/pkgs/development/compilers/llvm/3.8/llvm.nix b/pkgs/development/compilers/llvm/3.8/llvm.nix
index a3f652d783be..0f259977f702 100644
--- a/pkgs/development/compilers/llvm/3.8/llvm.nix
+++ b/pkgs/development/compilers/llvm/3.8/llvm.nix
@@ -1,11 +1,12 @@
 { stdenv
 , fetch
+, fetchpatch
 , perl
 , groff
 , cmake
 , python
 , libffi
-, binutils
+, libbfd
 , libxml2
 , valgrind
 , ncurses
@@ -44,7 +45,23 @@ in stdenv.mkDerivation rec {
   # 10.9. This is a temporary measure until nixpkgs darwin support is
   # updated.
   postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
-        sed -i 's/os_trace(\(.*\)");$/printf(\1\\n");/g' ./projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
+    sed -i 's/os_trace(\(.*\)");$/printf(\1\\n");/g' ./projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
+
+    substituteInPlace CMakeLists.txt \
+      --replace 'set(CMAKE_INSTALL_NAME_DIR "@rpath")' "set(CMAKE_INSTALL_NAME_DIR "$out/lib")" \
+      --replace 'set(CMAKE_INSTALL_RPATH "@executable_path/../lib")' ""
+  ''
+  + stdenv.lib.optionalString (stdenv ? glibc) ''
+    (
+      cd projects/compiler-rt
+      patch -p1 < ${
+        fetchpatch {
+          name = "sigaltstack.patch"; # for glibc-2.26
+          url = https://github.com/llvm-mirror/compiler-rt/commit/8a5e425a68d.diff;
+          sha256 = "0h4y5vl74qaa7dl54b1fcyqalvlpd8zban2d1jxfkxpzyi7m8ifi";
+        }
+      }
+    )
   '';
 
   # hacky fix: created binaries need to be run before installation
@@ -62,7 +79,7 @@ in stdenv.mkDerivation rec {
   ] ++ stdenv.lib.optional enableSharedLibraries [
     "-DLLVM_LINK_LLVM_DYLIB=ON"
   ] ++ stdenv.lib.optional (!isDarwin)
-    "-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include"
+    "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
     ++ stdenv.lib.optionals ( isDarwin) [
     "-DLLVM_ENABLE_LIBCXX=ON"
     "-DCAN_TARGET_i386=false"
@@ -75,7 +92,6 @@ in stdenv.mkDerivation rec {
   '';
 
   postInstall = stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
-    install_name_tool -id $out/lib/libLLVM.dylib $out/lib/libLLVM.dylib
     ln -s $out/lib/libLLVM.dylib $out/lib/libLLVM-${version}.dylib
   '';
 
diff --git a/pkgs/development/compilers/llvm/3.9/default.nix b/pkgs/development/compilers/llvm/3.9/default.nix
index a01e47efb753..755b417c78d4 100644
--- a/pkgs/development/compilers/llvm/3.9/default.nix
+++ b/pkgs/development/compilers/llvm/3.9/default.nix
@@ -1,4 +1,4 @@
-{ newScope, stdenv, isl, fetchurl, overrideCC, wrapCC, darwin, ccWrapperFun }:
+{ newScope, stdenv, libstdcxxHook, isl, fetchurl, overrideCC, wrapCC, ccWrapperFun, darwin }:
 let
   callPackage = newScope (self // { inherit stdenv isl version fetch; });
 
@@ -22,20 +22,35 @@ let
       inherit clang-tools-extra_src stdenv;
     };
 
-    clang = wrapCC self.clang-unwrapped;
+    clang = if stdenv.cc.isGNU then self.libstdcxxClang else self.libcxxClang;
+
+    libstdcxxClang = ccWrapperFun {
+      cc = self.clang-unwrapped;
+      /* FIXME is this right? */
+      inherit (stdenv.cc) libc nativeTools nativeLibc;
+      extraPackages = [ libstdcxxHook ];
+    };
 
     libcxxClang = ccWrapperFun {
       cc = self.clang-unwrapped;
-      isClang = true;
-      inherit (self) stdenv;
       /* FIXME is this right? */
       inherit (stdenv.cc) libc nativeTools nativeLibc;
       extraPackages = [ self.libcxx self.libcxxabi ];
     };
 
-    stdenv = overrideCC stdenv self.clang;
-
-    libcxxStdenv = overrideCC stdenv self.libcxxClang;
+    stdenv = stdenv.override (drv: {
+      allowedRequisites = null;
+      cc = self.clang;
+      # Don't include the libc++ and libc++abi from the original stdenv.
+      extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF;
+    });
+
+    libcxxStdenv = stdenv.override (drv: {
+      allowedRequisites = null;
+      cc = self.libcxxClang;
+      # Don't include the libc++ and libc++abi from the original stdenv.
+      extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF;
+    });
 
     lldb = callPackage ./lldb.nix {};
 
diff --git a/pkgs/development/compilers/llvm/3.9/libc++/default.nix b/pkgs/development/compilers/llvm/3.9/libc++/default.nix
index f656f553f16b..ad514b0daa54 100644
--- a/pkgs/development/compilers/llvm/3.9/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/3.9/libc++/default.nix
@@ -14,7 +14,10 @@ stdenv.mkDerivation rec {
     cmakeFlagsArray=($cmakeFlagsArray -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$NIX_BUILD_TOP/libcxxabi-${version}.src/include")
   '';
 
-  patches = lib.optional stdenv.isDarwin ./darwin.patch;
+  patches = [
+    # glibc 2.26 fix
+    ./xlocale-glibc-2.26.patch
+  ] ++ lib.optional stdenv.isDarwin ./darwin.patch;
 
   buildInputs = [ cmake libcxxabi ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
 
diff --git a/pkgs/development/compilers/llvm/3.9/libc++/xlocale-glibc-2.26.patch b/pkgs/development/compilers/llvm/3.9/libc++/xlocale-glibc-2.26.patch
new file mode 100644
index 000000000000..4cc042554c85
--- /dev/null
+++ b/pkgs/development/compilers/llvm/3.9/libc++/xlocale-glibc-2.26.patch
@@ -0,0 +1,19 @@
+diff --git a/include/__locale b/include/__locale
+index 7bc701d..ea75c86 100644
+--- a/include/__locale
++++ b/include/__locale
+@@ -34,12 +34,12 @@
+ # include <support/solaris/xlocale.h>
+ #elif defined(_NEWLIB_VERSION)
+ # include <support/newlib/xlocale.h>
+-#elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
++#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
+     || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
+ # include <xlocale.h>
+ #elif defined(_LIBCPP_HAS_MUSL_LIBC)
+ # include <support/musl/xlocale.h>
+-#endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
++#endif // __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #pragma GCC system_header
diff --git a/pkgs/development/compilers/llvm/3.9/llvm.nix b/pkgs/development/compilers/llvm/3.9/llvm.nix
index 654e1ce0023b..f80201167505 100644
--- a/pkgs/development/compilers/llvm/3.9/llvm.nix
+++ b/pkgs/development/compilers/llvm/3.9/llvm.nix
@@ -6,7 +6,7 @@
 , cmake
 , python
 , libffi
-, binutils
+, libbfd
 , libxml2
 , valgrind
 , ncurses
@@ -26,7 +26,6 @@ assert (hostPlatform != buildPlatform) -> !enableSharedLibraries;
 
 let
   src = fetch "llvm" "1vi9sf7rx1q04wj479rsvxayb6z740iaz3qniwp266fgp5a07n8z";
-  shlib = if stdenv.isDarwin then "dylib" else "so";
 
   # Used when creating a version-suffixed symlink of libLLVM.dylib
   shortVersion = with stdenv.lib;
@@ -83,11 +82,29 @@ in stdenv.mkDerivation rec {
   + stdenv.lib.optionalString stdenv.isDarwin ''
     substituteInPlace ./projects/compiler-rt/cmake/config-ix.cmake \
       --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
+
+    substituteInPlace CMakeLists.txt \
+      --replace 'set(CMAKE_INSTALL_NAME_DIR "@rpath")' "set(CMAKE_INSTALL_NAME_DIR "$lib/lib")" \
+      --replace 'set(CMAKE_INSTALL_RPATH "@executable_path/../lib")' ""
   ''
   # Patch llvm-config to return correct library path based on --link-{shared,static}.
   + stdenv.lib.optionalString (enableSharedLibraries) ''
     substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
     patch -p1 < ./llvm-outputs.patch
+  ''
+  + stdenv.lib.optionalString (stdenv ? glibc) ''
+    (
+      cd projects/compiler-rt
+      patch -p1 < ${
+        fetchpatch {
+          name = "sigaltstack.patch"; # for glibc-2.26
+          url = https://github.com/llvm-mirror/compiler-rt/commit/8a5e425a68d.diff;
+          sha256 = "0h4y5vl74qaa7dl54b1fcyqalvlpd8zban2d1jxfkxpzyi7m8ifi";
+        }
+      }
+      substituteInPlace lib/esan/esan_sideline_linux.cpp \
+        --replace 'struct sigaltstack' 'stack_t'
+    )
   '';
 
   # hacky fix: created binaries need to be run before installation
@@ -106,7 +123,7 @@ in stdenv.mkDerivation rec {
   ] ++ stdenv.lib.optional enableSharedLibraries [
     "-DLLVM_LINK_LLVM_DYLIB=ON"
   ] ++ stdenv.lib.optional (!isDarwin)
-    "-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include"
+    "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
     ++ stdenv.lib.optionals (isDarwin) [
     "-DLLVM_ENABLE_LIBCXX=ON"
     "-DCAN_TARGET_i386=false"
@@ -124,15 +141,13 @@ in stdenv.mkDerivation rec {
   postInstall = ""
   + stdenv.lib.optionalString (enableSharedLibraries) ''
     moveToOutput "lib/libLLVM-*" "$lib"
-    moveToOutput "lib/libLLVM.${shlib}" "$lib"
+    moveToOutput "lib/libLLVM${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib"
     substituteInPlace "$out/lib/cmake/llvm/LLVMExports-release.cmake" \
       --replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
   ''
   + stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
     substituteInPlace "$out/lib/cmake/llvm/LLVMExports-release.cmake" \
       --replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
-    install_name_tool -id $lib/lib/libLLVM.dylib $lib/lib/libLLVM.dylib
-    install_name_tool -change @rpath/libLLVM.dylib $lib/lib/libLLVM.dylib $out/bin/llvm-config
     ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib
     ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${version}.dylib
   '';
diff --git a/pkgs/development/compilers/llvm/4/default.nix b/pkgs/development/compilers/llvm/4/default.nix
index 9e5bccff3556..25bb008567f7 100644
--- a/pkgs/development/compilers/llvm/4/default.nix
+++ b/pkgs/development/compilers/llvm/4/default.nix
@@ -1,4 +1,8 @@
-{ lowPrio, newScope, stdenv, cmake, libxml2, python2, isl, fetchurl, overrideCC, wrapCC, darwin, ccWrapperFun }:
+{ lowPrio, newScope, stdenv, targetPlatform, cmake, libstdcxxHook
+, libxml2, python2, isl, fetchurl, overrideCC, wrapCC, ccWrapperFun
+, darwin
+}:
+
 let
   callPackage = newScope (self // { inherit stdenv cmake libxml2 python2 isl release_version version fetch; });
 
@@ -6,7 +10,7 @@ let
   version = release_version; # differentiating these is important for rc's
 
   fetch = name: sha256: fetchurl {
-    url = "http://llvm.org/releases/${release_version}/${name}-${version}.src.tar.xz";
+    url = "https://releases.llvm.org/${release_version}/${name}-${version}.src.tar.xz";
     inherit sha256;
   };
 
@@ -33,22 +37,35 @@ let
     llvm-manpages = lowPrio self.llvm.man;
     clang-manpages = lowPrio self.clang-unwrapped.man;
 
-    clang = wrapCC self.clang-unwrapped;
+    clang = if stdenv.cc.isGNU then self.libstdcxxClang else self.libcxxClang;
 
-    openmp = callPackage ./openmp.nix {};
+    libstdcxxClang = ccWrapperFun {
+      cc = self.clang-unwrapped;
+      /* FIXME is this right? */
+      inherit (stdenv.cc) libc nativeTools nativeLibc;
+      extraPackages = [ libstdcxxHook ];
+    };
 
     libcxxClang = ccWrapperFun {
       cc = self.clang-unwrapped;
-      isClang = true;
-      inherit (self) stdenv;
       /* FIXME is this right? */
       inherit (stdenv.cc) libc nativeTools nativeLibc;
       extraPackages = [ self.libcxx self.libcxxabi ];
     };
 
-    stdenv = overrideCC stdenv self.clang;
+    stdenv = stdenv.override (drv: {
+      allowedRequisites = null;
+      cc = self.clang;
+      # Don't include the libc++ and libc++abi from the original stdenv.
+      extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF;
+    });
 
-    libcxxStdenv = overrideCC stdenv self.libcxxClang;
+    libcxxStdenv = stdenv.override (drv: {
+      allowedRequisites = null;
+      cc = self.libcxxClang;
+      # Don't include the libc++ and libc++abi from the original stdenv.
+      extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF;
+    });
 
     lld = callPackage ./lld.nix {};
 
@@ -57,5 +74,8 @@ let
     libcxx = callPackage ./libc++ {};
 
     libcxxabi = callPackage ./libc++abi.nix {};
+
+    openmp = callPackage ./openmp.nix {};
   };
+
 in self
diff --git a/pkgs/development/compilers/llvm/4/libc++/default.nix b/pkgs/development/compilers/llvm/4/libc++/default.nix
index b74d2fb89dcd..db751bcffd42 100644
--- a/pkgs/development/compilers/llvm/4/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/4/libc++/default.nix
@@ -10,8 +10,12 @@ stdenv.mkDerivation rec {
     export LIBCXXABI_INCLUDE_DIR="$PWD/$(ls -d libcxxabi-${version}*)/include"
   '';
 
-  # https://github.com/llvm-mirror/libcxx/commit/bcc92d75df0274b9593ebd097fcae60494e3bffc
-  patches = [ ./pthread_mach_thread_np.patch ];
+  patches = [
+    # https://github.com/llvm-mirror/libcxx/commit/bcc92d75df0274b9593ebd097fcae60494e3bffc
+    ./pthread_mach_thread_np.patch
+    # glibc 2.26 fix
+    ./xlocale-glibc-2.26.patch
+  ];
 
   prePatch = ''
     substituteInPlace lib/CMakeLists.txt --replace "/usr/lib/libc++" "\''${LIBCXX_LIBCXXABI_LIB_PATH}/libc++"
diff --git a/pkgs/development/compilers/llvm/4/libc++/xlocale-glibc-2.26.patch b/pkgs/development/compilers/llvm/4/libc++/xlocale-glibc-2.26.patch
new file mode 100644
index 000000000000..e411d85066b4
--- /dev/null
+++ b/pkgs/development/compilers/llvm/4/libc++/xlocale-glibc-2.26.patch
@@ -0,0 +1,19 @@
+diff --git a/include/__locale b/include/__locale
+index f4882de..29443b4 100644
+--- a/include/__locale
++++ b/include/__locale
+@@ -34,12 +34,12 @@
+ # include <support/solaris/xlocale.h>
+ #elif defined(_NEWLIB_VERSION)
+ # include <support/newlib/xlocale.h>
+-#elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
++#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
+     || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
+ # include <xlocale.h>
+ #elif defined(_LIBCPP_HAS_MUSL_LIBC)
+ # include <support/musl/xlocale.h>
+-#endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
++#endif // __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #pragma GCC system_header
diff --git a/pkgs/development/compilers/llvm/4/llvm.nix b/pkgs/development/compilers/llvm/4/llvm.nix
index abfac1cce143..0559a7aee232 100644
--- a/pkgs/development/compilers/llvm/4/llvm.nix
+++ b/pkgs/development/compilers/llvm/4/llvm.nix
@@ -6,7 +6,7 @@
 , cmake
 , python
 , libffi
-, binutils
+, libbfd
 , libxml2
 , valgrind
 , ncurses
@@ -23,7 +23,6 @@
 
 let
   src = fetch "llvm" "0l9bf7kdwhlj0kq1hawpyxhna1062z3h7qcz2y8nfl9dz2qksy6s";
-  shlib = if stdenv.isDarwin then "dylib" else "so";
 
   # Used when creating a version-suffixed symlink of libLLVM.dylib
   shortVersion = with stdenv.lib;
@@ -59,11 +58,29 @@ in stdenv.mkDerivation rec {
   postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
     substituteInPlace ./projects/compiler-rt/cmake/config-ix.cmake \
       --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
+
+    substituteInPlace cmake/modules/AddLLVM.cmake \
+      --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir INSTALL_NAME_DIR "$lib/lib")" \
+      --replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' ""
   ''
   # Patch llvm-config to return correct library path based on --link-{shared,static}.
   + stdenv.lib.optionalString (enableSharedLibraries) ''
     substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
     patch -p1 < ./llvm-outputs.patch
+  ''
+  + stdenv.lib.optionalString (stdenv ? glibc) ''
+    (
+      cd projects/compiler-rt
+      patch -p1 < ${
+        fetchpatch {
+          name = "sigaltstack.patch"; # for glibc-2.26
+          url = https://github.com/llvm-mirror/compiler-rt/commit/8a5e425a68d.diff;
+          sha256 = "0h4y5vl74qaa7dl54b1fcyqalvlpd8zban2d1jxfkxpzyi7m8ifi";
+        }
+      }
+      substituteInPlace lib/esan/esan_sideline_linux.cpp \
+        --replace 'struct sigaltstack' 'stack_t'
+    )
   '';
 
   # hacky fix: created binaries need to be run before installation
@@ -90,7 +107,7 @@ in stdenv.mkDerivation rec {
     "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
   ]
   ++ stdenv.lib.optional (!isDarwin)
-    "-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include"
+    "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
   ++ stdenv.lib.optionals (isDarwin) [
     "-DLLVM_ENABLE_LIBCXX=ON"
     "-DCAN_TARGET_i386=false"
@@ -115,20 +132,18 @@ in stdenv.mkDerivation rec {
   ''
   + stdenv.lib.optionalString enableSharedLibraries ''
     moveToOutput "lib/libLLVM-*" "$lib"
-    moveToOutput "lib/libLLVM.${shlib}" "$lib"
+    moveToOutput "lib/libLLVM${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib"
     substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
       --replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
   ''
   + stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
     substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
       --replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
-    install_name_tool -id $lib/lib/libLLVM.dylib $lib/lib/libLLVM.dylib
-    install_name_tool -change @rpath/libLLVM.dylib $lib/lib/libLLVM.dylib $out/bin/llvm-config
     ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib
     ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib
   '';
 
-  doCheck = stdenv.isLinux;
+  doCheck = stdenv.isLinux && (!stdenv.isi686);
 
   checkTarget = "check-all";
 
diff --git a/pkgs/development/compilers/llvm/5/clang/default.nix b/pkgs/development/compilers/llvm/5/clang/default.nix
new file mode 100644
index 000000000000..fa8502ebd67a
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/clang/default.nix
@@ -0,0 +1,97 @@
+{ stdenv, fetch, cmake, libxml2, libedit, llvm, version, release_version, clang-tools-extra_src, python
+, fixDarwinDylibNames
+, enableManpages ? false
+}:
+
+let
+  gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
+  self = stdenv.mkDerivation {
+    name = "clang-${version}";
+
+    unpackPhase = ''
+      unpackFile ${fetch "cfe" "0w09s8fn3lkn6i04nj0cisgp821r815fk5b5fjn97xrd371277q1"}
+      mv cfe-${version}* clang
+      sourceRoot=$PWD/clang
+      unpackFile ${clang-tools-extra_src}
+      mv clang-tools-extra-* $sourceRoot/tools/extra
+    '';
+
+    nativeBuildInputs = [ cmake python ]
+      ++ stdenv.lib.optional enableManpages python.pkgs.sphinx;
+
+    buildInputs = [ libedit libxml2 llvm ]
+      ++ stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames;
+
+    cmakeFlags = [
+      "-DCMAKE_CXX_FLAGS=-std=c++11"
+    ] ++ stdenv.lib.optionals enableManpages [
+      "-DCLANG_INCLUDE_DOCS=ON"
+      "-DLLVM_ENABLE_SPHINX=ON"
+      "-DSPHINX_OUTPUT_MAN=ON"
+      "-DSPHINX_OUTPUT_HTML=OFF"
+      "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
+    ]
+    # Maybe with compiler-rt this won't be needed?
+    ++ stdenv.lib.optional stdenv.isLinux "-DGCC_INSTALL_PREFIX=${gcc}"
+    ++ stdenv.lib.optional (stdenv.cc.libc != null) "-DC_INCLUDE_DIRS=${stdenv.cc.libc}/include";
+
+    patches = [ ./purity.patch ];
+
+    postBuild = stdenv.lib.optionalString enableManpages ''
+      cmake --build . --target docs-clang-man
+    '';
+
+    postPatch = ''
+      sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \
+             -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \
+             lib/Driver/ToolChains/*.cpp
+
+      # Patch for standalone doc building
+      sed -i '1s,^,find_package(Sphinx REQUIRED)\n,' docs/CMakeLists.txt
+    '';
+
+    outputs = [ "out" "python" ]
+      ++ stdenv.lib.optional enableManpages "man";
+
+    # Clang expects to find LLVMgold in its own prefix
+    # Clang expects to find sanitizer libraries in its own prefix
+    postInstall = ''
+      ln -sv ${llvm}/lib/LLVMgold.so $out/lib
+      ln -sv ${llvm}/lib/clang/${release_version}/lib $out/lib/clang/${release_version}/
+      ln -sv $out/bin/clang $out/bin/cpp
+
+      mkdir -p $python/bin $python/share/clang/
+      mv $out/bin/{git-clang-format,scan-view} $python/bin
+      if [ -e $out/bin/set-xcode-analyzer ]; then
+        mv $out/bin/set-xcode-analyzer $python/bin
+      fi
+      mv $out/share/clang/*.py $python/share/clang
+
+      rm $out/bin/c-index-test
+    ''
+    + stdenv.lib.optionalString enableManpages ''
+      # Manually install clang manpage
+      cp docs/man/*.1 $out/share/man/man1/
+
+      # Move it and other man pages to 'man' output
+      moveToOutput "share/man" "$man"
+    '';
+
+    enableParallelBuilding = true;
+
+    passthru = {
+      lib = self; # compatibility with gcc, so that `stdenv.cc.cc.lib` works on both
+      isClang = true;
+      inherit llvm;
+    } // stdenv.lib.optionalAttrs stdenv.isLinux {
+      inherit gcc;
+    };
+
+    meta = {
+      description = "A c, c++, objective-c, and objective-c++ frontend for the llvm compiler";
+      homepage    = http://llvm.org/;
+      license     = stdenv.lib.licenses.ncsa;
+      platforms   = stdenv.lib.platforms.all;
+    };
+  };
+in self
diff --git a/pkgs/development/compilers/llvm/5/clang/purity.patch b/pkgs/development/compilers/llvm/5/clang/purity.patch
new file mode 100644
index 000000000000..b30d0d0b5d5b
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/clang/purity.patch
@@ -0,0 +1,30 @@
+From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001
+From: Will Dietz <w@wdtz.org>
+Date: Thu, 18 May 2017 11:56:12 -0500
+Subject: [PATCH] "purity" patch for 5.0
+
+---
+ lib/Driver/ToolChains/Gnu.cpp | 7 -------
+ 1 file changed, 7 deletions(-)
+
+diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
+index fe3c0191bb..c6a482bece 100644
+--- a/lib/Driver/ToolChains/Gnu.cpp
++++ b/lib/Driver/ToolChains/Gnu.cpp
+@@ -494,13 +494,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+   if (!Args.hasArg(options::OPT_static)) {
+     if (Args.hasArg(options::OPT_rdynamic))
+       CmdArgs.push_back("-export-dynamic");
+-
+-    if (!Args.hasArg(options::OPT_shared)) {
+-      const std::string Loader =
+-          D.DyldPrefix + ToolChain.getDynamicLinker(Args);
+-      CmdArgs.push_back("-dynamic-linker");
+-      CmdArgs.push_back(Args.MakeArgString(Loader));
+-    }
+   }
+ 
+   CmdArgs.push_back("-o");
+-- 
+2.11.0
+
diff --git a/pkgs/development/compilers/llvm/5/compiler-rt-codesign.patch b/pkgs/development/compilers/llvm/5/compiler-rt-codesign.patch
new file mode 100644
index 000000000000..8f4c76bca1eb
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/compiler-rt-codesign.patch
@@ -0,0 +1,155 @@
+From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001
+From: Will Dietz <w@wdtz.org>
+Date: Tue, 19 Sep 2017 13:13:06 -0500
+Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that
+ needs it
+
+---
+ cmake/Modules/AddCompilerRT.cmake |  8 ------
+ test/asan/CMakeLists.txt          | 52 ---------------------------------------
+ test/tsan/CMakeLists.txt          | 47 -----------------------------------
+ 3 files changed, 107 deletions(-)
+
+diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
+index bc5fb9ff7..b64eb4246 100644
+--- a/cmake/Modules/AddCompilerRT.cmake
++++ b/cmake/Modules/AddCompilerRT.cmake
+@@ -210,14 +210,6 @@ function(add_compiler_rt_runtime name type)
+         set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
+         set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
+       endif()
+-      if(APPLE)
+-        # Ad-hoc sign the dylibs
+-        add_custom_command(TARGET ${libname}
+-          POST_BUILD  
+-          COMMAND codesign --sign - $<TARGET_FILE:${libname}>
+-          WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+-        )
+-      endif()
+     endif()
+     install(TARGETS ${libname}
+       ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
+diff --git a/test/asan/CMakeLists.txt b/test/asan/CMakeLists.txt
+index 8bfc15b5c..f23d0f71a 100644
+--- a/test/asan/CMakeLists.txt
++++ b/test/asan/CMakeLists.txt
+@@ -83,58 +83,6 @@ foreach(arch ${ASAN_TEST_ARCH})
+   endif()
+ endforeach()
+ 
+-# iOS and iOS simulator test suites
+-# These are not added into "check-all", in order to run these tests, use
+-# "check-asan-iossim-x86_64" and similar. They also require that an extra env
+-# variable to select which iOS device or simulator to use, e.g.:
+-# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
+-if(APPLE)
+-  set(EXCLUDE_FROM_ALL ON)
+-
+-  set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
+-  set(ASAN_TEST_IOS "1")
+-  pythonize_bool(ASAN_TEST_IOS)
+-  set(ASAN_TEST_DYNAMIC True)
+-
+-  foreach(arch ${DARWIN_iossim_ARCHS})
+-    set(ASAN_TEST_IOSSIM "1")
+-    pythonize_bool(ASAN_TEST_IOSSIM)
+-    set(ASAN_TEST_TARGET_ARCH ${arch})
+-    set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
+-    set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-iossim")
+-    get_bits_for_arch(${arch} ASAN_TEST_BITS)
+-    string(TOUPPER ${arch} ARCH_UPPER_CASE)
+-    set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config")
+-    configure_lit_site_cfg(
+-      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
+-      )
+-    add_lit_testsuite(check-asan-iossim-${arch} "AddressSanitizer iOS Simulator ${arch} tests"
+-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
+-      DEPENDS ${ASAN_TEST_DEPS})
+-  endforeach()
+-
+-  foreach (arch ${DARWIN_ios_ARCHS})
+-    set(ASAN_TEST_IOSSIM "0")
+-    pythonize_bool(ASAN_TEST_IOSSIM)
+-    set(ASAN_TEST_TARGET_ARCH ${arch})
+-    set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
+-    set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-ios")
+-    get_bits_for_arch(${arch} ASAN_TEST_BITS)
+-    string(TOUPPER ${arch} ARCH_UPPER_CASE)
+-    set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")
+-    configure_lit_site_cfg(
+-      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
+-      )
+-    add_lit_testsuite(check-asan-ios-${arch} "AddressSanitizer iOS ${arch} tests"
+-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
+-      DEPENDS ${ASAN_TEST_DEPS})
+-  endforeach()
+-
+-  set(EXCLUDE_FROM_ALL OFF)
+-endif()
+-
+ # Add unit tests.
+ if(COMPILER_RT_INCLUDE_TESTS)
+   set(ASAN_TEST_DYNAMIC False)
+diff --git a/test/tsan/CMakeLists.txt b/test/tsan/CMakeLists.txt
+index a68908612..cde0accb5 100644
+--- a/test/tsan/CMakeLists.txt
++++ b/test/tsan/CMakeLists.txt
+@@ -42,53 +42,6 @@ foreach(arch ${TSAN_TEST_ARCH})
+   list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+ endforeach()
+ 
+-# iOS and iOS simulator test suites
+-# These are not added into "check-all", in order to run these tests, use
+-# "check-tsan-iossim-x86_64" and similar. They also require an extra environment
+-# variable to select which iOS device or simulator to use, e.g.:
+-# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
+-if(APPLE)
+-  set(EXCLUDE_FROM_ALL ON)
+-
+-  set(TSAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
+-  set(TSAN_TEST_IOS "1")
+-  pythonize_bool(TSAN_TEST_IOS)
+-
+-  set(arch "x86_64")
+-  set(TSAN_TEST_IOSSIM "1")
+-  pythonize_bool(TSAN_TEST_IOSSIM)
+-  set(TSAN_TEST_TARGET_ARCH ${arch})
+-  set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
+-  set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-iossim")
+-  string(TOUPPER ${arch} ARCH_UPPER_CASE)
+-  set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config")
+-  configure_lit_site_cfg(
+-    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+-    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
+-    )
+-  add_lit_testsuite(check-tsan-iossim-${arch} "ThreadSanitizer iOS Simulator ${arch} tests"
+-    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
+-    DEPENDS ${TSAN_TEST_DEPS})
+-
+-  set(arch "arm64")
+-  set(TSAN_TEST_IOSSIM "0")
+-  pythonize_bool(TSAN_TEST_IOSSIM)
+-  set(TSAN_TEST_TARGET_ARCH ${arch})
+-  set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
+-  set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-ios")
+-  string(TOUPPER ${arch} ARCH_UPPER_CASE)
+-  set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")
+-  configure_lit_site_cfg(
+-    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+-    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
+-    )
+-  add_lit_testsuite(check-tsan-ios-${arch} "ThreadSanitizer iOS Simulator ${arch} tests"
+-    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
+-    DEPENDS ${TSAN_TEST_DEPS})
+-
+-  set(EXCLUDE_FROM_ALL OFF)
+-endif()
+-
+ if(COMPILER_RT_INCLUDE_TESTS)
+   configure_lit_site_cfg(
+     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
+-- 
+2.14.1
+
diff --git a/pkgs/development/compilers/llvm/5/default.nix b/pkgs/development/compilers/llvm/5/default.nix
new file mode 100644
index 000000000000..1d5cc0e504b7
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/default.nix
@@ -0,0 +1,81 @@
+{ lowPrio, newScope, stdenv, targetPlatform, cmake, libstdcxxHook
+, libxml2, python2, isl, fetchurl, overrideCC, wrapCC, ccWrapperFun
+, darwin
+}:
+
+let
+  callPackage = newScope (self // { inherit stdenv cmake libxml2 python2 isl release_version version fetch; });
+
+  release_version = "5.0.0";
+  version = release_version; # differentiating these is important for rc's
+
+  fetch = name: sha256: fetchurl {
+    url = "http://llvm.org/releases/${release_version}/${name}-${version}.src.tar.xz";
+    inherit sha256;
+  };
+
+  compiler-rt_src = fetch "compiler-rt" "1cy0y389zxn7mk8vffqvfirk9bbcbc8ziwc1nf1a8d118rk55bfm";
+  clang-tools-extra_src = fetch "clang-tools-extra" "1ikkv6k8cfgpjqlm24iqz52i5nyafzsc4dyikzzyb9n4b6wpil47";
+
+  # Add man output without introducing extra dependencies.
+  overrideManOutput = drv:
+    let drv-manpages = drv.override { enableManpages = true; }; in
+    drv // { man = drv-manpages.man; /*outputs = drv.outputs ++ ["man"];*/ };
+
+  llvm = callPackage ./llvm.nix {
+    inherit compiler-rt_src stdenv;
+  };
+
+  clang-unwrapped = callPackage ./clang {
+    inherit clang-tools-extra_src stdenv;
+  };
+
+  self = {
+    llvm = overrideManOutput llvm;
+    clang-unwrapped = overrideManOutput clang-unwrapped;
+
+    llvm-manpages = lowPrio self.llvm.man;
+    clang-manpages = lowPrio self.clang-unwrapped.man;
+
+    clang = if stdenv.cc.isGNU then self.libstdcxxClang else self.libcxxClang;
+
+    libstdcxxClang = ccWrapperFun {
+      cc = self.clang-unwrapped;
+      /* FIXME is this right? */
+      inherit (stdenv.cc) libc nativeTools nativeLibc;
+      extraPackages = [ libstdcxxHook ];
+    };
+
+    libcxxClang = ccWrapperFun {
+      cc = self.clang-unwrapped;
+      /* FIXME is this right? */
+      inherit (stdenv.cc) libc nativeTools nativeLibc;
+      extraPackages = [ self.libcxx self.libcxxabi ];
+    };
+
+    stdenv = stdenv.override (drv: {
+      allowedRequisites = null;
+      cc = self.clang;
+      # Don't include the libc++ and libc++abi from the original stdenv.
+      extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF;
+    });
+
+    libcxxStdenv = stdenv.override (drv: {
+      allowedRequisites = null;
+      cc = self.libcxxClang;
+      # Don't include the libc++ and libc++abi from the original stdenv.
+      extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF;
+    });
+
+    lld = callPackage ./lld.nix {};
+
+    lldb = callPackage ./lldb.nix {};
+
+    libcxx = callPackage ./libc++ {};
+
+    libcxxabi = callPackage ./libc++abi.nix {};
+
+    openmp = callPackage ./openmp.nix {};
+  };
+
+in self
diff --git a/pkgs/development/compilers/llvm/5/libc++/default.nix b/pkgs/development/compilers/llvm/5/libc++/default.nix
new file mode 100644
index 000000000000..036161f7b889
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/libc++/default.nix
@@ -0,0 +1,44 @@
+{ lib, stdenv, fetch, cmake, llvm, libcxxabi, fixDarwinDylibNames, version }:
+
+stdenv.mkDerivation rec {
+  name = "libc++-${version}";
+
+  src = fetch "libcxx" "1cf953msb0vwgjjrapw06950dnsdb2ps305czkn0vvr1k8g9irga";
+
+  postUnpack = ''
+    unpackFile ${libcxxabi.src}
+    export LIBCXXABI_INCLUDE_DIR="$PWD/$(ls -d libcxxabi-${version}*)/include"
+  '';
+
+  prePatch = ''
+    substituteInPlace lib/CMakeLists.txt --replace "/usr/lib/libc++" "\''${LIBCXX_LIBCXXABI_LIB_PATH}/libc++"
+  '';
+
+  preConfigure = ''
+    # Get headers from the cxxabi source so we can see private headers not installed by the cxxabi package
+    cmakeFlagsArray=($cmakeFlagsArray -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$LIBCXXABI_INCLUDE_DIR")
+  '';
+
+  nativeBuildInputs = [ cmake ];
+
+  buildInputs = [ libcxxabi ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
+
+  cmakeFlags = [
+    "-DLIBCXX_LIBCXXABI_LIB_PATH=${libcxxabi}/lib"
+    "-DLIBCXX_LIBCPPABI_VERSION=2"
+    "-DLIBCXX_CXX_ABI=libcxxabi"
+  ];
+
+  enableParallelBuilding = true;
+
+  linkCxxAbi = stdenv.isLinux;
+
+  setupHook = ./setup-hook.sh;
+
+  meta = {
+    homepage = http://libcxx.llvm.org/;
+    description = "A new implementation of the C++ standard library, targeting C++11";
+    license = with stdenv.lib.licenses; [ ncsa mit ];
+    platforms = stdenv.lib.platforms.unix;
+  };
+}
diff --git a/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh
new file mode 100644
index 000000000000..9022fced6ecf
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh
@@ -0,0 +1,3 @@
+linkCxxAbi="@linkCxxAbi@"
+export NIX_CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
+export NIX_CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
diff --git a/pkgs/development/compilers/llvm/5/libc++abi.nix b/pkgs/development/compilers/llvm/5/libc++abi.nix
new file mode 100644
index 000000000000..5a2a269345d6
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/libc++abi.nix
@@ -0,0 +1,47 @@
+{ stdenv, cmake, fetch, libcxx, libunwind, llvm, version }:
+
+stdenv.mkDerivation {
+  name = "libc++abi-${version}";
+
+  src = fetch "libcxxabi" "04c9dfmrr8diih73x0wq99dk9xb99mg0bvsnbhx5q912xg3ihs8p";
+
+  nativeBuildInputs = [ cmake ];
+  buildInputs = stdenv.lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD) libunwind;
+
+  postUnpack = ''
+    unpackFile ${libcxx.src}
+    unpackFile ${llvm.src}
+    export cmakeFlags="-DLLVM_PATH=$PWD/$(ls -d llvm-*) -DLIBCXXABI_LIBCXX_PATH=$PWD/$(ls -d libcxx-*)"
+  '' + stdenv.lib.optionalString stdenv.isDarwin ''
+    export TRIPLE=x86_64-apple-darwin
+  '';
+
+  installPhase = if stdenv.isDarwin
+    then ''
+      for file in lib/*.dylib; do
+        # this should be done in CMake, but having trouble figuring out
+        # the magic combination of necessary CMake variables
+        # if you fancy a try, take a look at
+        # http://www.cmake.org/Wiki/CMake_RPATH_handling
+        install_name_tool -id $out/$file $file
+      done
+      make install
+      install -d 755 $out/include
+      install -m 644 ../include/*.h $out/include
+    ''
+    else ''
+      install -d -m 755 $out/include $out/lib
+      install -m 644 lib/libc++abi.so.1.0 $out/lib
+      install -m 644 ../include/cxxabi.h $out/include
+      ln -s libc++abi.so.1.0 $out/lib/libc++abi.so
+      ln -s libc++abi.so.1.0 $out/lib/libc++abi.so.1
+    '';
+
+  meta = {
+    homepage = http://libcxxabi.llvm.org/;
+    description = "A new implementation of low level support for a standard C++ library";
+    license = with stdenv.lib.licenses; [ ncsa mit ];
+    maintainers = with stdenv.lib.maintainers; [ vlstill ];
+    platforms = stdenv.lib.platforms.unix;
+  };
+}
diff --git a/pkgs/development/compilers/llvm/5/lld.nix b/pkgs/development/compilers/llvm/5/lld.nix
new file mode 100644
index 000000000000..f19a9afc8044
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/lld.nix
@@ -0,0 +1,33 @@
+{ stdenv
+, fetch
+, cmake
+, zlib
+, llvm
+, python
+, version
+}:
+
+stdenv.mkDerivation {
+  name = "lld-${version}";
+
+  src = fetch "lld" "15rqsmfw0jlsri7hszbs8l0j7v1030cy9xvvdb245397llh7k6ir";
+
+  nativeBuildInputs = [ cmake ];
+  buildInputs = [ llvm ];
+
+  outputs = [ "out" "dev" ];
+
+  enableParallelBuilding = true;
+
+  postInstall = ''
+    moveToOutput include "$dev"
+    moveToOutput lib "$dev"
+  '';
+
+  meta = {
+    description = "The LLVM Linker";
+    homepage    = http://lld.llvm.org/;
+    license     = stdenv.lib.licenses.ncsa;
+    platforms   = stdenv.lib.platforms.all;
+  };
+}
diff --git a/pkgs/development/compilers/llvm/5/lldb.nix b/pkgs/development/compilers/llvm/5/lldb.nix
new file mode 100644
index 000000000000..fac23b290bcb
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/lldb.nix
@@ -0,0 +1,51 @@
+{ stdenv
+, fetch
+, cmake
+, zlib
+, ncurses
+, swig
+, which
+, libedit
+, libxml2
+, llvm
+, clang-unwrapped
+, python
+, version
+, darwin
+}:
+
+stdenv.mkDerivation {
+  name = "lldb-${version}";
+
+  src = fetch "lldb" "0zcbav39srf6awv9znvzr7nqdrj704i8da3wdgc8362y20rcm860";
+
+  postPatch = ''
+    # Fix up various paths that assume llvm and clang are installed in the same place
+    sed -i 's,".*ClangConfig.cmake","${clang-unwrapped}/lib/cmake/clang/ClangConfig.cmake",' \
+      cmake/modules/LLDBStandalone.cmake
+    sed -i 's,".*tools/clang/include","${clang-unwrapped}/include",' \
+      cmake/modules/LLDBStandalone.cmake
+    sed -i 's,"$.LLVM_LIBRARY_DIR.",${llvm}/lib ${clang-unwrapped}/lib,' \
+      cmake/modules/LLDBStandalone.cmake
+  '';
+
+  nativeBuildInputs = [ cmake python which swig ];
+  buildInputs = [ ncurses zlib libedit libxml2 llvm ]
+    ++ stdenv.lib.optionals stdenv.isDarwin [ darwin.libobjc darwin.apple_sdk.libs.xpc darwin.apple_sdk.frameworks.Foundation darwin.bootstrap_cmds darwin.apple_sdk.frameworks.Carbon darwin.apple_sdk.frameworks.Cocoa ];
+
+  CXXFLAGS = "-fno-rtti";
+  hardeningDisable = [ "format" ];
+
+  cmakeFlags = [
+    "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic
+  ];
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "A next-generation high-performance debugger";
+    homepage    = http://llvm.org/;
+    license     = licenses.ncsa;
+    platforms   = platforms.all;
+  };
+}
diff --git a/pkgs/development/compilers/llvm/5/llvm-outputs.patch b/pkgs/development/compilers/llvm/5/llvm-outputs.patch
new file mode 100644
index 000000000000..40096fa3497f
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/llvm-outputs.patch
@@ -0,0 +1,26 @@
+diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
+index 94d426b..37f7794 100644
+--- a/tools/llvm-config/llvm-config.cpp
++++ b/tools/llvm-config/llvm-config.cpp
+@@ -333,6 +333,21 @@ int main(int argc, char **argv) {
+     ActiveIncludeOption = "-I" + ActiveIncludeDir;
+   }
+ 
++  /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared
++  if (!IsInDevelopmentTree) {
++    bool WantShared = true;
++    for (int i = 1; i < argc; ++i) {
++      StringRef Arg = argv[i];
++      if (Arg == "--link-shared")
++        WantShared = true;
++      else if (Arg == "--link-static")
++        WantShared = false; // the last one wins
++    }
++
++    if (WantShared)
++      ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
++  }
++
+   /// We only use `shared library` mode in cases where the static library form
+   /// of the components provided are not available; note however that this is
+   /// skipped if we're run from within the build dir. However, once installed,
diff --git a/pkgs/development/compilers/llvm/5/llvm.nix b/pkgs/development/compilers/llvm/5/llvm.nix
new file mode 100644
index 000000000000..520e42c33604
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/llvm.nix
@@ -0,0 +1,155 @@
+{ stdenv
+, fetch
+, fetchpatch
+, perl
+, groff
+, cmake
+, python
+, libffi
+, libbfd
+, libxml2
+, valgrind
+, ncurses
+, version
+, release_version
+, zlib
+, compiler-rt_src
+, libcxxabi
+, debugVersion ? false
+, enableManpages ? false
+, enableSharedLibraries ? true
+, darwin
+}:
+
+let
+  src = fetch "llvm" "1nin64vz21hyng6jr19knxipvggaqlkl2l9jpd5czbc4c2pcnpg3";
+
+  # Used when creating a version-suffixed symlink of libLLVM.dylib
+  shortVersion = with stdenv.lib;
+    concatStringsSep "." (take 2 (splitString "." release_version));
+in stdenv.mkDerivation rec {
+  name = "llvm-${version}";
+
+  unpackPhase = ''
+    unpackFile ${src}
+    mv llvm-${version}* llvm
+    sourceRoot=$PWD/llvm
+    unpackFile ${compiler-rt_src}
+    mv compiler-rt-* $sourceRoot/projects/compiler-rt
+  '';
+
+  outputs = [ "out" ]
+    ++ stdenv.lib.optional enableSharedLibraries "lib"
+    ++ stdenv.lib.optional enableManpages "man";
+
+  nativeBuildInputs = [ perl groff cmake python ]
+    ++ stdenv.lib.optional enableManpages python.pkgs.sphinx;
+
+  buildInputs = [ libxml2 libffi ]
+    ++ stdenv.lib.optionals stdenv.isDarwin [ libcxxabi ];
+
+  propagatedBuildInputs = [ ncurses zlib ];
+
+  # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
+  # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
+  # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd
+  # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by
+  # a flag and turn the flag off during the stdenv build.
+  postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
+    substituteInPlace ./projects/compiler-rt/cmake/config-ix.cmake \
+      --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
+
+    substituteInPlace cmake/modules/AddLLVM.cmake \
+      --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir INSTALL_NAME_DIR "$lib/lib")" \
+      --replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' ""
+  ''
+  # Patch llvm-config to return correct library path based on --link-{shared,static}.
+  + stdenv.lib.optionalString (enableSharedLibraries) ''
+    substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
+    patch -p1 < ./llvm-outputs.patch
+  '' + ''
+    # FileSystem permissions tests fail with various special bits
+    substituteInPlace unittests/Support/CMakeLists.txt \
+      --replace "Path.cpp" ""
+    rm unittests/Support/Path.cpp
+
+    # Revert compiler-rt commit that makes codesign mandatory
+    patch -p1 -i ${./compiler-rt-codesign.patch} -d projects/compiler-rt
+  '';
+
+  # hacky fix: created binaries need to be run before installation
+  preBuild = ''
+    mkdir -p $out/
+    ln -sv $PWD/lib $out
+  '';
+
+  cmakeFlags = with stdenv; [
+    "-DCMAKE_BUILD_TYPE=${if debugVersion then "Debug" else "Release"}"
+    "-DLLVM_INSTALL_UTILS=ON"  # Needed by rustc
+    "-DLLVM_BUILD_TESTS=ON"
+    "-DLLVM_ENABLE_FFI=ON"
+    "-DLLVM_ENABLE_RTTI=ON"
+    "-DCOMPILER_RT_INCLUDE_TESTS=OFF" # FIXME: requires clang source code
+  ]
+  ++ stdenv.lib.optional enableSharedLibraries
+    "-DLLVM_LINK_LLVM_DYLIB=ON"
+  ++ stdenv.lib.optionals enableManpages [
+    "-DLLVM_BUILD_DOCS=ON"
+    "-DLLVM_ENABLE_SPHINX=ON"
+    "-DSPHINX_OUTPUT_MAN=ON"
+    "-DSPHINX_OUTPUT_HTML=OFF"
+    "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
+  ]
+  ++ stdenv.lib.optional (!isDarwin)
+    "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
+  ++ stdenv.lib.optionals (isDarwin) [
+    "-DLLVM_ENABLE_LIBCXX=ON"
+    "-DCAN_TARGET_i386=false"
+  ];
+
+  postBuild = ''
+    rm -fR $out
+
+    paxmark m bin/{lli,llvm-rtdyld}
+    paxmark m unittests/ExecutionEngine/MCJIT/MCJITTests
+    paxmark m unittests/ExecutionEngine/Orc/OrcJITTests
+    paxmark m unittests/Support/SupportTests
+    paxmark m bin/lli-child-target
+  '';
+
+  preCheck = ''
+    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib
+  '';
+
+  postInstall = stdenv.lib.optionalString enableManpages ''
+    moveToOutput "share/man" "$man"
+  ''
+  + stdenv.lib.optionalString enableSharedLibraries ''
+    moveToOutput "lib/libLLVM-*" "$lib"
+    moveToOutput "lib/libLLVM${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib"
+    substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
+      --replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
+  ''
+  + stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
+    substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
+      --replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
+    ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib
+    ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib
+  '';
+
+  doCheck = stdenv.isLinux && (!stdenv.isi686);
+
+  checkTarget = "check-all";
+
+  enableParallelBuilding = true;
+
+  passthru.src = src;
+
+  meta = {
+    description = "Collection of modular and reusable compiler and toolchain technologies";
+    homepage    = http://llvm.org/;
+    license     = stdenv.lib.licenses.ncsa;
+    maintainers = with stdenv.lib.maintainers; [ lovek323 raskin viric dtzWill ];
+    platforms   = stdenv.lib.platforms.all;
+  };
+}
diff --git a/pkgs/development/compilers/llvm/5/openmp.nix b/pkgs/development/compilers/llvm/5/openmp.nix
new file mode 100644
index 000000000000..9ba42eed2e2e
--- /dev/null
+++ b/pkgs/development/compilers/llvm/5/openmp.nix
@@ -0,0 +1,26 @@
+{ stdenv
+, fetch
+, cmake
+, zlib
+, llvm
+, perl
+, version
+}:
+
+stdenv.mkDerivation {
+  name = "openmp-${version}";
+
+  src = fetch "openmp" "1igplg89bl6k6r9q88hnpcznq3g9lb79w7bix025lwp00ldhivy0";
+
+  nativeBuildInputs = [ cmake perl ];
+  buildInputs = [ llvm ];
+
+  enableParallelBuilding = true;
+
+  meta = {
+    description = "Components required to build an executable OpenMP program";
+    homepage    = http://openmp.llvm.org/;
+    license     = stdenv.lib.licenses.mit;
+    platforms   = stdenv.lib.platforms.all;
+  };
+}
diff --git a/pkgs/development/compilers/microscheme/default.nix b/pkgs/development/compilers/microscheme/default.nix
index 4fd71b748cc2..cfee1b0d8639 100644
--- a/pkgs/development/compilers/microscheme/default.nix
+++ b/pkgs/development/compilers/microscheme/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchzip, vim, avrdude, avrgcclibc, makeWrapper }:
+{ stdenv, fetchzip, vim, avrdude, avrbinutils, avrgcc, avrlibc, makeWrapper }:
 
 stdenv.mkDerivation rec {
   name = "microscheme-${version}";
@@ -10,13 +10,15 @@ stdenv.mkDerivation rec {
     sha256 = "1r3ng4pw1s9yy1h5rafra1rq19d3vmb5pzbpcz1913wz22qdd976";
   };
 
+  # Just a guess
+  propagatedBuildInputs = [ avrlibc ];
   buildInputs = [ makeWrapper vim ];
 
   installPhase = ''
     make install PREFIX=$out
 
     wrapProgram $out/bin/microscheme \
-      --prefix PATH : "${stdenv.lib.makeBinPath [ avrdude avrgcclibc ]}"
+      --prefix PATH : "${stdenv.lib.makeBinPath [ avrdude avrgcc avrbinutils ]}"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/compilers/mono/llvm.nix b/pkgs/development/compilers/mono/llvm.nix
index 1036e43ea941..8e9dcc1dbcb5 100644
--- a/pkgs/development/compilers/mono/llvm.nix
+++ b/pkgs/development/compilers/mono/llvm.nix
@@ -5,7 +5,7 @@
 , cmake
 , python
 , libffi
-, binutils
+, libbfd
 , libxml2
 , valgrind
 , ncurses
@@ -42,7 +42,7 @@ stdenv.mkDerivation rec {
 
   cmakeFlags = with stdenv; [
     "-DLLVM_ENABLE_FFI=ON"
-    "-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include"
+    "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
     "-DCMAKE_CXX_FLAGS=-std=c++11"
   ] ++ stdenv.lib.optional (!isDarwin) "-DBUILD_SHARED_LIBS=ON";
 
diff --git a/pkgs/development/compilers/nasm/default.nix b/pkgs/development/compilers/nasm/default.nix
index eb090e8b38ad..a84c5bbf7605 100644
--- a/pkgs/development/compilers/nasm/default.nix
+++ b/pkgs/development/compilers/nasm/default.nix
@@ -1,18 +1,26 @@
-{ stdenv, fetchurl }:
+{ stdenv, fetchurl, perl }:
 
 stdenv.mkDerivation rec {
   name = "nasm-${version}";
-  version = "2.12.02";
+  version = "2.13.01";
 
   src = fetchurl {
     url = "http://www.nasm.us/pub/nasm/releasebuilds/${version}/${name}.tar.bz2";
-    sha256 = "097318bjxvmffbjfd1k89parc04xf5jfxg2rr93581lccwf8kc00";
+    sha256 = "1ylqs4sqh0paia970v6hpdgq5icxns9zlg21qql232bz1apppy88";
   };
 
+  nativeBuildInputs = [ perl ];
+
+  doCheck = true;
+
+  checkPhase = ''
+    make golden && make test
+  '';
+
   meta = with stdenv.lib; {
     homepage = http://www.nasm.us/;
     description = "An 80x86 and x86-64 assembler designed for portability and modularity";
     platforms = platforms.unix;
-    maintainers = with maintainers; [ pSub ];
+    maintainers = with maintainers; [ pSub willibutz ];
   };
 }
diff --git a/pkgs/development/compilers/neko/default.nix b/pkgs/development/compilers/neko/default.nix
index e90f3af704df..5b90dc7debc1 100644
--- a/pkgs/development/compilers/neko/default.nix
+++ b/pkgs/development/compilers/neko/default.nix
@@ -30,6 +30,9 @@ stdenv.mkDerivation rec {
           + "c6d9c6d796200990b3b6a53a4dc716c9192398e6.patch";
       sha256 = "1pq0qhhb9gbhc3zbgylwp0amhwsz0q0ggpj6v2xgv0hfy7d63rcd";
     })
+    # Glibc 2.26 no longer has xlocale.h, patch backported from upstream commit
+    # e286c8f3301fa443255a3101d14b7392467051b8.
+    ./xlocale-fix.patch
   ];
 
   buildInputs =
diff --git a/pkgs/development/compilers/neko/xlocale-fix.patch b/pkgs/development/compilers/neko/xlocale-fix.patch
new file mode 100644
index 000000000000..f4c53f3a43d6
--- /dev/null
+++ b/pkgs/development/compilers/neko/xlocale-fix.patch
@@ -0,0 +1,59 @@
+commit 31d3ac3d691b2a1b07991e67302fd52b0f409cac
+Author: Andy Li <andy@onthewings.net>
+Date:   Thu Jul 13 13:23:33 2017 +0800
+
+    include xlocale.h only if it is available since it is removed in recent glibc
+    
+    see: https://bugzilla.redhat.com/show_bug.cgi?id=1464244
+    
+    (Backported from e286c8f3301fa443255a3101d14b7392467051b8)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 8de1702..d64cab9 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -1,5 +1,6 @@
+ cmake_minimum_required(VERSION 2.8.7)
+ 
++include(CheckIncludeFile)
+ project(neko C)
+ 
+ set(CMAKE_OSX_ARCHITECTURES x86_64)
+@@ -48,6 +49,8 @@ set(NEKO_VERSION_MAJOR 2)
+ set(NEKO_VERSION_MINOR 1)
+ set(NEKO_VERSION_PATCH 0)
+ 
++check_include_file(xlocale.h HAVE_XLOCALE_H)
++
+ configure_file (
+ 	"${CMAKE_SOURCE_DIR}/vm/neko.h.in"
+ 	"${CMAKE_BINARY_DIR}/neko.h"
+diff --git a/libs/std/sys.c b/libs/std/sys.c
+index 8003d41..ae0cfee 100644
+--- a/libs/std/sys.c
++++ b/libs/std/sys.c
+@@ -41,7 +41,11 @@
+ #	include <sys/time.h>
+ #	include <sys/times.h>
+ #	include <sys/wait.h>
++#ifdef HAVE_XLOCALE_H
+ #	include <xlocale.h>
++#else
++#	include <locale.h>
++#endif
+ #endif
+ 
+ #ifdef NEKO_MAC
+diff --git a/vm/neko.h.in b/vm/neko.h.in
+index bb9ec1b..147ecce 100644
+--- a/vm/neko.h.in
++++ b/vm/neko.h.in
+@@ -88,6 +88,8 @@
+ #	include <stdint.h>
+ #endif
+ 
++#cmakedefine HAVE_XLOCALE_H
++
+ #define NEKO_VERSION_MAJOR	@NEKO_VERSION_MAJOR@
+ #define NEKO_VERSION_MINOR	@NEKO_VERSION_MINOR@
+ #define NEKO_VERSION_PATCH	@NEKO_VERSION_PATCH@
diff --git a/pkgs/development/compilers/nim/default.nix b/pkgs/development/compilers/nim/default.nix
index 101f8ab64ba5..fde4861e982f 100644
--- a/pkgs/development/compilers/nim/default.nix
+++ b/pkgs/development/compilers/nim/default.nix
@@ -2,11 +2,11 @@
 
 stdenv.mkDerivation rec {
   name = "nim-${version}";
-  version = "0.17.0";
+  version = "0.17.2";
 
   src = fetchurl {
     url = "http://nim-lang.org/download/${name}.tar.xz";
-    sha256 = "16vsmk4rqnkg9lc9h9jk62ps0x778cdqg6qrs3k6fv2g73cqvq9n";
+    sha256 = "1gc2xk3ygmz9y4pm75pligssgw995a7gvnfpy445fjpw4d81pzxa";
   };
 
   doCheck = true;
diff --git a/pkgs/development/compilers/obliv-c/default.nix b/pkgs/development/compilers/obliv-c/default.nix
index f1f9a38a198f..f5bc00118a61 100644
--- a/pkgs/development/compilers/obliv-c/default.nix
+++ b/pkgs/development/compilers/obliv-c/default.nix
@@ -1,15 +1,21 @@
-{stdenv, fetchurl, ocaml, libgcrypt, fetchFromGitHub, ocamlPackages, perl}:
+{ stdenv, fetchurl, libgcrypt, fetchFromGitHub, ocamlPackages, perl }:
 stdenv.mkDerivation rec {
   name = "obliv-c-${version}";
-  version = "0.0pre20161001";
-  buildInputs = [ ocaml ocamlPackages.findlib perl ];
+  version = "0.0pre20170827";
+  buildInputs = [ perl ]
+  ++ (with ocamlPackages; [ ocaml findlib ocamlbuild ]);
   propagatedBuildInputs = [ libgcrypt ];
   src = fetchFromGitHub {
     owner = "samee";
     repo = "obliv-c";
-    rev = "32d71fb46983aded604045e8cda7874d8fb160a2";
-    sha256 = "05bicvalsfabngvf41q02bcyzkibmyihj7naqd53kdq75xa1yf37";
+    rev = "9a6be5a5f44d341bc357055e11922f6a4c4c3b65";
+    sha256 = "0jz2ayadx62zv2b5ji947bkvw63axl4a2q70lwli86zgmcl390gf";
   };
+
+  preBuild = ''
+    patchShebangs .
+  '';
+
   preInstall = ''
     mkdir -p "$out/bin"
     cp bin/* "$out/bin"
@@ -23,6 +29,7 @@ stdenv.mkDerivation rec {
     gcc $(ar t _build/libobliv.a | sed -e 's@^@_build/@') --shared -o _build/libobliv.so
     cp _build/lib*.a _build/lib*.so* "$out/lib"
   '';
+
   meta = {
     inherit version;
     description = ''A GCC wrapper that makes it easy to embed secure computation protocols inside regular C programs'';
diff --git a/pkgs/development/compilers/ocaml/4.06.nix b/pkgs/development/compilers/ocaml/4.06.nix
new file mode 100644
index 000000000000..b913d169e97a
--- /dev/null
+++ b/pkgs/development/compilers/ocaml/4.06.nix
@@ -0,0 +1,9 @@
+import ./generic.nix {
+  major_version = "4";
+  minor_version = "06";
+  patch_version = "0";
+  sha256 = "1dy542yfnnw10zvh5s9qzswliq11mg7l0bcyss3501qw3vwvadhj";
+
+  # If the executable is stipped it does not work
+  dontStrip = true;
+}
diff --git a/pkgs/development/compilers/opa/default.nix b/pkgs/development/compilers/opa/default.nix
index 9501b5a3a06e..7b9e00b105db 100644
--- a/pkgs/development/compilers/opa/default.nix
+++ b/pkgs/development/compilers/opa/default.nix
@@ -44,7 +44,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ which perl jdk openssl coreutils zlib ncurses
     makeWrapper gcc binutils gnumake nodejs
   ] ++ (with ocamlPackages; [
-    ocaml findlib ocaml_ssl cryptokit camlzip ulex ocamlgraph camlp4
+    ocaml findlib ssl cryptokit camlzip ulex ocamlgraph camlp4
   ]);
 
   NIX_LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
diff --git a/pkgs/development/compilers/openjdk/8.nix b/pkgs/development/compilers/openjdk/8.nix
index 3355304b3bb2..4499a9126a0c 100644
--- a/pkgs/development/compilers/openjdk/8.nix
+++ b/pkgs/development/compilers/openjdk/8.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, fetchurl, cpio, pkgconfig, file, which, unzip, zip, cups, freetype
+{ stdenv, lib, fetchurl, bash, cpio, pkgconfig, file, which, unzip, zip, cups, freetype
 , alsaLib, bootjdk, cacert, perl, liberation_ttf, fontconfig, zlib, lndir
 , libX11, libICE, libXrender, libXext, libXt, libXtst, libXi, libXinerama, libXcursor
 , libjpeg, giflib
@@ -22,41 +22,41 @@ let
       throw "openjdk requires i686-linux or x86_64 linux";
 
   update = "152";
-  build = "04";
+  build = "16";
   baseurl = "http://hg.openjdk.java.net/jdk8u/jdk8u";
   repover = "jdk8u${update}-b${build}";
   paxflags = if stdenv.isi686 then "msp" else "m";
   jdk8 = fetchurl {
              url = "${baseurl}/archive/${repover}.tar.gz";
-             sha256 = "1hnpbx0v89jmbg58ym4zm255da11zf5jq8y5s58zj4x2z6b1fpxi";
+             sha256 = "12r5v6srwbm5hcfwz5kib7419a72cppls1d1xkrh5pjlina74zpf";
           };
   langtools = fetchurl {
              url = "${baseurl}/langtools/archive/${repover}.tar.gz";
-             sha256 = "060q01msfyspn14c9mkf9x0l8sprki9n8zb3cwlgglhnr2d4gfbr";
+             sha256 = "002f0nfw2g3q41iy8cvaqyiglcy1fx9dglgik8gv067c2zslwwqm";
           };
   hotspot = fetchurl {
              url = "${baseurl}/hotspot/archive/${repover}.tar.gz";
-             sha256 = "0705667y6llsmszvdcbhbxzbn1csv1f2rlyghwggx5xnaq46dhx6";
+             sha256 = "0mnck2c3ky4hbcjfy6p3z831dxm1y2fkxq5k94zbswm4wcvlkzia";
           };
   corba = fetchurl {
              url = "${baseurl}/corba/archive/${repover}.tar.gz";
-             sha256 = "13f4h43lw9q1292fymn2d7whwvccpkcqraasdhvzf904101xcpsl";
+             sha256 = "1xl3mc3hd5lwh1bxzck4hw60d678h3mjh144kq90iz8kfi197hpj";
           };
   jdk = fetchurl {
              url = "${baseurl}/jdk/archive/${repover}.tar.gz";
-             sha256 = "16wqinqv0aqyf6jg3nsn6rj5s7ggq82wvx86zm584g56011vkgf6";
+             sha256 = "1hsfgjhp5nrsy4v6c282wq6cv37hgpm8l51cls0rnpbfqvd2cw16";
           };
   jaxws = fetchurl {
              url = "${baseurl}/jaxws/archive/${repover}.tar.gz";
-             sha256 = "0japl4nyb8y3w1mpfpkxn5vkf8fap1rg340vjnb6qm6fpqvl964f";
+             sha256 = "07ispgrzcf39nxs7a9yn6gkbq0ygdzlzyq32sfk57w6vy1mrgwjh";
           };
   jaxp = fetchurl {
              url = "${baseurl}/jaxp/archive/${repover}.tar.gz";
-             sha256 = "024zphx9r92ws9xjihvhyrbbbamfl7js0s24ff577v5z5gdb1lly";
+             sha256 = "1kj5w6gk579wh1iszq2bn6k1ib7kjpjf1lp46p5rqkx0qin79sn9";
           };
   nashorn = fetchurl {
              url = "${baseurl}/nashorn/archive/${repover}.tar.gz";
-             sha256 = "1crnbjjv1s6ndqpllcrggcpsxvqcnpr58zp51y0hjz3m3gpsxwcq";
+             sha256 = "1j9r5r8rihp02n0ciwqr01c07d91z1hs0069rd8hk6i03dkkhk84";
           };
   openjdk8 = stdenv.mkDerivation {
     name = "openjdk-8u${update}b${build}";
@@ -75,11 +75,14 @@ let
       gtk2 gnome_vfs GConf glib
     ];
 
+    #move the seven other source dirs under the main jdk8u directory,
+    #with version suffixes removed, as the remainder of the build will expect
     prePatch = ''
-      ls | grep jdk | grep -v '^jdk8u' | awk -F- '{print $1}' | while read p; do
-        mv $p-* $(ls | grep '^jdk8u')/$p
+      mainDir=$(find . -maxdepth 1 -name jdk8u\*);
+      find . -maxdepth 1 -name \*jdk\* -not -name jdk8u\* | awk -F- '{print $1}' | while read p; do
+        mv $p-* $mainDir/$p
       done
-      cd $(ls | grep '^jdk8u')
+      cd $mainDir
     '';
 
     patches = [
@@ -95,13 +98,14 @@ let
 
     preConfigure = ''
       chmod +x configure
-      substituteInPlace configure --replace /bin/bash "$shell"
+      substituteInPlace configure --replace /bin/bash "${bash}/bin/bash"
       substituteInPlace hotspot/make/linux/adlc_updater --replace /bin/sh "$shell"
       substituteInPlace hotspot/make/linux/makefiles/dtrace.make --replace /usr/include/sys/sdt.h "/no-such-path"
     ''
     # https://bugzilla.redhat.com/show_bug.cgi?id=1306558
+    # https://github.com/JetBrains/jdk8u/commit/eaa5e0711a43d64874111254d74893fa299d5716
     + stdenv.lib.optionalString stdenv.cc.isGNU ''
-      NIX_CFLAGS_COMPILE+=" -fno-lifetime-dse -fno-delete-null-pointer-checks"
+      NIX_CFLAGS_COMPILE+=" -fno-lifetime-dse -fno-delete-null-pointer-checks -std=gnu++98 -Wno-error"
     '';
 
     configureFlags = [
@@ -187,10 +191,11 @@ let
       done
 
       # Generate certificates.
-      pushd $jre/lib/openjdk/jre/lib/security
-      rm cacerts
-      perl ${./generate-cacerts.pl} $jre/lib/openjdk/jre/bin/keytool ${cacert}/etc/ssl/certs/ca-bundle.crt
-      popd
+      (
+        cd $jre/lib/openjdk/jre/lib/security
+        rm cacerts
+        perl ${./generate-cacerts.pl} $jre/lib/openjdk/jre/bin/keytool ${cacert}/etc/ssl/certs/ca-bundle.crt
+      )
 
       ln -s $out/lib/openjdk/bin $out/bin
       ln -s $jre/lib/openjdk/jre/bin $jre/bin
@@ -220,13 +225,13 @@ let
       # Build the set of output library directories to rpath against
       LIBDIRS=""
       for output in $outputs; do
-        LIBDIRS="$(find $(eval echo \$$output) -name \*.so\* -exec dirname {} \; | sort | uniq | tr '\n' ':'):$LIBDIRS"
+        LIBDIRS="$(find $(eval echo \$$output) -name \*.so\* -exec dirname {} \+ | sort | uniq | tr '\n' ':'):$LIBDIRS"
       done
 
       # Add the local library paths to remove dependencies on the bootstrap
       for output in $outputs; do
-        OUTPUTDIR="$(eval echo \$$output)"
-        BINLIBS="$(find $OUTPUTDIR/bin/ -type f; find $OUTPUTDIR -name \*.so\*)"
+        OUTPUTDIR=$(eval echo \$$output)
+        BINLIBS=$(find $OUTPUTDIR/bin/ -type f; find $OUTPUTDIR -name \*.so\*)
         echo "$BINLIBS" | while read i; do
           patchelf --set-rpath "$LIBDIRS:$(patchelf --print-rpath "$i")" "$i" || true
           patchelf --shrink-rpath "$i" || true
@@ -246,7 +251,7 @@ let
       homepage = http://openjdk.java.net/;
       license = licenses.gpl2;
       description = "The open-source Java Development Kit";
-      maintainers = with maintainers; [ edwtjo ];
+      maintainers = with maintainers; [ edwtjo nequissimus ];
       platforms = platforms.linux;
     };
 
diff --git a/pkgs/development/compilers/openjdk/9.nix b/pkgs/development/compilers/openjdk/9.nix
new file mode 100644
index 000000000000..ce556a32c11d
--- /dev/null
+++ b/pkgs/development/compilers/openjdk/9.nix
@@ -0,0 +1,262 @@
+{ stdenv, lib, fetchurl, bash, cpio, pkgconfig, file, which, unzip, zip, cups, freetype
+, alsaLib, bootjdk, cacert, perl, liberation_ttf, fontconfig, zlib, lndir
+, libX11, libICE, libXrender, libXext, libXt, libXtst, libXi, libXinerama, libXcursor
+, libjpeg, giflib
+, setJavaClassPath
+, minimal ? false
+#, enableInfinality ? true # font rendering patch
+, enableGnome2 ? true, gtk2, gnome_vfs, glib, GConf
+}:
+
+let
+
+  /**
+   * The JRE libraries are in directories that depend on the CPU.
+   */
+  architecture =
+    if stdenv.system == "i686-linux" then
+      "i386"
+    else if stdenv.system == "x86_64-linux" then
+      "amd64"
+    else
+      throw "openjdk requires i686-linux or x86_64 linux";
+
+  update = "";
+  build = "181";
+  baseurl = "http://hg.openjdk.java.net/jdk9/jdk9";
+  repover = "jdk-9${update}+${build}";
+  paxflags = if stdenv.isi686 then "msp" else "m";
+  jdk9 = fetchurl {
+             url = "${baseurl}/archive/${repover}.tar.gz";
+             sha256 = "0c7jwz4qvl93brs6c2v4dfc2v3lsv6ic0y72lkh04bnxg9343z82";
+          };
+  langtools = fetchurl {
+             url = "${baseurl}/langtools/archive/${repover}.tar.gz";
+             sha256 = "1wa5rjan6lcs8nnxndbwpw6gkx3qbw013s6zisjjczkcaiq044pp";
+          };
+  hotspot = fetchurl {
+             url = "${baseurl}/hotspot/archive/${repover}.tar.gz";
+             sha256 = "00jnj19rim1gxpsxrpr8ifx1glwrbma3qjiy1ya7n5f08fb263hs";
+          };
+  corba = fetchurl {
+             url = "${baseurl}/corba/archive/${repover}.tar.gz";
+             sha256 = "1gvx6dblzj7rb8648iqwdiv36x97ibykgs323dd9044n3vbqihvj";
+          };
+  jdk = fetchurl {
+             url = "${baseurl}/jdk/archive/${repover}.tar.gz";
+             sha256 = "15pwdw6s03rfyw2gx06xg4f70bjl8j19ycssxiigj39h524xc9aw";
+          };
+  jaxws = fetchurl {
+             url = "${baseurl}/jaxws/archive/${repover}.tar.gz";
+             sha256 = "0jz32pjbgr77ybb2v1vwr1n9ljdrc3y0d5lrj072g3is1hmn2wbh";
+          };
+  jaxp = fetchurl {
+             url = "${baseurl}/jaxp/archive/${repover}.tar.gz";
+             sha256 = "1jdxr9hcqx6va56ll5s2x9bx9dnlrs7zyvhjk1zgr5hxg5yfcqzr";
+          };
+  nashorn = fetchurl {
+             url = "${baseurl}/nashorn/archive/${repover}.tar.gz";
+             sha256 = "12lihmw9ga6yhz0h26fvfablcjkkma0k3idjggmap97xha8zgd6n";
+          };
+  openjdk9 = stdenv.mkDerivation {
+    name = "openjdk-9${update}-b${build}";
+
+    srcs = [ jdk9 langtools hotspot corba jdk jaxws jaxp nashorn ];
+    sourceRoot = ".";
+
+    outputs = [ "out" "jre" ];
+
+    nativeBuildInputs = [ pkgconfig ];
+    buildInputs = [
+      cpio file which unzip zip perl bootjdk zlib cups freetype alsaLib
+      libjpeg giflib libX11 libICE libXext libXrender libXtst libXt libXtst
+      libXi libXinerama libXcursor lndir fontconfig
+    ] ++ lib.optionals (!minimal && enableGnome2) [
+      gtk2 gnome_vfs GConf glib
+    ];
+
+    #move the seven other source dirs under the main jdk8u directory,
+    #with version suffixes removed, as the remainder of the build will expect
+    prePatch = ''
+      mainDir=$(find . -maxdepth 1 -name jdk9\*);
+      find . -maxdepth 1 -name \*jdk\* -not -name jdk9\* | awk -F- '{print $1}' | while read p; do
+        mv $p-* $mainDir/$p
+      done
+      cd $mainDir
+    '';
+
+    patches = [
+      ./fix-java-home-jdk9.patch
+      ./read-truststore-from-env-jdk9.patch
+      ./currency-date-range-jdk8.patch
+    #] ++ lib.optionals (!minimal && enableInfinality) [
+    #  ./004_add-fontconfig.patch
+    #  ./005_enable-infinality.patch
+    ] ++ lib.optionals (!minimal && enableGnome2) [
+      ./swing-use-gtk-jdk9.patch
+    ];
+
+    preConfigure = ''
+      chmod +x configure
+      substituteInPlace configure --replace /bin/bash "${bash}/bin/bash"
+
+      configureFlagsArray=(
+        "--with-boot-jdk=${bootjdk.home}"
+        "--with-update-version=${update}"
+        "--with-build-number=${build}"
+        "--with-milestone=fcs"
+        "--enable-unlimited-crypto"
+        "--disable-debug-symbols"
+        "--disable-freetype-bundling"
+        "--with-zlib=system"
+        "--with-giflib=system"
+        "--with-stdc++lib=dynamic"
+
+        # glibc 2.24 deprecated readdir_r so we need this
+        # See https://www.mail-archive.com/openembedded-devel@lists.openembedded.org/msg49006.html
+        "--with-extra-cflags=-Wno-error=deprecated-declarations -Wno-error=format-contains-nul -Wno-error=unused-result"
+    ''
+    + lib.optionalString minimal "\"--enable-headless-only\""
+    + ");"
+    # https://bugzilla.redhat.com/show_bug.cgi?id=1306558
+    # https://github.com/JetBrains/jdk8u/commit/eaa5e0711a43d64874111254d74893fa299d5716
+    + stdenv.lib.optionalString stdenv.cc.isGNU ''
+      NIX_CFLAGS_COMPILE+=" -fno-lifetime-dse -fno-delete-null-pointer-checks -std=gnu++98 -Wno-error"
+    '';
+
+    NIX_LDFLAGS= lib.optionals (!minimal) [
+      "-lfontconfig" "-lcups" "-lXinerama" "-lXrandr" "-lmagic"
+    ] ++ lib.optionals (!minimal && enableGnome2) [
+      "-lgtk-x11-2.0" "-lgio-2.0" "-lgnomevfs-2" "-lgconf-2"
+    ];
+
+    buildFlags = [ "all" ];
+
+    installPhase = ''
+      mkdir -p $out/lib/openjdk $out/share $jre/lib/openjdk
+
+      cp -av build/*/images/jdk/* $out/lib/openjdk
+
+      # Remove some broken manpages.
+      rm -rf $out/lib/openjdk/man/ja*
+
+      # Mirror some stuff in top-level.
+      mkdir $out/include $out/share/man
+      ln -s $out/lib/openjdk/include/* $out/include/
+      ln -s $out/lib/openjdk/man/* $out/share/man/
+
+      # jni.h expects jni_md.h to be in the header search path.
+      ln -s $out/include/linux/*_md.h $out/include/
+
+      # Copy the JRE to a separate output and setup fallback fonts
+      cp -av build/*/images/jre $jre/lib/openjdk/
+      mkdir $out/lib/openjdk/jre
+      ${lib.optionalString (!minimal) ''
+        mkdir -p $jre/lib/openjdk/jre/lib/fonts/fallback
+        lndir ${liberation_ttf}/share/fonts/truetype $jre/lib/openjdk/jre/lib/fonts/fallback
+      ''}
+
+      # Remove crap from the installation.
+      rm -rf $out/lib/openjdk/demo
+      ${lib.optionalString minimal ''
+        for d in $out/lib/openjdk/lib $jre/lib/openjdk/jre/lib; do
+          rm ''${d}/{libjsound,libjsoundalsa,libawt*,libfontmanager}.so
+        done
+      ''}
+
+      lndir $jre/lib/openjdk/jre $out/lib/openjdk/jre
+
+      # Make sure cmm/*.pf are not symlinks:
+      # https://youtrack.jetbrains.com/issue/IDEA-147272
+      # in 9, it seems no *.pf files end up in $out ... ?
+      # rm -rf $out/lib/openjdk/jre/lib/cmm
+      # ln -s {$jre,$out}/lib/openjdk/jre/lib/cmm
+
+      # Set PaX markings
+      exes=$(file $out/lib/openjdk/bin/* $jre/lib/openjdk/jre/bin/* 2> /dev/null | grep -E 'ELF.*(executable|shared object)' | sed -e 's/: .*$//')
+      echo "to mark: *$exes*"
+      for file in $exes; do
+        echo "marking *$file*"
+        paxmark ${paxflags} "$file"
+      done
+
+      # Remove duplicate binaries.
+      for i in $(cd $out/lib/openjdk/bin && echo *); do
+        if [ "$i" = java ]; then continue; fi
+        if cmp -s $out/lib/openjdk/bin/$i $jre/lib/openjdk/jre/bin/$i; then
+          ln -sfn $jre/lib/openjdk/jre/bin/$i $out/lib/openjdk/bin/$i
+        fi
+      done
+
+      # Generate certificates.
+      (
+        cd $jre/lib/openjdk/jre/lib/security
+        rm cacerts
+        perl ${./generate-cacerts.pl} $jre/lib/openjdk/jre/bin/keytool ${cacert}/etc/ssl/certs/ca-bundle.crt
+      )
+
+      ln -s $out/lib/openjdk/bin $out/bin
+      ln -s $jre/lib/openjdk/jre/bin $jre/bin
+      ln -s $jre/lib/openjdk/jre $out/jre
+    '';
+
+    # FIXME: this is unnecessary once the multiple-outputs branch is merged.
+    preFixup = ''
+      prefix=$jre stripDirs "$stripDebugList" "''${stripDebugFlags:--S}"
+      patchELF $jre
+      propagatedNativeBuildInputs+=" $jre"
+
+      # Propagate the setJavaClassPath setup hook from the JRE so that
+      # any package that depends on the JRE has $CLASSPATH set up
+      # properly.
+      mkdir -p $jre/nix-support
+      #TODO or printWords?  cf https://github.com/NixOS/nixpkgs/pull/27427#issuecomment-317293040
+      echo -n "${setJavaClassPath}" > $jre/nix-support/propagated-native-build-inputs
+
+      # Set JAVA_HOME automatically.
+      mkdir -p $out/nix-support
+      cat <<EOF > $out/nix-support/setup-hook
+      if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out/lib/openjdk; fi
+      EOF
+    '';
+
+    postFixup = ''
+      # Build the set of output library directories to rpath against
+      LIBDIRS=""
+      for output in $outputs; do
+        LIBDIRS="$(find $(eval echo \$$output) -name \*.so\* -exec dirname {} \+ | sort | uniq | tr '\n' ':'):$LIBDIRS"
+      done
+
+      # Add the local library paths to remove dependencies on the bootstrap
+      for output in $outputs; do
+        OUTPUTDIR=$(eval echo \$$output)
+        BINLIBS=$(find $OUTPUTDIR/bin/ -type f; find $OUTPUTDIR -name \*.so\*)
+        echo "$BINLIBS" | while read i; do
+          patchelf --set-rpath "$LIBDIRS:$(patchelf --print-rpath "$i")" "$i" || true
+          patchelf --shrink-rpath "$i" || true
+        done
+      done
+
+      # Test to make sure that we don't depend on the bootstrap
+      for output in $outputs; do
+        if grep -q -r '${bootjdk}' $(eval echo \$$output); then
+          echo "Extraneous references to ${bootjdk} detected"
+          exit 1
+        fi
+      done
+    '';
+
+    meta = with stdenv.lib; {
+      homepage = http://openjdk.java.net/;
+      license = licenses.gpl2;
+      description = "The open-source Java Development Kit";
+      maintainers = with maintainers; [ edwtjo ];
+      platforms = platforms.linux;
+    };
+
+    passthru = {
+      inherit architecture;
+      home = "${openjdk9}/lib/openjdk";
+    };
+  };
+in openjdk9
diff --git a/pkgs/development/compilers/openjdk/fix-java-home-jdk9.patch b/pkgs/development/compilers/openjdk/fix-java-home-jdk9.patch
new file mode 100644
index 000000000000..f9755d58e48f
--- /dev/null
+++ b/pkgs/development/compilers/openjdk/fix-java-home-jdk9.patch
@@ -0,0 +1,14 @@
+--- a/hotspot/src/os/linux/vm/os_linux.cpp	2017-07-04 23:09:02.533972226 -0400
++++ b/hotspot/src/os/linux/vm/os_linux.cpp	2017-07-04 23:07:52.118338845 -0400
+@@ -2318,10 +2318,7 @@
+   assert(ret, "cannot locate libjvm");
+   char *rp = NULL;
+   if (ret && dli_fname[0] != '\0') {
+-    rp = realpath(dli_fname, buf);
+-  }
+-  if (rp == NULL) {
+-    return;
++    snprintf(buf, buflen, "%s", dli_fname);
+   }
+ 
+   if (Arguments::sun_java_launcher_is_altjvm()) {
diff --git a/pkgs/development/compilers/openjdk/read-truststore-from-env-jdk9.patch b/pkgs/development/compilers/openjdk/read-truststore-from-env-jdk9.patch
new file mode 100644
index 000000000000..cb8d59ff8063
--- /dev/null
+++ b/pkgs/development/compilers/openjdk/read-truststore-from-env-jdk9.patch
@@ -0,0 +1,20 @@
+--- a/jdk/src/java.base/share/classes/sun/security/ssl/TrustStoreManager.java	2017-06-26 21:48:25.000000000 -0400
++++ b/jdk/src/java.base/share/classes/sun/security/ssl/TrustStoreManager.java.new	2017-07-05 20:45:57.491295030 -0400
+@@ -71,6 +71,7 @@
+      *
+      * The preference of the default trusted KeyStore is:
+      *    javax.net.ssl.trustStore
++     *    system environment variable JAVAX_NET_SSL_TRUSTSTORE
+      *    jssecacerts
+      *    cacerts
+      */
+@@ -144,6 +145,9 @@
+                     String temporaryName = "";
+                     File temporaryFile = null;
+                     long temporaryTime = 0L;
++                    if (storePropName == null){
++                        storePropName = System.getenv("JAVAX_NET_SSL_TRUSTSTORE");
++                    }
+                     if (!"NONE".equals(storePropName)) {
+                         String[] fileNames =
+                                 new String[] {storePropName, defaultStore};
diff --git a/pkgs/development/compilers/openjdk/swing-use-gtk-jdk9.patch b/pkgs/development/compilers/openjdk/swing-use-gtk-jdk9.patch
new file mode 100644
index 000000000000..07d95ba71b8a
--- /dev/null
+++ b/pkgs/development/compilers/openjdk/swing-use-gtk-jdk9.patch
@@ -0,0 +1,26 @@
+diff -ru3 a/jdk/src/share/classes/javax/swing/UIManager.java b/jdk/src/share/classes/javax/swing/UIManager.java
+--- a/jdk/src/java.desktop/share/classes/javax/swing/UIManager.java	2016-07-26 00:41:37.000000000 +0300
++++ b/jdk/src/java.desktop/share/classes/javax/swing/UIManager.java	2016-10-02 22:46:01.890071761 +0300
+@@ -607,11 +607,9 @@
+         if (osType == OSInfo.OSType.WINDOWS) {
+             return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
+         } else {
+-            String desktop = AccessController.doPrivileged(new GetPropertyAction("sun.desktop"));
+             Toolkit toolkit = Toolkit.getDefaultToolkit();
+-            if ("gnome".equals(desktop) &&
+-                    toolkit instanceof SunToolkit &&
+-                    ((SunToolkit) toolkit).isNativeGTKAvailable()) {
++            if (toolkit instanceof SunToolkit &&
++                    ((SunToolkit) toolkit).isNativeGTKAvailable()) {
+                 // May be set on Linux and Solaris boxs.
+                 return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
+             }
+@@ -1341,7 +1339,7 @@
+             lafName = (String) lafData.remove("defaultlaf");
+         }
+         if (lafName == null) {
+-            lafName = getCrossPlatformLookAndFeelClassName();
++            lafName = getSystemLookAndFeelClassName();
+         }
+         lafName = swingProps.getProperty(defaultLAFKey, lafName);
+ 
diff --git a/pkgs/development/compilers/oraclejdk/jdk8cpu-linux.nix b/pkgs/development/compilers/oraclejdk/jdk8cpu-linux.nix
index 0d12b3ac89b0..f8f37160a26f 100644
--- a/pkgs/development/compilers/oraclejdk/jdk8cpu-linux.nix
+++ b/pkgs/development/compilers/oraclejdk/jdk8cpu-linux.nix
@@ -1,9 +1,9 @@
 import ./jdk-linux-base.nix {
   productVersion = "8";
-  patchVersion = "144";
+  patchVersion = "151";
   downloadUrl = http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html;
-  sha256_i686 = "1i5pginc65xl5vxzwid21ykakmfkqn59v3g01vpr94v28w30jk32";
-  sha256_x86_64 = "1r5axvr8dg2qmr4zjanj73sk9x50m7p0w3vddz8c6ckgav7438z8";
+  sha256_i686 = "0w1snn9hxwvdnk77frhdzbsm6v30v99dy5zmpy8ij7yxd57z6ql0";
+  sha256_x86_64 = "0zq2dxbxmshz080yskhc8y2wbqi0y0kl9girxjbb4rwk837010n7";
   sha256_armv7l = "10r3nyssx8piyjaspravwgj2bnq4537041pn0lz4fk5b3473kgfb";
   jceName = "jce_policy-8.zip";
   jceDownloadUrl = http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html;
diff --git a/pkgs/development/compilers/oraclejdk/jdk8psu-linux.nix b/pkgs/development/compilers/oraclejdk/jdk8psu-linux.nix
index 0d12b3ac89b0..863621bf6b07 100644
--- a/pkgs/development/compilers/oraclejdk/jdk8psu-linux.nix
+++ b/pkgs/development/compilers/oraclejdk/jdk8psu-linux.nix
@@ -1,9 +1,9 @@
 import ./jdk-linux-base.nix {
   productVersion = "8";
-  patchVersion = "144";
+  patchVersion = "152";
   downloadUrl = http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html;
-  sha256_i686 = "1i5pginc65xl5vxzwid21ykakmfkqn59v3g01vpr94v28w30jk32";
-  sha256_x86_64 = "1r5axvr8dg2qmr4zjanj73sk9x50m7p0w3vddz8c6ckgav7438z8";
+  sha256_i686 = "0gjc7kcfx40f43z1w1qsn1fqxdz8d46wml2g11qgm55ishhv2q7w";
+  sha256_x86_64 = "1gv1348hrgna9l3sssv3g9jzs37y1lkx05xq83chav9z1hs3p2r1";
   sha256_armv7l = "10r3nyssx8piyjaspravwgj2bnq4537041pn0lz4fk5b3473kgfb";
   jceName = "jce_policy-8.zip";
   jceDownloadUrl = http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html;
diff --git a/pkgs/development/compilers/oraclejdk/jdk9-linux.nix b/pkgs/development/compilers/oraclejdk/jdk9-linux.nix
new file mode 100644
index 000000000000..fbda96e14258
--- /dev/null
+++ b/pkgs/development/compilers/oraclejdk/jdk9-linux.nix
@@ -0,0 +1,175 @@
+{ swingSupport ? true
+, stdenv
+, requireFile
+, makeWrapper
+, unzip
+, file
+, xorg ? null
+, packageType ? "JDK" # JDK, JRE, or ServerJRE
+, pluginSupport ? true
+, installjce ? false
+, glib
+, libxml2
+, ffmpeg_2
+, libxslt
+, mesa_noglu
+, freetype
+, fontconfig
+, gtk2
+, pango
+, cairo
+, alsaLib
+, atk
+, gdk_pixbuf
+, zlib
+, elfutils
+, setJavaClassPath
+}:
+
+assert stdenv.system == "x86_64-linux";
+assert swingSupport -> xorg != null;
+
+let
+  version = "9.0.1";
+
+  downloadUrlBase = http://www.oracle.com/technetwork/java/javase/downloads;
+
+  jce =
+    if installjce then
+      requireFile {
+        name = "jce_policy-8.zip";
+        url = "${downloadUrlBase}/jce8-download-2133166.html";
+        sha256 = "0n8b6b8qmwb14lllk2lk1q1ahd3za9fnjigz5xn65mpg48whl0pk";
+      }
+    else
+      "";
+
+  rSubPaths = [
+    "lib/jli"
+    "lib/server"
+    "lib"
+  ];
+
+in
+
+let result = stdenv.mkDerivation rec {
+  name = if packageType == "JDK"       then "oraclejdk-${version}"
+    else if packageType == "JRE"       then "oraclejre-${version}"
+    else if packageType == "ServerJRE" then "oracleserverjre-${version}"
+    else abort "unknown package Type ${packageType}";
+
+  src =
+    if packageType == "JDK" then
+      requireFile {
+        name = "jdk-${version}_linux-x64_bin.tar.gz";
+        url =  "${downloadUrlBase}/jdk9-downloads-3848520.html";
+        sha256 = "0560dc3icrwb0ifykshvzkr04b1jr153m26x1r8rp0nhjbzz1nic";
+      }
+    else if packageType == "JRE" then
+      requireFile {
+        name = "jre-${version}_linux-x64_bin.tar.gz";
+        url = "${downloadUrlBase}/jre9-downloads-3848532.html";
+        sha256 = "11pfcck8am48yv7riaj10g6h79xdiy8lm5a9wjqbm3g9cls9ar1w";
+      }
+    else if packageType == "ServerJRE" then
+      requireFile {
+        name = "serverjre-${version}_linux-x64_bin.tar.gz";
+        url = "${downloadUrlBase}/server-jre9-downloads-3848530.html";
+        sha256 = "1biyks6jy0a2kksaj9qbsjifv34ym5mdw8akibmkwr1xh0wavygc";
+      }
+    else abort "unknown package Type ${packageType}";
+
+  nativeBuildInputs = [ file ]
+    ++ stdenv.lib.optional installjce unzip;
+
+  buildInputs = [ makeWrapper ];
+
+  # See: https://github.com/NixOS/patchelf/issues/10
+  dontStrip = 1;
+
+  installPhase = ''
+    cd ..
+
+    # Set PaX markings
+    exes=$(file $sourceRoot/bin/* 2> /dev/null | grep -E 'ELF.*(executable|shared object)' | sed -e 's/: .*$//')
+    for file in $exes; do
+      paxmark m "$file"
+      # On x86 for heap sizes over 700MB disable SEGMEXEC and PAGEEXEC as well.
+      ${stdenv.lib.optionalString stdenv.isi686 ''paxmark msp "$file"''}
+    done
+
+    mv $sourceRoot $out
+
+    shopt -s extglob
+    for file in $out/*
+    do
+      if test -f $file ; then
+        rm $file
+      fi
+    done
+
+    if test -n "${jce}"; then
+      unzip ${jce}
+      cp -v UnlimitedJCEPolicy*/*.jar $out/lib/security
+    fi
+
+    if test -z "$pluginSupport"; then
+      rm -f $out/bin/javaws
+    fi
+
+    mkdir $out/lib/plugins
+    ln -s $out/lib/libnpjp2.so $out/lib/plugins
+
+    # for backward compatibility
+    ln -s $out $out/jre
+
+    mkdir -p $out/nix-support
+    printWords ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs
+
+    # Set JAVA_HOME automatically.
+    cat <<EOF >> $out/nix-support/setup-hook
+    if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
+    EOF
+  '';
+
+  postFixup = ''
+    rpath+="''${rpath:+:}${stdenv.lib.concatStringsSep ":" (map (a: "$out/${a}") rSubPaths)}"
+
+    # set all the dynamic linkers
+    find $out -type f -perm -0100 \
+        -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
+        --set-rpath "$rpath" {} \;
+
+    find $out -name "*.so" -exec patchelf --set-rpath "$rpath" {} \;
+
+    # Oracle Java Mission Control needs to know where libgtk-x11 and related is
+    if test -x $out/bin/jmc; then
+      wrapProgram "$out/bin/jmc" \
+          --suffix-each LD_LIBRARY_PATH ':' "$rpath"
+    fi
+  '';
+
+  /**
+   * libXt is only needed on amd64
+   */
+  libraries =
+    [stdenv.cc.libc glib libxml2 ffmpeg_2 libxslt mesa_noglu xorg.libXxf86vm alsaLib fontconfig freetype pango gtk2 cairo gdk_pixbuf atk zlib elfutils] ++
+    (if swingSupport then [xorg.libX11 xorg.libXext xorg.libXtst xorg.libXi xorg.libXp xorg.libXt xorg.libXrender stdenv.cc.cc] else []);
+
+  rpath = stdenv.lib.strings.makeLibraryPath libraries;
+
+  passthru.mozillaPlugin = "/lib/plugins";
+
+  passthru.jre = result; # FIXME: use multiple outputs or return actual JRE package
+
+  passthru.home = result;
+
+  # for backward compatibility
+  passthru.architecture = "";
+
+  meta = with stdenv.lib; {
+    license = licenses.unfree;
+    platforms = [ "x86_64-linux" ]; # some inherit jre.meta.platforms
+  };
+
+}; in result
diff --git a/pkgs/development/compilers/orc/default.nix b/pkgs/development/compilers/orc/default.nix
index 5e0cbb9d395d..543fc6dfa48f 100644
--- a/pkgs/development/compilers/orc/default.nix
+++ b/pkgs/development/compilers/orc/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchurl }:
 
 stdenv.mkDerivation rec {
-  name = "orc-0.4.26";
+  name = "orc-0.4.27";
 
   src = fetchurl {
-    url = "http://gstreamer.freedesktop.org/src/orc/${name}.tar.xz";
-    sha256 = "0jd69ynvr3k70mlxxgbsk047l1rd63m1wkj3qdcq7644xy0gllkx";
+    url = "https://gstreamer.freedesktop.org/src/orc/${name}.tar.xz";
+    sha256 = "14vbwdydwarcvswzf744jdjb3ibhv6k4j6hzdacfan41zic3xrai";
   };
 
   outputs = [ "out" "dev" ];
diff --git a/pkgs/development/compilers/picat/default.nix b/pkgs/development/compilers/picat/default.nix
index e86f3869e49a..8ee904a6ed6c 100644
--- a/pkgs/development/compilers/picat/default.nix
+++ b/pkgs/development/compilers/picat/default.nix
@@ -33,5 +33,6 @@ stdenv.mkDerivation {
     homepage = http://picat-lang.org/;
     license = stdenv.lib.licenses.mpl20;
     platforms = stdenv.lib.platforms.linux;
+    maintainers = [ stdenv.lib.maintainers.earldouglas ];
   };
 }
diff --git a/pkgs/development/compilers/ponyc/default.nix b/pkgs/development/compilers/ponyc/default.nix
index f605f31c06dc..8c744e7038e8 100644
--- a/pkgs/development/compilers/ponyc/default.nix
+++ b/pkgs/development/compilers/ponyc/default.nix
@@ -3,13 +3,13 @@
 
 stdenv.mkDerivation ( rec {
   name = "ponyc-${version}";
-  version = "0.18.0";
+  version = "0.20.0";
 
   src = fetchFromGitHub {
     owner = "ponylang";
     repo = "ponyc";
     rev = version;
-    sha256 = "0favj1895fp5j5i23cmjn9wvrrlchr2dmc18grlvbjr2cg2c76mg";
+    sha256 = "0shln9v0bp0q9qfipm3834vl284q5vwz9333yzgx46d0l2ivggyi";
   };
 
   buildInputs = [ llvm makeWrapper which ];
@@ -83,7 +83,7 @@ stdenv.mkDerivation ( rec {
     description = "Pony is an Object-oriented, actor-model, capabilities-secure, high performance programming language";
     homepage = http://www.ponylang.org;
     license = licenses.bsd2;
-    maintainers = with maintainers; [ doublec kamilchm ];
+    maintainers = with maintainers; [ doublec kamilchm patternspandemic ];
     platforms = subtractLists platforms.i686 platforms.unix;
   };
 })
diff --git a/pkgs/development/compilers/ponyc/pony-stable.nix b/pkgs/development/compilers/ponyc/pony-stable.nix
index 4353c425489e..0e382efd7079 100644
--- a/pkgs/development/compilers/ponyc/pony-stable.nix
+++ b/pkgs/development/compilers/ponyc/pony-stable.nix
@@ -2,13 +2,13 @@
 
 stdenv.mkDerivation rec {
   name = "pony-stable-${version}";
-  version = "0.0.1";
+  version = "0.1.1";
 
   src = fetchFromGitHub {
     owner = "ponylang";
     repo = "pony-stable";
     rev = version;
-    sha256 = "0q05135mnzzdwam7cnmxq34clqhmc83yp2gi63sx20c74rcw3p6v";
+    sha256 = "0v4039iijjv93m89s3dsikcbp1y0hml6g1agj44s6w2g4m8kiiw3";
   };
 
   buildInputs = [ ponyc ];
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
 
   meta = {
     description = "A simple dependency manager for the Pony language.";
-    homepage = http://www.ponylang.org;
+    homepage = https://www.ponylang.org;
     license = stdenv.lib.licenses.bsd2;
     maintainers = with stdenv.lib.maintainers; [ dipinhora kamilchm ];
     platforms = stdenv.lib.platforms.unix;
diff --git a/pkgs/development/compilers/purescript/psc-package/default.nix b/pkgs/development/compilers/purescript/psc-package/default.nix
index 306eaa93958f..8b2a0a0eb391 100644
--- a/pkgs/development/compilers/purescript/psc-package/default.nix
+++ b/pkgs/development/compilers/purescript/psc-package/default.nix
@@ -4,13 +4,13 @@ with lib;
 
 mkDerivation rec {
   pname = "psc-package";
-  version = "0.2.0";
+  version = "0.2.4";
 
   src = fetchFromGitHub {
     owner = "purescript";
     repo = pname;
     rev = "v${version}";
-    sha256 = "0vid8vc8n8xj0qa4gnm1any9s18rdh7yn960vgix17r7a3bdndwb";
+    sha256 = "0m1vcxa5zs4sqnnwgmxkhw1isdlmirp12yimn5345vwfvlxkc8kp";
   };
 
   isLibrary = false;
diff --git a/pkgs/development/compilers/rdmd/default.nix b/pkgs/development/compilers/rdmd/default.nix
deleted file mode 100644
index 38473897698d..000000000000
--- a/pkgs/development/compilers/rdmd/default.nix
+++ /dev/null
@@ -1,28 +0,0 @@
-{stdenv, lib, fetchurl, dmd}:
-
-stdenv.mkDerivation {
-  name = "rdmd-2.067.0";
-
-  buildInputs = [ dmd ];
-
-  src = fetchurl {
-    url = "https://github.com/D-Programming-Language/tools/archive/v2.067.0.tar.gz";
-    sha256 = "2702ecda0427c675084d9b688449bc8c8392fd73e30257d79e2488640d5a9982";
-  };
-
-  buildPhase = ''
-    dmd rdmd.d
-  '';
-
-  installPhase = ''
-    mkdir -p $out/bin
-    cp rdmd $out/bin/
-	'';
-
-  meta = {
-    description = "Wrapper for D language compiler";
-    homepage = http://dlang.org/rdmd.html;
-    license = lib.licenses.boost;
-    platforms = stdenv.lib.platforms.unix;
-  };
-}
diff --git a/pkgs/development/compilers/reason/default.nix b/pkgs/development/compilers/reason/default.nix
index e364f536c889..a4f0442d9d1b 100644
--- a/pkgs/development/compilers/reason/default.nix
+++ b/pkgs/development/compilers/reason/default.nix
@@ -1,41 +1,20 @@
 { stdenv, makeWrapper, buildOcaml, fetchFromGitHub,
   ocaml, opam, topkg, menhir, merlin_extend, ppx_tools_versioned, utop }:
 
-let 
-  version = "2.0.0";
+buildOcaml rec {
+  name = "reason";
+  version = "3.0.0";
+
   src = fetchFromGitHub {
     owner = "facebook";
     repo = "reason";
     rev = version;
-    sha256 = "0l3lwfvppplah707rq5nqjav2354lq6d7xfflfigkzhn74hlx6iy";
+    sha256 = "0vj3y9vlm9gqvj9grmb9n487avbrj4q5611m7wv1bsdpndvv96jr";
   };
-  meta = with stdenv.lib; {
-    homepage = https://facebook.github.io/reason/;
-    description = "Facebook's friendly syntax to OCaml";
-    license = licenses.bsd3;
-    maintainers = [ maintainers.volth ];
-  };
-
-  reason-parser = buildOcaml {
-    name = "reason-parser";
-    inherit version src meta;
-    sourceRoot = "reason-${version}-src/reason-parser";
 
-    minimumSupportedOcamlVersion = "4.02";
+  propagatedBuildInputs = [ menhir merlin_extend ppx_tools_versioned ];
 
-    propagatedBuildInputs = [ menhir merlin_extend ppx_tools_versioned ];
-    buildInputs = [ opam topkg ];
-
-    createFindlibDestdir = true;
-
-    inherit (topkg) installPhase;
-  };
-in
-buildOcaml {
-  name = "reason";
-  inherit version src meta;
-
-  buildInputs = [ makeWrapper opam topkg reason-parser utop ];
+  buildInputs = [ makeWrapper opam topkg utop menhir opam topkg ];
 
   buildFlags = [ "build" ]; # do not "make tests" before reason lib is installed
 
@@ -48,10 +27,15 @@ buildOcaml {
   installPhase = ''
     ${topkg.installPhase}
 
-    wrapProgram $out/bin/reup \
-      --prefix PATH : "${opam}/bin"
     wrapProgram $out/bin/rtop \
       --prefix PATH : "${utop}/bin" \
       --set OCAMLPATH $out/lib/ocaml/${ocaml.version}/site-lib:$OCAMLPATH
   '';
+
+  meta = with stdenv.lib; {
+    homepage = https://facebook.github.io/reason/;
+    description = "Facebook's friendly syntax to OCaml";
+    license = licenses.bsd3;
+    maintainers = [ maintainers.volth ];
+  };
 }
diff --git a/pkgs/development/compilers/rust/beta.nix b/pkgs/development/compilers/rust/beta.nix
deleted file mode 100644
index 93aaeb9e16e4..000000000000
--- a/pkgs/development/compilers/rust/beta.nix
+++ /dev/null
@@ -1,39 +0,0 @@
-{ stdenv, callPackage, recurseIntoAttrs, makeRustPlatform, llvm, fetchurl
-, targets ? []
-, targetToolchains ? []
-, targetPatches ? []
-}:
-
-let
-  rustPlatform = recurseIntoAttrs (makeRustPlatform (callPackage ./bootstrap.nix {}));
-in
-rec {
-  rustc = callPackage ./rustc.nix {
-    inherit llvm targets targetPatches targetToolchains rustPlatform;
-
-    version = "beta-2017-05-27";
-
-    configureFlags = [ "--release-channel=beta" ];
-
-    src = fetchurl {
-      url = "https://static.rust-lang.org/dist/2017-05-27/rustc-beta-src.tar.gz";
-      sha256 = "9f3f92efef7fb2b4bf38e57e4ff1f416dc221880b90841c4bdaee350801c0b57";
-    };
-
-    patches = [
-      ./patches/darwin-disable-fragile-tcp-tests.patch
-    ] ++ stdenv.lib.optional stdenv.needsPax ./patches/grsec.patch;
-
-    doCheck = false;
-  };
-
-  cargo = callPackage ./cargo.nix rec {
-    version = "0.18.0";
-    srcRev = "fe7b0cdcf5ca7aab81630706ce40b70f6aa2e666";
-    srcSha = "164iywv1l3v87b0pznf5kkzxigd6w19myv9d7ka4c65zgrk9n9px";
-    depsSha256 = "1mrgd8ib48vxxbhkvsqqq4p19sc6b74x3cd8p6lhhlm6plrajrvm";
-
-    inherit rustc; # the rustc that will be wrapped by cargo
-    inherit rustPlatform; # used to build cargo
-  };
-}
diff --git a/pkgs/development/compilers/rust/bootstrap.nix b/pkgs/development/compilers/rust/bootstrap.nix
index ad49b1305706..fbcac09fc458 100644
--- a/pkgs/development/compilers/rust/bootstrap.nix
+++ b/pkgs/development/compilers/rust/bootstrap.nix
@@ -1,6 +1,18 @@
 { stdenv, fetchurl, makeWrapper, cacert, zlib, curl }:
 
 let
+  # Note: the version MUST be one version prior to the version we're
+  # building
+  version = "1.19.0";
+
+  # fetch hashes by running `print-hashes.sh 1.19.0`
+  hashes = {
+    i686-unknown-linux-gnu = "657b78f3c1a1b4412e12f7278e20cc318022fa276a58f0d38a0d15b515e39713";
+    x86_64-unknown-linux-gnu = "30ff67884464d32f6bbbde4387e7557db98868e87fb2afbb77c9b7716e3bff09";
+    i686-apple-darwin = "bdfd2189245dc5764c9f26bdba1429c2bf9d57477d8e6e3f0ba42ea0dc63edeb";
+    x86_64-apple-darwin = "5c668fb60a3ba3e97dc2cb8967fc4bb9422b629155284dcb89f94d116bb17820";
+  };
+
   platform =
     if stdenv.system == "i686-linux"
     then "i686-unknown-linux-gnu"
@@ -12,27 +24,11 @@ let
     then "x86_64-apple-darwin"
     else throw "missing bootstrap url for platform ${stdenv.system}";
 
-  # fetch hashes by patching print-hashes.sh to not use the "$DATE" variable
-  # then running `print-hashes.sh 1.16.0`
-  bootstrapHash =
-    if stdenv.system == "i686-linux"
-    then "b5859161ebb182d3b75fa14a5741e5de87b088146fb0ef4a30f3b2439c6179c5"
-    else if stdenv.system == "x86_64-linux"
-    then "48621912c242753ba37cad5145df375eeba41c81079df46f93ffb4896542e8fd"
-    else if stdenv.system == "i686-darwin"
-    then "26356b14164354725bd0351e8084f9b164abab134fb05cddb7758af35aad2065"
-    else if stdenv.system == "x86_64-darwin"
-    then "2d08259ee038d3a2c77a93f1a31fc59e7a1d6d1bbfcba3dba3c8213b2e5d1926"
-    else throw "missing bootstrap hash for platform ${stdenv.system}";
-
   src = fetchurl {
      url = "https://static.rust-lang.org/dist/rust-${version}-${platform}.tar.gz";
-     sha256 = bootstrapHash;
+     sha256 = hashes."${platform}";
   };
 
-  # Note: the version  MUST be one version prior to the version we're
-  # building
-  version = "1.16.0";
 in import ./binaryBuild.nix
   { inherit stdenv fetchurl makeWrapper cacert zlib curl;
     buildRustPackage = null;
diff --git a/pkgs/development/compilers/rust/cargo.nix b/pkgs/development/compilers/rust/cargo.nix
index ac4102c9a63c..682e85ce867b 100644
--- a/pkgs/development/compilers/rust/cargo.nix
+++ b/pkgs/development/compilers/rust/cargo.nix
@@ -1,25 +1,30 @@
-{ stdenv, fetchgit, file, curl, pkgconfig, python, openssl, cmake, zlib
-, makeWrapper, libiconv, cacert, rustPlatform, rustc, libgit2
-, version, srcRev, srcSha, depsSha256
+{ stdenv, fetchFromGitHub, file, curl, pkgconfig, python, openssl, cmake, zlib
+, makeWrapper, libiconv, cacert, rustPlatform, rustc, libgit2, darwin
+, version, srcSha, cargoSha256
 , patches ? []}:
 
 rustPlatform.buildRustPackage rec {
   name = "cargo-${version}";
   inherit version;
 
-  src = fetchgit {
-    url = "https://github.com/rust-lang/cargo";
-    rev = srcRev;
+  src = fetchFromGitHub {
+    owner  = "rust-lang";
+    repo   = "cargo";
+    rev    = version;
     sha256 = srcSha;
   };
 
-  inherit depsSha256;
+  inherit cargoSha256;
   inherit patches;
 
   passthru.rustc = rustc;
 
-  buildInputs = [ file curl pkgconfig python openssl cmake zlib makeWrapper libgit2 ]
-    ++ stdenv.lib.optionals stdenv.isDarwin [ libiconv ];
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ file curl python openssl cmake zlib makeWrapper libgit2 ]
+    # FIXME: Use impure version of CoreFoundation because of missing symbols.
+    # CFURLSetResourcePropertyForKey is defined in the headers but there's no
+    # corresponding implementation in the sources from opensource.apple.com.
+    ++ stdenv.lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.CoreFoundation libiconv ];
 
   LIBGIT2_SYS_USE_PKG_CONFIG=1;
 
@@ -51,6 +56,6 @@ rustPlatform.buildRustPackage rec {
     description = "Downloads your Rust project's dependencies and builds your project";
     maintainers = with maintainers; [ wizeman retrry ];
     license = [ licenses.mit licenses.asl20 ];
-    platforms = platforms.linux ++ platforms.darwin;
+    platforms = [ "x86_64-linux" "x86_64-darwin" ];
   };
 }
diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix
index 0d7e26e06f47..c42c958b170c 100644
--- a/pkgs/development/compilers/rust/default.nix
+++ b/pkgs/development/compilers/rust/default.nix
@@ -6,30 +6,31 @@
 
 let
   rustPlatform = recurseIntoAttrs (makeRustPlatform (callPackage ./bootstrap.nix {}));
-  version = "1.17.0";
+  version = "1.20.0";
 in
 rec {
   rustc = callPackage ./rustc.nix {
     inherit llvm targets targetPatches targetToolchains rustPlatform version;
 
+    forceBundledLLVM = true;
+
     configureFlags = [ "--release-channel=stable" ];
 
     src = fetchurl {
       url = "https://static.rust-lang.org/dist/rustc-${version}-src.tar.gz";
-      sha256 = "4baba3895b75f2492df6ce5a28a916307ecd1c088dc1fd02dbfa8a8e86174f87";
+      sha256 = "0542y4rnzlsrricai130mqyxl8r6rd991frb4qsnwb27yigqg91a";
     };
 
     patches = [
-      ./patches/darwin-disable-fragile-tcp-tests.patch
+      ./patches/0001-Disable-fragile-tests-libstd-net-tcp-on-Darwin-Linux.patch
     ] ++ stdenv.lib.optional stdenv.needsPax ./patches/grsec.patch;
 
   };
 
   cargo = callPackage ./cargo.nix rec {
-    version = "0.18.0";
-    srcRev = "fe7b0cdcf5ca7aab81630706ce40b70f6aa2e666";
-    srcSha = "164iywv1l3v87b0pznf5kkzxigd6w19myv9d7ka4c65zgrk9n9px";
-    depsSha256 = "1mrgd8ib48vxxbhkvsqqq4p19sc6b74x3cd8p6lhhlm6plrajrvm";
+    version = "0.22.0";
+    srcSha = "0x9pm73hkkd1hq4qrmz8iv91djgpdsxzwll7jari0h77vpwajmw4";
+    cargoSha256 = "0xd0rb8gcqy6xngsx9l30jg3fqrcwccgv904ksqs9c4d44hga0gd";
 
     inherit rustc; # the rustc that will be wrapped by cargo
     inherit rustPlatform; # used to build cargo
diff --git a/pkgs/development/compilers/rust/nightly.nix b/pkgs/development/compilers/rust/nightly.nix
deleted file mode 100644
index b69dffbd8b38..000000000000
--- a/pkgs/development/compilers/rust/nightly.nix
+++ /dev/null
@@ -1,36 +0,0 @@
-{ stdenv, callPackage, rustPlatform, llvm, fetchurl
-, targets ? []
-, targetToolchains ? []
-, targetPatches ? []
-}:
-
-rec {
-  rustc = callPackage ./rustc.nix {
-    inherit llvm targets targetPatches targetToolchains rustPlatform;
-
-    version = "nightly-2017-05-30";
-
-    configureFlags = [ "--release-channel=nightly" ];
-
-    src = fetchurl {
-      url = "https://static.rust-lang.org/dist/2017-05-30/rustc-nightly-src.tar.gz";
-      sha256 = "90ce76db56a93f1b4532f2e62bbf12c243c4d156662b0d80c25319211ee7d0e0";
-    };
-
-    patches = [
-      ./patches/darwin-disable-fragile-tcp-tests.patch
-    ] ++ stdenv.lib.optional stdenv.needsPax ./patches/grsec.patch;
-
-    doCheck = false;
-  };
-
-  cargo = callPackage ./cargo.nix rec {
-    version = "0.18.0";
-    srcRev = "fe7b0cdcf5ca7aab81630706ce40b70f6aa2e666";
-    srcSha = "164iywv1l3v87b0pznf5kkzxigd6w19myv9d7ka4c65zgrk9n9px";
-    depsSha256 = "1mrgd8ib48vxxbhkvsqqq4p19sc6b74x3cd8p6lhhlm6plrajrvm";
-
-    inherit rustc; # the rustc that will be wrapped by cargo
-    inherit rustPlatform; # used to build cargo
-  };
-}
diff --git a/pkgs/development/compilers/rust/nightlyBin.nix b/pkgs/development/compilers/rust/nightlyBin.nix
deleted file mode 100644
index af06835c5def..000000000000
--- a/pkgs/development/compilers/rust/nightlyBin.nix
+++ /dev/null
@@ -1,23 +0,0 @@
-{ stdenv, fetchurl, makeWrapper, cacert, zlib, buildRustPackage, curl }:
-
-let
-  platform = if stdenv.system == "x86_64-linux"
-    then "x86_64-unknown-linux-gnu"
-    else throw "missing bootstrap url for platform ${stdenv.system}";
-
-  bootstrapHash =
-    if stdenv.system == "x86_64-linux"
-    then "0svlm4bxsdhdn4jsv46f278kid23a9w978q2137qrba4xnyb06kf"
-    else throw "missing bootstrap hash for platform ${stdenv.system}";
-
-  src = fetchurl {
-     url = "https://static.rust-lang.org/dist/${version}/rust-nightly-${platform}.tar.gz";
-     sha256 = bootstrapHash;
-  };
-
-  version = "2017-06-26";
-in import ./binaryBuild.nix
-  { inherit stdenv fetchurl makeWrapper cacert zlib buildRustPackage curl;
-    inherit version src platform;
-    versionType = "nightly";
-  }
diff --git a/pkgs/development/compilers/rust/patches/darwin-disable-fragile-tcp-tests.patch b/pkgs/development/compilers/rust/patches/0001-Disable-fragile-tests-libstd-net-tcp-on-Darwin-Linux.patch
index da550f0327d3..f55d0badb823 100644
--- a/pkgs/development/compilers/rust/patches/darwin-disable-fragile-tcp-tests.patch
+++ b/pkgs/development/compilers/rust/patches/0001-Disable-fragile-tests-libstd-net-tcp-on-Darwin-Linux.patch
@@ -1,17 +1,18 @@
-From 1d8a91d5b09cb762fe890d04bfb61b9eefd0624a Mon Sep 17 00:00:00 2001
-From: Moritz Ulrich <moritz@tarn-vedra.de>
-Date: Sun, 8 Jan 2017 10:28:17 +0100
-Subject: [PATCH] Disable libstd::net::tcp::{ttl, timeouts} on Darwin
+From 26d3b70abec1adf773522643b31ce9c03439916a Mon Sep 17 00:00:00 2001
+From: Joerg Thalheim <joerg@thalheim.io>
+Date: Tue, 10 Oct 2017 00:40:20 +0100
+Subject: [PATCH] Disable fragile tests libstd::net::tcp on Darwin/Linux
 
+Signed-off-by: Joerg Thalheim <joerg@thalheim.io>
 ---
- src/libstd/net/tcp.rs | 7 ++++++-
- 1 file changed, 6 insertions(+), 1 deletion(-)
+ src/libstd/net/tcp.rs | 8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
 
 diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs
-index 0e7c5b0671..d42fd26267 100644
+index 8d1e7882e5..2c223fb315 100644
 --- a/src/libstd/net/tcp.rs
 +++ b/src/libstd/net/tcp.rs
-@@ -551,6 +551,7 @@ mod tests {
+@@ -949,6 +949,7 @@ mod tests {
          })
      }
  
@@ -19,7 +20,7 @@ index 0e7c5b0671..d42fd26267 100644
      #[test]
      fn write_close() {
          each_ip(&mut |addr| {
-@@ -1022,7 +1023,10 @@ mod tests {
+@@ -1421,7 +1422,10 @@ mod tests {
  
      // FIXME: re-enabled bitrig/openbsd tests once their socket timeout code
      //        no longer has rounding errors.
@@ -31,7 +32,7 @@ index 0e7c5b0671..d42fd26267 100644
      #[test]
      fn timeouts() {
          let addr = next_test_ip4();
-@@ -1101,6 +1105,7 @@ mod tests {
+@@ -1500,6 +1504,7 @@ mod tests {
          assert_eq!(false, t!(stream.nodelay()));
      }
  
@@ -39,6 +40,14 @@ index 0e7c5b0671..d42fd26267 100644
      #[test]
      fn ttl() {
          let ttl = 100;
+@@ -1568,6 +1573,7 @@ mod tests {
+         })
+     }
+ 
++    #[cfg_attr(target_os = "linux", ignore)]
+     #[test]
+     fn connect_timeout_unroutable() {
+         // this IP is unroutable, so connections should always time out,
 -- 
-2.11.0
+2.14.2
 
diff --git a/pkgs/development/compilers/rust/patches/disable-lockfile-check-beta.patch b/pkgs/development/compilers/rust/patches/disable-lockfile-check-beta.patch
deleted file mode 100644
index a6fe3413fd21..000000000000
--- a/pkgs/development/compilers/rust/patches/disable-lockfile-check-beta.patch
+++ /dev/null
@@ -1,25 +0,0 @@
-From 5702d7cdb2bed7ac3af3c01087b181da35f6e108 Mon Sep 17 00:00:00 2001
-From: joachim schiele <js@lastlog.de>
-Date: Thu, 24 Nov 2016 22:25:48 +0100
-Subject: [PATCH 2/2] asdf
-
----
- src/tools/tidy/src/main.rs | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs
-index cabaee5..685df94 100644
---- a/src/tools/tidy/src/main.rs
-+++ b/src/tools/tidy/src/main.rs
-@@ -48,7 +48,7 @@ fn main() {
-     errors::check(&path, &mut bad);
-     cargo::check(&path, &mut bad);
-     features::check(&path, &mut bad);
--    cargo_lock::check(&path, &mut bad);
-+    //cargo_lock::check(&path, &mut bad);
-     pal::check(&path, &mut bad);
- 
-     if bad {
--- 
-2.10.0
-
diff --git a/pkgs/development/compilers/rust/patches/disable-lockfile-check-nightly.patch b/pkgs/development/compilers/rust/patches/disable-lockfile-check-nightly.patch
deleted file mode 100644
index c89d22dcb1ea..000000000000
--- a/pkgs/development/compilers/rust/patches/disable-lockfile-check-nightly.patch
+++ /dev/null
@@ -1,25 +0,0 @@
-From ac204f8be95cdb2350a1dd893641e38528aaf01d Mon Sep 17 00:00:00 2001
-From: joachim schiele <js@lastlog.de>
-Date: Fri, 25 Nov 2016 02:17:02 +0100
-Subject: [PATCH] asdf
-
----
- src/tools/tidy/src/main.rs | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs
-index cb11fe2..c9b7d2a 100644
---- a/src/tools/tidy/src/main.rs
-+++ b/src/tools/tidy/src/main.rs
-@@ -45,7 +45,7 @@ fn main() {
-     bins::check(&path, &mut bad);
-     style::check(&path, &mut bad);
-     errors::check(&path, &mut bad);
--    cargo::check(&path, &mut bad);
-+    //cargo::check(&path, &mut bad);
-     features::check(&path, &mut bad);
-     pal::check(&path, &mut bad);
- 
--- 
-2.10.0
-
diff --git a/pkgs/development/compilers/rust/print-hashes.sh b/pkgs/development/compilers/rust/print-hashes.sh
index da52ac37ab30..f3d094d65a8a 100755
--- a/pkgs/development/compilers/rust/print-hashes.sh
+++ b/pkgs/development/compilers/rust/print-hashes.sh
@@ -1,4 +1,5 @@
 #!/usr/bin/env bash
+set -euo pipefail
 
 # All rust-related downloads can be found at
 # https://static.rust-lang.org/dist/index.html.  To find the date on
@@ -6,25 +7,30 @@
 # file, e.g.
 # https://static.rust-lang.org/dist/channel-rust-beta-date.txt
 
-PLATFORMS="i686-unknown-linux-gnu x86_64-unknown-linux-gnu i686-apple-darwin x86_64-apple-darwin"
-BASEURL="https://static.rust-lang.org/dist"
-DATE=$1
-VERSION=$2
+PLATFORMS=(
+  i686-unknown-linux-gnu
+  x86_64-unknown-linux-gnu
+  i686-apple-darwin
+  x86_64-apple-darwin
+)
+BASEURL=https://static.rust-lang.org/dist
+VERSION=${1:-}
+DATE=${2:-}
 
-if [[ -z  $DATE ]]
+if [[ -z $VERSION ]]
 then
-    echo "No date supplied"
+    echo "No version supplied"
     exit -1
 fi
 
-if [[ -z  $VERSION ]]
+if [[ -n $DATE ]]
 then
-    echo "No version supplied"
-    exit -1
+    BASEURL=$BASEURL/$DATE
 fi
 
-for PLATFORM in $PLATFORMS
+for PLATFORM in "${PLATFORMS[@]}"
 do
-    URL="$BASEURL/$DATE/rust-$VERSION-$PLATFORM.tar.gz.sha256"
-    curl $URL
+    URL="$BASEURL/rust-$VERSION-$PLATFORM.tar.gz.sha256"
+    SHA256=$(curl -sSfL $URL | cut -d ' ' -f 1)
+    echo "$PLATFORM = \"$SHA256\";"
 done
diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix
index f5bcc73fd6d1..9f96d05c1163 100644
--- a/pkgs/development/compilers/rust/rustc.nix
+++ b/pkgs/development/compilers/rust/rustc.nix
@@ -1,5 +1,6 @@
-{ stdenv, fetchurl, fetchgit, fetchzip, file, python2, tzdata, procps
-, llvm, jemalloc, ncurses, darwin, binutils, rustPlatform, git, cmake, curl
+{ stdenv, targetPackages
+, fetchurl, fetchgit, fetchzip, file, python2, tzdata, procps
+, llvm, jemalloc, ncurses, darwin, rustPlatform, git, cmake, curl
 , which, libffi, gdb
 , version
 , forceBundledLLVM ? false
@@ -10,6 +11,7 @@
 , targetPatches
 , targetToolchains
 , doCheck ? true
+, broken ? false
 , buildPlatform, hostPlatform
 } @ args:
 
@@ -47,15 +49,18 @@ stdenv.mkDerivation {
   configureFlags = configureFlags
                 ++ [ "--enable-local-rust" "--local-rust-root=${rustPlatform.rust.rustc}" "--enable-rpath" ]
                 ++ [ "--enable-vendor" "--disable-locked-deps" ]
-                ++ [ "--enable-llvm-link-shared" ]
                 # ++ [ "--jemalloc-root=${jemalloc}/lib"
-                ++ [ "--default-linker=${stdenv.cc}/bin/cc" "--default-ar=${binutils.out}/bin/ar" ]
+                ++ [ "--default-linker=${targetPackages.stdenv.cc}/bin/cc" "--default-ar=${targetPackages.stdenv.cc.bintools}/bin/ar" ]
+                ++ optional (!forceBundledLLVM) [ "--enable-llvm-link-shared" ]
                 ++ optional (stdenv.cc.cc ? isClang) "--enable-clang"
                 ++ optional (targets != []) "--target=${target}"
                 ++ optional (!forceBundledLLVM) "--llvm-root=${llvmShared}";
 
   patches = patches ++ targetPatches;
 
+  # the rust build system complains that nix alters the checksums
+  dontFixLibtool = true;
+
   passthru.target = target;
 
   postPatch = ''
@@ -81,6 +86,9 @@ stdenv.mkDerivation {
     # https://reviews.llvm.org/rL281650
     rm -vr src/test/run-pass/issue-36474.rs || true
 
+    # On Hydra: `TcpListener::bind(&addr)`: Address already in use (os error 98)'
+    sed '/^ *fn fast_rebind()/i#[ignore]' -i src/libstd/net/tcp.rs
+
     # Disable some failing gdb tests. Try re-enabling these when gdb
     # is updated past version 7.12.
     rm src/test/debuginfo/basic-types-globals.rs
@@ -154,5 +162,6 @@ stdenv.mkDerivation {
     maintainers = with maintainers; [ madjar cstrahan wizeman globin havvy wkennington ];
     license = [ licenses.mit licenses.asl20 ];
     platforms = platforms.linux ++ platforms.darwin;
+    broken = broken;
   };
 }
diff --git a/pkgs/development/compilers/sbcl/1.2.0.nix b/pkgs/development/compilers/sbcl/1.2.0.nix
deleted file mode 100644
index 975cb7db1bbf..000000000000
--- a/pkgs/development/compilers/sbcl/1.2.0.nix
+++ /dev/null
@@ -1,84 +0,0 @@
-{ stdenv, fetchurl, sbclBootstrap, clisp}:
-
-stdenv.mkDerivation rec {
-  name    = "sbcl-${version}";
-  version = "1.2.0";
-
-  src = fetchurl {
-    url    = "mirror://sourceforge/project/sbcl/sbcl/${version}/${name}-source.tar.bz2";
-    sha256 = "13k20sys1v4lvgis8cnbczww6zs93rw176vz07g4jx06418k53x2";
-  };
-
-  buildInputs = [ ]
-    ++ (stdenv.lib.optional stdenv.isDarwin sbclBootstrap)
-    ++ (stdenv.lib.optional stdenv.isLinux clisp)
-    ;
-
-  patchPhase = ''
-    echo '"${version}.nixos"' > version.lisp-expr
-    echo "
-    (lambda (features)
-      (flet ((enable (x)
-               (pushnew x features))
-             (disable (x)
-               (setf features (remove x features))))
-        (enable :sb-thread))) " > customize-target-features.lisp
-
-    pwd
-
-    # SBCL checks whether files are up-to-date in many places..
-    # Unfortunately, same timestamp is not good enough
-    sed -e 's@> x y@>= x y@' -i contrib/sb-aclrepl/repl.lisp
-    sed -e '/(date)/i((= date 2208988801) 2208988800)' -i contrib/asdf/asdf.lisp
-    sed -i src/cold/slam.lisp -e \
-      '/file-write-date input/a)'
-    sed -i src/cold/slam.lisp -e \
-      '/file-write-date output/i(or (and (= 2208988801 (file-write-date output)) (= 2208988801 (file-write-date input)))'
-    sed -i src/code/target-load.lisp -e \
-      '/date defaulted-fasl/a)'
-    sed -i src/code/target-load.lisp -e \
-      '/date defaulted-source/i(or (and (= 2208988801 (file-write-date defaulted-source-truename)) (= 2208988801 (file-write-date defaulted-fasl-truename)))'
-
-    # Fix the tests
-    sed -e '/deftest pwent/inil' -i contrib/sb-posix/posix-tests.lisp
-    sed -e '/deftest grent/inil' -i contrib/sb-posix/posix-tests.lisp
-    sed -e '/deftest .*ent.non-existing/,+5d' -i contrib/sb-posix/posix-tests.lisp
-    sed -e '/deftest \(pw\|gr\)ent/,+3d' -i contrib/sb-posix/posix-tests.lisp
-
-    sed -e '5,$d' -i contrib/sb-bsd-sockets/tests.lisp
-    sed -e '5,$d' -i contrib/sb-simple-streams/*test*.lisp
-
-    # Use whatever `cc` the stdenv provides
-    substituteInPlace src/runtime/Config.x86-64-darwin --replace gcc cc
-
-    substituteInPlace src/runtime/Config.x86-64-darwin \
-      --replace mmacosx-version-min=10.4 mmacosx-version-min=10.5
-  '';
-
-  preBuild = ''
-    export INSTALL_ROOT=$out
-    mkdir -p test-home
-    export HOME=$PWD/test-home
-  '';
-
-  buildPhase = if stdenv.isLinux
-    then ''
-      sh make.sh clisp --prefix=$out
-    ''
-    else ''
-      sh make.sh --prefix=$out --xc-host='${sbclBootstrap}/bin/sbcl --disable-debugger --no-userinit --no-sysinit'
-    '';
-
-  installPhase = ''
-    INSTALL_ROOT=$out sh install.sh
-  '';
-
-  meta = {
-    description = "Lisp compiler";
-    homepage = http://www.sbcl.org;
-    license = stdenv.lib.licenses.bsd3;
-    maintainers = [stdenv.lib.maintainers.raskin];
-    platforms = stdenv.lib.platforms.all;
-    inherit version;
-  };
-}
diff --git a/pkgs/development/compilers/sbcl/1.3.12.nix b/pkgs/development/compilers/sbcl/1.3.12.nix
deleted file mode 100644
index 8fa4741a4a14..000000000000
--- a/pkgs/development/compilers/sbcl/1.3.12.nix
+++ /dev/null
@@ -1,104 +0,0 @@
-{ stdenv, fetchurl, writeText, sbclBootstrap
-, sbclBootstrapHost ? "${sbclBootstrap}/bin/sbcl --disable-debugger --no-userinit --no-sysinit"
-, threadSupport ? (stdenv.isi686 || stdenv.isx86_64)
-  # Meant for sbcl used for creating binaries portable to non-NixOS via save-lisp-and-die.
-  # Note that the created binaries still need `patchelf --set-interpreter ...`
-  # to get rid of ${glibc} dependency.
-, purgeNixReferences ? false
-}:
-
-stdenv.mkDerivation rec {
-  name    = "sbcl-${version}";
-  version = "1.3.12";
-
-  src = fetchurl {
-    url    = "mirror://sourceforge/project/sbcl/sbcl/${version}/${name}-source.tar.bz2";
-    sha256 = "1hjr2xqazy4j0m58y4na6fz8ii3xflqairxy7vpd7ajbs00yqfc0";
-  };
-
-  patchPhase = ''
-    echo '"${version}.nixos"' > version.lisp-expr
-    echo "
-    (lambda (features)
-      (flet ((enable (x)
-               (pushnew x features))
-             (disable (x)
-               (setf features (remove x features))))
-    ''
-    + (if threadSupport then "(enable :sb-thread)" else "(disable :sb-thread)")
-    + stdenv.lib.optionalString stdenv.isArm "(enable :arm)"
-    + ''
-      )) " > customize-target-features.lisp
-
-    pwd
-
-    # SBCL checks whether files are up-to-date in many places..
-    # Unfortunately, same timestamp is not good enough
-    sed -e 's@> x y@>= x y@' -i contrib/sb-aclrepl/repl.lisp
-    sed -e '/(date)/i((= date 2208988801) 2208988800)' -i contrib/asdf/asdf.lisp
-    sed -i src/cold/slam.lisp -e \
-      '/file-write-date input/a)'
-    sed -i src/cold/slam.lisp -e \
-      '/file-write-date output/i(or (and (= 2208988801 (file-write-date output)) (= 2208988801 (file-write-date input)))'
-    sed -i src/code/target-load.lisp -e \
-      '/date defaulted-fasl/a)'
-    sed -i src/code/target-load.lisp -e \
-      '/date defaulted-source/i(or (and (= 2208988801 (file-write-date defaulted-source-truename)) (= 2208988801 (file-write-date defaulted-fasl-truename)))'
-
-    # Fix the tests
-    sed -e '/deftest pwent/inil' -i contrib/sb-posix/posix-tests.lisp
-    sed -e '/deftest grent/inil' -i contrib/sb-posix/posix-tests.lisp
-    sed -e '/deftest .*ent.non-existing/,+5d' -i contrib/sb-posix/posix-tests.lisp
-    sed -e '/deftest \(pw\|gr\)ent/,+3d' -i contrib/sb-posix/posix-tests.lisp
-
-    sed -e '5,$d' -i contrib/sb-bsd-sockets/tests.lisp
-    sed -e '5,$d' -i contrib/sb-simple-streams/*test*.lisp
-
-    # Use whatever `cc` the stdenv provides
-    substituteInPlace src/runtime/Config.x86-64-darwin --replace gcc cc
-
-    substituteInPlace src/runtime/Config.x86-64-darwin \
-      --replace mmacosx-version-min=10.4 mmacosx-version-min=10.5
-  ''
-  + (if purgeNixReferences
-    then
-      # This is the default location to look for the core; by default in $out/lib/sbcl
-      ''
-        sed 's@^\(#define SBCL_HOME\) .*$@\1 "/no-such-path"@' \
-          -i src/runtime/runtime.c
-      ''
-    else
-      # Fix software version retrieval
-      ''
-        sed -e "s@/bin/uname@$(command -v uname)@g" -i src/code/*-os.lisp
-      ''
-    );
-
-
-  preBuild = ''
-    export INSTALL_ROOT=$out
-    mkdir -p test-home
-    export HOME=$PWD/test-home
-  '';
-
-  buildPhase = ''
-    sh make.sh --prefix=$out --xc-host="${sbclBootstrapHost}"
-  '';
-
-  installPhase = ''
-    INSTALL_ROOT=$out sh install.sh
-  '';
-
-  # Specifying $SBCL_HOME is only truly needed with `purgeNixReferences = true`.
-  setupHook = writeText "setupHook.sh" ''
-    envHooks+=(_setSbclHome)
-    _setSbclHome() {
-      export SBCL_HOME='@out@/lib/sbcl/'
-    }
-  '';
-
-  meta = sbclBootstrap.meta // {
-    inherit version;
-    updateWalker = true;
-  };
-}
diff --git a/pkgs/development/compilers/sbcl/default.nix b/pkgs/development/compilers/sbcl/default.nix
index 82859a0e4298..9b7ce4120c48 100644
--- a/pkgs/development/compilers/sbcl/default.nix
+++ b/pkgs/development/compilers/sbcl/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, writeText, sbclBootstrap
+{ stdenv, fetchurl, fetchgit, writeText, sbclBootstrap
 , sbclBootstrapHost ? "${sbclBootstrap}/bin/sbcl --disable-debugger --no-userinit --no-sysinit"
 , threadSupport ? (stdenv.isi686 || stdenv.isx86_64 || "aarch64-linux" == stdenv.system)
   # Meant for sbcl used for creating binaries portable to non-NixOS via save-lisp-and-die.
@@ -9,11 +9,16 @@
 
 stdenv.mkDerivation rec {
   name    = "sbcl-${version}";
-  version = "1.3.20";
+  version = "1.4.1.0.20171104";
 
-  src = fetchurl {
-    url    = "mirror://sourceforge/project/sbcl/sbcl/${version}/${name}-source.tar.bz2";
-    sha256 = "0qhzrl2msdyzqp3165qlh9s6jrif5rddsmj9q50z0bxnaf0330jj";
+  #src = fetchurl {
+  #  url    = "mirror://sourceforge/project/sbcl/sbcl/${version}/${name}-source.tar.bz2";
+  #  sha256 = "1qdaf847g5p2zgq00ax5hdy4r82bl3ss382psd0kkca1h83cdiz8";
+  #};
+  src = fetchgit {
+    url    = "https://git.code.sf.net/p/sbcl/sbcl";
+    sha256 = "1fq34h8h8pax5q17w84kwv5amiaag3ikkq3cdmb31r64736mxi6r";
+    rev    = "11aa57d23bc464d6a6867a80e946907404ceadd1";
   };
 
   patchPhase = ''
@@ -35,7 +40,7 @@ stdenv.mkDerivation rec {
     # SBCL checks whether files are up-to-date in many places..
     # Unfortunately, same timestamp is not good enough
     sed -e 's@> x y@>= x y@' -i contrib/sb-aclrepl/repl.lisp
-    sed -e '/(date)/i((= date 2208988801) 2208988800)' -i contrib/asdf/asdf.lisp
+    #sed -e '/(date)/i((= date 2208988801) 2208988800)' -i contrib/asdf/asdf.lisp
     sed -i src/cold/slam.lisp -e \
       '/file-write-date input/a)'
     sed -i src/cold/slam.lisp -e \
diff --git a/pkgs/development/compilers/scala/default.nix b/pkgs/development/compilers/scala/default.nix
index d4d4a0f31bc5..7622fbb9d18d 100644
--- a/pkgs/development/compilers/scala/default.nix
+++ b/pkgs/development/compilers/scala/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchurl, makeWrapper, jre, gnugrep, coreutils }:
 
 stdenv.mkDerivation rec {
-  name = "scala-2.12.3";
+  name = "scala-2.12.4";
 
   src = fetchurl {
     url = "http://www.scala-lang.org/files/archive/${name}.tgz";
-    sha256 = "133w4r2214ci7r4sg2yyk9lhn62ldm4ad0d89drwrvgvffvnly9b";
+    sha256 = "089a54qj8psh4jxqbrrwk5zahw13fyqq24l87s3031xa675a0m4m";
   };
 
   propagatedBuildInputs = [ jre ] ;
diff --git a/pkgs/development/compilers/shaderc/default.nix b/pkgs/development/compilers/shaderc/default.nix
index df0c136d05f5..9df718694913 100644
--- a/pkgs/development/compilers/shaderc/default.nix
+++ b/pkgs/development/compilers/shaderc/default.nix
@@ -27,5 +27,6 @@ stdenv.mkDerivation rec {
   meta = with stdenv.lib; {
     inherit (src.meta) homepage;
     description = "A collection of tools, libraries and tests for shader compilation.";
+    broken = true;
   };
 }
diff --git a/pkgs/development/compilers/solc/default.nix b/pkgs/development/compilers/solc/default.nix
index 714f06d0b53f..078cf3e36c27 100644
--- a/pkgs/development/compilers/solc/default.nix
+++ b/pkgs/development/compilers/solc/default.nix
@@ -1,9 +1,9 @@
-{ stdenv, fetchzip, fetchgit, boost, cmake }:
+{ stdenv, fetchzip, fetchgit, boost, cmake, z3 }:
 
 let
-  version = "0.4.13";
-  rev = "0fb4cb1ab9bb4b6cc72e28cc5a1753ad14781f14";
-  sha256 = "0rhrm0bmk5s2358j40yx7dzr1938q17dchzflrxw6y7yvkhscxrm";
+  version = "0.4.17";
+  rev = "bdeb9e52a2211510644fb53df93fb98258b40a65";
+  sha256 = "1x6q2rlq6gxggidgsy6li7m4phwr1hcfi65pq9yimz64ddqfiira";
   jsoncppURL = https://github.com/open-source-parsers/jsoncpp/archive/1.7.7.tar.gz;
   jsoncpp = fetchzip {
     url = jsoncppURL;
@@ -23,16 +23,18 @@ stdenv.mkDerivation {
   patchPhase = ''
     echo >commit_hash.txt '${rev}'
     echo >prerelease.txt
-    substituteInPlace deps/jsoncpp.cmake \
+    substituteInPlace cmake/jsoncpp.cmake \
       --replace '${jsoncppURL}' ${jsoncpp}
     substituteInPlace cmake/EthCompilerSettings.cmake \
       --replace 'add_compile_options(-Werror)' ""
-    substituteInPlace cmake/EthDependencies.cmake \
-      --replace 'set(Boost_USE_STATIC_LIBS ON)'   \
-                'set(Boost_USE_STATIC_LIBS OFF)'
   '';
 
-  buildInputs = [ boost cmake ];
+  cmakeFlags = [
+    "-DBoost_USE_STATIC_LIBS=OFF"
+  ];
+
+  nativeBuildInputs = [ cmake ];
+  buildInputs = [ boost z3 ];
 
   meta = {
     description = "Compiler for Ethereum smart contract language Solidity";
diff --git a/pkgs/development/compilers/souffle/default.nix b/pkgs/development/compilers/souffle/default.nix
index 217b2aecd334..c56ea8cc6495 100644
--- a/pkgs/development/compilers/souffle/default.nix
+++ b/pkgs/development/compilers/souffle/default.nix
@@ -29,7 +29,8 @@ stdenv.mkDerivation rec {
 
   preConfigure = "./bootstrap";
 
-  enableParallelBuilding = true;
+  # in 1.0.0: parser.hh:40:0: error: unterminated #ifndef
+  enableParallelBuilding = false;
 
   # See https://github.com/souffle-lang/souffle/issues/176
   hardeningDisable = [ "fortify" ];
diff --git a/pkgs/development/compilers/souper/default.nix b/pkgs/development/compilers/souper/default.nix
index 327139ce0455..2203dc980b13 100644
--- a/pkgs/development/compilers/souper/default.nix
+++ b/pkgs/development/compilers/souper/default.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchFromGitHub, cmake, makeWrapper
-, llvmPackages_4, hiredis, z3_opt, gtest
+, llvmPackages_4, hiredis, z3, gtest
 }:
 
 let
@@ -46,7 +46,7 @@ in stdenv.mkDerivation rec {
       cp -v ./souper       $out/bin/
       cp -v ./clang-souper $out/bin/
       wrapProgram "$out/bin/souper" \
-          --add-flags "-z3-path=\"${z3_opt}/bin/z3\""
+          --add-flags "-z3-path=\"${z3}/bin/z3\""
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix
index 96b22b630f4f..937977b0a97d 100644
--- a/pkgs/development/compilers/swift/default.nix
+++ b/pkgs/development/compilers/swift/default.nix
@@ -1,4 +1,5 @@
 { stdenv
+, targetPackages
 , cmake
 , coreutils
 , glibc
@@ -26,7 +27,6 @@
 , rsync
 , git
 , libgit2
-, binutils
 , fetchFromGitHub
 , paxctl
 , findutils
@@ -250,7 +250,7 @@ stdenv.mkDerivation rec {
 
     # TODO: Use wrappers to get these on the PATH for swift tools, instead
     ln -s ${clang}/bin/* $out/bin/
-    ln -s ${binutils}/bin/ar $out/bin/ar
+    ln -s ${targetPackages.stdenv.cc.bintools}/bin/ar $out/bin/ar
   '';
 
   # Hack to avoid TMPDIR in RPATHs.
@@ -259,10 +259,11 @@ stdenv.mkDerivation rec {
   meta = with stdenv.lib; {
     description = "The Swift Programming Language";
     homepage = https://github.com/apple/swift;
-    maintainers = with maintainers; [ jb55 dtzWill ];
+    maintainers = with maintainers; [ dtzWill ];
     license = licenses.asl20;
     # Swift doesn't support 32bit Linux, unknown on other platforms.
     platforms = [ "x86_64-linux" ];
+    broken = true;
   };
 }
 
diff --git a/pkgs/development/compilers/teyjus/default.nix b/pkgs/development/compilers/teyjus/default.nix
index 301915b7a26b..222a22bf1cd9 100644
--- a/pkgs/development/compilers/teyjus/default.nix
+++ b/pkgs/development/compilers/teyjus/default.nix
@@ -4,7 +4,7 @@ stdenv.mkDerivation {
   name = "teyjus-2.0b2";
 
   src = fetchurl {
-    url = "https://teyjus.googlecode.com/files/teyjus-source-2.0-b2.tar.gz";
+    url = "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/teyjus/teyjus-source-2.0-b2.tar.gz";
     sha256 = "f589fb460d7095a6e674b7a6413772c41b98654c38602c3e8c477a976da99052";
   };
 
@@ -22,7 +22,7 @@ stdenv.mkDerivation {
 
   meta = with stdenv.lib; {
     description = "An efficient implementation of the Lambda Prolog language";
-    homepage = https://code.google.com/p/teyjus/;
+    homepage = https://github.com/teyjus/teyjus;
     license = stdenv.lib.licenses.gpl3;
     maintainers = [ maintainers.bcdarwin ];
     platforms = platforms.linux;
diff --git a/pkgs/development/compilers/tinycc/default.nix b/pkgs/development/compilers/tinycc/default.nix
index 7e083ffe67be..e88246ecb939 100644
--- a/pkgs/development/compilers/tinycc/default.nix
+++ b/pkgs/development/compilers/tinycc/default.nix
@@ -2,10 +2,10 @@
 with stdenv.lib;
 
 let
-  date = "20170710";
+  date = "20171016";
+  rev = "da8c62f75d893449e232944fc62566c020b4d010";
+  sha256 = "0pdvyhrx7g9imxpc7gr75116imi6ifn0ihsl4fbffsji2dpi61y2";
   version = "0.9.27pre-${date}";
-  rev = "2acb04f7f2077a4cff103421d79ceee48441918a";
-  sha256 = "1rh89dx1myqfm752d4rlzrm8aadfm17fm88ps0q9ibmbxavb45qw";
 in
 
 stdenv.mkDerivation rec {
diff --git a/pkgs/development/compilers/urweb/default.nix b/pkgs/development/compilers/urweb/default.nix
index 7145a8f2fa04..74ca5dc4c4b0 100644
--- a/pkgs/development/compilers/urweb/default.nix
+++ b/pkgs/development/compilers/urweb/default.nix
@@ -1,5 +1,5 @@
 { stdenv, lib, fetchurl, file, openssl, mlton
-, mysql, postgresql, sqlite
+, mysql, postgresql, sqlite, gcc
 }:
 
 stdenv.mkDerivation rec {
@@ -24,8 +24,10 @@ stdenv.mkDerivation rec {
     export MSHEADER="${lib.getDev mysql.client}/include/mysql/mysql.h";
     export SQHEADER="${sqlite.dev}/include/sqlite3.h";
 
+    export CC="${gcc}/bin/gcc";
     export CCARGS="-I$out/include \
-                   -L${lib.getLib mysql.client}/lib/mysql \
+                   -L${openssl.out}/lib \
+                   -L${lib.getLib mysql.client}/lib \
                    -L${postgresql.lib}/lib \
                    -L${sqlite.out}/lib";
   '';
@@ -37,7 +39,7 @@ stdenv.mkDerivation rec {
     description = "Advanced purely-functional web programming language";
     homepage    = "http://www.impredicative.com/ur/";
     license     = stdenv.lib.licenses.bsd3;
-    platforms   = stdenv.lib.platforms.linux;
+    platforms   = stdenv.lib.platforms.linux ++ stdenv.lib.platforms.darwin;
     maintainers = [ stdenv.lib.maintainers.thoughtpolice stdenv.lib.maintainers.sheganinans ];
   };
 }
diff --git a/pkgs/development/compilers/vala/default.nix b/pkgs/development/compilers/vala/default.nix
index 42b81a21a671..baf48d7a532c 100644
--- a/pkgs/development/compilers/vala/default.nix
+++ b/pkgs/development/compilers/vala/default.nix
@@ -1,9 +1,9 @@
-{ stdenv, fetchurl, pkgconfig, flex, bison, libxslt
-, glib, libiconv, libintlOrEmpty
+{ stdenv, fetchurl, pkgconfig, flex, bison, libxslt, autoconf, graphviz
+, glib, libiconv, libintlOrEmpty, libtool, expat
 }:
 
 let
-  generic = { major, minor, sha256 }:
+  generic = { major, minor, sha256, extraNativeBuildInputs ? [], extraBuildInputs ? [] }:
   stdenv.mkDerivation rec {
     name = "vala-${major}.${minor}";
 
@@ -12,9 +12,9 @@ let
       inherit sha256;
     };
 
-    nativeBuildInputs = [ pkgconfig flex bison libxslt ];
+    nativeBuildInputs = [ pkgconfig flex bison libxslt ] ++ extraNativeBuildInputs;
 
-    buildInputs = [ glib libiconv ] ++ libintlOrEmpty;
+    buildInputs = [ glib libiconv ] ++ libintlOrEmpty ++ extraBuildInputs;
 
     meta = with stdenv.lib; {
       description = "Compiler for GObject type system";
@@ -57,5 +57,13 @@ in rec {
     sha256  = "16cjybjw100qps6jg0jdyjh8hndz8a876zmxpybnf30a8vygrk7m";
   };
 
+  vala_0_38 = generic {
+    major   = "0.38";
+    minor   = "1";
+    sha256  = "112hl3lkcyakrk8c3qgw12gzn3nxjkvx7bn0jhl5f2m57d7k8d8h";
+    extraNativeBuildInputs = [ autoconf ] ++ stdenv.lib.optionals stdenv.isDarwin [ libtool expat ];
+    extraBuildInputs = [ graphviz ];
+  };
+
   vala = vala_0_34;
 }
diff --git a/pkgs/development/compilers/yosys/default.nix b/pkgs/development/compilers/yosys/default.nix
index b91eddee3bfd..b1c36f841a4b 100644
--- a/pkgs/development/compilers/yosys/default.nix
+++ b/pkgs/development/compilers/yosys/default.nix
@@ -1,28 +1,32 @@
-{ stdenv, fetchFromGitHub, fetchFromBitbucket, pkgconfig, tcl, readline, libffi, python3, bison, flex }:
+{ stdenv, fetchFromGitHub, fetchFromBitbucket
+, pkgconfig, tcl, readline, libffi, python3, bison, flex
+}:
 
 stdenv.mkDerivation rec {
   name = "yosys-${version}";
-  version = "2016.11.25";
+  version = "2017.11.05";
 
   srcs = [
     (fetchFromGitHub {
       owner = "cliffordwolf";
       repo = "yosys";
-      rev = "5c2c78e2dd12a860f830dafd73fbed8edf1a3823";
-      sha256 = "1cvfkg0hllp7k2g52mxczd8d0ad7inlpkg27rrbyani2kg0066bk";
+      rev = "4f31cb6daddedcee467d85797d81b79360ce1826";
+      sha256 = "1a5n0g5kpjsy8f99f64w81gkrr450wvffp407r1pddl8pmb0c3r7";
       name = "yosys";
     })
     (fetchFromBitbucket {
       owner = "alanmi";
       repo = "abc";
-      rev = "238674cd44f2";
-      sha256 = "18xk7lqai05am11zymixilgam4jvz5f2jwy9cgillz035man2yzw";
+      rev = "f6838749f234";
+      sha256 = "0n7ywvih958h1c4n7a398a9w3qikhkv885fx5j3y2a0xwqc86m4y";
       name = "yosys-abc";
     })
   ];
   sourceRoot = "yosys";
 
-  buildInputs = [ pkgconfig tcl readline libffi python3 bison flex ];
+  enableParallelBuilding = true;
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ tcl readline libffi python3 bison flex ];
   preBuild = ''
     chmod -R u+w ../yosys-abc
     ln -s ../yosys-abc abc
@@ -42,9 +46,9 @@ stdenv.mkDerivation rec {
       adding additional passes as needed by extending the yosys C++
       code base.
     '';
-    homepage = http://www.clifford.at/yosys/;
-    license = stdenv.lib.licenses.isc;
-    maintainers = [ stdenv.lib.maintainers.shell ];
-    platforms = stdenv.lib.platforms.linux;
+    homepage    = http://www.clifford.at/yosys/;
+    license     = stdenv.lib.licenses.isc;
+    maintainers = with stdenv.lib.maintainers; [ shell thoughtpolice ];
+    platforms   = stdenv.lib.platforms.linux;
   };
 }
diff --git a/pkgs/development/compilers/zig/default.nix b/pkgs/development/compilers/zig/default.nix
new file mode 100644
index 000000000000..6f0c6d19e450
--- /dev/null
+++ b/pkgs/development/compilers/zig/default.nix
@@ -0,0 +1,34 @@
+{ stdenv, fetchFromGitHub, cmake, llvmPackages_5, llvm_5 }:
+
+stdenv.mkDerivation rec {
+  version = "0.1.1";
+  name = "zig-${version}";
+
+  src = fetchFromGitHub {
+    owner = "zig-lang";
+    repo = "zig";
+    rev = "${version}";
+    sha256 = "01yqjyi25f99bfmxxwyh45k7j84z0zg7n9jl8gg0draf96mzdh06";
+  };
+
+  buildInputs = [ cmake llvmPackages_5.clang-unwrapped llvm_5 ];
+
+  cmakeFlags = [
+    "-DZIG_LIBC_INCLUDE_DIR=${stdenv.cc.libc_dev}/include"
+    "-DZIG_LIBC_LIB_DIR=${stdenv.cc.libc}/lib"
+    "-DCMAKE_BUILD_TYPE=Release"
+    "-DZIG_EACH_LIB_RPATH=On"
+  ];
+
+  preConfigure = ''
+    cmakeFlags="$cmakeFlags -DZIG_LIBC_STATIC_LIB_DIR=$(dirname $(cc -print-file-name=crtbegin.o)) -DZIG_DYNAMIC_LINKER=$(cc -print-file-name=ld-linux-x86-64.so.2)"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Programming languaged designed for robustness, optimality, and clarity";
+    homepage = http://ziglang.org/;
+    license = licenses.mit;
+    platforms = platforms.unix;
+    maintainers = [ maintainers.andrewrk ];
+  };
+}
diff --git a/pkgs/development/compilers/zulu/8.nix b/pkgs/development/compilers/zulu/8.nix
new file mode 100644
index 000000000000..f7638757ff7a
--- /dev/null
+++ b/pkgs/development/compilers/zulu/8.nix
@@ -0,0 +1,82 @@
+{ stdenv, lib, fetchurl, unzip, makeWrapper, setJavaClassPath
+, zulu, glib, libxml2, libav_0_8, ffmpeg, libxslt, mesa_noglu, alsaLib
+, fontconfig, freetype, gnome2, cairo, gdk_pixbuf, atk, xorg
+, swingSupport ? true }:
+
+let
+  version = "8.21.0.1";
+  openjdk = "8.0.131";
+
+  sha256_linux = "0cr1wvk1ifdq69ia8sr6171yzciba8l5x7dszwa5g2v0vmmqq88p";
+  sha256_darwin = "0xq9bdzbdq8wq48gj6j56bw30l2iafz6sy1wdhrf92n9bnz5qmw7";
+
+  platform = if stdenv.isDarwin then "macosx" else "linux";
+  hash = if stdenv.isDarwin then sha256_darwin else sha256_linux;
+  extension = if stdenv.isDarwin then "zip" else "tar.gz";
+
+  libraries = [
+    stdenv.cc.libc glib libxml2 libav_0_8 ffmpeg libxslt mesa_noglu
+    xorg.libXxf86vm alsaLib fontconfig freetype gnome2.pango
+    gnome2.gtk cairo gdk_pixbuf atk
+  ] ++ (lib.optionals swingSupport (with xorg; [
+    xorg.libX11 xorg.libXext xorg.libXtst xorg.libXi xorg.libXp
+    xorg.libXt xorg.libXrender stdenv.cc.cc
+  ]));
+
+in stdenv.mkDerivation rec {
+  inherit version openjdk platform hash extension;
+
+  name = "zulu-${version}";
+
+  src = fetchurl {
+    url = "https://cdn.azul.com/zulu/bin/zulu${version}-jdk${openjdk}-${platform}_x64.${extension}";
+    sha256 = hash;
+  };
+
+  buildInputs = [ makeWrapper ] ++ lib.optional stdenv.isDarwin unzip;
+
+  installPhase = ''
+    mkdir -p $out
+    cp -r ./* "$out/"
+
+    jrePath="$out/jre"
+
+    rpath=$rpath''${rpath:+:}$jrePath/lib/amd64/jli
+    rpath=$rpath''${rpath:+:}$jrePath/lib/amd64/server
+    rpath=$rpath''${rpath:+:}$jrePath/lib/amd64/xawt
+    rpath=$rpath''${rpath:+:}$jrePath/lib/amd64
+
+    # set all the dynamic linkers
+    find $out -type f -perm -0100 \
+        -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
+        --set-rpath "$rpath" {} \;
+
+    find $out -name "*.so" -exec patchelf --set-rpath "$rpath" {} \;
+
+    mkdir -p $out/nix-support
+    printWords ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs
+
+    # Set JAVA_HOME automatically.
+    cat <<EOF >> $out/nix-support/setup-hook
+    if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
+    EOF
+  '';
+
+  rpath = stdenv.lib.strings.makeLibraryPath libraries;
+
+  passthru = {
+    home = "${zulu}";
+  };
+
+  meta = with stdenv.lib; {
+    homepage = https://www.azul.com/products/zulu/;
+    license = licenses.gpl2;
+    description = "Certified builds of OpenJDK";
+    longDescription = ''
+      Certified builds of OpenJDK that can be deployed across multiple
+      operating systems, containers, hypervisors and Cloud platforms.
+    '';
+    maintainers = with maintainers; [ nequissimus fpletz ];
+    platforms = [ "x86_64-linux" "x86_64-darwin" ];
+  };
+}
diff --git a/pkgs/development/compilers/zulu/default.nix b/pkgs/development/compilers/zulu/default.nix
index f7638757ff7a..92f1f0a111ed 100644
--- a/pkgs/development/compilers/zulu/default.nix
+++ b/pkgs/development/compilers/zulu/default.nix
@@ -1,14 +1,14 @@
 { stdenv, lib, fetchurl, unzip, makeWrapper, setJavaClassPath
 , zulu, glib, libxml2, libav_0_8, ffmpeg, libxslt, mesa_noglu, alsaLib
-, fontconfig, freetype, gnome2, cairo, gdk_pixbuf, atk, xorg
+, fontconfig, freetype, gnome2, cairo, gdk_pixbuf, atk, xorg, zlib
 , swingSupport ? true }:
 
 let
-  version = "8.21.0.1";
-  openjdk = "8.0.131";
+  version = "9.0.0.15";
+  openjdk = "9.0.0";
 
-  sha256_linux = "0cr1wvk1ifdq69ia8sr6171yzciba8l5x7dszwa5g2v0vmmqq88p";
-  sha256_darwin = "0xq9bdzbdq8wq48gj6j56bw30l2iafz6sy1wdhrf92n9bnz5qmw7";
+  sha256_linux = "0s9vr135yhdnxqds4hfafyrlh33j6g78v6l1v0ap2y6yqgabh9qi";
+  sha256_darwin = "104w1msrwijf8dv3n65hjinp7i47z6ygzjipdzqriqam2zljxn4b";
 
   platform = if stdenv.isDarwin then "macosx" else "linux";
   hash = if stdenv.isDarwin then sha256_darwin else sha256_linux;
@@ -17,7 +17,7 @@ let
   libraries = [
     stdenv.cc.libc glib libxml2 libav_0_8 ffmpeg libxslt mesa_noglu
     xorg.libXxf86vm alsaLib fontconfig freetype gnome2.pango
-    gnome2.gtk cairo gdk_pixbuf atk
+    gnome2.gtk cairo gdk_pixbuf atk zlib
   ] ++ (lib.optionals swingSupport (with xorg; [
     xorg.libX11 xorg.libXext xorg.libXtst xorg.libXi xorg.libXp
     xorg.libXt xorg.libXrender stdenv.cc.cc
@@ -39,12 +39,9 @@ in stdenv.mkDerivation rec {
     mkdir -p $out
     cp -r ./* "$out/"
 
-    jrePath="$out/jre"
-
-    rpath=$rpath''${rpath:+:}$jrePath/lib/amd64/jli
-    rpath=$rpath''${rpath:+:}$jrePath/lib/amd64/server
-    rpath=$rpath''${rpath:+:}$jrePath/lib/amd64/xawt
-    rpath=$rpath''${rpath:+:}$jrePath/lib/amd64
+    rpath=$rpath''${rpath:+:}$out/lib/jli
+    rpath=$rpath''${rpath:+:}$out/lib/server
+    rpath=$rpath''${rpath:+:}$out/lib
 
     # set all the dynamic linkers
     find $out -type f -perm -0100 \