summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/applications/editors/vim/default.nix6
-rw-r--r--pkgs/applications/version-management/subversion/default.nix10
-rw-r--r--pkgs/build-support/cabal/default.nix5
-rw-r--r--pkgs/build-support/clang-wrapper/add-flags24
-rw-r--r--pkgs/build-support/clang-wrapper/builder.sh137
-rw-r--r--pkgs/build-support/clang-wrapper/clang-wrapper.sh150
-rw-r--r--pkgs/build-support/clang-wrapper/default.nix89
-rw-r--r--pkgs/build-support/clang-wrapper/setup-hook.sh38
-rw-r--r--pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh11
-rw-r--r--pkgs/build-support/gcc-wrapper/add-flags16
-rw-r--r--pkgs/build-support/gcc-wrapper/builder.sh214
-rw-r--r--pkgs/build-support/gcc-wrapper/default.nix246
-rw-r--r--pkgs/build-support/gcc-wrapper/gcc-wrapper.sh80
-rw-r--r--pkgs/build-support/gcc-wrapper/gnat-wrapper.sh50
-rw-r--r--pkgs/build-support/gcc-wrapper/gnatlink-wrapper.sh22
-rw-r--r--pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh2
-rw-r--r--pkgs/build-support/gcc-wrapper/ld-wrapper.sh62
-rw-r--r--pkgs/build-support/gcc-wrapper/setup-hook.sh20
-rw-r--r--pkgs/build-support/gcc-wrapper/utils.sh8
-rw-r--r--pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh6
-rw-r--r--pkgs/development/compilers/gcc/4.2-apple64/default.nix1
-rw-r--r--pkgs/development/compilers/ghc/7.4.2-binary.nix3
-rw-r--r--pkgs/development/compilers/ghc/7.8.3-binary.nix93
-rw-r--r--pkgs/development/compilers/ghc/7.8.3.nix2
-rw-r--r--pkgs/development/compilers/llvm/3.4/clang.nix4
-rw-r--r--pkgs/development/compilers/llvm/3.4/llvm.nix6
-rw-r--r--pkgs/development/compilers/ocaml/4.01.0.nix2
-rw-r--r--pkgs/development/compilers/ocaml/fix-clang-build-on-osx.diff20
-rw-r--r--pkgs/development/interpreters/guile/clang.patch14
-rw-r--r--pkgs/development/interpreters/guile/default.nix6
-rw-r--r--pkgs/development/interpreters/lua-5/5.1.nix2
-rw-r--r--pkgs/development/interpreters/perl/5.16/default.nix1
-rw-r--r--pkgs/development/interpreters/ruby/ruby-1.9.3.nix2
-rw-r--r--pkgs/development/libraries/apr-util/default.nix3
-rw-r--r--pkgs/development/libraries/aspell/clang.patch18
-rw-r--r--pkgs/development/libraries/aspell/default.nix4
-rw-r--r--pkgs/development/libraries/boost/1.55.nix6
-rw-r--r--pkgs/development/libraries/boost/boost-155-clang.patch90
-rw-r--r--pkgs/development/libraries/cyrus-sasl/default.nix9
-rw-r--r--pkgs/development/libraries/db/generic.nix4
-rw-r--r--pkgs/development/libraries/db/osx.patch20
-rw-r--r--pkgs/development/libraries/gmp/5.1.x.nix3
-rw-r--r--pkgs/development/libraries/libc++/darwin.patch30
-rw-r--r--pkgs/development/libraries/libc++/default.nix30
-rw-r--r--pkgs/development/libraries/libc++/setup-hook.sh2
-rw-r--r--pkgs/development/libraries/libc++abi/darwin.patch17
-rw-r--r--pkgs/development/libraries/libc++abi/default.nix36
-rw-r--r--pkgs/development/libraries/libc++abi/no-stdc++.patch12
-rw-r--r--pkgs/development/libraries/libdevil/default.nix9
-rw-r--r--pkgs/development/libraries/libedit/default.nix2
-rw-r--r--pkgs/development/libraries/libffi/default.nix5
-rw-r--r--pkgs/development/libraries/libgcrypt/default.nix2
-rw-r--r--pkgs/development/libraries/libunistring/clang.patch14
-rw-r--r--pkgs/development/libraries/libunistring/default.nix2
-rw-r--r--pkgs/development/libraries/mesa-darwin/default.nix2
-rw-r--r--pkgs/development/libraries/mpc/default.nix2
-rw-r--r--pkgs/development/libraries/mpfr/default.nix2
-rw-r--r--pkgs/development/libraries/ncurses/clang.patch42
-rw-r--r--pkgs/development/libraries/ncurses/default.nix4
-rw-r--r--pkgs/development/libraries/qt-4.x/4.8/default.nix2
-rw-r--r--pkgs/development/libraries/readline/6.2.nix1
-rw-r--r--pkgs/development/libraries/readline/clang.patch13
-rw-r--r--pkgs/development/libraries/serf/default.nix14
-rw-r--r--pkgs/development/libraries/v8/default.nix2
-rw-r--r--pkgs/development/tools/misc/ccache/default.nix2
-rw-r--r--pkgs/development/tools/misc/distcc/masq.nix4
-rw-r--r--pkgs/development/tools/misc/sloccount/default.nix1
-rw-r--r--pkgs/games/spring/default.nix4
-rw-r--r--pkgs/servers/http/nginx/default.nix2
-rw-r--r--pkgs/servers/x11/xorg/overrides.nix10
-rw-r--r--pkgs/stdenv/adapters.nix25
-rw-r--r--pkgs/stdenv/darwin/default.nix49
-rw-r--r--pkgs/stdenv/default.nix22
-rw-r--r--pkgs/stdenv/generic/default.nix3
-rw-r--r--pkgs/stdenv/native/default.nix9
-rw-r--r--pkgs/stdenv/nix/default.nix17
-rw-r--r--pkgs/tools/archivers/sharutils/default.nix6
-rw-r--r--pkgs/tools/compression/bzip2/default.nix2
-rw-r--r--pkgs/tools/misc/getopt/default.nix3
-rw-r--r--pkgs/tools/networking/isync/default.nix2
-rw-r--r--pkgs/tools/networking/strongswan/default.nix2
-rw-r--r--pkgs/tools/package-management/nix/default.nix3
-rw-r--r--pkgs/tools/package-management/nix/unstable.nix5
-rw-r--r--pkgs/tools/security/gnupg/clang.patch13
-rw-r--r--pkgs/tools/security/gnupg/default.nix1
-rw-r--r--pkgs/tools/system/tree/default.nix1
-rw-r--r--pkgs/tools/text/sgml/opensp/default.nix7
-rw-r--r--pkgs/tools/typesetting/tex/tetex/clang.patch13
-rw-r--r--pkgs/tools/typesetting/tex/tetex/default.nix2
-rw-r--r--pkgs/tools/typesetting/tex/tex4ht/default.nix2
-rw-r--r--pkgs/tools/typesetting/tex/texlive/default.nix1
-rw-r--r--pkgs/top-level/all-packages.nix87
-rw-r--r--pkgs/top-level/haskell-defaults.nix4
93 files changed, 1020 insertions, 1036 deletions
diff --git a/pkgs/applications/editors/vim/default.nix b/pkgs/applications/editors/vim/default.nix
index 95f654eb8ca..8f27f540997 100644
--- a/pkgs/applications/editors/vim/default.nix
+++ b/pkgs/applications/editors/vim/default.nix
@@ -3,12 +3,12 @@
 stdenv.mkDerivation rec {
   name = "vim-${version}";
 
-  version = "7.4.335";
+  version = "7.4.410";
 
   src = fetchhg {
     url = "https://vim.googlecode.com/hg/";
-    rev = "v7-4-335";
-    sha256 = "0qnpzfcbi6fhz82pj68l4vrnigca1akq2ksrxz6krwlfhns6jhhj";
+    rev = "v7-4-410";
+    sha256 = "145llhj6gq2bh9b7p8xkxc388krrximq80b87f3cn4w4d4k9fhqp";
   };
 
   enableParallelBuilding = true;
diff --git a/pkgs/applications/version-management/subversion/default.nix b/pkgs/applications/version-management/subversion/default.nix
index 283ea759153..ff19b0af16f 100644
--- a/pkgs/applications/version-management/subversion/default.nix
+++ b/pkgs/applications/version-management/subversion/default.nix
@@ -38,16 +38,14 @@ stdenv.mkDerivation rec {
     ${if pythonBindings || perlBindings then "--with-swig=${swig}" else "--without-swig"}
     ${if javahlBindings then "--enable-javahl --with-jdk=${jdk}" else ""}
     ${if stdenv.isDarwin then "--enable-keychain" else "--disable-keychain"}
-    ${if saslSupport then "--enable-sasl --with-sasl=${sasl}" else "--disable-sasl"}
-    ${if httpSupport then "--enable-serf --with-serf=${serf}" else "--disable-serf"}
+    ${if saslSupport then "--with-sasl=${sasl}" else "--without-sasl"}
+    ${if httpSupport then "--with-serf=${serf}" else "--without-serf"}
     --with-zlib=${zlib}
     --with-sqlite=${sqlite}
   '';
 
   preBuild = ''
     makeFlagsArray=(APACHE_LIBEXECDIR=$out/modules)
-  '' + stdenv.lib.optionalString stdenv.isDarwin ''
-    substituteInPlace configure --replace "-no-cpp-precomp" ""
   '';
 
   postInstall = ''
@@ -73,10 +71,6 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
-  # Hack to build on Mac OS X. The system header files use C99-style
-  # comments, but Subversion passes -std=c90.
-  NIX_CFLAGS_COMPILE = "-std=c99";
-
   meta = {
     description = "A version control system intended to be a compelling replacement for CVS in the open source community";
     homepage = http://subversion.apache.org/;
diff --git a/pkgs/build-support/cabal/default.nix b/pkgs/build-support/cabal/default.nix
index 3fa83387692..49618266d79 100644
--- a/pkgs/build-support/cabal/default.nix
+++ b/pkgs/build-support/cabal/default.nix
@@ -218,6 +218,10 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
                 configureFlags+=" --ghc-option=-optl=-Wl,-headerpad_max_install_names"
               ''}
 
+              ${optionalString self.stdenv.isDarwin ''
+                configureFlags+=" --with-gcc=clang"
+              ''}
+
               echo "configure flags: $extraConfigureFlags $configureFlags"
               ./Setup configure --verbose --prefix="$out" --libdir='$prefix/lib/$compiler' \
                 --libsubdir='$pkgid' $extraConfigureFlags $configureFlags 2>&1 \
@@ -240,6 +244,7 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
 
               export GHC_PACKAGE_PATH=$(${ghc.GHCPackages})
               test -n "$noHaddock" || ./Setup haddock --html --hoogle \
+                  --ghc-options=-optP-P \
                   ${optionalString self.hyperlinkSource "--hyperlink-source"}
 
               eval "$postBuild"
diff --git a/pkgs/build-support/clang-wrapper/add-flags b/pkgs/build-support/clang-wrapper/add-flags
deleted file mode 100644
index 7a9711290aa..00000000000
--- a/pkgs/build-support/clang-wrapper/add-flags
+++ /dev/null
@@ -1,24 +0,0 @@
-# `-B@out@/bin' forces clang to use ld-wrapper.sh when calling ld.
-export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
-
-if test -e @out@/nix-support/libc-cflags; then
-    export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
-fi
-
-if test -e @out@/nix-support/clang-cflags; then
-    export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/clang-cflags) $NIX_CFLAGS_COMPILE"
-fi
-
-if test -e @out@/nix-support/libc-ldflags; then
-    export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/libc-ldflags)"
-fi
-
-if test -e @out@/nix-support/clang-ldflags; then
-    export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/clang-ldflags)"
-fi
-
-if test -e @out@/nix-support/libc-ldflags-before; then
-    export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
-fi
-
-export NIX_GCC_WRAPPER_FLAGS_SET=1
diff --git a/pkgs/build-support/clang-wrapper/builder.sh b/pkgs/build-support/clang-wrapper/builder.sh
deleted file mode 100644
index 0cdb2b96135..00000000000
--- a/pkgs/build-support/clang-wrapper/builder.sh
+++ /dev/null
@@ -1,137 +0,0 @@
-source $stdenv/setup
-
-
-mkdir -p $out/bin
-mkdir -p $out/nix-support
-
-
-if test -z "$nativeLibc"; then
-    dynamicLinker="$libc/lib/$dynamicLinker"
-    echo $dynamicLinker > $out/nix-support/dynamic-linker
-
-    if test -e $libc/lib/32/ld-linux.so.2; then
-        echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
-    fi
-
-    # The "-B$libc/lib/" flag is a quick hack to force clang to link
-    # against the crt1.o from our own glibc, rather than the one in
-    # /usr/lib.  (This is only an issue when using an `impure'
-    # compiler/linker, i.e., one that searches /usr/lib and so on.)
-    echo "-B$libc/lib/ -idirafter $libc/include" > $out/nix-support/libc-cflags
-
-    echo "-L$libc/lib" > $out/nix-support/libc-ldflags
-
-    # The dynamic linker is passed in `ldflagsBefore' to allow
-    # explicit overrides of the dynamic linker by callers to clang/ld
-    # (the *last* value counts, so ours should come first).
-    echo "-dynamic-linker $dynamicLinker" > $out/nix-support/libc-ldflags-before
-fi
-
-if test -n "$nativeTools"; then
-    clangPath="$nativePrefix/bin"
-    ldPath="$nativePrefix/bin"
-else
-    basePath=`echo $gcc/lib/*/*/*`
-    # Need libgcc until the llvm compiler-rt library is complete
-    clangLDFlags="$clangLDFlags -L$basePath"
-    if test -e "$gcc/lib64"; then
-        clangLDFlags="$clangLDFlags -L$gcc/lib64"
-    else
-        clangLDFlags="$clangLDFlags -L$gcc/lib"
-    fi
-
-    clangLDFlags="$clangLDFlags -L$clang/lib"
-    echo "$clangLDFlags" > $out/nix-support/clang-ldflags
-
-    # Need files like crtbegin.o from gcc
-    # It's unclear if these will ever be provided by an LLVM project
-    clangCFlags="$clangCFlags -B$basePath"
-
-    clangCFlags="$clangCFlags -isystem$clang/lib/clang/$clangVersion/include"
-    echo "$clangCFlags" > $out/nix-support/clang-cflags
-    
-    clangPath="$clang/bin"
-    ldPath="$binutils/bin"
-fi
-
-
-doSubstitute() {
-    local src=$1
-    local dst=$2
-    local uselibcxx=
-    local uselibcxxabi=
-    if test -n "$libcxx" && echo $dst | fgrep ++; then uselibcxx=$libcxx; fi
-    if test -n "$libcxxabi" && echo $dst | fgrep ++; then uselibcxxabi=$libcxxabi; fi
-    # Can't use substitute() here, because replace may not have been
-    # built yet (in the bootstrap).
-    sed \
-        -e "s^@out@^$out^g" \
-        -e "s^@shell@^$shell^g" \
-        -e "s^@libcxx@^$uselibcxx^g" \
-        -e "s^@libcxxabi@^$uselibcxxabi^g" \
-        -e "s^@clang@^$clang^g" \
-        -e "s^@clangProg@^$clangProg^g" \
-        -e "s^@binutils@^$binutils^g" \
-        -e "s^@coreutils@^$coreutils^g" \
-        -e "s^@libc@^$libc^g" \
-        -e "s^@ld@^$ldPath/ld^g" \
-        < "$src" > "$dst" 
-}
-
-
-# Make wrapper scripts around clang and clang++.  Also make symlinks
-# cc and c++
-mkClangWrapper() {
-    local dst=$1
-    local src=$2
-
-    if ! test -f "$src"; then
-        echo "$src does not exist (skipping)"
-        return 1
-    fi
-
-    clangProg="$src"
-    doSubstitute "$clangWrapper" "$dst"
-    chmod +x "$dst"
-}
-
-if mkClangWrapper $out/bin/clang $clangPath/clang
-then
-    ln -sv clang $out/bin/cc
-fi
-
-if mkClangWrapper $out/bin/clang++ $clangPath/clang++
-then
-    ln -sv clang++ $out/bin/c++
-fi
-
-
-# Create a symlink to as (the assembler).  This is useful when a
-# clang-wrapper is installed in a user environment, as it ensures that
-# the right assembler is called.
-ln -s $ldPath/as $out/bin/as
-
-
-# Make a wrapper around the linker.
-doSubstitute "$ldWrapper" "$out/bin/ld"
-chmod +x "$out/bin/ld"
-
-
-# Emit a setup hook.  Also store the path to the original Clang and
-# libc.
-test -n "$clang" && echo $clang > $out/nix-support/orig-clang
-test -n "$libc" && echo $libc > $out/nix-support/orig-libc
-
-doSubstitute "$addFlags" "$out/nix-support/add-flags.sh"
-
-doSubstitute "$setupHook" "$out/nix-support/setup-hook"
-
-cp -p $utils $out/nix-support/utils.sh
-
-
-# Propagate the wrapped clang so that if you install the wrapper, you get
-# llvm tools, the manpages, etc. as well (including for binutils
-# and Glibc).
-if test -z "$nativeTools"; then
-    echo $clang $binutils $libc > $out/nix-support/propagated-user-env-packages
-fi
diff --git a/pkgs/build-support/clang-wrapper/clang-wrapper.sh b/pkgs/build-support/clang-wrapper/clang-wrapper.sh
deleted file mode 100644
index 57715274f1e..00000000000
--- a/pkgs/build-support/clang-wrapper/clang-wrapper.sh
+++ /dev/null
@@ -1,150 +0,0 @@
-#! @shell@ -e
-
-if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then
-    source "$NIX_GCC_WRAPPER_START_HOOK"
-fi
-
-if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
-    source @out@/nix-support/add-flags.sh
-fi
-
-source @out@/nix-support/utils.sh
-
-
-# Figure out if linker flags should be passed.  Clang prints annoying
-# warnings when they are not needed. (does it really? Copied from gcc-wrapper)
-dontLink=0
-getVersion=0
-nonFlagArgs=0
-
-for i in "$@"; do
-    if test "$i" = "-c"; then
-        dontLink=1
-    elif test "$i" = "-S"; then
-        dontLink=1
-    elif test "$i" = "-E"; then
-        dontLink=1
-    elif test "$i" = "-E"; then
-        dontLink=1
-    elif test "$i" = "-M"; then
-        dontLink=1
-    elif test "$i" = "-MM"; then
-        dontLink=1
-    elif test "$i" = "-x"; then
-        # At least for the cases c-header or c++-header we should set dontLink.
-        # I expect no one use -x other than making precompiled headers.
-        dontLink=1
-    elif test "${i:0:1}" != "-"; then
-        nonFlagArgs=1
-    elif test "$i" = "-m32"; then
-        if test -e @out@/nix-support/dynamic-linker-m32; then
-            NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
-        fi
-    fi
-done
-
-# If we pass a flag like -Wl, then clang will call the linker unless it
-# can figure out that it has to do something else (e.g., because of a
-# "-c" flag).  So if no non-flag arguments are given, don't pass any
-# linker flags.  This catches cases like "clang" (should just print
-# "clang: no input files") and "clang -v" (should print the version).
-if test "$nonFlagArgs" = "0"; then
-    dontLink=1
-fi
-
-# Optionally filter out paths not refering to the store.
-params=("$@")
-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
-    rest=()
-    n=0
-    while test $n -lt ${#params[*]}; do
-        p=${params[n]}
-        p2=${params[$((n+1))]}
-        if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
-            skip $p
-        elif test "$p" = "-L" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        elif test "${p:0:3}" = "-I/" && badPath "${p:2}"; then
-            skip $p
-        elif test "$p" = "-I" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        elif test "$p" = "-isystem" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        else
-            rest=("${rest[@]}" "$p")
-        fi
-        n=$((n + 1))
-    done
-    params=("${rest[@]}")
-    NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE --sysroot=/var/empty"
-fi
-
-if test -n "@libcxx@"; then
-    NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem@libcxx@/include/c++/v1 -stdlib=libc++"
-    NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK -L@libcxx@/lib -stdlib=libc++ -L@libcxxabi@/lib -lc++abi"
-fi
-
-# Add the flags for the C compiler proper.
-extraAfter=($NIX_CFLAGS_COMPILE)
-extraBefore=()
-
-if test "$dontLink" != "1"; then
-
-    # Add the flags that should only be passed to the compiler when
-    # linking.
-    extraAfter=(${extraAfter[@]} $NIX_CFLAGS_LINK)
-
-    # Add the flags that should be passed to the linker (and prevent
-    # `ld-wrapper' from adding NIX_LDFLAGS again).
-    for i in $NIX_LDFLAGS_BEFORE; do
-        extraBefore=(${extraBefore[@]} "-Wl,$i")
-    done
-    for i in $NIX_LDFLAGS; do
-	if test "${i:0:3}" = "-L/"; then
-	    extraAfter=(${extraAfter[@]} "$i")
-	else
-	    extraAfter=(${extraAfter[@]} "-Wl,$i")
-	fi
-    done
-    export NIX_LDFLAGS_SET=1
-fi
-
-# As a very special hack, if the arguments are just `-v', then don't
-# add anything.  This is to prevent `clang -v' (which normally prints
-# out the version number and returns exit code 0) from printing out
-# `No input files specified' and returning exit code 1.
-if test "$*" = "-v"; then
-    extraAfter=()
-    extraBefore=()
-fi    
-
-# Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @clangProg@:" >&2
-  for i in "${params[@]}"; do
-      echo "  $i" >&2
-  done
-  echo "extraBefore flags to @clangProg@:" >&2
-  for i in ${extraBefore[@]}; do
-      echo "  $i" >&2
-  done
-  echo "extraAfter flags to @clangProg@:" >&2
-  for i in ${extraAfter[@]}; do
-      echo "  $i" >&2
-  done
-fi
-
-if test -n "$NIX_CLANG_WRAPPER_EXEC_HOOK"; then
-    source "$NIX_CLANG_WRAPPER_EXEC_HOOK"
-fi
-
-# Call the real `clang'.  Filter out warnings from stderr about unused
-# `-B' flags, since they confuse some programs.  Deep bash magic to
-# apply grep to stderr (by swapping stdin/stderr twice).
-if test -z "$NIX_CLANG_NEEDS_GREP"; then
-    @clangProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
-else
-    (@clangProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
-        | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
-    exit $?
-fi    
diff --git a/pkgs/build-support/clang-wrapper/default.nix b/pkgs/build-support/clang-wrapper/default.nix
deleted file mode 100644
index 7a5d87127d9..00000000000
--- a/pkgs/build-support/clang-wrapper/default.nix
+++ /dev/null
@@ -1,89 +0,0 @@
-# The Nix `clang' stdenv.mkDerivation is not directly usable, since it doesn't
-# know where the C library and standard header files are.  Therefore
-# the compiler produced by that package cannot be installed directly
-# in a user environment and used from the command line.  This
-# stdenv.mkDerivation provides a wrapper that sets up the right environment
-# variables so that the compiler and the linker just "work".
-
-{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
-, clang ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
-, zlib ? null, libcxx ? null
-}:
-
-assert nativeTools -> nativePrefix != "";
-assert !nativeTools -> clang != null && binutils != null && coreutils != null;
-assert !nativeLibc -> libc != null;
-
-let
-
-  clangVersion = (builtins.parseDrvName clang.name).version;
-  clangName = (builtins.parseDrvName clang.name).name;
-
-in
-
-stdenv.mkDerivation {
-  name =
-    (if name != "" then name else clangName + "-wrapper") +
-    (if clang != null && clangVersion != "" then "-" + clangVersion else "");
-
-  builder = ./builder.sh;
-  setupHook = ./setup-hook.sh;
-  clangWrapper = ./clang-wrapper.sh;
-  ldWrapper = ../gcc-wrapper/ld-wrapper.sh;
-  utils = ../gcc-wrapper/utils.sh;
-  addFlags = ./add-flags;
-
-  inherit nativeTools nativeLibc nativePrefix clang clangVersion libcxx;
-
-  libcxxabi = libcxx.abi or null;
-
-  gcc = clang.gcc;
-  libc = if nativeLibc then null else libc;
-  binutils = if nativeTools then null else binutils;
-  # The wrapper scripts use 'cat', so we may need coreutils
-  coreutils = if nativeTools then null else coreutils;
-
-  langC = true;
-  langCC = true;
-  shell = if shell == "" then stdenv.shell else
-    if builtins.isAttrs shell then (shell + shell.shellPath)
-    else shell;
-
-  crossAttrs = {
-    shell = shell.crossDrv + shell.crossDrv.shellPath;
-    libc = libc.crossDrv;
-    coreutils = coreutils.crossDrv;
-    binutils = binutils.crossDrv;
-    clang = clang.crossDrv;
-    #
-    # This is not the best way to do this. I think the reference should be
-    # the style in the gcc-cross-wrapper, but to keep a stable stdenv now I
-    # do this sufficient if/else.
-    dynamicLinker =
-      (if stdenv.cross.arch == "arm" then "ld-linux.so.3" else
-       if stdenv.cross.arch == "mips" then "ld.so.1" else
-       if stdenv.lib.hasSuffix "pc-gnu" stdenv.cross.config then "ld.so.1" else
-       abort "don't know the name of the dynamic linker for this platform");
-  };
-
-  meta =
-    let clang_ = if clang != null then clang else {}; in
-    (if clang_ ? meta then removeAttrs clang.meta ["priority"] else {}) //
-    { description =
-        stdenv.lib.attrByPath ["meta" "description"] "System C compiler" clang_
-        + " (wrapper script)";
-    };
-
-  # The dynamic linker has different names on different Linux platforms.
-  dynamicLinker =
-    if !nativeLibc then
-      (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
-       if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
-       if stdenv.isArm then "ld-linux.so.3" else
-       if stdenv.system == "powerpc-linux" then "ld.so.1" else
-       if stdenv.system == "mips64el-linux" then "ld.so.1" else
-       abort "don't know the name of the dynamic linker for this platform")
-    else "";
-
-  preferLocalBuild = true;
-}
diff --git a/pkgs/build-support/clang-wrapper/setup-hook.sh b/pkgs/build-support/clang-wrapper/setup-hook.sh
deleted file mode 100644
index 0bd531050c4..00000000000
--- a/pkgs/build-support/clang-wrapper/setup-hook.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-export NIX_GCC=@out@
-
-addCVars () {
-    if test -d $1/include; then
-        export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
-    fi
-
-    if test -d $1/lib64; then
-        export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib64"
-    fi
-
-    if test -d $1/lib; then
-        export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib"
-    fi
-}
-
-envHooks+=(addCVars)
-
-# Note: these come *after* $out in the PATH (see setup.sh).
-
-if test -n "@clang@"; then
-    addToSearchPath PATH @clang@/bin
-fi
-
-if test -n "@binutils@"; then
-    addToSearchPath PATH @binutils@/bin
-fi
-
-if test -n "@libc@"; then
-    addToSearchPath PATH @libc@/bin
-fi
-
-if test -n "@coreutils@"; then
-    addToSearchPath PATH @coreutils@/bin
-fi
-
-: ${CXX:=clang++}
-export CXX
diff --git a/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh
index f954cae05d8..ec1f6004edd 100644
--- a/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh
+++ b/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh
@@ -114,13 +114,4 @@ fi
 # We want gcc to call the wrapper linker, not that of binutils.
 export PATH="@ldPath@:$PATH"
 
-# Call the real `gcc'.  Filter out warnings from stderr about unused
-# `-B' flags, since they confuse some programs.  Deep bash magic to
-# apply grep to stderr (by swapping stdin/stderr twice).
-if test -z "$NIX_GCC_NEEDS_GREP"; then
-    @gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
-else
-    (@gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
-        | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
-    exit $?
-fi    
+exec @gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
diff --git a/pkgs/build-support/gcc-wrapper/add-flags b/pkgs/build-support/gcc-wrapper/add-flags
index 26e536f6d57..d75f378e2c9 100644
--- a/pkgs/build-support/gcc-wrapper/add-flags
+++ b/pkgs/build-support/gcc-wrapper/add-flags
@@ -1,27 +1,27 @@
 # `-B@out@/bin' forces gcc to use ld-wrapper.sh when calling ld.
 export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
 
-if test -e @out@/nix-support/libc-cflags; then
+if [ -e @out@/nix-support/libc-cflags ]; then
     export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
 fi
 
-if test -e @out@/nix-support/gcc-cflags; then
+if [ -e @out@/nix-support/gcc-cflags ]; then
     export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/gcc-cflags) $NIX_CFLAGS_COMPILE"
 fi
 
-if test -e @out@/nix-support/gnat-cflags; then
+if [ -e @out@/nix-support/gnat-cflags ]; then
     export NIX_GNATFLAGS_COMPILE="$(cat @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE"
 fi
 
-if test -e @out@/nix-support/libc-ldflags; then
-    export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/libc-ldflags)"
+if [ -e @out@/nix-support/libc-ldflags ]; then
+    export NIX_LDFLAGS+=" $(cat @out@/nix-support/libc-ldflags)"
 fi
 
-if test -e @out@/nix-support/gcc-ldflags; then
-    export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/gcc-ldflags)"
+if [ -e @out@/nix-support/gcc-ldflags ]; then
+    export NIX_LDFLAGS+=" $(cat @out@/nix-support/gcc-ldflags)"
 fi
 
-if test -e @out@/nix-support/libc-ldflags-before; then
+if [ -e @out@/nix-support/libc-ldflags-before ]; then
     export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
 fi
 
diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh
deleted file mode 100644
index c79680712ee..00000000000
--- a/pkgs/build-support/gcc-wrapper/builder.sh
+++ /dev/null
@@ -1,214 +0,0 @@
-source $stdenv/setup
-
-
-mkdir -p $out/bin
-mkdir -p $out/nix-support
-
-
-if test -z "$nativeLibc"; then
-    dynamicLinker="$libc/lib/$dynamicLinker"
-    echo $dynamicLinker > $out/nix-support/dynamic-linker
-
-    if test -e $libc/lib/32/ld-linux.so.2; then
-        echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
-    fi
-
-    # The "-B$libc/lib/" flag is a quick hack to force gcc to link
-    # against the crt1.o from our own glibc, rather than the one in
-    # /usr/lib.  (This is only an issue when using an `impure'
-    # compiler/linker, i.e., one that searches /usr/lib and so on.)
-    #
-    # Unfortunately, setting -B appears to override the default search
-    # path. Thus, the gcc-specific "../includes-fixed" directory is
-    # now longer searched and glibc's <limits.h> header fails to
-    # compile, because it uses "#include_next <limits.h>" to find the
-    # limits.h file in ../includes-fixed. To remedy the problem,
-    # another -idirafter is necessary to add that directory again.
-    echo "-B$libc/lib/ -idirafter $libc/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
-
-    echo "-L$libc/lib" > $out/nix-support/libc-ldflags
-
-    # The dynamic linker is passed in `ldflagsBefore' to allow
-    # explicit overrides of the dynamic linker by callers to gcc/ld
-    # (the *last* value counts, so ours should come first).
-    echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
-fi
-
-if test -n "$nativeTools"; then
-    gccPath="$nativePrefix/bin"
-    ldPath="$nativePrefix/bin"
-else
-    if test -e "$gcc/lib64"; then
-        gccLDFlags="$gccLDFlags -L$gcc/lib64"
-    fi
-    gccLDFlags="$gccLDFlags -L$gcc/lib"
-    if [ -n "$langVhdl" ]; then
-        gccLDFlags="$gccLDFlags -L$zlib/lib"
-    fi
-    echo "$gccLDFlags" > $out/nix-support/gcc-ldflags
-
-    # GCC shows $gcc/lib in `gcc -print-search-dirs', but not
-    # $gcc/lib64 (even though it does actually search there...)..
-    # This confuses libtool.  So add it to the compiler tool search
-    # path explicitly.
-    if test -e "$gcc/lib64"; then
-        gccCFlags="$gccCFlags -B$gcc/lib64"
-    fi
-
-    # Find the gcc libraries path (may work only without multilib)
-    if [ -n "$langAda" ]; then
-        basePath=`echo $gcc/lib/*/*/*`
-        gccCFlags="$gccCFlags -B$basePath -I$basePath/adainclude"
-
-        gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib"
-        echo "$gnatCFlags" > $out/nix-support/gnat-cflags
-    fi
-    echo "$gccCFlags" > $out/nix-support/gcc-cflags
-    
-    gccPath="$gcc/bin"
-    # On Illumos/Solaris we might prefer native ld
-    if test -n "$nativePrefix"; then
-      ldPath="$nativePrefix/bin"
-    else
-      ldPath="$binutils/bin"
-    fi;
-fi
-
-
-doSubstitute() {
-    local src=$1
-    local dst=$2
-    local ld="$ldPath/ld"
-    if $ld -V 2>&1 |grep Solaris; then
-      # Use Solaris specific linker wrapper
-      ld="$out/bin/ld-solaris"
-    fi
-    # Can't use substitute() here, because replace may not have been
-    # built yet (in the bootstrap).
-    sed \
-        -e "s^@out@^$out^g" \
-        -e "s^@shell@^$shell^g" \
-        -e "s^@gcc@^$gcc^g" \
-        -e "s^@gccProg@^$gccProg^g" \
-        -e "s^@gnatProg@^$gnatProg^g" \
-        -e "s^@gnatlinkProg@^$gnatlinkProg^g" \
-        -e "s^@binutils@^$binutils^g" \
-        -e "s^@coreutils@^$coreutils^g" \
-        -e "s^@libc@^$libc^g" \
-        -e "s^@ld@^$ld^g" \
-        < "$src" > "$dst" 
-}
-
-
-# Make wrapper scripts around gcc, g++, and gfortran.  Also make symlinks
-# cc, c++, and f77.
-mkGccWrapper() {
-    local dst=$1
-    local src=$2
-
-    if ! test -f "$src"; then
-        echo "$src does not exist (skipping)"
-        return 1
-    fi
-
-    gccProg="$src"
-    doSubstitute "$gccWrapper" "$dst"
-    chmod +x "$dst"
-}
-
-mkGnatWrapper() {
-    local dst=$1
-    local src=$2
-
-    if ! test -f "$src"; then
-        echo "$src does not exist (skipping)"
-        return 1
-    fi
-
-    gnatProg="$src"
-    doSubstitute "$gnatWrapper" "$dst"
-    chmod +x "$dst"
-}
-
-mkGnatLinkWrapper() {
-    local dst=$1
-    local src=$2
-
-    if ! test -f "$src"; then
-        echo "$src does not exist (skipping)"
-        return 1
-    fi
-
-    gnatlinkProg="$src"
-    doSubstitute "$gnatlinkWrapper" "$dst"
-    chmod +x "$dst"
-}
-
-if mkGccWrapper $out/bin/gcc $gccPath/gcc
-then
-    ln -sv gcc $out/bin/cc
-fi
-
-if mkGccWrapper $out/bin/g++ $gccPath/g++
-then
-    ln -sv g++ $out/bin/c++
-fi
-
-mkGccWrapper $out/bin/cpp $gccPath/cpp || true
-
-if mkGccWrapper $out/bin/gfortran $gccPath/gfortran
-then
-    ln -sv gfortran $out/bin/g77
-    ln -sv gfortran $out/bin/f77
-fi
-
-mkGccWrapper $out/bin/gcj $gccPath/gcj || true
-
-mkGccWrapper $out/bin/gccgo $gccPath/gccgo || true
-
-mkGccWrapper $out/bin/gnatgcc $gccPath/gnatgcc || true
-mkGnatWrapper $out/bin/gnatmake $gccPath/gnatmake || true
-mkGnatWrapper $out/bin/gnatbind $gccPath/gnatbind || true
-mkGnatLinkWrapper $out/bin/gnatlink $gccPath/gnatlink || true
-
-if [ -f $gccPath/ghdl ]; then
-    ln -sf $gccPath/ghdl $out/bin/ghdl
-fi
-
-
-# Create a symlink to as (the assembler).  This is useful when a
-# gcc-wrapper is installed in a user environment, as it ensures that
-# the right assembler is called.
-ln -s $ldPath/as $out/bin/as
-
-
-# Make a wrapper around the linker.
-doSubstitute "$ldWrapper" "$out/bin/ld"
-chmod +x "$out/bin/ld"
-
-# Copy solaris ld wrapper if needed
-if $ldPath/ld -V 2>&1 |grep Solaris; then
-  # Use Solaris specific linker wrapper
-  sed -e "s^@ld@^$ldPath/ld^g" < "$ldSolarisWrapper" > "$out/bin/ld-solaris"
-  chmod +x "$out/bin/ld-solaris"
-fi
-
-
-# Emit a setup hook.  Also store the path to the original GCC and
-# Glibc.
-test -n "$gcc" && echo $gcc > $out/nix-support/orig-gcc
-test -n "$libc" && echo $libc > $out/nix-support/orig-libc
-
-doSubstitute "$addFlags" "$out/nix-support/add-flags.sh"
-
-doSubstitute "$setupHook" "$out/nix-support/setup-hook"
-
-cp -p $utils $out/nix-support/utils.sh
-
-
-# Propagate the wrapped gcc so that if you install the wrapper, you get
-# tools like gcov, the manpages, etc. as well (including for binutils
-# and Glibc).
-if test -z "$nativeTools"; then
-    echo $gcc $binutils $libc > $out/nix-support/propagated-user-env-packages
-fi
diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix
index 8e8b0b90945..b2f7d07560d 100644
--- a/pkgs/build-support/gcc-wrapper/default.nix
+++ b/pkgs/build-support/gcc-wrapper/default.nix
@@ -1,28 +1,29 @@
-# The Nix `gcc' stdenv.mkDerivation is not directly usable, since it doesn't
-# know where the C library and standard header files are.  Therefore
-# the compiler produced by that package cannot be installed directly
-# in a user environment and used from the command line.  This
-# stdenv.mkDerivation provides a wrapper that sets up the right environment
-# variables so that the compiler and the linker just "work".
+# The Nixpkgs GCC is not directly usable, since it doesn't know where
+# the C library and standard header files are. Therefore the compiler
+# produced by that package cannot be installed directly in a user
+# environment and used from the command line. So we use a wrapper
+# script that sets up the right environment variables so that the
+# compiler and the linker just "work".
 
 { name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
-, gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
-, zlib ? null
+, gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? stdenv.shell
+, zlib ? null, extraPackages ? []
 }:
 
+with stdenv.lib;
+
 assert nativeTools -> nativePrefix != "";
 assert !nativeTools -> gcc != null && binutils != null && coreutils != null;
 assert !nativeLibc -> libc != null;
 
-# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper
-assert (gcc != null && gcc ? langVhdl && gcc.langVhdl) -> zlib != null;
+# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper.
+assert gcc.langVhdl or false -> zlib != null;
 
 let
 
   gccVersion = (builtins.parseDrvName gcc.name).version;
   gccName = (builtins.parseDrvName gcc.name).name;
 
-  langGo = if nativeTools then false else gcc ? langGo && gcc.langGo;
 in
 
 stdenv.mkDerivation {
@@ -30,31 +31,198 @@ stdenv.mkDerivation {
     (if name != "" then name else gccName + "-wrapper") +
     (if gcc != null && gccVersion != "" then "-" + gccVersion else "");
 
-  builder = ./builder.sh;
-  setupHook = ./setup-hook.sh;
-  gccWrapper = ./gcc-wrapper.sh;
-  gnatWrapper = ./gnat-wrapper.sh;
-  gnatlinkWrapper = ./gnatlink-wrapper.sh;
-  ldWrapper = ./ld-wrapper.sh;
-  ldSolarisWrapper = ./ld-solaris-wrapper.sh;
-  utils = ./utils.sh;
-  addFlags = ./add-flags;
-
-  inherit nativeTools nativeLibc nativePrefix gcc;
+  preferLocalBuild = true;
+
+  inherit gcc shell;
   libc = if nativeLibc then null else libc;
   binutils = if nativeTools then null else binutils;
-  # The wrapper scripts use 'cat', so we may need coreutils
+  # The wrapper scripts use 'cat', so we may need coreutils.
   coreutils = if nativeTools then null else coreutils;
 
-  langC = if nativeTools then true else gcc.langC;
-  langCC = if nativeTools then true else gcc.langCC;
-  langFortran = if nativeTools then false else gcc ? langFortran;
-  langAda = if nativeTools then false else gcc ? langAda && gcc.langAda;
-  langVhdl = if nativeTools then false else gcc ? langVhdl && gcc.langVhdl;
-  zlib = if gcc != null && gcc ? langVhdl then zlib else null;
-  shell = if shell == "" then stdenv.shell else
-    if builtins.isAttrs shell then (shell + shell.shellPath)
-    else shell;
+  passthru = { inherit nativeTools nativeLibc nativePrefix; };
+
+  buildCommand =
+    ''
+      mkdir -p $out/bin $out/nix-support
+
+      wrap() {
+        local dst="$1"
+        local wrapper="$2"
+        export prog="$3"
+        substituteAll "$wrapper" "$out/bin/$dst"
+        chmod +x "$out/bin/$dst"
+      }
+    ''
+
+    + optionalString (!nativeLibc) ''
+      dynamicLinker="$libc/lib/$dynamicLinker"
+      echo $dynamicLinker > $out/nix-support/dynamic-linker
+
+      if [ -e $libc/lib/32/ld-linux.so.2 ]; then
+        echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
+      fi
+
+      # The "-B$libc/lib/" flag is a quick hack to force gcc to link
+      # against the crt1.o from our own glibc, rather than the one in
+      # /usr/lib.  (This is only an issue when using an `impure'
+      # compiler/linker, i.e., one that searches /usr/lib and so on.)
+      #
+      # Unfortunately, setting -B appears to override the default search
+      # path. Thus, the gcc-specific "../includes-fixed" directory is
+      # now longer searched and glibc's <limits.h> header fails to
+      # compile, because it uses "#include_next <limits.h>" to find the
+      # limits.h file in ../includes-fixed. To remedy the problem,
+      # another -idirafter is necessary to add that directory again.
+      echo "-B$libc/lib/ -idirafter $libc/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
+
+      echo "-L$libc/lib" > $out/nix-support/libc-ldflags
+
+      # The dynamic linker is passed in `ldflagsBefore' to allow
+      # explicit overrides of the dynamic linker by callers to gcc/ld
+      # (the *last* value counts, so ours should come first).
+      echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
+
+      echo $libc > $out/nix-support/orig-libc
+    ''
+
+    + (if nativeTools then ''
+      gccPath="${nativePrefix}/bin"
+      ldPath="${nativePrefix}/bin"
+    '' else ''
+      echo $gcc > $out/nix-support/orig-gcc
+
+      # GCC shows $gcc/lib in `gcc -print-search-dirs', but not
+      # $gcc/lib64 (even though it does actually search there...)..
+      # This confuses libtool.  So add it to the compiler tool search
+      # path explicitly.
+      if [ -e "$gcc/lib64" -a ! -L "$gcc/lib64" ]; then
+        gccLDFlags+=" -L$gcc/lib64"
+        gccCFlags+=" -B$gcc/lib64"
+      fi
+      gccLDFlags+=" -L$gcc/lib"
+
+      ${optionalString gcc.langVhdl or false ''
+        gccLDFlags+=" -L${zlib}/lib"
+      ''}
+
+      # Find the gcc libraries path (may work only without multilib).
+      ${optionalString gcc.langAda or false ''
+        basePath=`echo $gcc/lib/*/*/*`
+        gccCFlags+=" -B$basePath -I$basePath/adainclude"
+        gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib"
+        echo "$gnatCFlags" > $out/nix-support/gnat-cflags
+      ''}
+
+      echo "$gccLDFlags" > $out/nix-support/gcc-ldflags
+      echo "$gccCFlags" > $out/nix-support/gcc-cflags
+
+      gccPath="$gcc/bin"
+      ldPath="$binutils/bin"
+
+      # Propagate the wrapped gcc so that if you install the wrapper,
+      # you get tools like gcov, the manpages, etc. as well (including
+      # for binutils and Glibc).
+      echo $gcc $binutils $libc > $out/nix-support/propagated-user-env-packages
+
+      echo ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs
+    ''
+
+    + optionalString (stdenv.isSunOS && nativePrefix != "") ''
+      # Solaris needs an additional ld wrapper.
+      ldPath="${nativePrefix}/bin"
+      ld="$out/bin/ld-solaris"
+      wrap ld-solaris ${./ld-solaris-wrapper.sh}
+    '')
+
+    + ''
+      # Create a symlink to as (the assembler).  This is useful when a
+      # gcc-wrapper is installed in a user environment, as it ensures that
+      # the right assembler is called.
+      if [ -e $ldPath/as ]; then
+        ln -s $ldPath/as $out/bin/as
+      fi
+
+      wrap ld ${./ld-wrapper.sh} ''${ld:-$ldPath/ld}
+
+      if [ -e $binutils/bin/ld.gold ]; then
+        wrap ld.gold ${./ld-wrapper.sh} $binutils/bin/ld.gold
+      fi
+
+      if [ -e $binutils/bin/ld.bfd ]; then
+        wrap ld.bfd ${./ld-wrapper.sh} $binutils/bin/ld.bfd
+      fi
+
+      if [ -e $gccPath/gcc ]; then
+        wrap gcc ${./gcc-wrapper.sh} $gccPath/gcc
+        ln -s gcc $out/bin/cc
+      elif [ -e $gccPath/clang ]; then
+        wrap clang ${./gcc-wrapper.sh} $gccPath/clang
+        ln -s clang $out/bin/cc
+      fi
+
+      if [ -e $gccPath/g++ ]; then
+        wrap g++ ${./gcc-wrapper.sh} $gccPath/g++
+        ln -s g++ $out/bin/c++
+      elif [ -e $gccPath/clang++ ]; then
+        wrap clang++ ${./gcc-wrapper.sh} $gccPath/clang++
+        ln -s clang++ $out/bin/c++
+      fi
+
+      if [ -e $gccPath/cpp ]; then
+        wrap cpp ${./gcc-wrapper.sh} $gccPath/cpp
+      fi
+    ''
+
+    + optionalString gcc.langFortran or false ''
+      wrap gfortran ${./gcc-wrapper.sh} $gccPath/gfortran
+      ln -sv gfortran $out/bin/g77
+      ln -sv gfortran $out/bin/f77
+    ''
+
+    + optionalString gcc.langJava or false ''
+      wrap gcj ${./gcc-wrapper.sh} $gccPath/gcj
+    ''
+
+    + optionalString gcc.langGo or false ''
+      wrap gccgo ${./gcc-wrapper.sh} $gccPath/gccgo
+    ''
+
+    + optionalString gcc.langAda or false ''
+      wrap gnatgcc ${./gcc-wrapper.sh} $gccPath/gnatgcc
+      wrap gnatmake ${./gnat-wrapper.sh} $gccPath/gnatmake
+      wrap gnatbind ${./gnat-wrapper.sh} $gccPath/gnatbind
+      wrap gnatlink ${./gnatlink-wrapper.sh} $gccPath/gnatlink
+    ''
+
+    + optionalString gcc.langVhdl or false ''
+      ln -s $gccPath/ghdl $out/bin/ghdl
+    ''
+
+    + ''
+      substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook
+      substituteAll ${./add-flags} $out/nix-support/add-flags.sh
+      cp -p ${./utils.sh} $out/nix-support/utils.sh
+
+      if [ -e $out/bin/clang ]; then
+        echo 'export CC; : ''${CC:=clang}' >> $out/nix-support/setup-hook
+      fi
+
+      if [ -e $out/bin/clang++ ]; then
+        echo 'export CXX; : ''${CXX:=clang++}' >> $out/nix-support/setup-hook
+      fi
+    '';
+
+  # The dynamic linker has different names on different Linux platforms.
+  dynamicLinker =
+    if !nativeLibc then
+      (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
+       if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
+       # ARM with a wildcard, which can be "" or "-armhf".
+       if stdenv.isArm then "ld-linux*.so.3" else
+       if stdenv.system == "powerpc-linux" then "ld.so.1" else
+       if stdenv.system == "mips64el-linux" then "ld.so.1" else
+       abort "Don't know the name of the dynamic linker for this platform.")
+    else "";
 
   crossAttrs = {
     shell = shell.crossDrv + shell.crossDrv.shellPath;
@@ -73,8 +241,6 @@ stdenv.mkDerivation {
        abort "don't know the name of the dynamic linker for this platform");
   };
 
-  preferLocalBuild = true;
-
   meta =
     let gcc_ = if gcc != null then gcc else {}; in
     (if gcc_ ? meta then removeAttrs gcc.meta ["priority"] else {}) //
@@ -82,16 +248,4 @@ stdenv.mkDerivation {
         stdenv.lib.attrByPath ["meta" "description"] "System C compiler" gcc_
         + " (wrapper script)";
     };
-
-  # The dynamic linker has different names on different Linux platforms.
-  dynamicLinker =
-    if !nativeLibc then
-      (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
-       if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
-       # ARM with a wildcard, which can be "" or "-armhf".
-       if stdenv.isArm then "ld-linux*.so.3" else
-       if stdenv.system == "powerpc-linux" then "ld.so.1" else
-       if stdenv.system == "mips64el-linux" then "ld.so.1" else
-       abort "don't know the name of the dynamic linker for this platform")
-    else "";
 }
diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
index 11ee8592932..d0c82c82dc1 100644
--- a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
@@ -1,10 +1,10 @@
 #! @shell@ -e
 
-if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then
+if [ -n "$NIX_GCC_WRAPPER_START_HOOK" ]; then
     source "$NIX_GCC_WRAPPER_START_HOOK"
 fi
 
-if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
+if [ -z "$NIX_GCC_WRAPPER_FLAGS_SET" ]; then
     source @out@/nix-support/add-flags.sh
 fi
 
@@ -18,26 +18,26 @@ getVersion=0
 nonFlagArgs=0
 
 for i in "$@"; do
-    if test "$i" = "-c"; then
+    if [ "$i" = -c ]; then
         dontLink=1
-    elif test "$i" = "-S"; then
+    elif [ "$i" = -S ]; then
         dontLink=1
-    elif test "$i" = "-E"; then
+    elif [ "$i" = -E ]; then
         dontLink=1
-    elif test "$i" = "-E"; then
+    elif [ "$i" = -E ]; then
         dontLink=1
-    elif test "$i" = "-M"; then
+    elif [ "$i" = -M ]; then
         dontLink=1
-    elif test "$i" = "-MM"; then
+    elif [ "$i" = -MM ]; then
         dontLink=1
-    elif test "$i" = "-x"; then
+    elif [ "$i" = -x ]; then
         # At least for the cases c-header or c++-header we should set dontLink.
         # I expect no one use -x other than making precompiled headers.
         dontLink=1
-    elif test "${i:0:1}" != "-"; then
+    elif [ "${i:0:1}" != - ]; then
         nonFlagArgs=1
-    elif test "$i" = "-m32"; then
-        if test -e @out@/nix-support/dynamic-linker-m32; then
+    elif [ "$i" = -m32 ]; then
+        if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
             NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
         fi
     fi
@@ -48,28 +48,28 @@ done
 # "-c" flag).  So if no non-flag arguments are given, don't pass any
 # linker flags.  This catches cases like "gcc" (should just print
 # "gcc: no input files") and "gcc -v" (should print the version).
-if test "$nonFlagArgs" = "0"; then
+if [ "$nonFlagArgs" = 0 ]; then
     dontLink=1
 fi
 
 
 # Optionally filter out paths not refering to the store.
 params=("$@")
-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
+if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
     rest=()
     n=0
-    while test $n -lt ${#params[*]}; do
+    while [ $n -lt ${#params[*]} ]; do
         p=${params[n]}
         p2=${params[$((n+1))]}
-        if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
+        if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
             skip $p
-        elif test "$p" = "-L" && badPath "$p2"; then
+        elif [ "$p" = -L ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "${p:0:3}" = "-I/" && badPath "${p:2}"; then
+        elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
             skip $p
-        elif test "$p" = "-I" && badPath "$p2"; then
+        elif [ "$p" = -I ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "$p" = "-isystem" && badPath "$p2"; then
+        elif [ "$p" = -isystem ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
         else
             rest=("${rest[@]}" "$p")
@@ -86,14 +86,14 @@ extraBefore=()
 
 # When enforcing purity, pretend gcc can't find the current date and
 # time
-if test "$NIX_ENFORCE_PURITY" = "1"; then
+if [ "$NIX_ENFORCE_PURITY" = 1 ]; then
     extraAfter+=('-D__DATE__="Jan 01 1970"'
         '-D__TIME__="00:00:01"'
         -Wno-builtin-macro-redefined)
 fi
 
 
-if test "$dontLink" != "1"; then
+if [ "$dontLink" != 1 ]; then
 
     # Add the flags that should only be passed to the compiler when
     # linking.
@@ -105,11 +105,11 @@ if test "$dontLink" != "1"; then
         extraBefore=(${extraBefore[@]} "-Wl,$i")
     done
     for i in $NIX_LDFLAGS; do
-	if test "${i:0:3}" = "-L/"; then
-	    extraAfter+=("$i")
-	else
-	    extraAfter+=("-Wl,$i")
-	fi
+        if [ "${i:0:3}" = -L/ ]; then
+            extraAfter+=("$i")
+        else
+            extraAfter+=("-Wl,$i")
+        fi
     done
     export NIX_LDFLAGS_SET=1
 fi
@@ -118,39 +118,29 @@ fi
 # add anything.  This is to prevent `gcc -v' (which normally prints
 # out the version number and returns exit code 0) from printing out
 # `No input files specified' and returning exit code 1.
-if test "$*" = "-v"; then
+if [ "$*" = -v ]; then
     extraAfter=()
     extraBefore=()
-fi    
+fi
 
 # Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @gccProg@:" >&2
+if [ -n "$NIX_DEBUG" ]; then
+  echo "original flags to @prog@:" >&2
   for i in "${params[@]}"; do
       echo "  $i" >&2
   done
-  echo "extraBefore flags to @gccProg@:" >&2
+  echo "extraBefore flags to @prog@:" >&2
   for i in ${extraBefore[@]}; do
       echo "  $i" >&2
   done
-  echo "extraAfter flags to @gccProg@:" >&2
+  echo "extraAfter flags to @prog@:" >&2
   for i in ${extraAfter[@]}; do
       echo "  $i" >&2
   done
 fi
 
-if test -n "$NIX_GCC_WRAPPER_EXEC_HOOK"; then
+if [ -n "$NIX_GCC_WRAPPER_EXEC_HOOK" ]; then
     source "$NIX_GCC_WRAPPER_EXEC_HOOK"
 fi
 
-
-# Call the real `gcc'.  Filter out warnings from stderr about unused
-# `-B' flags, since they confuse some programs.  Deep bash magic to
-# apply grep to stderr (by swapping stdin/stderr twice).
-if test -z "$NIX_GCC_NEEDS_GREP"; then
-    @gccProg@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}"
-else
-    (@gccProg@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}" 3>&2 2>&1 1>&3- \
-        | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
-    exit $?
-fi    
+exec @prog@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}"
diff --git a/pkgs/build-support/gcc-wrapper/gnat-wrapper.sh b/pkgs/build-support/gcc-wrapper/gnat-wrapper.sh
index f6fa4b18400..3514ccd6732 100644
--- a/pkgs/build-support/gcc-wrapper/gnat-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/gnat-wrapper.sh
@@ -1,10 +1,10 @@
 #! @shell@ -e
 
-if test -n "$NIX_GNAT_WRAPPER_START_HOOK"; then
+if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then
     source "$NIX_GNAT_WRAPPER_START_HOOK"
 fi
 
-if test -z "$NIX_GNAT_WRAPPER_FLAGS_SET"; then
+if [ -z "$NIX_GNAT_WRAPPER_FLAGS_SET" ]; then
     source @out@/nix-support/add-flags.sh
 fi
 
@@ -18,14 +18,14 @@ getVersion=0
 nonFlagArgs=0
 
 for i in "$@"; do
-    if test "$i" = "-c"; then
+    if [ "$i" = -c ]; then
         dontLink=1
-    elif test "$i" = "-M"; then
+    elif [ "$i" = -M ]; then
         dontLink=1
-    elif test "${i:0:1}" != "-"; then
+    elif [ "${i:0:1}" != - ]; then
         nonFlagArgs=1
-    elif test "$i" = "-m32"; then
-        if test -e @out@/nix-support/dynamic-linker-m32; then
+    elif [ "$i" = -m32 ]; then
+        if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
             NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
         fi
     fi
@@ -36,26 +36,26 @@ done
 # "-c" flag).  So if no non-flag arguments are given, don't pass any
 # linker flags.  This catches cases like "gcc" (should just print
 # "gcc: no input files") and "gcc -v" (should print the version).
-if test "$nonFlagArgs" = "0"; then
+if [ "$nonFlagArgs" = 0 ]; then
     dontLink=1
 fi
 
 
 # Optionally filter out paths not refering to the store.
 params=("$@")
-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
+if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
     rest=()
     n=0
-    while test $n -lt ${#params[*]}; do
+    while [ $n -lt ${#params[*]} ]; do
         p=${params[n]}
         p2=${params[$((n+1))]}
-        if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
+        if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
             skip $p
-        elif test "${p:0:3}" = "-I/" && badPath "${p:2}"; then
+        elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
             skip $p
-        elif test "${p:0:4}" = "-aI/" && badPath "${p:3}"; then
+        elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then
             skip $p
-        elif test "${p:0:4}" = "-aO/" && badPath "${p:3}"; then
+        elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then
             skip $p
         else
             rest=("${rest[@]}" "$p")
@@ -81,33 +81,23 @@ fi
 #done
 
 # Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @gnatProg@:" >&2
+if [ -n "$NIX_DEBUG" ]; then
+  echo "original flags to @prog@:" >&2
   for i in "${params[@]}"; do
       echo "  $i" >&2
   done
-  echo "extraBefore flags to @gnatProg@:" >&2
+  echo "extraBefore flags to @prog@:" >&2
   for i in ${extraBefore[@]}; do
       echo "  $i" >&2
   done
-  echo "extraAfter flags to @gnatProg@:" >&2
+  echo "extraAfter flags to @prog@:" >&2
   for i in ${extraAfter[@]}; do
       echo "  $i" >&2
   done
 fi
 
-if test -n "$NIX_GNAT_WRAPPER_EXEC_HOOK"; then
+if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
     source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
 fi
 
-
-# Call the real `gcc'.  Filter out warnings from stderr about unused
-# `-B' flags, since they confuse some programs.  Deep bash magic to
-# apply grep to stderr (by swapping stdin/stderr twice).
-if test -z "$NIX_GNAT_NEEDS_GREP"; then
-    @gnatProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
-else
-    (@gnatProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
-        | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
-    exit $?
-fi
+exec @prog@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
diff --git a/pkgs/build-support/gcc-wrapper/gnatlink-wrapper.sh b/pkgs/build-support/gcc-wrapper/gnatlink-wrapper.sh
index 25907108b4d..c9958dbbb41 100644
--- a/pkgs/build-support/gcc-wrapper/gnatlink-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/gnatlink-wrapper.sh
@@ -11,33 +11,23 @@ extraBefore=()
 #done
 
 # Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @gnatlinkProg@:" >&2
+if [ -n "$NIX_DEBUG" ]; then
+  echo "original flags to @prog@:" >&2
   for i in "$@"; do
       echo "  $i" >&2
   done
-  echo "extraBefore flags to @gnatlinkProg@:" >&2
+  echo "extraBefore flags to @prog@:" >&2
   for i in ${extraBefore[@]}; do
       echo "  $i" >&2
   done
-  echo "extraAfter flags to @gnatlinkProg@:" >&2
+  echo "extraAfter flags to @prog@:" >&2
   for i in ${extraAfter[@]}; do
       echo "  $i" >&2
   done
 fi
 
-if test -n "$NIX_GNAT_WRAPPER_EXEC_HOOK"; then
+if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
     source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
 fi
 
-
-# Call the real `gcc'.  Filter out warnings from stderr about unused
-# `-B' flags, since they confuse some programs.  Deep bash magic to
-# apply grep to stderr (by swapping stdin/stderr twice).
-if test -z "$NIX_GNAT_NEEDS_GREP"; then
-    @gnatlinkProg@ ${extraBefore[@]} "$@" ${extraAfter[@]}
-else
-    (@gnatlinkProg@ ${extraBefore[@]} "$@" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
-        | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
-    exit $?
-fi
+exec @prog@ ${extraBefore[@]} "$@" ${extraAfter[@]}
diff --git a/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh
index 5a7b92b5ad7..9216ea3198d 100644
--- a/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh
@@ -6,7 +6,7 @@ set -u
 # I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'(
 # Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3
 #   but still no success.
-cmd="@ld@ -z ignore"
+cmd="@prog@ -z ignore"
 
 args=("$@");
 
diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
index 822c4a03a21..894dbf9a352 100644
--- a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
@@ -1,10 +1,10 @@
 #! @shell@ -e
 
-if test -n "$NIX_LD_WRAPPER_START_HOOK"; then
+if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then
     source "$NIX_LD_WRAPPER_START_HOOK"
 fi
 
-if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
+if [ -z "$NIX_GCC_WRAPPER_FLAGS_SET" ]; then
     source @out@/nix-support/add-flags.sh
 fi
 
@@ -13,26 +13,26 @@ source @out@/nix-support/utils.sh
 
 # Optionally filter out paths not refering to the store.
 params=("$@")
-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE" \
-        -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \); then
+if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" \
+        -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \) ]; then
     rest=()
     n=0
-    while test $n -lt ${#params[*]}; do
+    while [ $n -lt ${#params[*]} ]; do
         p=${params[n]}
         p2=${params[$((n+1))]}
-        if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
+        if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
             skip $p
-        elif test "$p" = "-L" && badPath "$p2"; then
+        elif [ "$p" = -L ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "$p" = "-rpath" && badPath "$p2"; then
+        elif [ "$p" = -rpath ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "$p" = "-dynamic-linker" && badPath "$p2"; then
+        elif [ "$p" = -dynamic-linker ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "${p:0:1}" = "/" && badPath "$p"; then
+        elif [ "${p:0:1}" = / ] && badPath "$p"; then
             # We cannot skip this; barf.
             echo "impure path \`$p' used in link" >&2
             exit 1
-        elif test "${p:0:9}" = "--sysroot"; then
+        elif [ "${p:0:9}" = --sysroot ]; then
             # Our ld is not built with sysroot support (Can we fix that?)
             :
         else
@@ -47,7 +47,7 @@ fi
 extra=()
 extraBefore=()
 
-if test -z "$NIX_LDFLAGS_SET"; then
+if [ -z "$NIX_LDFLAGS_SET" ]; then
     extra+=($NIX_LDFLAGS)
     extraBefore+=($NIX_LDFLAGS_BEFORE)
 fi
@@ -56,12 +56,12 @@ extra+=($NIX_LDFLAGS_AFTER)
 
 
 # Add all used dynamic libraries to the rpath.
-if test "$NIX_DONT_SET_RPATH" != "1"; then
+if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
 
     libPath=""
     addToLibPath() {
         local path="$1"
-        if test "${path:0:1}" != "/"; then return 0; fi
+        if [ "${path:0:1}" != / ]; then return 0; fi
         case "$path" in
             *..*|*./*|*/.*|*//*)
                 local path2
@@ -75,12 +75,12 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then
         esac
         libPath="$libPath $path "
     }
-    
+
     addToRPath() {
         # If the path is not in the store, don't add it to the rpath.
         # This typically happens for libraries in /tmp that are later
         # copied to $out/lib.  If not, we're screwed.
-        if test "${1:0:${#NIX_STORE}}" != "$NIX_STORE"; then return 0; fi
+        if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi
         case $rpath in
             *\ $1\ *) return 0 ;;
         esac
@@ -97,21 +97,21 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then
     # First, find all -L... switches.
     allParams=("${params[@]}" ${extra[@]})
     n=0
-    while test $n -lt ${#allParams[*]}; do
+    while [ $n -lt ${#allParams[*]} ]; do
         p=${allParams[n]}
         p2=${allParams[$((n+1))]}
-        if test "${p:0:3}" = "-L/"; then
+        if [ "${p:0:3}" = -L/ ]; then
             addToLibPath ${p:2}
-        elif test "$p" = "-L"; then
+        elif [ "$p" = -L ]; then
             addToLibPath ${p2}
             n=$((n + 1))
-        elif test "$p" = "-l"; then
+        elif [ "$p" = -l ]; then
             addToLibs ${p2}
             n=$((n + 1))
-        elif test "${p:0:2}" = "-l"; then
+        elif [ "${p:0:2}" = -l ]; then
             addToLibs ${p:2}
-        elif test "$p" = "-dynamic-linker"; then
-            # Ignore the dynamic linker argument, or it 
+        elif [ "$p" = -dynamic-linker ]; then
+            # Ignore the dynamic linker argument, or it
             # will get into the next 'elif'. We don't want
             # the dynamic linker path rpath to go always first.
             n=$((n + 1))
@@ -129,16 +129,16 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then
     # so, add the directory to the rpath.
     # It's important to add the rpath in the order of -L..., so
     # the link time chosen objects will be those of runtime linking.
-    
+
     for i in $libPath; do
         for j in $libs; do
-            if test -f "$i/lib$j.so"; then
+            if [ -f "$i/lib$j.so" ]; then
                 addToRPath $i
                 break
             fi
         done
     done
-    
+
 
     # Finally, add `-rpath' switches.
     for i in $rpath; do
@@ -148,19 +148,19 @@ fi
 
 
 # Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @ld@:" >&2
+if [ -n "$NIX_DEBUG" ]; then
+  echo "original flags to @prog@:" >&2
   for i in "${params[@]}"; do
       echo "  $i" >&2
   done
-  echo "extra flags to @ld@:" >&2
+  echo "extra flags to @prog@:" >&2
   for i in ${extra[@]}; do
       echo "  $i" >&2
   done
 fi
 
-if test -n "$NIX_LD_WRAPPER_EXEC_HOOK"; then
+if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then
     source "$NIX_LD_WRAPPER_EXEC_HOOK"
 fi
 
-exec @ld@ ${extraBefore[@]} "${params[@]}" ${extra[@]}
+exec @prog@ ${extraBefore[@]} "${params[@]}" ${extra[@]}
diff --git a/pkgs/build-support/gcc-wrapper/setup-hook.sh b/pkgs/build-support/gcc-wrapper/setup-hook.sh
index a3ada9e984f..a6b7edbcb69 100644
--- a/pkgs/build-support/gcc-wrapper/setup-hook.sh
+++ b/pkgs/build-support/gcc-wrapper/setup-hook.sh
@@ -1,16 +1,16 @@
 export NIX_GCC=@out@
 
 addCVars () {
-    if test -d $1/include; then
-        export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
+    if [ -d $1/include ]; then
+        export NIX_CFLAGS_COMPILE+=" -isystem $1/include"
     fi
 
-    if test -d $1/lib64; then
-        export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib64"
+    if [ -d $1/lib64 -a ! -L $1/lib64 ]; then
+        export NIX_LDFLAGS+=" -L$1/lib64"
     fi
 
-    if test -d $1/lib; then
-        export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib"
+    if [ -d $1/lib ]; then
+        export NIX_LDFLAGS+=" -L$1/lib"
     fi
 }
 
@@ -18,18 +18,18 @@ envHooks+=(addCVars)
 
 # Note: these come *after* $out in the PATH (see setup.sh).
 
-if test -n "@gcc@"; then
+if [ -n "@gcc@" ]; then
     addToSearchPath PATH @gcc@/bin
 fi
 
-if test -n "@binutils@"; then
+if [ -n "@binutils@" ]; then
     addToSearchPath PATH @binutils@/bin
 fi
 
-if test -n "@libc@"; then
+if [ -n "@libc@" ]; then
     addToSearchPath PATH @libc@/bin
 fi
 
-if test -n "@coreutils@"; then
+if [ -n "@coreutils@" ]; then
     addToSearchPath PATH @coreutils@/bin
 fi
diff --git a/pkgs/build-support/gcc-wrapper/utils.sh b/pkgs/build-support/gcc-wrapper/utils.sh
index 753b3772e95..3ab512d85c4 100644
--- a/pkgs/build-support/gcc-wrapper/utils.sh
+++ b/pkgs/build-support/gcc-wrapper/utils.sh
@@ -1,5 +1,5 @@
 skip () {
-    if test "$NIX_DEBUG" = "1"; then
+    if [ -n "$NIX_DEBUG" ]; then
         echo "skipping impure path $1" >&2
     fi
 }
@@ -9,11 +9,11 @@ skip () {
 # `/nix/store/.../lib/foo.so' isn't.
 badPath() {
     local p=$1
-    
+
     # Relative paths are okay (since they're presumably relative to
     # the temporary build directory).
-    if test "${p:0:1}" != "/"; then return 1; fi
-    
+    if [ "${p:0:1}" != / ]; then return 1; fi
+
     # Otherwise, the path should refer to the store or some temporary
     # directory (including the build directory).
     test \
diff --git a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
index 5962bf03906..2b64fbf8f09 100644
--- a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
+++ b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
@@ -10,6 +10,8 @@
 # their absolute path (using "install_name_tool -id").  It also
 # rewrites references in other dylibs to absolute paths.
 
+postFixupHooks+=('fixDarwinDylibNamesIn $prefix')
+
 fixDarwinDylibNames() {
     local flags=()
     local old_id
@@ -29,7 +31,3 @@ fixDarwinDylibNamesIn() {
     local dir="$1"
     fixDarwinDylibNames $(find "$dir" -name "*.dylib")
 }
-
-postFixup() {
-    fixDarwinDylibNamesIn "$prefix"
-}
diff --git a/pkgs/development/compilers/gcc/4.2-apple64/default.nix b/pkgs/development/compilers/gcc/4.2-apple64/default.nix
index b2444ebb9bf..42d9f29e2b5 100644
--- a/pkgs/development/compilers/gcc/4.2-apple64/default.nix
+++ b/pkgs/development/compilers/gcc/4.2-apple64/default.nix
@@ -4,6 +4,7 @@
 , gmp ? null, mpfr ? null, bison ? null, flex ? null
 }:
 
+assert false;
 assert stdenv.isDarwin;
 assert langF77 -> gmp != null;
 
diff --git a/pkgs/development/compilers/ghc/7.4.2-binary.nix b/pkgs/development/compilers/ghc/7.4.2-binary.nix
index 7000081e5db..f6dc974227c 100644
--- a/pkgs/development/compilers/ghc/7.4.2-binary.nix
+++ b/pkgs/development/compilers/ghc/7.4.2-binary.nix
@@ -62,7 +62,8 @@ stdenv.mkDerivation rec {
      '' else "");
 
   configurePhase = ''
-    ./configure --prefix=$out --with-gmp-libraries=${gmp}/lib --with-gmp-includes=${gmp}/include
+    ./configure --prefix=$out --with-gmp-libraries=${gmp}/lib --with-gmp-includes=${gmp}/include \
+      --with-clang
   '';
 
   # Stripping combined with patchelf breaks the executables (they die
diff --git a/pkgs/development/compilers/ghc/7.8.3-binary.nix b/pkgs/development/compilers/ghc/7.8.3-binary.nix
new file mode 100644
index 00000000000..f2c65c6ad05
--- /dev/null
+++ b/pkgs/development/compilers/ghc/7.8.3-binary.nix
@@ -0,0 +1,93 @@
+{stdenv, fetchurl, perl, ncurses, gmp}:
+
+stdenv.mkDerivation rec {
+  version = "7.8.3";
+
+  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 = "1ja0cq5xyjcvjpvjmm4nzhkpmwfs2kjlldbc48lxcs9rmqi7rnay";
+      }
+    else throw "cannot bootstrap GHC on this platform";
+
+  buildInputs = [perl];
+
+  postUnpack =
+    # Strip is harmful, see also below. It's important that this happens
+    # 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}/lib@" {} \;
+     '' +
+    # On Linux, use patchelf to modify the executables so that they can
+    # find editline/gmp.
+    (if stdenv.isLinux then ''
+      find . -type f -perm +100 \
+          -exec patchelf --interpreter "$(cat $NIX_GCC/nix-support/dynamic-linker)" \
+          --set-rpath "${ncurses}/lib:${gmp}/lib" {} \;
+      sed -i "s|/usr/bin/perl|perl\x00        |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
+      sed -i "s|/usr/bin/gcc|gcc\x00        |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
+      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=${gmp}/lib \
+      --with-gmp-includes=${gmp}/include
+  '';
+
+  # Stripping combined with patchelf breaks the executables (they die
+  # with a segfault or the kernel even refuses the execve). (NIXPKGS-85)
+  dontStrip = true;
+
+  # No building is necessary, but calling make without flags ironically
+  # calls install-strip ...
+  buildPhase = "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" ]
+      '';
+
+  meta.license = stdenv.lib.licenses.bsd3;
+  meta.platforms = ["x86_64-linux" "i686-linux" "i686-darwin" "x86_64-darwin"];
+}
diff --git a/pkgs/development/compilers/ghc/7.8.3.nix b/pkgs/development/compilers/ghc/7.8.3.nix
index 0c142883e65..9f5fc4b4e50 100644
--- a/pkgs/development/compilers/ghc/7.8.3.nix
+++ b/pkgs/development/compilers/ghc/7.8.3.nix
@@ -26,8 +26,6 @@ stdenv.mkDerivation rec {
     export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/ghc-${version}"
   '';
 
-  configureFlags = "--with-gcc=${stdenv.gcc}/bin/gcc";
-
   # required, because otherwise all symbols from HSffi.o are stripped, and
   # that in turn causes GHCi to abort
   stripDebugFlags = [ "-S" "--keep-file-symbols" ];
diff --git a/pkgs/development/compilers/llvm/3.4/clang.nix b/pkgs/development/compilers/llvm/3.4/clang.nix
index 6ec3f7bf44a..fc33a7809a6 100644
--- a/pkgs/development/compilers/llvm/3.4/clang.nix
+++ b/pkgs/development/compilers/llvm/3.4/clang.nix
@@ -1,5 +1,9 @@
 { stdenv, fetch, cmake, libxml2, libedit, llvm, version, clang-tools-extra_src }:
 
+# be sure not to rebuild clang on darwin; some packages request it specifically
+# we need to fix those
+assert stdenv.isDarwin -> stdenv.gcc.nativeTools;
+
 stdenv.mkDerivation {
   name = "clang-${version}";
 
diff --git a/pkgs/development/compilers/llvm/3.4/llvm.nix b/pkgs/development/compilers/llvm/3.4/llvm.nix
index fbc881fc8e0..d3beb2e7461 100644
--- a/pkgs/development/compilers/llvm/3.4/llvm.nix
+++ b/pkgs/development/compilers/llvm/3.4/llvm.nix
@@ -27,7 +27,10 @@ in stdenv.mkDerivation rec {
     mv compiler-rt-* $sourceRoot/projects/compiler-rt
   '';
 
-  buildInputs = [ perl groff cmake libxml2 python libffi ] ++ stdenv.lib.optional stdenv.isLinux valgrind;
+  buildInputs =
+    [ perl groff cmake libxml2 libffi ]
+    ++ stdenv.lib.optional (!stdenv.isDarwin) python /*
+    ++ stdenv.lib.optional stdenv.isLinux valgrind */;
 
   propagatedBuildInputs = [ ncurses zlib ];
 
@@ -65,6 +68,5 @@ in stdenv.mkDerivation rec {
     license     = stdenv.lib.licenses.bsd3;
     maintainers = with stdenv.lib.maintainers; [ shlevy lovek323 raskin viric ];
     platforms   = stdenv.lib.platforms.all;
-    broken      = stdenv.isDarwin;
   };
 }
diff --git a/pkgs/development/compilers/ocaml/4.01.0.nix b/pkgs/development/compilers/ocaml/4.01.0.nix
index 2876bce9caf..5e3cb61c339 100644
--- a/pkgs/development/compilers/ocaml/4.01.0.nix
+++ b/pkgs/development/compilers/ocaml/4.01.0.nix
@@ -26,6 +26,8 @@ stdenv.mkDerivation rec {
     sha256 = "b1ca708994180236917ae79e17606da5bd334ca6acd6873a550027e1c0ec874a";
   };
 
+  patches = [ ./fix-clang-build-on-osx.diff ];
+
   prefixKey = "-prefix ";
   configureFlags = ["-no-tk"] ++ optionals useX11 [ "-x11lib" x11lib
                                                     "-x11include" x11inc ];
diff --git a/pkgs/development/compilers/ocaml/fix-clang-build-on-osx.diff b/pkgs/development/compilers/ocaml/fix-clang-build-on-osx.diff
new file mode 100644
index 00000000000..d7d9c863858
--- /dev/null
+++ b/pkgs/development/compilers/ocaml/fix-clang-build-on-osx.diff
@@ -0,0 +1,20 @@
+diff --git a/configure b/configure
+index d45e88f..25d872b 100755
+--- a/configure
++++ b/configure
+@@ -322,7 +322,14 @@ case "$bytecc,$target" in
+     bytecccompopts="-fno-defer-pop $gcc_warnings -DSHRINKED_GNUC"
+     mathlib="";;
+   *,*-*-darwin*)
+-    bytecccompopts="-fno-defer-pop $gcc_warnings"
++    # On recent version of OSX, gcc is a symlink to clang
++    if $bytecc --version | grep -q clang; then
++        # -fno-defer-pop is not supported by clang, and make recent
++        # versions of clang to fail
++        bytecccompopts="$gcc_warnings"
++    else
++        bytecccompopts="-fno-defer-pop $gcc_warnings"
++    fi
+     mathlib=""
+     mkexe="$mkexe -Wl,-no_compact_unwind"
+     # Tell gcc that we can use 32-bit code addresses for threaded code
diff --git a/pkgs/development/interpreters/guile/clang.patch b/pkgs/development/interpreters/guile/clang.patch
new file mode 100644
index 00000000000..4d0f342b211
--- /dev/null
+++ b/pkgs/development/interpreters/guile/clang.patch
@@ -0,0 +1,14 @@
+diff --git a/lib/stdint.in.h b/lib/stdint.in.h
+index 889bca7..15d39b0 100644
+--- a/lib/stdint.in.h
++++ b/lib/stdint.in.h
+@@ -74,7 +74,8 @@
+      in <inttypes.h> would reinclude us, skipping our contents because
+      _@GUARD_PREFIX@_STDINT_H is defined.
+      The include_next requires a split double-inclusion guard.  */
+-# @INCLUDE_NEXT@ @NEXT_STDINT_H@
++# include <inttypes.h>
++// # @INCLUDE_NEXT@ @NEXT_STDINT_H@
+ #endif
+ 
+ #if ! defined _@GUARD_PREFIX@_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
diff --git a/pkgs/development/interpreters/guile/default.nix b/pkgs/development/interpreters/guile/default.nix
index 2ddad5cde67..ad5d2f1cc58 100644
--- a/pkgs/development/interpreters/guile/default.nix
+++ b/pkgs/development/interpreters/guile/default.nix
@@ -7,11 +7,11 @@
  else stdenv.mkDerivation)
 
 (rec {
-  name = "guile-2.0.9";
+  name = "guile-2.0.11";
 
   src = fetchurl {
     url = "mirror://gnu/guile/${name}.tar.xz";
-    sha256 = "0nw9y8vjyz4r61v06p9msks5lm58pd91irmzg4k487vmv743h2pp";
+    sha256 = "1qh3j7308qvsjgwf7h94yqgckpbgz2k3yqdkzsyhqcafvfka9l5f";
   };
 
   nativeBuildInputs = [ makeWrapper gawk pkgconfig ];
@@ -29,7 +29,7 @@
 
   enableParallelBuilding = true;
 
-  patches = [ ./disable-gc-sensitive-tests.patch ./eai_system.patch ] ++
+  patches = [ ./disable-gc-sensitive-tests.patch ./eai_system.patch ./clang.patch ] ++
     (stdenv.lib.optional (coverageAnalysis != null) ./gcov-file-name.patch);
 
   # Explicitly link against libgcc_s, to work around the infamous
diff --git a/pkgs/development/interpreters/lua-5/5.1.nix b/pkgs/development/interpreters/lua-5/5.1.nix
index 444ecbc787a..adeaa9fae7b 100644
--- a/pkgs/development/interpreters/lua-5/5.1.nix
+++ b/pkgs/development/interpreters/lua-5/5.1.nix
@@ -29,7 +29,7 @@ stdenv.mkDerivation rec {
   configurePhase =
     if stdenv.isDarwin
     then ''
-    makeFlagsArray=( INSTALL_TOP=$out INSTALL_MAN=$out/share/man/man1 PLAT=macosx CFLAGS="-DLUA_USE_LINUX -fno-common -O2" LDFLAGS="" )
+    makeFlagsArray=( INSTALL_TOP=$out INSTALL_MAN=$out/share/man/man1 PLAT=macosx CFLAGS="-DLUA_USE_LINUX -fno-common -O2" LDFLAGS="" CC="$CC" )
     installFlagsArray=( TO_BIN="lua luac" TO_LIB="liblua.5.1.5.dylib" INSTALL_DATA='cp -d' )
   '' else ''
     makeFlagsArray=( INSTALL_TOP=$out INSTALL_MAN=$out/share/man/man1 PLAT=linux CFLAGS="-DLUA_USE_LINUX -O2 -fPIC" LDFLAGS="-fPIC" )
diff --git a/pkgs/development/interpreters/perl/5.16/default.nix b/pkgs/development/interpreters/perl/5.16/default.nix
index d7d6b54e94a..db9b821b888 100644
--- a/pkgs/development/interpreters/perl/5.16/default.nix
+++ b/pkgs/development/interpreters/perl/5.16/default.nix
@@ -31,7 +31,6 @@ stdenv.mkDerivation rec {
   # Miniperl needs -lm. perl needs -lrt.
   configureFlags =
     [ "-de"
-      "-Dcc=gcc"
       "-Uinstallusrbinperl"
       "-Dinstallstyle=lib/perl5"
       "-Duseshrplib"
diff --git a/pkgs/development/interpreters/ruby/ruby-1.9.3.nix b/pkgs/development/interpreters/ruby/ruby-1.9.3.nix
index 77880870dd9..9f7252bdc48 100644
--- a/pkgs/development/interpreters/ruby/ruby-1.9.3.nix
+++ b/pkgs/development/interpreters/ruby/ruby-1.9.3.nix
@@ -86,6 +86,8 @@ stdenv.mkDerivation rec {
 
   installFlags = stdenv.lib.optionalString docSupport "install-doc";
 
+  CFLAGS = stdenv.lib.optionalString stdenv.isDarwin "-mmacosx-version-min=10.7";
+
   postInstall = ''
     # Bundler tries to create this directory
     mkdir -pv $out/${passthru.gemPath}
diff --git a/pkgs/development/libraries/apr-util/default.nix b/pkgs/development/libraries/apr-util/default.nix
index 6932f389b84..76477d38b6d 100644
--- a/pkgs/development/libraries/apr-util/default.nix
+++ b/pkgs/development/libraries/apr-util/default.nix
@@ -2,6 +2,7 @@
 , sslSupport ? true, openssl
 , bdbSupport ? false, db
 , ldapSupport ? true, openldap
+, libiconvOrNull
 }:
 
 assert sslSupport -> openssl != null;
@@ -28,7 +29,7 @@ stdenv.mkDerivation rec {
     ${stdenv.lib.optionalString ldapSupport "--with-ldap"}
   '';
 
-  propagatedBuildInputs = [ makeWrapper apr expat ]
+  propagatedBuildInputs = [ makeWrapper apr expat libiconvOrNull ]
     ++ optional sslSupport openssl
     ++ optional bdbSupport db
     ++ optional ldapSupport openldap;
diff --git a/pkgs/development/libraries/aspell/clang.patch b/pkgs/development/libraries/aspell/clang.patch
new file mode 100644
index 00000000000..c4cfa426588
--- /dev/null
+++ b/pkgs/development/libraries/aspell/clang.patch
@@ -0,0 +1,18 @@
+--- interfaces/cc/aspell.h	2013-10-13 20:29:33.000000000 +0200
++++ interfaces/cc/aspell.h	2013-10-13 20:30:01.000000000 +0200
+@@ -237,6 +237,7 @@
+ /******************************** errors ********************************/
+ 
+ 
++#ifndef __cplusplus
+ extern const struct AspellErrorInfo * const aerror_other;
+ extern const struct AspellErrorInfo * const aerror_operation_not_supported;
+ extern const struct AspellErrorInfo * const   aerror_cant_copy;
+@@ -322,6 +323,7 @@
+ extern const struct AspellErrorInfo * const   aerror_bad_magic;
+ extern const struct AspellErrorInfo * const aerror_expression;
+ extern const struct AspellErrorInfo * const   aerror_invalid_expression;
++#endif
+ 
+ 
+ /******************************* speller *******************************/
diff --git a/pkgs/development/libraries/aspell/default.nix b/pkgs/development/libraries/aspell/default.nix
index 4ac6dc58ba9..38d734e902c 100644
--- a/pkgs/development/libraries/aspell/default.nix
+++ b/pkgs/development/libraries/aspell/default.nix
@@ -8,6 +8,10 @@ stdenv.mkDerivation rec {
     sha256 = "1qgn5psfyhbrnap275xjfrzppf5a83fb67gpql0kfqv37al869gm";
   };
 
+  patchPhase = ''
+    patch interfaces/cc/aspell.h < ${./clang.patch}
+  '';
+
   buildInputs = [ perl ];
 
   doCheck = true;
diff --git a/pkgs/development/libraries/boost/1.55.nix b/pkgs/development/libraries/boost/1.55.nix
index 31469b3e06c..2c02ce13e8d 100644
--- a/pkgs/development/libraries/boost/1.55.nix
+++ b/pkgs/development/libraries/boost/1.55.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchurl, icu, expat, zlib, bzip2, python, fixDarwinDylibNames
-, toolset ? null
+, toolset ? if stdenv.isDarwin then "clang" else null
 , enableRelease ? true
 , enableDebug ? false
 , enableSingleThreaded ? false
@@ -57,6 +57,8 @@ let res = stdenv.mkDerivation {
     sha256 = "0lkv5dzssbl5fmh2nkaszi8x9qbj80pr4acf9i26sj3rvlih1w7z";
   };
 
+  patches = stdenv.lib.optional (toolset == "clang") [ ./boost-155-clang.patch ];
+
   enableParallelBuilding = true;
 
   buildInputs =
@@ -66,7 +68,7 @@ let res = stdenv.mkDerivation {
   configureScript = "./bootstrap.sh";
   configureFlags = "--with-icu=${icu} --with-python=${python}/bin/python" + withToolset;
 
-  buildPhase = "${stdenv.lib.optionalString (toolset == "clang") "unset NIX_ENFORCE_PURITY; "}./b2 -j$NIX_BUILD_CORES -sEXPAT_INCLUDE=${expat}/include -sEXPAT_LIBPATH=${expat}/lib --layout=${layout} variant=${variant} threading=${threading} link=${link} ${cflags} install${withToolset}";
+  buildPhase = "${stdenv.lib.optionalString (toolset == "clang") "unset NIX_ENFORCE_PURITY; "}./b2 -j$NIX_BUILD_CORES -sEXPAT_INCLUDE=${expat}/include -sEXPAT_LIBPATH=${expat}/lib --layout=${layout} variant=${variant} threading=${threading} link=${link} ${cflags} install";
 
   # normal install does not install bjam, this is a separate step
   installPhase = ''
diff --git a/pkgs/development/libraries/boost/boost-155-clang.patch b/pkgs/development/libraries/boost/boost-155-clang.patch
new file mode 100644
index 00000000000..9c4e3a74cd2
--- /dev/null
+++ b/pkgs/development/libraries/boost/boost-155-clang.patch
@@ -0,0 +1,90 @@
+diff --git a/boost/atomic/detail/cas128strong.hpp b/boost/atomic/detail/cas128strong.hpp
+index 906c13e..dcb4d7d 100644
+--- a/boost/atomic/detail/cas128strong.hpp
++++ b/boost/atomic/detail/cas128strong.hpp
+@@ -196,15 +196,17 @@ class base_atomic<T, void, 16, Sign>
+ 
+ public:
+     BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
+-    explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0)
++    explicit base_atomic(value_type const& v) BOOST_NOEXCEPT
+     {
++        memset(&v_, 0, sizeof(v_));
+         memcpy(&v_, &v, sizeof(value_type));
+     }
+ 
+     void
+     store(value_type const& value, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
+     {
+-        storage_type value_s = 0;
++        storage_type value_s;
++        memset(&value_s, 0, sizeof(value_s));
+         memcpy(&value_s, &value, sizeof(value_type));
+         platform_fence_before_store(order);
+         platform_store128(value_s, &v_);
+@@ -247,7 +249,9 @@ class base_atomic<T, void, 16, Sign>
+         memory_order success_order,
+         memory_order failure_order) volatile BOOST_NOEXCEPT
+     {
+-        storage_type expected_s = 0, desired_s = 0;
++        storage_type expected_s, desired_s;
++        memset(&expected_s, 0, sizeof(expected_s));
++        memset(&desired_s, 0, sizeof(desired_s));
+         memcpy(&expected_s, &expected, sizeof(value_type));
+         memcpy(&desired_s, &desired, sizeof(value_type));
+
+diff --git a/boost/atomic/detail/gcc-atomic.hpp b/boost/atomic/detail/gcc-atomic.hpp
+index a130590..4af99a1 100644
+--- a/boost/atomic/detail/gcc-atomic.hpp
++++ b/boost/atomic/detail/gcc-atomic.hpp
+@@ -958,14 +958,16 @@ class base_atomic<T, void, 16, Sign>
+ 
+ public:
+     BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
+-    explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0)
++    explicit base_atomic(value_type const& v) BOOST_NOEXCEPT
+     {
++        memset(&v_, 0, sizeof(v_));
+         memcpy(&v_, &v, sizeof(value_type));
+     }
+ 
+     void store(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
+     {
+-        storage_type tmp = 0;
++        storage_type tmp;
++        memset(&tmp, 0, sizeof(tmp));
+         memcpy(&tmp, &v, sizeof(value_type));
+         __atomic_store_n(&v_, tmp, atomics::detail::convert_memory_order_to_gcc(order));
+     }
+@@ -980,7 +982,8 @@ class base_atomic<T, void, 16, Sign>
+ 
+     value_type exchange(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
+     {
+-        storage_type tmp = 0;
++        storage_type tmp;
++        memset(&tmp, 0, sizeof(tmp));
+         memcpy(&tmp, &v, sizeof(value_type));
+         tmp = __atomic_exchange_n(&v_, tmp, atomics::detail::convert_memory_order_to_gcc(order));
+         value_type res;
+@@ -994,7 +997,9 @@ class base_atomic<T, void, 16, Sign>
+         memory_order success_order,
+         memory_order failure_order) volatile BOOST_NOEXCEPT
+     {
+-        storage_type expected_s = 0, desired_s = 0;
++        storage_type expected_s, desired_s;
++        memset(&expected_s, 0, sizeof(expected_s));
++        memset(&desired_s, 0, sizeof(desired_s));
+         memcpy(&expected_s, &expected, sizeof(value_type));
+         memcpy(&desired_s, &desired, sizeof(value_type));
+         const bool success = __atomic_compare_exchange_n(&v_, &expected_s, desired_s, false,
+@@ -1010,7 +1015,9 @@ class base_atomic<T, void, 16, Sign>
+         memory_order success_order,
+         memory_order failure_order) volatile BOOST_NOEXCEPT
+     {
+-        storage_type expected_s = 0, desired_s = 0;
++        storage_type expected_s, desired_s;
++        memset(&expected_s, 0, sizeof(expected_s));
++        memset(&desired_s, 0, sizeof(desired_s));
+         memcpy(&expected_s, &expected, sizeof(value_type));
+         memcpy(&desired_s, &desired, sizeof(value_type));
+         const bool success = __atomic_compare_exchange_n(&v_, &expected_s, desired_s, true,
diff --git a/pkgs/development/libraries/cyrus-sasl/default.nix b/pkgs/development/libraries/cyrus-sasl/default.nix
index 712f05b8d65..391638548fb 100644
--- a/pkgs/development/libraries/cyrus-sasl/default.nix
+++ b/pkgs/development/libraries/cyrus-sasl/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, openssl, db, gettext, pam }:
+{ lib, stdenv, fetchurl, openssl, db, gettext, pam, fixDarwinDylibNames }:
 
 stdenv.mkDerivation rec {
   name = "cyrus-sasl-2.1.26";
@@ -8,7 +8,10 @@ stdenv.mkDerivation rec {
     sha256 = "1hvvbcsg21nlncbgs0cgn3iwlnb3vannzwsp6rwvnn9ba4v53g4g";
   };
 
-  buildInputs = [ openssl db gettext ] ++ stdenv.lib.optional stdenv.isLinux pam;
+  buildInputs =
+    [ openssl db gettext ]
+    ++ lib.optional stdenv.isLinux pam
+    ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
 
   patches = [ ./missing-size_t.patch ]; # https://bugzilla.redhat.com/show_bug.cgi?id=906519
   patchFlags = "-p0";
@@ -22,7 +25,7 @@ stdenv.mkDerivation rec {
                         )
   '';
 
-  installFlags = if stdenv.isDarwin then [ "framedir=$(out)/Library/Frameworks/SASL2.framework" ] else null;
+  installFlags = lib.optional stdenv.isDarwin [ "framedir=$(out)/Library/Frameworks/SASL2.framework" ];
 
   meta = {
     homepage = "http://cyrusimap.web.cmu.edu/";
diff --git a/pkgs/development/libraries/db/generic.nix b/pkgs/development/libraries/db/generic.nix
index 6217bc46124..9d3f87ad5cb 100644
--- a/pkgs/development/libraries/db/generic.nix
+++ b/pkgs/development/libraries/db/generic.nix
@@ -18,6 +18,10 @@ stdenv.mkDerivation rec {
 
   patches = extraPatches;
 
+  patchPhase = ''
+    patch src/dbinc/atomic.h < ${./osx.patch}
+  '';
+
   configureFlags = [
     (if cxxSupport then "--enable-cxx" else "--disable-cxx")
     (if compat185 then "--enable-compat185" else "--disable-compat185")
diff --git a/pkgs/development/libraries/db/osx.patch b/pkgs/development/libraries/db/osx.patch
new file mode 100644
index 00000000000..398aa1d3700
--- /dev/null
+++ b/pkgs/development/libraries/db/osx.patch
@@ -0,0 +1,20 @@
+--- src/dbinc/atomic.h	2013-03-12 14:07:22.000000000 -0400
++++ src/dbinc/atomic.h.change	2013-03-12 14:06:35.000000000 -0400
+@@ -144,7 +144,7 @@
+ #define	atomic_inc(env, p)	__atomic_inc(p)
+ #define	atomic_dec(env, p)	__atomic_dec(p)
+ #define	atomic_compare_exchange(env, p, o, n)	\
+-	__atomic_compare_exchange((p), (o), (n))
++	__atomic_compare_exchange_db((p), (o), (n))
+ static inline int __atomic_inc(db_atomic_t *p)
+ {
+ 	int	temp;
+@@ -176,7 +176,7 @@
+  * http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
+  * which configure could be changed to use.
+  */
+-static inline int __atomic_compare_exchange(
++static inline int __atomic_compare_exchange_db(
+ 	db_atomic_t *p, atomic_value_t oldval, atomic_value_t newval)
+ {
+ 	atomic_value_t was;
diff --git a/pkgs/development/libraries/gmp/5.1.x.nix b/pkgs/development/libraries/gmp/5.1.x.nix
index 14a6d34d932..e9495b796dd 100644
--- a/pkgs/development/libraries/gmp/5.1.x.nix
+++ b/pkgs/development/libraries/gmp/5.1.x.nix
@@ -16,10 +16,13 @@ stdenv.mkDerivation (rec {
     # Build a "fat binary", with routines for several sub-architectures
     # (x86), except on Solaris where some tests crash with "Memory fault".
     # See <http://hydra.nixos.org/build/2760931>, for instance.
+    #
+    # no darwin because gmp uses ASM that clang doesn't like
     optional (!stdenv.isSunOS) "--enable-fat"
     ++ (if cxx then [ "--enable-cxx"  ]
                else [ "--disable-cxx" ])
     ++ optional (cxx && stdenv.isDarwin) "CPPFLAGS=-fexceptions"
+    ++ optional stdenv.isDarwin "ABI=64"
     ++ optional stdenv.is64bit "--with-pic"
     ;
 
diff --git a/pkgs/development/libraries/libc++/darwin.patch b/pkgs/development/libraries/libc++/darwin.patch
new file mode 100644
index 00000000000..bf83f169cfc
--- /dev/null
+++ b/pkgs/development/libraries/libc++/darwin.patch
@@ -0,0 +1,30 @@
+diff -ru -x '*~' libcxx-3.4.2.src-orig/lib/CMakeLists.txt libcxx-3.4.2.src/lib/CMakeLists.txt
+--- libcxx-3.4.2.src-orig/lib/CMakeLists.txt	2013-11-15 18:18:57.000000000 +0100
++++ libcxx-3.4.2.src/lib/CMakeLists.txt	2014-09-24 14:04:01.000000000 +0200
+@@ -56,7 +56,7 @@
+       "-compatibility_version 1"
+       "-current_version ${LIBCXX_VERSION}"
+       "-install_name /usr/lib/libc++.1.dylib"
+-      "-Wl,-reexport_library,/usr/lib/libc++abi.dylib"
++      "-Wl,-reexport_library,${LIBCXX_LIBCXXABI_LIB_PATH}/libc++abi.dylib"
+       "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp"
+       "/usr/lib/libSystem.B.dylib")
+   else()
+@@ -64,14 +64,14 @@
+       list(FIND ${CMAKE_OSX_ARCHITECTURES} "armv7" OSX_HAS_ARMV7)
+       if (OSX_HAS_ARMV7)
+         set(OSX_RE_EXPORT_LINE
+-          "${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib"
++          "${CMAKE_OSX_SYSROOT}${LIBCXX_LIBCXXABI_LIB_PATH}/libc++abi.dylib"
+           "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++sjlj-abi.exp")
+       else()
+         set(OSX_RE_EXPORT_LINE
+-          "-Wl,-reexport_library,${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib")
++          "-Wl,-reexport_library,${CMAKE_OSX_SYSROOT}${LIBCXX_LIBCXXABI_LIB_PATH}/libc++abi.dylib")
+       endif()
+     else()
+-      set (OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp")
++      set (OSX_RE_EXPORT_LINE "${LIBCXX_LIBCXXABI_LIB_PATH}/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp")
+     endif()
+ 
+     list(APPEND link_flags
diff --git a/pkgs/development/libraries/libc++/default.nix b/pkgs/development/libraries/libc++/default.nix
index 732ae08b797..99e9bfe1de2 100644
--- a/pkgs/development/libraries/libc++/default.nix
+++ b/pkgs/development/libraries/libc++/default.nix
@@ -1,9 +1,8 @@
-{ stdenv, fetchurl, cmake, libcxxabi, python }:
+{ lib, stdenv, fetchurl, cmake, libcxxabi, fixDarwinDylibNames }:
 
-let
-  version = "3.4.2";
+let version = "3.4.2"; in
 
-in stdenv.mkDerivation rec {
+stdenv.mkDerivation rec {
   name = "libc++-${version}";
 
   src = fetchurl {
@@ -11,21 +10,32 @@ in stdenv.mkDerivation rec {
     sha256 = "0z3jdvgcq995khkpis5c5vaxhbmvbqjlalbhn09k6pgb5zp46rc2";
   };
 
-  buildInputs = [ cmake libcxxabi python ];
+  patches = [ ./darwin.patch ];
 
-  cmakeFlags = [ "-DCMAKE_BUILD_TYPE=Release"
-                 "-DLIBCXX_LIBCXXABI_INCLUDE_PATHS=${libcxxabi}/include"
-                 "-DLIBCXX_CXX_ABI=libcxxabi" ];
+  buildInputs = [ cmake libcxxabi ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
+
+  cmakeFlags =
+    [ "-DCMAKE_BUILD_TYPE=Release"
+      "-DLIBCXX_LIBCXXABI_INCLUDE_PATHS=${libcxxabi}/include"
+      "-DLIBCXX_LIBCXXABI_LIB_PATH=${libcxxabi}/lib"
+      "-DLIBCXX_LIBCPPABI_VERSION=2"
+      "-DLIBCXX_CXX_ABI=libcxxabi"
+    ];
 
   enableParallelBuilding = true;
 
-  passthru.abi = libcxxabi;
+  inherit libcxxabi;
+
+  # Remove a Makefile that causes many retained dependencies.
+  postInstall = "rm $out/include/c++/v1/Makefile";
+
+  setupHook = ./setup-hook.sh;
 
   meta = {
     homepage = http://libcxx.llvm.org/;
     description = "A new implementation of the C++ standard library, targeting C++11";
     license = "BSD";
     maintainers = [ stdenv.lib.maintainers.shlevy ];
-    platforms = stdenv.lib.platforms.linux;
+    platforms = stdenv.lib.platforms.unix;
   };
 }
diff --git a/pkgs/development/libraries/libc++/setup-hook.sh b/pkgs/development/libraries/libc++/setup-hook.sh
new file mode 100644
index 00000000000..8543d09d8f5
--- /dev/null
+++ b/pkgs/development/libraries/libc++/setup-hook.sh
@@ -0,0 +1,2 @@
+export NIX_CFLAGS_COMPILE+=" -isystem @out@/include/c++/v1 -stdlib=libc++"
+export NIX_CFLAGS_LINK+=" -stdlib=libc++ -Wl,-rpath,@libcxxabi@/lib"
diff --git a/pkgs/development/libraries/libc++abi/darwin.patch b/pkgs/development/libraries/libc++abi/darwin.patch
new file mode 100644
index 00000000000..53ea8783f7a
--- /dev/null
+++ b/pkgs/development/libraries/libc++abi/darwin.patch
@@ -0,0 +1,17 @@
+diff -ru -x '*~' libcxxabi-orig/lib/buildit libcxxabi/lib/buildit
+--- libcxxabi-orig/lib/buildit	2014-09-18 16:54:14.000000000 +0200
++++ libcxxabi/lib/buildit	2014-09-24 13:22:27.000000000 +0200
+@@ -51,12 +51,8 @@
+         -dynamiclib -nodefaultlibs  \
+         -current_version ${RC_ProjectSourceVersion} \
+         -compatibility_version 1 \
+-        -install_name /usr/lib/libc++abi.dylib \
++        -install_name $out/lib/libc++abi.dylib \
+         -lSystem"
+-	if [ -f "${SDKROOT}/usr/local/lib/libCrashReporterClient.a" ]
+-	then
+-		LDSHARED_FLAGS+=" -lCrashReporterClient"
+-	fi
+     ;;
+   *-*-mingw*)
+     # FIXME: removing libgcc and libsupc++ dependencies means porting libcxxrt and LLVM/compiler-rt
diff --git a/pkgs/development/libraries/libc++abi/default.nix b/pkgs/development/libraries/libc++abi/default.nix
index a03caa9f571..ec87254c170 100644
--- a/pkgs/development/libraries/libc++abi/default.nix
+++ b/pkgs/development/libraries/libc++abi/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, libcxx, libunwind }:
+{ lib, stdenv, fetchurl, libcxx, coreutils, gnused }:
 
 let rev = "199626"; in
 
@@ -10,22 +10,32 @@ stdenv.mkDerivation {
     sha256 = "09wr6qwgmdzbmgfkdzfhph9giy0zd6fp3s017fcfy4g0prjn5s4c";
   };
 
-  NIX_CFLAGS_LINK = "-L${libunwind}/lib -lunwind";
+  patches = [ ./no-stdc++.patch ./darwin.patch ];
+
+  buildInputs = [ coreutils ];
 
   postUnpack = ''
     unpackFile ${libcxx.src}
-    export NIX_CFLAGS_COMPILE="-I${libunwind}/include -I$PWD/include -I$(readlink -f libcxx-*)/include"
-  '';
-
-  installPhase = ''
-    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
+  '' + lib.optionalString stdenv.isDarwin ''
+    export TRIPLE=x86_64-apple-darwin
+    # Hack: NIX_CFLAGS_COMPILE doesn't work here because clang++ isn't
+    # wrapped at this point.
+    export CXX="clang++ -D_LIBCXX_DYNAMIC_FALLBACK=1"
   '';
 
-  patchPhase = "sed -e s,-lstdc++,, -i lib/buildit";
+  installPhase = if stdenv.isDarwin
+    then ''
+      install -d -m 755 $out/include $out/lib
+      install -m 644 lib/libc++abi.dylib $out/lib
+      install -m 644 include/cxxabi.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
+    '';
 
   buildPhase = "(cd lib; ./buildit)";
 
@@ -34,6 +44,6 @@ stdenv.mkDerivation {
     description = "A new implementation of low level support for a standard C++ library";
     license = "BSD";
     maintainers = [ stdenv.lib.maintainers.shlevy ];
-    platforms = stdenv.lib.platforms.linux;
+    platforms = stdenv.lib.platforms.unix;
   };
 }
diff --git a/pkgs/development/libraries/libc++abi/no-stdc++.patch b/pkgs/development/libraries/libc++abi/no-stdc++.patch
new file mode 100644
index 00000000000..ddc9778a486
--- /dev/null
+++ b/pkgs/development/libraries/libc++abi/no-stdc++.patch
@@ -0,0 +1,12 @@
+diff -ru -x '*~' libcxxabi-orig/lib/buildit libcxxabi/lib/buildit
+--- libcxxabi-orig/lib/buildit	2014-09-18 16:54:14.000000000 +0200
++++ libcxxabi/lib/buildit	2014-09-24 13:22:27.000000000 +0200
+@@ -70,7 +66,7 @@
+     SOEXT=so
+     LDSHARED_FLAGS="-o libc++abi.so.1.0 \
+         -shared -nodefaultlibs -Wl,-soname,libc++abi.so.1 \
+-        -lpthread -lrt -lc -lstdc++"
++        -lpthread -lrt -lc"
+     ;;
+ esac
+ 
diff --git a/pkgs/development/libraries/libdevil/default.nix b/pkgs/development/libraries/libdevil/default.nix
index d3053b4d2a5..6cbbddfdba8 100644
--- a/pkgs/development/libraries/libdevil/default.nix
+++ b/pkgs/development/libraries/libdevil/default.nix
@@ -16,6 +16,15 @@ stdenv.mkDerivation rec {
 
   configureFlags = [ "--enable-ILU" "--enable-ILUT" ];
 
+  preConfigure = ''
+    sed -i 's, -std=gnu99,,g' configure
+    sed -i 's,malloc.h,stdlib.h,g' src-ILU/ilur/ilur.c
+  '';
+
+  postConfigure = ''
+    sed -i '/RESTRICT_KEYWORD/d' include/IL/config.h
+  '';
+
   patches =
     [ ( fetchurl {
         url = http://patch-tracker.debian.org/patch/series/dl/devil/1.7.8-6.1/03_CVE-2009-3994.diff;
diff --git a/pkgs/development/libraries/libedit/default.nix b/pkgs/development/libraries/libedit/default.nix
index 27c803fd81e..f913ab8e493 100644
--- a/pkgs/development/libraries/libedit/default.nix
+++ b/pkgs/development/libraries/libedit/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
   NROFF = "${groff}/bin/nroff";
 
   postInstall = ''
-    sed -i s/-lncurses/-lncursesw/g $out/lib/pkgconfig/libedit.pc
+    sed -i ${stdenv.lib.optionalString (stdenv.isDarwin && stdenv.gcc.nativeTools) "''"} s/-lncurses/-lncursesw/g $out/lib/pkgconfig/libedit.pc
   '';
 
   configureFlags = [ "--enable-widec" ];
diff --git a/pkgs/development/libraries/libffi/default.nix b/pkgs/development/libraries/libffi/default.nix
index da5a080521c..d661bbfc7a2 100644
--- a/pkgs/development/libraries/libffi/default.nix
+++ b/pkgs/development/libraries/libffi/default.nix
@@ -16,13 +16,14 @@ stdenv.mkDerivation rec {
     "--with-gcc-arch=generic" # no detection of -march= or -mtune=
   ] ++ stdenv.lib.optional (stdenv.needsPax) "--enable-pax_emutramp";
 
-  doCheck = stdenv.isLinux; # until we solve dejagnu problems on darwin and expect on BSD
+  #doCheck = stdenv.isLinux; # until we solve dejagnu problems on darwin and expect on BSD
+  doCheck = false;
 
   dontStrip = stdenv ? cross; # Don't run the native `strip' when cross-compiling.
 
   postInstall =
     # Install headers in the right place.
-    '' ln -s${if stdenv.isFreeBSD then "" else "r"}v "$out/lib/"libffi*/include "$out/include"
+    '' ln -s${if stdenv.isBSD then "" else "r"}v "$out/lib/"libffi*/include "$out/include"
     '';
 
   meta = {
diff --git a/pkgs/development/libraries/libgcrypt/default.nix b/pkgs/development/libraries/libgcrypt/default.nix
index b47709940dd..af231632022 100644
--- a/pkgs/development/libraries/libgcrypt/default.nix
+++ b/pkgs/development/libraries/libgcrypt/default.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation (rec {
 
   propagatedBuildInputs = [ libgpgerror ];
 
+  configureFlags = stdenv.lib.optional stdenv.isDarwin "--disable-asm";
+
   doCheck = stdenv.system != "i686-linux"; # "basic" test fails after stdenv+glibc-2.18
 
   # For some reason the tests don't find `libgpg-error.so'.
diff --git a/pkgs/development/libraries/libunistring/clang.patch b/pkgs/development/libraries/libunistring/clang.patch
new file mode 100644
index 00000000000..fdcbc0d528d
--- /dev/null
+++ b/pkgs/development/libraries/libunistring/clang.patch
@@ -0,0 +1,14 @@
+diff --git a/lib/stdint.in.h b/lib/stdint.in.h
+index 997e406..e0827f5 100644
+--- a/lib/stdint.in.h
++++ b/lib/stdint.in.h
+@@ -53,7 +53,8 @@
+      in <inttypes.h> would reinclude us, skipping our contents because
+      _GL_STDINT_H is defined.
+      The include_next requires a split double-inclusion guard.  */
+-# @INCLUDE_NEXT@ @NEXT_STDINT_H@
++# include <inttypes.h>
++// # @INCLUDE_NEXT@ @NEXT_STDINT_H@
+ #endif
+ 
+ #if ! defined _GL_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
diff --git a/pkgs/development/libraries/libunistring/default.nix b/pkgs/development/libraries/libunistring/default.nix
index 2a87d7a3249..9470240fc14 100644
--- a/pkgs/development/libraries/libunistring/default.nix
+++ b/pkgs/development/libraries/libunistring/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation (rec {
     sha256 = "18q620269xzpw39dwvr9zpilnl2dkw5z5kz3mxaadnpv4k3kw3b1";
   };
 
+  patches = stdenv.lib.optional stdenv.isDarwin [ ./clang.patch ];
+
   propagatedBuildInputs =
     stdenv.lib.optional ((! (stdenv ? glibc))
                          || (stdenv ? cross &&
diff --git a/pkgs/development/libraries/mesa-darwin/default.nix b/pkgs/development/libraries/mesa-darwin/default.nix
index 98936904be5..f259a397c84 100644
--- a/pkgs/development/libraries/mesa-darwin/default.nix
+++ b/pkgs/development/libraries/mesa-darwin/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, stdenvAdapters, gccApple, fetchurl, pkgconfig, intltool, flex, bison
+{ stdenv, stdenvAdapters, fetchurl, pkgconfig, intltool, flex, bison
 , python, libxml2Python, file, expat, makedepend, xorg, llvm, libffi, libvdpau
 , enableTextureFloats ? false # Texture floats are patented, see docs/patents.txt
 , enableExtraFeatures ? false # not maintained
diff --git a/pkgs/development/libraries/mpc/default.nix b/pkgs/development/libraries/mpc/default.nix
index 3d05fa2e040..dd132cfb5b7 100644
--- a/pkgs/development/libraries/mpc/default.nix
+++ b/pkgs/development/libraries/mpc/default.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ gmp mpfr ];
 
+  CFLAGS = "-I${gmp}/include";
+
   doCheck = true;
 
   meta = {
diff --git a/pkgs/development/libraries/mpfr/default.nix b/pkgs/development/libraries/mpfr/default.nix
index 653481aeccd..d999ba0cda5 100644
--- a/pkgs/development/libraries/mpfr/default.nix
+++ b/pkgs/development/libraries/mpfr/default.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ gmp ];
 
+  CFLAGS = "-I${gmp}/include";
+
   configureFlags =
     /* Work around a FreeBSD bug that otherwise leads to segfaults in the test suite:
           http://hydra.bordeaux.inria.fr/build/34862
diff --git a/pkgs/development/libraries/ncurses/clang.patch b/pkgs/development/libraries/ncurses/clang.patch
new file mode 100644
index 00000000000..ce33049bf40
--- /dev/null
+++ b/pkgs/development/libraries/ncurses/clang.patch
@@ -0,0 +1,42 @@
+diff -ruNp ncurses-5.8.orig/c++/cursesf.h ncurses-5.8/c++/cursesf.h
+--- ncurses-5.8.orig/c++/cursesf.h	2005-08-13 21:08:24.000000000 +0300
++++ ncurses-5.8/c++/cursesf.h	2011-04-03 18:29:29.000000000 +0300
+@@ -681,7 +681,7 @@ public:
+ 		   const T* p_UserData = STATIC_CAST(T*)(0),
+ 		   bool with_frame=FALSE,
+ 		   bool autoDelete_Fields=FALSE)
+-    : NCursesForm (Fields, with_frame, autoDelete_Fields) {
++    : NCursesForm (&Fields, with_frame, autoDelete_Fields) {
+       if (form)
+ 	set_user (const_cast<void *>(p_UserData));
+   };
+@@ -694,7 +694,7 @@ public:
+ 		   const T* p_UserData = STATIC_CAST(T*)(0),
+ 		   bool with_frame=FALSE,
+ 		   bool autoDelete_Fields=FALSE)
+-    : NCursesForm (Fields, nlines, ncols, begin_y, begin_x,
++    : NCursesForm (&Fields, nlines, ncols, begin_y, begin_x,
+ 		   with_frame, autoDelete_Fields) {
+       if (form)
+ 	set_user (const_cast<void *>(p_UserData));
+diff -ruNp ncurses-5.8.orig/c++/cursesm.h ncurses-5.8/c++/cursesm.h
+--- ncurses-5.8.orig/c++/cursesm.h	2005-08-13 21:10:36.000000000 +0300
++++ ncurses-5.8/c++/cursesm.h	2011-04-03 18:31:42.000000000 +0300
+@@ -639,7 +639,7 @@ public:
+ 		   const T* p_UserData = STATIC_CAST(T*)(0),
+ 		   bool with_frame=FALSE,
+ 		   bool autoDelete_Items=FALSE)
+-    : NCursesMenu (Items, with_frame, autoDelete_Items) {
++    : NCursesMenu (&Items, with_frame, autoDelete_Items) {
+       if (menu)
+ 	set_user (const_cast<void *>(p_UserData));
+   };
+@@ -651,7 +651,7 @@ public:
+ 		   int begin_x = 0,
+ 		   const T* p_UserData = STATIC_CAST(T*)(0),
+ 		   bool with_frame=FALSE)
+-    : NCursesMenu (Items, nlines, ncols, begin_y, begin_x, with_frame) {
++    : NCursesMenu (&Items, nlines, ncols, begin_y, begin_x, with_frame) {
+       if (menu)
+ 	set_user (const_cast<void *>(p_UserData));
+   };
diff --git a/pkgs/development/libraries/ncurses/default.nix b/pkgs/development/libraries/ncurses/default.nix
index 631199bf87c..3aa27480a0f 100644
--- a/pkgs/development/libraries/ncurses/default.nix
+++ b/pkgs/development/libraries/ncurses/default.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation rec {
     sha256 = "0fsn7xis81za62afan0vvm38bvgzg5wfmv1m86flqcj0nj7jjilh";
   };
 
-  patches = [ ./patch-ac ];
+  patches = [ ./patch-ac ./clang.patch ];
 
   configureFlags = ''
     --with-shared --without-debug --enable-pc-files --enable-symlinks
@@ -35,8 +35,6 @@ stdenv.mkDerivation rec {
     export configureFlags="$configureFlags --includedir=$out/include"
     export PKG_CONFIG_LIBDIR="$out/lib/pkgconfig"
     mkdir -p "$PKG_CONFIG_LIBDIR"
-  '' + lib.optionalString stdenv.isDarwin ''
-    substituteInPlace configure --replace -no-cpp-precomp ""
   '';
 
   selfNativeBuildInput = true;
diff --git a/pkgs/development/libraries/qt-4.x/4.8/default.nix b/pkgs/development/libraries/qt-4.x/4.8/default.nix
index 1679b4953e7..6c534f4220d 100644
--- a/pkgs/development/libraries/qt-4.x/4.8/default.nix
+++ b/pkgs/development/libraries/qt-4.x/4.8/default.nix
@@ -78,8 +78,6 @@ stdenv.mkDerivation rec {
       -translationdir $out/share/${name}/translations
     "
   '' + optionalString stdenv.isDarwin ''
-    export CXX=clang++
-    export CC=clang
     sed -i 's/QMAKE_CC = gcc/QMAKE_CC = clang/' mkspecs/common/g++-base.conf
     sed -i 's/QMAKE_CXX = g++/QMAKE_CXX = clang++/' mkspecs/common/g++-base.conf
   '';
diff --git a/pkgs/development/libraries/readline/6.2.nix b/pkgs/development/libraries/readline/6.2.nix
index d72d6566bbc..1555f255c51 100644
--- a/pkgs/development/libraries/readline/6.2.nix
+++ b/pkgs/development/libraries/readline/6.2.nix
@@ -14,6 +14,7 @@ stdenv.mkDerivation (rec {
   patches =
     [ ./link-against-ncurses.patch
       ./no-arch_only.patch
+      ./clang.patch
     ]
     ++
     (let
diff --git a/pkgs/development/libraries/readline/clang.patch b/pkgs/development/libraries/readline/clang.patch
new file mode 100644
index 00000000000..42bb0be09c3
--- /dev/null
+++ b/pkgs/development/libraries/readline/clang.patch
@@ -0,0 +1,13 @@
+diff --git a/support/shobj-conf b/support/shobj-conf
+index 5a63e80..4b2a741 100644
+--- support/shobj-conf
++++ support/shobj-conf
+@@ -189,7 +189,7 @@ darwin*|macosx*)
+ 	darwin[789]*|darwin10*)	SHOBJ_LDFLAGS=''
+ 			SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v'
+ 			;;
+-	*)		SHOBJ_LDFLAGS='-dynamic'
++	*)		SHOBJ_LDFLAGS='-dynamiclib'
+ 			SHLIB_XLDFLAGS='-arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v'
+ 			;;
+ 	esac
diff --git a/pkgs/development/libraries/serf/default.nix b/pkgs/development/libraries/serf/default.nix
index 1e8eec6ae45..49d7cec9590 100644
--- a/pkgs/development/libraries/serf/default.nix
+++ b/pkgs/development/libraries/serf/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, apr, scons, openssl, aprutil, zlib, krb5, pkgconfig }:
+{ stdenv, fetchurl, apr, scons, openssl, aprutil, zlib, krb5, pkgconfig, gnused }:
 
 stdenv.mkDerivation rec {
   name = "serf-1.3.7";
@@ -11,16 +11,20 @@ stdenv.mkDerivation rec {
   buildInputs = [ apr scons openssl aprutil zlib krb5 pkgconfig ];
 
   configurePhase = ''
-    sed -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"PATH":os.environ["PATH"]})' -i SConstruct
-    sed -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"NIX_CFLAGS_COMPILE":os.environ["NIX_CFLAGS_COMPILE"]})' -i SConstruct
-    sed -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"NIX_LDFLAGS":os.environ["NIX_LDFLAGS"]})' -i SConstruct
+    ${gnused}/bin/sed -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"PATH":os.environ["PATH"]})' -i SConstruct
+    ${gnused}/bin/sed -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"NIX_CFLAGS_COMPILE":os.environ["NIX_CFLAGS_COMPILE"]})' -i SConstruct
+    ${gnused}/bin/sed -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"NIX_LDFLAGS":os.environ["NIX_LDFLAGS"]})' -i SConstruct
   '';
 
   buildPhase = ''
     scons PREFIX="$out" OPENSSL="${openssl}" ZLIB="${zlib}" APR="$(echo "${apr}"/bin/*-config)" \
-        APU="$(echo "${aprutil}"/bin/*-config)" GSSAPI="${krb5}" CC="${stdenv.gcc}/bin/gcc"
+        APU="$(echo "${aprutil}"/bin/*-config)" GSSAPI="${krb5}" CC="${
+          if stdenv.isDarwin then "clang" else "${stdenv.gcc}/bin/gcc"
+        }"
   '';
 
+  NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-L/usr/lib";
+
   installPhase = ''
     scons install
   '';
diff --git a/pkgs/development/libraries/v8/default.nix b/pkgs/development/libraries/v8/default.nix
index fda32a7ddbd..3abac0feab3 100644
--- a/pkgs/development/libraries/v8/default.nix
+++ b/pkgs/development/libraries/v8/default.nix
@@ -63,7 +63,7 @@ stdenv.mkDerivation rec {
 
   meta = with stdenv.lib; {
     description = "Google's open source JavaScript engine";
-    platforms = with platforms; linux ++ darwin;
+    platforms = with platforms; linux;
     license = licenses.bsd3;
   };
 }
diff --git a/pkgs/development/tools/misc/ccache/default.nix b/pkgs/development/tools/misc/ccache/default.nix
index 3dd634274f3..7207767a896 100644
--- a/pkgs/development/tools/misc/ccache/default.nix
+++ b/pkgs/development/tools/misc/ccache/default.nix
@@ -1,5 +1,7 @@
 {stdenv, fetchurl, runCommand, gcc, zlib}:
 
+assert stdenv.isLinux;
+
 let
   ccache =
 stdenv.mkDerivation {
diff --git a/pkgs/development/tools/misc/distcc/masq.nix b/pkgs/development/tools/misc/distcc/masq.nix
index 753c35b5d3a..28b31cbb48d 100644
--- a/pkgs/development/tools/misc/distcc/masq.nix
+++ b/pkgs/development/tools/misc/distcc/masq.nix
@@ -3,6 +3,10 @@
 stdenv.mkDerivation {
   name = "distcc-masq-${gccRaw.name}";
 
+  meta = {
+    platforms = stdenv.lib.platforms.linux;
+  };
+
   phases = [ "installPhase" ];
   installPhase = ''
     mkdir -p $out/bin
diff --git a/pkgs/development/tools/misc/sloccount/default.nix b/pkgs/development/tools/misc/sloccount/default.nix
index 1aa9a2c058d..fffb8074748 100644
--- a/pkgs/development/tools/misc/sloccount/default.nix
+++ b/pkgs/development/tools/misc/sloccount/default.nix
@@ -31,6 +31,7 @@ stdenv.mkDerivation rec {
 
   configurePhase = ''
     sed -i "makefile" -"es|PREFIX[[:blank:]]*=.*$|PREFIX = $out|g"
+    sed -i "makefile" -"es|gcc|$CC|g"
   '';
 
   doCheck = true;
diff --git a/pkgs/games/spring/default.nix b/pkgs/games/spring/default.nix
index 1c26dde00a9..1a5eaf6a861 100644
--- a/pkgs/games/spring/default.nix
+++ b/pkgs/games/spring/default.nix
@@ -32,7 +32,7 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     wrapProgram "$out/bin/spring" \
-      --prefix LD_LIBRARY_PATH : "${stdenv.gcc.gcc}/lib64:${stdenv.gcc.gcc}/lib::${systemd}/lib"
+      --prefix LD_LIBRARY_PATH : "${stdenv.gcc.gcc}/lib::${systemd}/lib"
   '';
 
   meta = with stdenv.lib; {
@@ -40,6 +40,6 @@ stdenv.mkDerivation rec {
     description = "A powerful real-time strategy (RTS) game engine";
     license = licenses.gpl2;
     maintainers = [ maintainers.phreedom maintainers.qknight maintainers.iElectric ];
-    platforms = platforms.mesaPlatforms;
+    platforms = platforms.linux;
   };
 }
diff --git a/pkgs/servers/http/nginx/default.nix b/pkgs/servers/http/nginx/default.nix
index e5c9b9b9456..1d2887bcc21 100644
--- a/pkgs/servers/http/nginx/default.nix
+++ b/pkgs/servers/http/nginx/default.nix
@@ -112,7 +112,7 @@ stdenv.mkDerivation rec {
     ++ optional (elem stdenv.system (with platforms; linux ++ freebsd)) "--with-file-aio";
 
 
-  additionalFlags = optionalString stdenv.isDarwin "-Wno-error=deprecated-declarations";
+  additionalFlags = optionalString stdenv.isDarwin "-Wno-error=deprecated-declarations -Wno-error=conditional-uninitialized";
 
   preConfigure = ''
     export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${libxml2}/include/libxml2 $additionalFlags"
diff --git a/pkgs/servers/x11/xorg/overrides.nix b/pkgs/servers/x11/xorg/overrides.nix
index 246ed94cd1a..fd5e863d599 100644
--- a/pkgs/servers/x11/xorg/overrides.nix
+++ b/pkgs/servers/x11/xorg/overrides.nix
@@ -69,12 +69,15 @@ in
   };
 
   libX11 = attrs: attrs // {
-    preConfigure = setMalloc0ReturnsNullCrossCompiling;
+    preConfigure = setMalloc0ReturnsNullCrossCompiling + ''
+      sed 's,^as_dummy.*,as_dummy="\$PATH",' -i configure
+    '';
     postInstall =
       ''
         # Remove useless DocBook XML files.
         rm -rf $out/share/doc
       '';
+    CPP = stdenv.lib.optionalString stdenv.isDarwin "clang -E -";
   };
 
   libXfont = attrs: attrs // {
@@ -99,8 +102,11 @@ in
   # Note: most of these are in Requires.private, so maybe builder.sh
   # should propagate them automatically.
   libXt = attrs: attrs // {
-    preConfigure = setMalloc0ReturnsNullCrossCompiling;
+    preConfigure = setMalloc0ReturnsNullCrossCompiling + ''
+      sed 's,^as_dummy.*,as_dummy="\$PATH",' -i configure
+    '';
     propagatedBuildInputs = [ xorg.libSM ];
+    CPP = stdenv.lib.optionalString stdenv.isDarwin "clang -E -";
   };
 
   # See https://bugs.freedesktop.org/show_bug.cgi?id=47792
diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix
index d223cf1708c..9e82359865b 100644
--- a/pkgs/stdenv/adapters.nix
+++ b/pkgs/stdenv/adapters.nix
@@ -285,18 +285,17 @@ rec {
     };
 
 
-  /* Modify a stdenv so that it uses the Gold linker. FIXME: should
-     use -fuse-ld=gold instead, but then the ld-wrapper won't be
-     invoked. */
-  useGoldLinker = stdenv:
-    let
-      binutils = stdenv.gcc.binutils;
-      binutils' = pkgs.runCommand "${binutils.name}-gold" { }
-        ''
-          mkdir -p $out/bin
-          ln -s ${binutils}/bin/* $out/bin/
-          ln -sfn ${binutils}/bin/ld.gold $out/bin/ld
-        ''; # */
-    in overrideGCC stdenv (stdenv.gcc.override { binutils = binutils'; });
+  /* Modify a stdenv so that it uses the Gold linker. */
+  useGoldLinker = stdenv: stdenv //
+    { mkDerivation = args: stdenv.mkDerivation (args // {
+        dontStrip = true;
+        NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_COMPILE or "") + " -fuse-ld=gold";
+      });
+    };
 
+  dropCxx = drv: drv.override {
+    stdenv = if pkgs.stdenv.isDarwin
+      then pkgs.allStdenvs.stdenvDarwinNaked
+      else pkgs.stdenv;
+  };
 }
diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix
new file mode 100644
index 00000000000..9131f0742d0
--- /dev/null
+++ b/pkgs/stdenv/darwin/default.nix
@@ -0,0 +1,49 @@
+{ stdenv, pkgs, config
+, haveLibCxx ? true
+, useClang33 ? true }:
+
+import ../generic rec {
+  inherit config;
+
+  preHook =
+    ''
+      export NIX_ENFORCE_PURITY=
+      export NIX_IGNORE_LD_THROUGH_GCC=1
+      export NIX_DONT_SET_RPATH=1
+      export NIX_NO_SELF_RPATH=1
+      dontFixLibtool=1
+      stripAllFlags=" " # the Darwin "strip" command doesn't know "-s"
+      xargsFlags=" "
+      export MACOSX_DEPLOYMENT_TARGET=10.9
+      export SDKROOT=$(/usr/bin/xcrun --sdk macosx10.9 --show-sdk-path 2> /dev/null || true)
+      export NIX_CFLAGS_COMPILE+=" --sysroot=/var/empty -idirafter $SDKROOT/usr/include -F$SDKROOT/System/Library/Frameworks -Wno-multichar -Wno-deprecated-declarations"
+      export NIX_LDFLAGS_AFTER+=" -L$SDKROOT/usr/lib"
+    '';
+
+  initialPath = (import ../common-path.nix) {pkgs = pkgs;};
+
+  system = stdenv.system;
+
+  gcc = import ../../build-support/gcc-wrapper {
+    nativeTools = false;
+    nativeLibc = true;
+    inherit stdenv;
+    extraPackages = stdenv.lib.optional haveLibCxx pkgs.libcxx;
+    binutils = import ../../build-support/native-darwin-cctools-wrapper {inherit stdenv;};
+    gcc = if useClang33 then pkgs.clang_33.gcc else pkgs.clang.gcc;
+    coreutils = pkgs.coreutils;
+    shell = pkgs.bash + "/bin/sh";
+  };
+
+  shell = pkgs.bash + "/bin/sh";
+
+  fetchurlBoot = stdenv.fetchurlBoot;
+
+  overrides = pkgs_: {
+    inherit gcc;
+    inherit (gcc) binutils;
+    inherit (pkgs)
+      gzip bzip2 xz bash coreutils diffutils findutils gawk
+      gnumake gnused gnutar gnugrep gnupatch perl libcxx libcxxabi;
+  };
+}
diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix
index e056505f1b7..de0042a9adb 100644
--- a/pkgs/stdenv/default.nix
+++ b/pkgs/stdenv/default.nix
@@ -33,6 +33,26 @@ rec {
     pkgs = stdenvNativePkgs;
   };
 
+  stdenvDarwin = import ./darwin {
+    inherit config;
+    stdenv = stdenvNative;
+    pkgs = stdenvNativePkgs;
+  };
+
+  stdenvDarwinNaked = import ./darwin {
+    inherit config;
+    stdenv = stdenvNative;
+    pkgs = stdenvNativePkgs;
+    haveLibCxx = false;
+  };
+
+  stdenvDarwin33 = import ./darwin {
+    inherit config;
+    stdenv = stdenvNative;
+    pkgs = stdenvNativePkgs;
+    useClang33 = true;
+  };
+
 
   # Linux standard environment.
   stdenvLinux = (import ./linux { inherit system allPackages platform config lib; }).stdenvLinux;
@@ -47,7 +67,7 @@ rec {
     if system == "armv7l-linux" then stdenvLinux else
     if system == "mips64el-linux" then stdenvLinux else
     if system == "powerpc-linux" then /* stdenvLinux */ stdenvNative else
-    if system == "x86_64-darwin" then stdenvNix else
+    if system == "x86_64-darwin" then stdenvDarwin else
     if system == "x86_64-solaris" then stdenvNix else
     stdenvNative;
 }
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index 4febd228679..827e0a260df 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -164,7 +164,8 @@ let
       isBSD = system == "i686-freebsd"
            || system == "x86_64-freebsd"
            || system == "i686-openbsd"
-           || system == "x86_64-openbsd";
+           || system == "x86_64-openbsd"
+           || system == "x86_64-darwin";
       isi686 = system == "i686-linux"
             || system == "i686-gnu"
             || system == "i686-freebsd"
diff --git a/pkgs/stdenv/native/default.nix b/pkgs/stdenv/native/default.nix
index 715bc02758b..b0ed7c93f78 100644
--- a/pkgs/stdenv/native/default.nix
+++ b/pkgs/stdenv/native/default.nix
@@ -35,9 +35,6 @@ rec {
     alias sed=gsed
     export MAKE=gmake
     shopt -s expand_aliases
-
-    # Filter out stupid GCC warnings (in gcc-wrapper).
-    export NIX_GCC_NEEDS_GREP=1
   '';
 
   prehookOpenBSD = ''
@@ -52,9 +49,6 @@ rec {
 
     export MAKE=gmake
     shopt -s expand_aliases
-
-    # Filter out stupid GCC warnings (in gcc-wrapper).
-    export NIX_GCC_NEEDS_GREP=1
   '';
 
   prehookNetBSD = ''
@@ -65,9 +59,6 @@ rec {
     alias tar=gtar
     export MAKE=gmake
     shopt -s expand_aliases
-
-    # Filter out stupid GCC warnings (in gcc-wrapper).
-    export NIX_GCC_NEEDS_GREP=1
   '';
 
   prehookCygwin = ''
diff --git a/pkgs/stdenv/nix/default.nix b/pkgs/stdenv/nix/default.nix
index c7dd659195b..476e0eae397 100644
--- a/pkgs/stdenv/nix/default.nix
+++ b/pkgs/stdenv/nix/default.nix
@@ -7,17 +7,6 @@ import ../generic rec {
     ''
       export NIX_ENFORCE_PURITY=1
       export NIX_IGNORE_LD_THROUGH_GCC=1
-    '' + lib.optionalString stdenv.isDarwin ''
-      export NIX_ENFORCE_PURITY=
-      export NIX_DONT_SET_RPATH=1
-      export NIX_NO_SELF_RPATH=1
-      dontFixLibtool=1
-      stripAllFlags=" " # the Darwin "strip" command doesn't know "-s"
-      xargsFlags=" "
-      export MACOSX_DEPLOYMENT_TARGET=10.6
-      export SDKROOT=$(/usr/bin/xcrun --show-sdk-path 2> /dev/null || true)
-      export NIX_CFLAGS_COMPILE+=" --sysroot=/var/empty -idirafter $SDKROOT/usr/include -F$SDKROOT/System/Library/Frameworks -Wno-multichar -Wno-deprecated-declarations"
-      export NIX_LDFLAGS_AFTER+=" -L$SDKROOT/usr/lib"
     '';
 
   initialPath = (import ../common-path.nix) {pkgs = pkgs;};
@@ -29,11 +18,7 @@ import ../generic rec {
     nativePrefix = stdenv.lib.optionalString stdenv.isSunOS "/usr";
     nativeLibc = true;
     inherit stdenv;
-    binutils =
-      if stdenv.isDarwin then
-        import ../../build-support/native-darwin-cctools-wrapper {inherit stdenv;}
-      else
-        pkgs.binutils;
+    binutils = pkgs.binutils;
     gcc = pkgs.gcc.gcc;
     coreutils = pkgs.coreutils;
     shell = pkgs.bash + "/bin/sh";
diff --git a/pkgs/tools/archivers/sharutils/default.nix b/pkgs/tools/archivers/sharutils/default.nix
index f19564e4ad9..281a148a5ca 100644
--- a/pkgs/tools/archivers/sharutils/default.nix
+++ b/pkgs/tools/archivers/sharutils/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, gettext }:
+{ stdenv, fetchurl, gettext, coreutils }:
 
 stdenv.mkDerivation rec {
   name = "sharutils-4.11.1";
@@ -12,11 +12,11 @@ stdenv.mkDerivation rec {
     ''
        # Fix for building on Glibc 2.16.  Won't be needed once the
        # gnulib in sharutils is updated.
-       sed -i '/gets is a security hole/d' lib/stdio.in.h
+       sed -i ${stdenv.lib.optionalString (stdenv.isBSD && stdenv.gcc.nativeTools) "''"} '/gets is a security hole/d' lib/stdio.in.h
     '';
 
   # GNU Gettext is needed on non-GNU platforms.
-  buildInputs = [ gettext ];
+  buildInputs = [ gettext coreutils ];
 
   doCheck = true;
 
diff --git a/pkgs/tools/compression/bzip2/default.nix b/pkgs/tools/compression/bzip2/default.nix
index 55fca6ca3cb..256f574c2e0 100644
--- a/pkgs/tools/compression/bzip2/default.nix
+++ b/pkgs/tools/compression/bzip2/default.nix
@@ -26,6 +26,8 @@ stdenv.mkDerivation {
   sharedLibrary =
     !stdenv.isDarwin && !(stdenv ? isDietLibC) && !(stdenv ? isStatic) && stdenv.system != "i686-cygwin" && !linkStatic;
 
+  patchPhase = stdenv.lib.optionalString stdenv.isDarwin "substituteInPlace Makefile --replace 'CC=gcc' 'CC=clang'";
+
   preConfigure = "substituteInPlace Makefile --replace '$(PREFIX)/man' '$(PREFIX)/share/man'";
 
   makeFlags = if linkStatic then "LDFLAGS=-static" else "";
diff --git a/pkgs/tools/misc/getopt/default.nix b/pkgs/tools/misc/getopt/default.nix
index d181388f6c7..ed4cde69eda 100644
--- a/pkgs/tools/misc/getopt/default.nix
+++ b/pkgs/tools/misc/getopt/default.nix
@@ -7,4 +7,7 @@ stdenv.mkDerivation {
     url = http://tarballs.nixos.org/getopt-1.1.4.tar.gz;
     sha256 = "1arvjfzw6p310zbgv629w5hkyslrj44imf3r3s2r4ry2jfcks221";
   };
+  preBuild = ''
+    export buildFlags=CC="$CC" # for darwin
+  '';
 }
diff --git a/pkgs/tools/networking/isync/default.nix b/pkgs/tools/networking/isync/default.nix
index 2d3ffb2cb0a..021f470af24 100644
--- a/pkgs/tools/networking/isync/default.nix
+++ b/pkgs/tools/networking/isync/default.nix
@@ -16,6 +16,6 @@ stdenv.mkDerivation rec {
     license = [ "GPLv2+" ];
 
     maintainers = with stdenv.lib.maintainers; [ the-kenny viric ];
-    platforms = stdenv.lib.platforms.linux;
+    platforms = stdenv.lib.platforms.unix;
   };
 }
diff --git a/pkgs/tools/networking/strongswan/default.nix b/pkgs/tools/networking/strongswan/default.nix
index 391fd883364..16997ac8e3d 100644
--- a/pkgs/tools/networking/strongswan/default.nix
+++ b/pkgs/tools/networking/strongswan/default.nix
@@ -19,6 +19,6 @@ stdenv.mkDerivation rec {
     description = "OpenSource IPsec-based VPN Solution";
     homepage = https://www.strongswan.org;
     license = stdenv.lib.licenses.gpl2Plus;
-    inherit (stdenv.gcc.clang.meta) platforms;
+    inherit (stdenv.gcc.gcc.meta) platforms;
   };
 }
diff --git a/pkgs/tools/package-management/nix/default.nix b/pkgs/tools/package-management/nix/default.nix
index 6631214f39a..55f5b0aedc9 100644
--- a/pkgs/tools/package-management/nix/default.nix
+++ b/pkgs/tools/package-management/nix/default.nix
@@ -66,6 +66,9 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = true;
 
   meta = {
+    # due to builder args bug; see
+    # https://github.com/NixOS/nix/commit/b224ac15201c57b40ea855f5a98b1bd166c1c7f6
+    broken = stdenv.isDarwin;
     description = "Powerful package manager that makes package management reliable and reproducible";
     longDescription = ''
       Nix is a powerful package manager for Linux and other Unix systems that
diff --git a/pkgs/tools/package-management/nix/unstable.nix b/pkgs/tools/package-management/nix/unstable.nix
index 23ecf9ac6e0..e3126fd40a3 100644
--- a/pkgs/tools/package-management/nix/unstable.nix
+++ b/pkgs/tools/package-management/nix/unstable.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchurl, perl, curl, bzip2, sqlite, openssl ? null
-, pkgconfig, boehmgc, perlPackages
+, pkgconfig, boehmgc, perlPackages, bash
 , storeDir ? "/nix/store"
 , stateDir ? "/nix/var"
 }:
@@ -24,6 +24,7 @@ stdenv.mkDerivation rec {
   postUnpack =
     '' export CPATH="${bzip2}/include"
        export LIBRARY_PATH="${bzip2}/lib"
+       export CXXFLAGS="-O3 -Wno-error=reserved-user-defined-literal"
     '';
 
   configureFlags =
@@ -34,7 +35,7 @@ stdenv.mkDerivation rec {
       --with-www-curl=${perlPackages.WWWCurl}/${perl.libPrefix}
       --disable-init-state
       --enable-gc
-      CFLAGS=-O3 CXXFLAGS=-O3
+      CFLAGS=-O3
     '';
 
   makeFlags = "profiledir=$(out)/etc/profile.d";
diff --git a/pkgs/tools/security/gnupg/clang.patch b/pkgs/tools/security/gnupg/clang.patch
new file mode 100644
index 00000000000..842785e5c93
--- /dev/null
+++ b/pkgs/tools/security/gnupg/clang.patch
@@ -0,0 +1,13 @@
+diff --git a/gl/stdint_.h b/gl/stdint_.h
+index bc27595..303e81a 100644
+--- a/gl/stdint_.h
++++ b/gl/stdint_.h
+@@ -62,7 +62,7 @@
+      int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
+      <inttypes.h> also defines intptr_t and uintptr_t.  */
+ # define _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
+-# include <inttypes.h>
++// # include <inttypes.h>
+ # undef _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
+ #elif @HAVE_SYS_INTTYPES_H@
+   /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
diff --git a/pkgs/tools/security/gnupg/default.nix b/pkgs/tools/security/gnupg/default.nix
index 45a25d7e242..58a7cb7e34c 100644
--- a/pkgs/tools/security/gnupg/default.nix
+++ b/pkgs/tools/security/gnupg/default.nix
@@ -20,6 +20,7 @@ stdenv.mkDerivation rec {
 
   patchPhase = ''
     find tests -type f | xargs sed -e 's@/bin/pwd@${coreutils}&@g' -i
+    patch gl/stdint_.h < ${./clang.patch}
   '';
 
   configureFlags =
diff --git a/pkgs/tools/system/tree/default.nix b/pkgs/tools/system/tree/default.nix
index e108589aaef..eca8882643d 100644
--- a/pkgs/tools/system/tree/default.nix
+++ b/pkgs/tools/system/tree/default.nix
@@ -37,6 +37,7 @@ stdenv.mkDerivation {
       prefix=$out
       MANDIR=$out/share/man/man1
       ${systemFlags}
+      CC="$CC"
     )
   '';
 
diff --git a/pkgs/tools/text/sgml/opensp/default.nix b/pkgs/tools/text/sgml/opensp/default.nix
index 23ce8ccc5a8..4b807718baa 100644
--- a/pkgs/tools/text/sgml/opensp/default.nix
+++ b/pkgs/tools/text/sgml/opensp/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl, xmlto, docbook_xml_dtd_412, libxslt, docbook_xsl}:
+{ lib, stdenv, fetchurl, xmlto, docbook_xml_dtd_412, libxslt, docbook_xsl }:
 
 stdenv.mkDerivation {
   name = "opensp-1.5.2";
@@ -13,6 +13,10 @@ stdenv.mkDerivation {
       docsrc/*.xml
   '';
 
+  configureFlags = lib.optional stdenv.isDarwin [
+    "--with-libintl-prefix=/usr"
+    "--with-libiconv-prefix=/usr"
+  ];
 
   setupHook = ./setup-hook.sh;
 
@@ -22,7 +26,6 @@ stdenv.mkDerivation {
     sed -i -e 's/name="idm.*"//g' $out/share/doc/OpenSP/releasenotes.html
     '';
 
-
   buildInputs = [ xmlto docbook_xml_dtd_412 libxslt docbook_xsl ];
 
   meta = {
diff --git a/pkgs/tools/typesetting/tex/tetex/clang.patch b/pkgs/tools/typesetting/tex/tetex/clang.patch
new file mode 100644
index 00000000000..50d83f62443
--- /dev/null
+++ b/pkgs/tools/typesetting/tex/tetex/clang.patch
@@ -0,0 +1,13 @@
+diff --git a/texk/ps2pkm/type1.c b/texk/ps2pkm/type1.c
+index 027bf1f..4dcbad0 100644
+--- a/texk/ps2pkm/type1.c
++++ b/texk/ps2pkm/type1.c
+@@ -800,7 +800,7 @@ static void PSFakePush(Num)
+ static DOUBLE PSFakePop ()
+ {
+   if (PSFakeTop >= 0) return(PSFakeStack[PSFakeTop--]);
+-  else Error0("PSFakePop : Stack empty\n");
++  else { CC; IfTrace0(TRUE, "PSFakePop : Stack empty\n"); errflag = TRUE; return 0; }
+   /*NOTREACHED*/
+ }
+  
diff --git a/pkgs/tools/typesetting/tex/tetex/default.nix b/pkgs/tools/typesetting/tex/tetex/default.nix
index 5cd3228aced..173571eda23 100644
--- a/pkgs/tools/typesetting/tex/tetex/default.nix
+++ b/pkgs/tools/typesetting/tex/tetex/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation {
     sed -i 57d texk/kpathsea/c-std.h
   '';
 
-  patches = [ ./environment.patch ./getline.patch ];
+  patches = [ ./environment.patch ./getline.patch ./clang.patch ];
 
   setupHook = ./setup-hook.sh;
 
diff --git a/pkgs/tools/typesetting/tex/tex4ht/default.nix b/pkgs/tools/typesetting/tex/tex4ht/default.nix
index 69d02a275b3..93d33439084 100644
--- a/pkgs/tools/typesetting/tex/tex4ht/default.nix
+++ b/pkgs/tools/typesetting/tex/tex4ht/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
     cd src
     for f in tex4ht t4ht htcmd ; do
       # -DENVFILE="$out/share/texmf-nix/tex4ht/base/unix/tex4ht.env"
-      gcc -o $f $f.c -I${tetex}/include -L${tetex}/lib  -DHAVE_DIRENT_H -DHAVE_DIRENT_H -DKPATHSEA -lkpathsea
+      $CC -o $f $f.c -I${tetex}/include -L${tetex}/lib  -DHAVE_DIRENT_H -DHAVE_DIRENT_H -DKPATHSEA -lkpathsea
     done
     cd -
   '';
diff --git a/pkgs/tools/typesetting/tex/texlive/default.nix b/pkgs/tools/typesetting/tex/texlive/default.nix
index dc821fe6660..7179c353861 100644
--- a/pkgs/tools/typesetting/tex/texlive/default.nix
+++ b/pkgs/tools/typesetting/tex/texlive/default.nix
@@ -22,7 +22,6 @@ rec {
   setupHook = ./setup-hook.sh;
 
   doMainBuild = fullDepEntry ( stdenv.lib.optionalString stdenv.isDarwin ''
-    export MACOSX_DEPLOYMENT_TARGET=10.9
     export DYLD_LIBRARY_PATH="${poppler}/lib"
   '' + ''
     mkdir -p $out
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 7b35f1e93a8..79fac68a56a 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -231,8 +231,6 @@ let
       else
         defaultStdenv;
 
-  stdenvApple = stdenvAdapters.overrideGCC allStdenvs.stdenvNative gccApple;
-
   forceNativeDrv = drv : if crossSystem == null then drv else
     (drv // { crossDrv = drv.nativeDrv; });
 
@@ -1923,7 +1921,11 @@ let
 
   openssh_with_kerberos = pkgs.appendToName "with-kerberos" (openssh.override { withKerberos = true; });
 
-  opensp = callPackage ../tools/text/sgml/opensp { };
+  opensp = callPackage ../tools/text/sgml/opensp {
+    stdenv = if stdenv.isDarwin
+      then allStdenvs.stdenvDarwinNaked
+      else stdenv;
+  };
 
   spCompat = callPackage ../tools/text/sgml/opensp/compat.nix { };
 
@@ -2853,10 +2855,10 @@ let
 
   ccl = builderDefsPackage ../development/compilers/ccl {};
 
-  clang = wrapClang llvmPackages.clang;
+  clang = wrapGCC llvmPackages.clang;
 
-  clang_34 = wrapClang llvmPackages_34.clang;
-  clang_33 = wrapClang (clangUnwrapped llvm_33 ../development/compilers/llvm/3.3/clang.nix);
+  clang_34 = wrapGCC llvmPackages_34.clang;
+  clang_33 = wrapGCC (clangUnwrapped llvm_33 ../development/compilers/llvm/3.3/clang.nix);
 
   clangAnalyzer = callPackage ../development/tools/analysis/clang-analyzer {
     clang = clang_34;
@@ -2864,25 +2866,24 @@ let
   };
 
   clangUnwrapped = llvm: pkg: callPackage pkg {
-    stdenv = if stdenv.isDarwin then stdenvApple else stdenv;
-    inherit llvm;
+    inherit stdenv llvm;
   };
 
   clangSelf = clangWrapSelf llvmPackagesSelf.clang;
 
-  clangWrapSelf = build: (import ../build-support/clang-wrapper) {
-    clang = build;
+  clangWrapSelf = build: (import ../build-support/gcc-wrapper) {
+    gcc = build;
     stdenv = clangStdenv;
     libc = glibc;
     binutils = binutils;
-    shell = bash;
-    inherit libcxx coreutils zlib;
+    inherit coreutils zlib;
+    extraPackages = [ libcxx ];
     nativeTools = false;
     nativeLibc = false;
   };
 
   #Use this instead of stdenv to build with clang
-  clangStdenv = lowPrio (stdenvAdapters.overrideGCC stdenv clang);
+  clangStdenv = if stdenv.isDarwin then stdenv else lowPrio (stdenvAdapters.overrideGCC stdenv clang);
   libcxxStdenv = stdenvAdapters.overrideGCC stdenv (clangWrapSelf llvmPackages.clang);
 
   clean = callPackage ../development/compilers/clean { };
@@ -2919,6 +2920,8 @@ let
   gcc       = gcc48;
   gcc_multi = gcc48_multi;
 
+  gccApple = throw "gccApple is no longer supported";
+
   gcc33 = wrapGCC (import ../development/compilers/gcc/3.3 {
     inherit fetchurl stdenv noSysDirs;
   });
@@ -3089,16 +3092,6 @@ let
       else null;
   }));
 
-  gccApple =
-    assert stdenv.isDarwin;
-    wrapGCC (makeOverridable (import ../development/compilers/gcc/4.2-apple64) {
-      inherit fetchurl noSysDirs;
-      profiledCompiler = true;
-      # Since it fails to build with GCC 4.6, build it with the "native"
-      # Apple-GCC.
-      stdenv = allStdenvs.stdenvNative;
-    });
-
   gfortran = gfortran48;
 
   gfortran48 = wrapGCC (gcc48.gcc.override {
@@ -3419,15 +3412,9 @@ let
   llvm_34 = llvmPackages_34.llvm;
   llvm_33 = llvm_v ../development/compilers/llvm/3.3/llvm.nix;
 
-  llvm_v = path: callPackage path {
-    stdenv = if stdenv.isDarwin then stdenvApple else stdenv;
-  };
+  llvm_v = path: callPackage path { };
 
-  llvmPackages = if !stdenv.isDarwin then llvmPackages_34 else llvmPackages_34 // {
-    # until someone solves build problems with _34
-    llvm = llvm_33;
-    clang = clang_33;
-  };
+  llvmPackages = llvmPackages_34;
 
   llvmPackages_34 = recurseIntoAttrs (import ../development/compilers/llvm/3.4 {
     inherit stdenv newScope fetchurl;
@@ -3810,28 +3797,14 @@ let
   win32hello = callPackage ../development/compilers/visual-c++/test { };
 
   wrapGCCWith = gccWrapper: glibc: baseGCC: gccWrapper {
-    nativeTools = stdenv ? gcc && stdenv.gcc.nativeTools;
-    nativeLibc = stdenv ? gcc && stdenv.gcc.nativeLibc;
-    nativePrefix = if stdenv ? gcc then stdenv.gcc.nativePrefix else "";
-    gcc = baseGCC;
-    libc = glibc;
-    shell = bash;
-    inherit stdenv binutils coreutils zlib;
-  };
-
-  wrapClangWith = clangWrapper: glibc: baseClang: clangWrapper {
     nativeTools = stdenv.gcc.nativeTools or false;
     nativeLibc = stdenv.gcc.nativeLibc or false;
     nativePrefix = stdenv.gcc.nativePrefix or "";
-    clang = baseClang;
+    gcc = baseGCC;
     libc = glibc;
-    shell = bash;
-    binutils = stdenv.gcc.binutils;
-    inherit stdenv coreutils zlib;
+    inherit stdenv binutils coreutils zlib;
   };
 
-  wrapClang = wrapClangWith (makeOverridable (import ../build-support/clang-wrapper)) glibc;
-
   wrapGCC = wrapGCCWith (makeOverridable (import ../build-support/gcc-wrapper)) glibc;
 
   wrapGCCCross =
@@ -4260,7 +4233,7 @@ let
   bam = callPackage ../development/tools/build-managers/bam {};
 
   binutils = if stdenv.isDarwin
-    then stdenv.gcc.binutils
+    then import ../build-support/native-darwin-cctools-wrapper {inherit stdenv;}
     else callPackage ../development/tools/misc/binutils {
       inherit noSysDirs;
     };
@@ -4405,10 +4378,12 @@ let
      wrapGCC (distcc.links extraConfig)) {};
   distccStdenv = lowPrio (overrideGCC stdenv distccWrapper);
 
-  distccMasquerade = callPackage ../development/tools/misc/distcc/masq.nix {
-    gccRaw = gcc.gcc;
-    binutils = binutils;
-  };
+  distccMasquerade = if stdenv.isDarwin
+    then null
+    else callPackage ../development/tools/misc/distcc/masq.nix {
+      gccRaw = gcc.gcc;
+      binutils = binutils;
+    };
 
   docutils = builderDefsPackage (import ../development/tools/documentation/docutils) {
     inherit python pil makeWrapper;
@@ -4909,7 +4884,7 @@ let
 
   coredumper = callPackage ../development/libraries/coredumper { };
 
-  ctl = callPackage ../development/libraries/ctl { };
+  ctl = dropCxx (callPackage ../development/libraries/ctl { });
 
   cpp-netlib = callPackage ../development/libraries/cpp-netlib { };
 
@@ -5440,7 +5415,7 @@ let
 
   ilixi = callPackage ../development/libraries/ilixi { };
 
-  ilmbase = callPackage ../development/libraries/ilmbase { };
+  ilmbase = dropCxx (callPackage ../development/libraries/ilmbase { });
 
   imlib = callPackage ../development/libraries/imlib {
     libpng = libpng12;
@@ -5622,7 +5597,7 @@ let
 
   libdc1394avt = callPackage ../development/libraries/libdc1394avt { };
 
-  libdevil = callPackage ../development/libraries/libdevil { };
+  libdevil = dropCxx (callPackage ../development/libraries/libdevil { });
 
   libdiscid = callPackage ../development/libraries/libdiscid { };
 
@@ -6388,7 +6363,7 @@ let
   # this ctl version is needed by openexr_viewers
   openexr_ctl = callPackage ../development/libraries/openexr_ctl { };
 
-  openexr = callPackage ../development/libraries/openexr { };
+  openexr = dropCxx (callPackage ../development/libraries/openexr { });
 
   openldap = callPackage ../development/libraries/openldap {
     stdenv = if stdenv.isDarwin
diff --git a/pkgs/top-level/haskell-defaults.nix b/pkgs/top-level/haskell-defaults.nix
index 6ee3e4d9e0a..fdb9ac42910 100644
--- a/pkgs/top-level/haskell-defaults.nix
+++ b/pkgs/top-level/haskell-defaults.nix
@@ -214,6 +214,8 @@
     gmp = pkgs.gmp4;
   });
 
+  ghc783Binary = lowPrio (callPackage ../development/compilers/ghc/7.8.3-binary.nix {});
+
   ghc6101BinaryDarwin = if stdenv.isDarwin then ghc704Binary else ghc6101Binary;
   ghc6121BinaryDarwin = if stdenv.isDarwin then ghc704Binary else ghc6121Binary;
 
@@ -234,7 +236,7 @@
 
   packages_ghc783 =
     packages { ghcPath = ../development/compilers/ghc/7.8.3.nix;
-               ghcBinary = ghc742Binary;
+               ghcBinary = if stdenv.isDarwin then ghc783Binary else ghc742Binary;
                prefFun = ghc783Prefs;
              };