summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--nixos/doc/manual/default.nix2
-rw-r--r--nixos/lib/make-iso9660-image.sh4
-rw-r--r--nixos/lib/make-system-tarball.sh4
-rw-r--r--nixos/modules/services/amqp/activemq/default.nix2
-rw-r--r--nixos/modules/services/desktops/gnome3/at-spi2-core.nix7
-rw-r--r--nixos/modules/services/hardware/acpid.nix2
-rw-r--r--nixos/modules/services/monitoring/nagios.nix2
-rw-r--r--nixos/modules/services/monitoring/systemhealth.nix2
-rw-r--r--nixos/modules/services/network-filesystems/openafs-client/default.nix2
-rw-r--r--nixos/modules/services/networking/ircd-hybrid/builder.sh4
-rw-r--r--nixos/modules/services/system/dbus.nix2
-rw-r--r--nixos/modules/services/web-servers/apache-httpd/default.nix4
-rw-r--r--nixos/modules/services/web-servers/apache-httpd/mediawiki.nix4
-rw-r--r--nixos/modules/services/web-servers/apache-httpd/mercurial.nix2
-rw-r--r--nixos/modules/services/x11/display-managers/lightdm.nix2
-rw-r--r--nixos/modules/services/x11/display-managers/slim.nix2
-rw-r--r--nixos/modules/system/boot/stage-1.nix2
-rw-r--r--nixos/modules/tasks/tty-backgrounds-combine.sh2
-rw-r--r--nixos/modules/virtualisation/qemu-vm.nix2
-rw-r--r--pkgs/applications/audio/flac/default.nix2
-rw-r--r--pkgs/applications/audio/mixxx/default.nix2
-rw-r--r--pkgs/applications/audio/praat/default.nix2
-rw-r--r--pkgs/applications/editors/atom/default.nix4
-rw-r--r--pkgs/applications/editors/dhex/default.nix6
-rw-r--r--pkgs/applications/editors/emacs-modes/calfw/default.nix4
-rw-r--r--pkgs/applications/editors/emacs-modes/ocaml/default.nix2
-rw-r--r--pkgs/applications/editors/emacs-modes/tuareg/default.nix2
-rw-r--r--pkgs/applications/editors/vim/macvim.nix2
-rw-r--r--pkgs/applications/graphics/alchemy/default.nix2
-rw-r--r--pkgs/applications/misc/camlistore/default.nix2
-rw-r--r--pkgs/applications/misc/keepass/default.nix4
-rw-r--r--pkgs/applications/misc/librecad/2.0.nix2
-rw-r--r--pkgs/applications/misc/librecad/default.nix2
-rw-r--r--pkgs/applications/misc/synergy/default.nix2
-rw-r--r--pkgs/applications/misc/vanitygen/default.nix2
-rw-r--r--pkgs/applications/networking/bittorrentsync/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/chromium/browser.nix2
-rw-r--r--pkgs/applications/networking/browsers/chromium/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/chromium/plugins.nix6
-rw-r--r--pkgs/applications/networking/browsers/chromium/source/default.nix2
-rw-r--r--pkgs/applications/networking/dropbox-cli/default.nix2
-rw-r--r--pkgs/applications/networking/dropbox/default.nix6
-rw-r--r--pkgs/applications/networking/instant-messengers/pidgin-plugins/skype4pidgin/default.nix2
-rw-r--r--pkgs/applications/networking/irc/irssi/fish/default.nix2
-rw-r--r--pkgs/applications/networking/p2p/freenet/default.nix2
-rw-r--r--pkgs/applications/networking/syncthing/default.nix2
-rw-r--r--pkgs/applications/office/zotero/default.nix4
-rw-r--r--pkgs/applications/science/logic/twelf/default.nix8
-rw-r--r--pkgs/applications/science/math/gap/default.nix2
-rw-r--r--pkgs/applications/version-management/git-and-tools/git-bz/default.nix4
-rw-r--r--pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix2
-rw-r--r--pkgs/applications/video/makemkv/builder.sh6
-rw-r--r--pkgs/applications/video/omxplayer/default.nix2
-rw-r--r--pkgs/build-support/cabal/default.nix6
-rw-r--r--pkgs/build-support/clang-wrapper/add-flags2
-rw-r--r--pkgs/build-support/clang-wrapper/clang-wrapper.sh6
-rw-r--r--pkgs/build-support/clang-wrapper/default.nix4
-rw-r--r--pkgs/build-support/clang-wrapper/ld-wrapper.sh164
-rw-r--r--pkgs/build-support/clang-wrapper/utils.sh24
-rw-r--r--pkgs/build-support/gcc-wrapper/gcc-wrapper.sh1
-rw-r--r--pkgs/build-support/gcc-wrapper/ld-wrapper.sh9
-rw-r--r--pkgs/build-support/kdewrapper/default.nix2
-rw-r--r--pkgs/build-support/make-startupitem/default.nix2
-rw-r--r--pkgs/build-support/release/functions.sh2
-rw-r--r--pkgs/build-support/vm/windows/bootstrap.nix2
-rw-r--r--pkgs/build-support/vm/windows/install/default.nix4
-rw-r--r--pkgs/data/misc/tzdata/default.nix2
-rw-r--r--pkgs/desktops/e18/enlightenment.nix1
-rw-r--r--pkgs/desktops/gnome-3/3.10/core/at-spi2-atk/default.nix21
-rw-r--r--pkgs/desktops/gnome-3/3.10/core/caribou/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.10/core/gnome-shell/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.10/default.nix4
-rw-r--r--pkgs/desktops/gnome-3/3.12/core/at-spi2-core/default.nix32
-rw-r--r--pkgs/desktops/gnome-3/3.12/core/caribou/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.12/core/gnome-shell/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.12/default.nix4
-rw-r--r--pkgs/development/compilers/gcc/4.2-apple64/default.nix2
-rw-r--r--pkgs/development/compilers/gcc/4.8/builder.sh27
-rw-r--r--pkgs/development/compilers/gcc/4.8/default.nix30
-rw-r--r--pkgs/development/compilers/gcc/4.8/no-sys-dirs.patch41
-rw-r--r--pkgs/development/compilers/ghdl/default.nix6
-rw-r--r--pkgs/development/compilers/go/1.3.nix2
-rw-r--r--pkgs/development/compilers/go/gox.nix2
-rw-r--r--pkgs/development/compilers/gwt/2.4.0.nix2
-rw-r--r--pkgs/development/compilers/mercury/default.nix2
-rw-r--r--pkgs/development/compilers/ocaml/3.11.2.nix2
-rw-r--r--pkgs/development/compilers/openjdk-darwin/default.nix14
-rw-r--r--pkgs/development/compilers/pakcs/default.nix8
-rw-r--r--pkgs/development/compilers/sbcl/bootstrap.nix4
-rw-r--r--pkgs/development/compilers/sbcl/default.nix2
-rw-r--r--pkgs/development/compilers/smlnj/bootstrap.nix4
-rw-r--r--pkgs/development/eclipse/ecj/default.nix2
-rw-r--r--pkgs/development/interpreters/perl/5.16/default.nix24
-rw-r--r--pkgs/development/libraries/aacskeys/default.nix2
-rw-r--r--pkgs/development/libraries/apache-activemq/default.nix2
-rw-r--r--pkgs/development/libraries/at-spi2-atk/default.nix (renamed from pkgs/desktops/gnome-3/3.12/core/at-spi2-atk/default.nix)0
-rw-r--r--pkgs/development/libraries/at-spi2-core/default.nix (renamed from pkgs/desktops/gnome-3/3.10/core/at-spi2-core/default.nix)0
-rw-r--r--pkgs/development/libraries/boost/1.55.nix1
-rw-r--r--pkgs/development/libraries/bwidget/default.nix2
-rw-r--r--pkgs/development/libraries/fontconfig/default.nix3
-rw-r--r--pkgs/development/libraries/gdk-pixbuf/setup-hook.sh2
-rw-r--r--pkgs/development/libraries/glib/darwin-compilation.patch24
-rw-r--r--pkgs/development/libraries/glib/default.nix7
-rw-r--r--pkgs/development/libraries/glibc/2.19/common.nix2
-rw-r--r--pkgs/development/libraries/glibc/2.19/cve-2014-0475.patch170
-rw-r--r--pkgs/development/libraries/haskell/ghc-heap-view/default.nix2
-rw-r--r--pkgs/development/libraries/haskell/ghc-mod/default.nix2
-rw-r--r--pkgs/development/libraries/haskell/ghc-vis/default.nix2
-rw-r--r--pkgs/development/libraries/haskell/hoogle/local.nix2
-rw-r--r--pkgs/development/libraries/java/junixsocket/default.nix5
-rw-r--r--pkgs/development/libraries/libav/default.nix2
-rw-r--r--pkgs/development/libraries/libsamplerate/default.nix12
-rw-r--r--pkgs/development/libraries/libsndfile/default.nix9
-rw-r--r--pkgs/development/libraries/mesa/default.nix4
-rw-r--r--pkgs/development/libraries/ncurses/default.nix28
-rw-r--r--pkgs/development/libraries/opencv/default.nix10
-rw-r--r--pkgs/development/libraries/openssl/default.nix6
-rw-r--r--pkgs/development/libraries/readline/no-arch_only-6.3.patch13
-rw-r--r--pkgs/development/libraries/readline/no-arch_only.patch14
-rw-r--r--pkgs/development/libraries/readline/readline6.3.nix4
-rw-r--r--pkgs/development/libraries/readline/readline6.nix4
-rw-r--r--pkgs/development/mobile/androidenv/androidsdk.nix2
-rw-r--r--pkgs/development/mobile/xcodeenv/simulate-app.nix2
-rw-r--r--pkgs/development/mobile/xcodeenv/xcodewrapper.nix2
-rw-r--r--pkgs/development/ocaml-modules/ocamlmake/default.nix2
-rw-r--r--pkgs/development/tools/apktool/default.nix2
-rw-r--r--pkgs/development/tools/etcdctl/default.nix2
-rw-r--r--pkgs/development/tools/gocode/default.nix2
-rw-r--r--pkgs/development/tools/literate-programming/noweb/default.nix2
-rw-r--r--pkgs/development/tools/misc/autoconf/default.nix3
-rw-r--r--pkgs/development/tools/misc/distcc/masq.nix2
-rw-r--r--pkgs/development/tools/misc/grafana/default.nix2
-rw-r--r--pkgs/development/tools/misc/opengrok/default.nix2
-rw-r--r--pkgs/development/tools/node-webkit/default.nix4
-rw-r--r--pkgs/development/tools/ocaml/deriving/default.nix2
-rw-r--r--pkgs/development/tools/packer/default.nix2
-rw-r--r--pkgs/development/tools/yuicompressor/default.nix2
-rw-r--r--pkgs/games/0ad/default.nix6
-rw-r--r--pkgs/games/andyetitmoves/default.nix2
-rw-r--r--pkgs/games/crafty/default.nix6
-rw-r--r--pkgs/games/gsb/default.nix4
-rw-r--r--pkgs/games/minecraft/default.nix4
-rw-r--r--pkgs/games/openlierox/default.nix2
-rw-r--r--pkgs/games/opentyrian/default.nix4
-rw-r--r--pkgs/games/vessel/default.nix4
-rw-r--r--pkgs/games/worldofgoo/default.nix4
-rw-r--r--pkgs/misc/emulators/bsod/default.nix2
-rw-r--r--pkgs/misc/vim-plugins/default.nix4
-rw-r--r--pkgs/os-specific/darwin/xcode/default.nix4
-rw-r--r--pkgs/os-specific/linux/apparmor/default.nix2
-rw-r--r--pkgs/os-specific/linux/bbswitch/default.nix4
-rw-r--r--pkgs/os-specific/linux/frandom/default.nix4
-rw-r--r--pkgs/os-specific/linux/gogoclient/default.nix2
-rw-r--r--pkgs/os-specific/linux/google-authenticator/default.nix2
-rw-r--r--pkgs/os-specific/linux/i7z/default.nix2
-rw-r--r--pkgs/os-specific/linux/iomelt/default.nix4
-rw-r--r--pkgs/os-specific/linux/mcelog/default.nix2
-rw-r--r--pkgs/os-specific/linux/microcode/converter.nix2
-rw-r--r--pkgs/os-specific/linux/netatop/default.nix4
-rw-r--r--pkgs/os-specific/linux/otpw/default.nix2
-rw-r--r--pkgs/os-specific/linux/rfkill/udev.nix4
-rw-r--r--pkgs/os-specific/linux/util-linux/default.nix4
-rw-r--r--pkgs/os-specific/linux/x86info/default.nix2
-rw-r--r--pkgs/servers/dict/dictd-wiktionary.nix2
-rw-r--r--pkgs/servers/dict/dictd-wordnet.nix2
-rw-r--r--pkgs/servers/etcd/default.nix2
-rw-r--r--pkgs/servers/fleet/default.nix2
-rw-r--r--pkgs/servers/http/thttpd/default.nix2
-rw-r--r--pkgs/servers/monitoring/seyren/default.nix2
-rw-r--r--pkgs/servers/nosql/influxdb/default.nix2
-rw-r--r--pkgs/servers/nsq/default.nix2
-rw-r--r--pkgs/servers/serfdom/default.nix4
-rw-r--r--pkgs/shells/bash/bash-4.2-patches.nix2
-rw-r--r--pkgs/stdenv/default.nix34
-rw-r--r--pkgs/stdenv/generic/default.nix3
-rw-r--r--pkgs/stdenv/generic/setup.sh2
-rw-r--r--pkgs/stdenv/linux/make-bootstrap-tools-crosspi.nix2
-rwxr-xr-xpkgs/stdenv/mingw/builder.sh18
-rwxr-xr-xpkgs/stdenv/mingw/cygpath/builder.sh5
-rw-r--r--pkgs/stdenv/mingw/cygpath/default.nix9
-rwxr-xr-xpkgs/stdenv/mingw/default-builder.sh2
-rw-r--r--pkgs/stdenv/mingw/default.nix233
-rwxr-xr-xpkgs/stdenv/mingw/fetchurl/builder.sh34
-rw-r--r--pkgs/stdenv/mingw/fetchurl/default.nix28
-rwxr-xr-xpkgs/stdenv/mingw/fix-builder.sh23
-rw-r--r--pkgs/stdenv/mingw/msys-builder.sh15
-rw-r--r--pkgs/stdenv/mingw/pkgs/bin-builder.sh5
-rwxr-xr-xpkgs/stdenv/mingw/pkgs/curl.exebin240128 -> 0 bytes
-rw-r--r--pkgs/stdenv/mingw/pkgs/default.nix157
-rw-r--r--pkgs/stdenv/mingw/pkgs/pkgconfig-builder.sh8
-rw-r--r--pkgs/stdenv/mingw/pkgs/single-exe-builder.sh12
-rw-r--r--pkgs/stdenv/mingw/pkgs/src-builder.sh7
-rwxr-xr-xpkgs/stdenv/mingw/setup.sh759
-rw-r--r--pkgs/stdenv/mingw/simple-stdenv/builder.sh80
-rw-r--r--pkgs/stdenv/mingw/simple-stdenv/default.nix31
-rw-r--r--pkgs/stdenv/nix/default.nix22
-rw-r--r--pkgs/tools/backup/store-backup/default.nix2
-rw-r--r--pkgs/tools/filesystems/unionfs-fuse/default.nix2
-rw-r--r--pkgs/tools/misc/debootstrap/default.nix6
-rw-r--r--pkgs/tools/misc/logstash/default.nix10
-rw-r--r--pkgs/tools/misc/megacli/default.nix2
-rw-r--r--pkgs/tools/misc/multitail/default.nix2
-rw-r--r--pkgs/tools/misc/picocom/default.nix2
-rw-r--r--pkgs/tools/misc/rkflashtool/default.nix2
-rw-r--r--pkgs/tools/misc/sl/default.nix2
-rw-r--r--pkgs/tools/networking/connect/default.nix2
-rw-r--r--pkgs/tools/networking/filegive/default.nix2
-rw-r--r--pkgs/tools/networking/reaver-wps/default.nix2
-rw-r--r--pkgs/tools/networking/udptunnel/default.nix2
-rw-r--r--pkgs/tools/security/fprot/default.nix12
-rw-r--r--pkgs/tools/security/meo/default.nix2
-rw-r--r--pkgs/tools/security/tor/torbrowser.nix4
-rw-r--r--pkgs/tools/system/storebrowse/default.nix2
-rw-r--r--pkgs/tools/system/vboot_reference/default.nix2
-rw-r--r--pkgs/tools/text/enscript/default.nix7
-rw-r--r--pkgs/tools/text/gawk/default.nix4
-rw-r--r--pkgs/tools/typesetting/djvu2pdf/default.nix4
-rw-r--r--pkgs/tools/typesetting/tex/pgfplots/default.nix2
-rw-r--r--pkgs/top-level/all-packages.nix78
-rw-r--r--pkgs/top-level/mingw.nix27
220 files changed, 611 insertions, 2164 deletions
diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix
index a79a77f40df..e118f8b8943 100644
--- a/nixos/doc/manual/default.nix
+++ b/nixos/doc/manual/default.nix
@@ -67,7 +67,7 @@ in rec {
 
       # Generate the HTML manual.
       dst=$out/share/doc/nixos
-      ensureDir $dst
+      mkdir -p $dst
       xsltproc $xsltFlags --nonet --xinclude \
         --output $dst/manual.html \
         ${pkgs.docbook5_xsl}/xml/xsl/docbook/xhtml/docbook.xsl \
diff --git a/nixos/lib/make-iso9660-image.sh b/nixos/lib/make-iso9660-image.sh
index 89b681ed2cd..675b5bb3514 100644
--- a/nixos/lib/make-iso9660-image.sh
+++ b/nixos/lib/make-iso9660-image.sh
@@ -78,7 +78,7 @@ done
 cat pathlist | sed -e 's/=\(.*\)=\(.*\)=/\\=\1=\2\\=/' | tee pathlist.safer
 
 
-ensureDir $out/iso
+mkdir -p $out/iso
 genCommand="genisoimage -iso-level 4 -r -J $bootFlags -hide-rr-moved -graft-points -path-list pathlist.safer ${volumeID:+-V $volumeID}"
 if test -z "$compressImage"; then
     $genCommand -o $out/iso/$isoName
@@ -87,5 +87,5 @@ else
 fi
 
 
-ensureDir $out/nix-support
+mkdir -p $out/nix-support
 echo $system > $out/nix-support/system
diff --git a/nixos/lib/make-system-tarball.sh b/nixos/lib/make-system-tarball.sh
index aadd0f6428c..096d96ac1c8 100644
--- a/nixos/lib/make-system-tarball.sh
+++ b/nixos/lib/make-system-tarball.sh
@@ -48,11 +48,11 @@ for ((n = 0; n < ${#objects[*]}; n++)); do
     fi
 done
 
-ensureDir $out/tarball
+mkdir -p $out/tarball
 
 tar cvJf $out/tarball/$fileName.tar.xz *
 
-ensureDir $out/nix-support
+mkdir -p $out/nix-support
 echo $system > $out/nix-support/system
 echo "file system-tarball $out/tarball/$fileName.tar.xz" > $out/nix-support/hydra-build-products
 
diff --git a/nixos/modules/services/amqp/activemq/default.nix b/nixos/modules/services/amqp/activemq/default.nix
index f731900070e..261f9761766 100644
--- a/nixos/modules/services/amqp/activemq/default.nix
+++ b/nixos/modules/services/amqp/activemq/default.nix
@@ -12,7 +12,7 @@ let
     phases = [ "installPhase" ];
     buildInputs = [ jdk ];
     installPhase = ''
-      ensureDir $out/lib
+      mkdir -p $out/lib
       source ${activemq}/lib/classpath.env
       export CLASSPATH
       ln -s "${./ActiveMQBroker.java}" ActiveMQBroker.java
diff --git a/nixos/modules/services/desktops/gnome3/at-spi2-core.nix b/nixos/modules/services/desktops/gnome3/at-spi2-core.nix
index 615f272e7b9..6e4c59f4bb3 100644
--- a/nixos/modules/services/desktops/gnome3/at-spi2-core.nix
+++ b/nixos/modules/services/desktops/gnome3/at-spi2-core.nix
@@ -4,9 +4,6 @@
 
 with lib;
 
-let
-  gnome3 = config.environment.gnome3.packageSet;
-in
 {
 
   ###### interface
@@ -33,9 +30,9 @@ in
 
   config = mkIf config.services.gnome3.at-spi2-core.enable {
 
-    environment.systemPackages = [ gnome3.at_spi2_core ];
+    environment.systemPackages = [ pkgs.at_spi2_core ];
 
-    services.dbus.packages = [ gnome3.at_spi2_core ];
+    services.dbus.packages = [ pkgs.at_spi2_core ];
 
   };
 
diff --git a/nixos/modules/services/hardware/acpid.nix b/nixos/modules/services/hardware/acpid.nix
index b87899e4598..a20b1a1ee3a 100644
--- a/nixos/modules/services/hardware/acpid.nix
+++ b/nixos/modules/services/hardware/acpid.nix
@@ -6,7 +6,7 @@ let
 
   acpiConfDir = pkgs.runCommand "acpi-events" {}
     ''
-      ensureDir $out
+      mkdir -p $out
       ${
         # Generate a configuration file for each event. (You can't have
         # multiple events in one config file...)
diff --git a/nixos/modules/services/monitoring/nagios.nix b/nixos/modules/services/monitoring/nagios.nix
index 97d153153a5..c1f7ba0eca7 100644
--- a/nixos/modules/services/monitoring/nagios.nix
+++ b/nixos/modules/services/monitoring/nagios.nix
@@ -12,7 +12,7 @@ let
   nagiosObjectDefs = cfg.objectDefs;
 
   nagiosObjectDefsDir = pkgs.runCommand "nagios-objects" {inherit nagiosObjectDefs;}
-    "ensureDir $out; ln -s $nagiosObjectDefs $out/";
+    "mkdir -p $out; ln -s $nagiosObjectDefs $out/";
 
   nagiosCfgFile = pkgs.writeText "nagios.cfg"
     ''
diff --git a/nixos/modules/services/monitoring/systemhealth.nix b/nixos/modules/services/monitoring/systemhealth.nix
index b0e59595e13..20d1dadd3bf 100644
--- a/nixos/modules/services/monitoring/systemhealth.nix
+++ b/nixos/modules/services/monitoring/systemhealth.nix
@@ -13,7 +13,7 @@ let
     };
     buildInputs = [ python ];
     installPhase = ''
-      ensureDir $out/bin
+      mkdir -p $out/bin
       # Make it work for kernels 3.x, not so different than 2.6
       sed -i 's/2\.6/4.0/' system_health.py
       cp system_health.py $out/bin
diff --git a/nixos/modules/services/network-filesystems/openafs-client/default.nix b/nixos/modules/services/network-filesystems/openafs-client/default.nix
index 23ab39eb05f..0297da9e865 100644
--- a/nixos/modules/services/network-filesystems/openafs-client/default.nix
+++ b/nixos/modules/services/network-filesystems/openafs-client/default.nix
@@ -11,7 +11,7 @@ let
   };
 
   afsConfig = pkgs.runCommand "afsconfig" {} ''
-    ensureDir $out
+    mkdir -p $out
     echo ${cfg.cellName} > $out/ThisCell
     cp ${cellServDB} $out/CellServDB
     echo "/afs:${cfg.cacheDirectory}:${cfg.cacheSize}" > $out/cacheinfo
diff --git a/nixos/modules/services/networking/ircd-hybrid/builder.sh b/nixos/modules/services/networking/ircd-hybrid/builder.sh
index b8cb836db95..f2c92878a4d 100644
--- a/nixos/modules/services/networking/ircd-hybrid/builder.sh
+++ b/nixos/modules/services/networking/ircd-hybrid/builder.sh
@@ -3,7 +3,7 @@ source $stdenv/setup
 doSub() {
     local src=$1
     local dst=$2
-    ensureDir $(dirname $dst)
+    mkdir -p $(dirname $dst)
     substituteAll $src $dst
 }
 
@@ -28,4 +28,4 @@ for i in $substFiles; do
     fi
 done
 
-ensureDir $out/bin
+mkdir -p $out/bin
diff --git a/nixos/modules/services/system/dbus.nix b/nixos/modules/services/system/dbus.nix
index 8d02a6404ac..928f16c9448 100644
--- a/nixos/modules/services/system/dbus.nix
+++ b/nixos/modules/services/system/dbus.nix
@@ -14,7 +14,7 @@ let
     name = "dbus-conf";
     preferLocalBuild = true;
     buildCommand = ''
-      ensureDir $out
+      mkdir -p $out
 
       cp -v ${pkgs.dbus.daemon}/etc/dbus-1/system.conf $out/system.conf
 
diff --git a/nixos/modules/services/web-servers/apache-httpd/default.nix b/nixos/modules/services/web-servers/apache-httpd/default.nix
index eb3cb75b658..78f3cf2b7e4 100644
--- a/nixos/modules/services/web-servers/apache-httpd/default.nix
+++ b/nixos/modules/services/web-servers/apache-httpd/default.nix
@@ -80,7 +80,7 @@ let
 
   # !!! should be in lib
   writeTextInDir = name: text:
-    pkgs.runCommand name {inherit text;} "ensureDir $out; echo -n \"$text\" > $out/$name";
+    pkgs.runCommand name {inherit text;} "mkdir -p $out; echo -n \"$text\" > $out/$name";
 
 
   enableSSL = any (vhost: vhost.enableSSL) allHosts;
@@ -194,7 +194,7 @@ let
     ) null ([ cfg ] ++ subservices);
 
     documentRoot = if maybeDocumentRoot != null then maybeDocumentRoot else
-      pkgs.runCommand "empty" {} "ensureDir $out";
+      pkgs.runCommand "empty" {} "mkdir -p $out";
 
     documentRootConf = ''
       DocumentRoot "${documentRoot}"
diff --git a/nixos/modules/services/web-servers/apache-httpd/mediawiki.nix b/nixos/modules/services/web-servers/apache-httpd/mediawiki.nix
index fa65ec0ef70..aa9aec87f0c 100644
--- a/nixos/modules/services/web-servers/apache-httpd/mediawiki.nix
+++ b/nixos/modules/services/web-servers/apache-httpd/mediawiki.nix
@@ -92,7 +92,7 @@ let
 
     installPhase =
       ''
-        ensureDir $out
+        mkdir -p $out
         cp -r * $out
         cp ${mediawikiConfig} $out/LocalSettings.php
         sed -i \
@@ -106,7 +106,7 @@ let
   mediawikiScripts = pkgs.runCommand "mediawiki-${config.id}-scripts"
     { buildInputs = [ pkgs.makeWrapper ]; }
     ''
-      ensureDir $out/bin
+      mkdir -p $out/bin
       for i in changePassword.php createAndPromote.php userOptions.php edit.php nukePage.php update.php; do
         makeWrapper ${php}/bin/php $out/bin/mediawiki-${config.id}-$(basename $i .php) \
           --add-flags ${mediawikiRoot}/maintenance/$i
diff --git a/nixos/modules/services/web-servers/apache-httpd/mercurial.nix b/nixos/modules/services/web-servers/apache-httpd/mercurial.nix
index 1d4303b75b3..6dd91be00a7 100644
--- a/nixos/modules/services/web-servers/apache-httpd/mercurial.nix
+++ b/nixos/modules/services/web-servers/apache-httpd/mercurial.nix
@@ -9,7 +9,7 @@ let
   cgi = pkgs.stdenv.mkDerivation {
     name = "mercurial-cgi";
     buildCommand = ''
-      ensureDir $out
+      mkdir -p $out
       cp -v ${mercurial}/share/cgi-bin/hgweb.cgi $out
       sed -i "s|/path/to/repo/or/config|$out/hgweb.config|" $out/hgweb.cgi
       echo "
diff --git a/nixos/modules/services/x11/display-managers/lightdm.nix b/nixos/modules/services/x11/display-managers/lightdm.nix
index d459c59b048..f8ce06738fe 100644
--- a/nixos/modules/services/x11/display-managers/lightdm.nix
+++ b/nixos/modules/services/x11/display-managers/lightdm.nix
@@ -26,7 +26,7 @@ let
     buildInputs = [ pkgs.makeWrapper ];
 
     buildCommand = ''
-      ensureDir $out/gtk-3.0/
+      mkdir -p $out/gtk-3.0/
 
       # This wrapper ensures that we actually get fonts
       makeWrapper ${pkgs.lightdm_gtk_greeter}/sbin/lightdm-gtk-greeter \
diff --git a/nixos/modules/services/x11/display-managers/slim.nix b/nixos/modules/services/x11/display-managers/slim.nix
index 48feb12d044..9ee4e0dc7cb 100644
--- a/nixos/modules/services/x11/display-managers/slim.nix
+++ b/nixos/modules/services/x11/display-managers/slim.nix
@@ -27,7 +27,7 @@ let
       unpackedTheme = pkgs.stdenv.mkDerivation {
         name = "slim-theme";
         buildCommand = ''
-          ensureDir $out
+          mkdir -p $out
           cd $out
           unpackFile ${cfg.theme}
           ln -s * default
diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix
index 58ff97671f3..6a069c5d054 100644
--- a/nixos/modules/system/boot/stage-1.nix
+++ b/nixos/modules/system/boot/stage-1.nix
@@ -119,7 +119,7 @@ let
   udevRules = pkgs.stdenv.mkDerivation {
     name = "udev-rules";
     buildCommand = ''
-      ensureDir $out
+      mkdir -p $out
 
       echo 'ENV{LD_LIBRARY_PATH}="${extraUtils}/lib"' > $out/00-env.rules
 
diff --git a/nixos/modules/tasks/tty-backgrounds-combine.sh b/nixos/modules/tasks/tty-backgrounds-combine.sh
index 1e0d8758a6e..55c3a1ebfa8 100644
--- a/nixos/modules/tasks/tty-backgrounds-combine.sh
+++ b/nixos/modules/tasks/tty-backgrounds-combine.sh
@@ -3,7 +3,7 @@ source $stdenv/setup
 ttys=($ttys)
 themes=($themes)
 
-ensureDir $out
+mkdir -p $out
 
 defaultName=$(cd $default && ls | grep -v default)
 echo $defaultName
diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix
index 17acd08f086..58386ce5cf5 100644
--- a/nixos/modules/virtualisation/qemu-vm.nix
+++ b/nixos/modules/virtualisation/qemu-vm.nix
@@ -376,7 +376,7 @@ in
 
     system.build.vm = pkgs.runCommand "nixos-vm" { preferLocalBuild = true; }
       ''
-        ensureDir $out/bin
+        mkdir -p $out/bin
         ln -s ${config.system.build.toplevel} $out/system
         ln -s ${pkgs.writeScript "run-nixos-vm" startVM} $out/bin/run-${vmName}-vm
       '';
diff --git a/pkgs/applications/audio/flac/default.nix b/pkgs/applications/audio/flac/default.nix
index 1c8dc56de61..fe4b43539d4 100644
--- a/pkgs/applications/audio/flac/default.nix
+++ b/pkgs/applications/audio/flac/default.nix
@@ -10,7 +10,7 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ libogg ];
 
-  doCheck = true; # takes lots of time but will be run rarely (small build-time closure)
+  #doCheck = true; # takes lots of time
 
   meta = with stdenv.lib; {
     homepage = http://xiph.org/flac/;
diff --git a/pkgs/applications/audio/mixxx/default.nix b/pkgs/applications/audio/mixxx/default.nix
index b76eecc9e4a..e3422d4ba06 100644
--- a/pkgs/applications/audio/mixxx/default.nix
+++ b/pkgs/applications/audio/mixxx/default.nix
@@ -28,7 +28,7 @@ stdenv.mkDerivation rec {
 
   buildPhase = ''
     runHook preBuild
-    ensureDir "$out"
+    mkdir -p "$out"
     scons \
       -j$NIX_BUILD_CORES -l$NIX_BUILD_CORES \
       $sconsFlags "prefix=$out"
diff --git a/pkgs/applications/audio/praat/default.nix b/pkgs/applications/audio/praat/default.nix
index 4859377ab52..86c68d087b7 100644
--- a/pkgs/applications/audio/praat/default.nix
+++ b/pkgs/applications/audio/praat/default.nix
@@ -13,7 +13,7 @@ stdenv.mkDerivation {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp praat $out/bin
   '';
 
diff --git a/pkgs/applications/editors/atom/default.nix b/pkgs/applications/editors/atom/default.nix
index 725b4520e69..51844f64179 100644
--- a/pkgs/applications/editors/atom/default.nix
+++ b/pkgs/applications/editors/atom/default.nix
@@ -43,8 +43,8 @@ in stdenv.mkDerivation rec {
   phases = [ "installPhase" ];
 
   installPhase = ''
-    ensureDir $out/share/atom
-    ensureDir $out/bin
+    mkdir -p $out/share/atom
+    mkdir -p $out/bin
     tar -C $out/share/atom -xvf $src
     patchelf --set-interpreter "$(cat $NIX_GCC/nix-support/dynamic-linker)" \
       $out/share/atom/atom
diff --git a/pkgs/applications/editors/dhex/default.nix b/pkgs/applications/editors/dhex/default.nix
index 45b7de900e2..7a0e9e59d7e 100644
--- a/pkgs/applications/editors/dhex/default.nix
+++ b/pkgs/applications/editors/dhex/default.nix
@@ -12,9 +12,9 @@ stdenv.mkDerivation rec {
   buildInputs = [ ncurses ];
  
   installPhase = ''
-    ensureDir $out/bin
-    ensureDir $out/share/man/man1
-    ensureDir $out/share/man/man5
+    mkdir -p $out/bin
+    mkdir -p $out/share/man/man1
+    mkdir -p $out/share/man/man5
 
     cp dhex $out/bin
     cp dhex.1 $out/share/man/man1
diff --git a/pkgs/applications/editors/emacs-modes/calfw/default.nix b/pkgs/applications/editors/emacs-modes/calfw/default.nix
index 83c9ddebe81..c173684fab4 100644
--- a/pkgs/applications/editors/emacs-modes/calfw/default.nix
+++ b/pkgs/applications/editors/emacs-modes/calfw/default.nix
@@ -16,10 +16,10 @@ stdenv.mkDerivation rec {
 
   installPhase =
     ''
-       ensureDir "$out/share/doc/${name}"
+       mkdir -p "$out/share/doc/${name}"
        cp -v readme.md "$out/share/doc/${name}"
 
-       ensureDir "$out/share/emacs/site-lisp/"
+       mkdir -p "$out/share/emacs/site-lisp/"
        cp *.el "$out/share/emacs/site-lisp/"
     '';
 
diff --git a/pkgs/applications/editors/emacs-modes/ocaml/default.nix b/pkgs/applications/editors/emacs-modes/ocaml/default.nix
index 1d81a0b7ff1..9e4496ff1a4 100644
--- a/pkgs/applications/editors/emacs-modes/ocaml/default.nix
+++ b/pkgs/applications/editors/emacs-modes/ocaml/default.nix
@@ -18,7 +18,7 @@ in stdenv.mkDerivation {
 
   installPhase = ''
     cd emacs;
-    ensureDir "$out/share/emacs/site-lisp" "$out/bin"
+    mkdir -p "$out/share/emacs/site-lisp" "$out/bin"
     EMACSDIR=$out/share/emacs/site-lisp make simple-install install-ocamltags
   '';
 
diff --git a/pkgs/applications/editors/emacs-modes/tuareg/default.nix b/pkgs/applications/editors/emacs-modes/tuareg/default.nix
index 17957ffc276..3fd592f3dba 100644
--- a/pkgs/applications/editors/emacs-modes/tuareg/default.nix
+++ b/pkgs/applications/editors/emacs-modes/tuareg/default.nix
@@ -15,7 +15,7 @@ in stdenv.mkDerivation {
   buildInputs = [ emacs ];
 
   installPhase = ''
-    ensureDir "$out/share/emacs/site-lisp"
+    mkdir -p "$out/share/emacs/site-lisp"
     cp *.el *.elc  "$out/share/emacs/site-lisp"
   '';
 
diff --git a/pkgs/applications/editors/vim/macvim.nix b/pkgs/applications/editors/vim/macvim.nix
index 2390a390854..feafa7b9977 100644
--- a/pkgs/applications/editors/vim/macvim.nix
+++ b/pkgs/applications/editors/vim/macvim.nix
@@ -62,7 +62,7 @@ in mkDerivation rec {
   '';
 
   postInstall = ''
-    ensureDir $out/Applications
+    mkdir -p $out/Applications
     cp -r src/MacVim/build/Release/MacVim.app $out/Applications
 
     rm $out/bin/{Vimdiff,Vimtutor,Vim,ex,rVim,rview,view}
diff --git a/pkgs/applications/graphics/alchemy/default.nix b/pkgs/applications/graphics/alchemy/default.nix
index ee8543f7039..263c411a8db 100644
--- a/pkgs/applications/graphics/alchemy/default.nix
+++ b/pkgs/applications/graphics/alchemy/default.nix
@@ -10,7 +10,7 @@ stdenv.mkDerivation {
   };
 
   installPhase = ''
-    ensureDir $out/bin $out/share
+    mkdir -p $out/bin $out/share
     cp -a . $out/share/alchemy
     cat >> $out/bin/alchemy << EOF
     #!/bin/sh
diff --git a/pkgs/applications/misc/camlistore/default.nix b/pkgs/applications/misc/camlistore/default.nix
index 80d8dd801a9..56131425ab4 100644
--- a/pkgs/applications/misc/camlistore/default.nix
+++ b/pkgs/applications/misc/camlistore/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp bin/* $out/bin
   '';
 
diff --git a/pkgs/applications/misc/keepass/default.nix b/pkgs/applications/misc/keepass/default.nix
index 0098e626b42..89f794850d2 100644
--- a/pkgs/applications/misc/keepass/default.nix
+++ b/pkgs/applications/misc/keepass/default.nix
@@ -24,12 +24,12 @@ stdenv.mkDerivation rec {
 
 
   installPhase = ''
-    ensureDir "$out/bin"
+    mkdir -p "$out/bin"
     echo "${mono}/bin/mono $out/KeePass.exe" > $out/bin/keepass
     chmod +x $out/bin/keepass
     echo $out
     cp -r ./* $out/
-    ensureDir "$out/share/applications"
+    mkdir -p "$out/share/applications"
     cp ${desktopItem}/share/applications/* $out/share/applications
   '';
 
diff --git a/pkgs/applications/misc/librecad/2.0.nix b/pkgs/applications/misc/librecad/2.0.nix
index 59d25a98040..8b7a9a40c87 100644
--- a/pkgs/applications/misc/librecad/2.0.nix
+++ b/pkgs/applications/misc/librecad/2.0.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation {
   '';
 
   installPhase = ''
-    ensureDir $out/bin $out/share
+    mkdir -p $out/bin $out/share
     cp -R unix/librecad $out/bin
     cp -R unix/resources $out/share/librecad
   '';
diff --git a/pkgs/applications/misc/librecad/default.nix b/pkgs/applications/misc/librecad/default.nix
index be3fa4128b6..b2960e9f47d 100644
--- a/pkgs/applications/misc/librecad/default.nix
+++ b/pkgs/applications/misc/librecad/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation {
   configurePhase = "qmake PREFIX=$out";
 
   installPhase = ''
-    ensureDir $out/bin $out/share
+    mkdir -p $out/bin $out/share
     cp -R unix/librecad $out/bin
     cp -R unix/resources $out/share/librecad
   '';
diff --git a/pkgs/applications/misc/synergy/default.nix b/pkgs/applications/misc/synergy/default.nix
index 4e0efc5f3e5..8d914c26221 100644
--- a/pkgs/applications/misc/synergy/default.nix
+++ b/pkgs/applications/misc/synergy/default.nix
@@ -32,7 +32,7 @@ stdenv.mkDerivation rec {
   # http://synergy-foss.org/spit/issues/details/3317/
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp ../bin/synergyc $out/bin
     cp ../bin/synergys $out/bin
     cp ../bin/synergyd $out/bin
diff --git a/pkgs/applications/misc/vanitygen/default.nix b/pkgs/applications/misc/vanitygen/default.nix
index 720240d0d79..6be2dc394cc 100644
--- a/pkgs/applications/misc/vanitygen/default.nix
+++ b/pkgs/applications/misc/vanitygen/default.nix
@@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ openssl pcre ];
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp vanitygen $out/bin
     cp keyconv $out/bin/vanitygen-keyconv
   '';
diff --git a/pkgs/applications/networking/bittorrentsync/default.nix b/pkgs/applications/networking/bittorrentsync/default.nix
index abb94a32bd7..989ceb235b0 100644
--- a/pkgs/applications/networking/bittorrentsync/default.nix
+++ b/pkgs/applications/networking/bittorrentsync/default.nix
@@ -25,7 +25,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ patchelf ];
 
   installPhase = ''
-    ensureDir "$out/bin/"
+    mkdir -p "$out/bin/"
     cp -r "btsync" "$out/bin/"
 
     patchelf --interpreter "$(cat $NIX_GCC/nix-support/dynamic-linker)" \
diff --git a/pkgs/applications/networking/browsers/chromium/browser.nix b/pkgs/applications/networking/browsers/chromium/browser.nix
index d425c3f0738..ffc23a9d968 100644
--- a/pkgs/applications/networking/browsers/chromium/browser.nix
+++ b/pkgs/applications/networking/browsers/chromium/browser.nix
@@ -8,7 +8,7 @@ mkChromiumDerivation (base: rec {
   buildTargets = [ "mksnapshot" "chrome" ];
 
   installPhase = ''
-    ensureDir "$libExecPath"
+    mkdir -p "$libExecPath"
     cp -v "$buildPath/"*.pak "$libExecPath/"
     cp -v "$buildPath/icudtl.dat" "$libExecPath/"
     cp -vLR "$buildPath/locales" "$buildPath/resources" "$libExecPath/"
diff --git a/pkgs/applications/networking/browsers/chromium/default.nix b/pkgs/applications/networking/browsers/chromium/default.nix
index 44fd3c69e53..4dfdca882bc 100644
--- a/pkgs/applications/networking/browsers/chromium/default.nix
+++ b/pkgs/applications/networking/browsers/chromium/default.nix
@@ -67,7 +67,7 @@ in stdenv.mkDerivation {
     browserBinary = "${chromium.browser}/libexec/chromium/chromium";
     sandboxBinary = "${chromium.sandbox}/bin/chromium-sandbox";
   in ''
-    ensureDir "$out/bin" "$out/share/applications"
+    mkdir -p "$out/bin" "$out/share/applications"
 
     ln -s "${chromium.browser}/share" "$out/share"
     makeWrapper "${browserBinary}" "$out/bin/chromium" \
diff --git a/pkgs/applications/networking/browsers/chromium/plugins.nix b/pkgs/applications/networking/browsers/chromium/plugins.nix
index f760b06fe24..e0c45f91075 100644
--- a/pkgs/applications/networking/browsers/chromium/plugins.nix
+++ b/pkgs/applications/networking/browsers/chromium/plugins.nix
@@ -22,7 +22,7 @@ let
         else if source.channel == "stable" then "chrome"
         else "chrome-${source.channel}";
     in ''
-      ensureDir plugins
+      mkdir -p plugins
       ar p "$src" data.tar.lzma | tar xJ -C plugins --strip-components=4 \
         ./opt/google/${chan}/PepperFlash \
         ./opt/google/${chan}/libpdf.so
@@ -53,7 +53,7 @@ let
       pdfInfo = "#${pdfName}#${pdfDescription};${pdfMimeTypes}";
     in ''
       install -vD libpdf.so "$pdf/lib/libpdf.so"
-      ensureDir "$pdf/nix-support"
+      mkdir -p "$pdf/nix-support"
       echo "--register-pepper-plugins='$pdf/lib/libpdf.so${pdfInfo}'" \
         > "$pdf/nix-support/chromium-flags"
 
@@ -63,7 +63,7 @@ let
 
       install -vD PepperFlash/libpepflashplayer.so \
         "$flash/lib/libpepflashplayer.so"
-      ensureDir "$flash/nix-support"
+      mkdir -p "$flash/nix-support"
       echo "--ppapi-flash-path='$flash/lib/libpepflashplayer.so'" \
            "--ppapi-flash-version=$flashVersion" \
            > "$flash/nix-support/chromium-flags"
diff --git a/pkgs/applications/networking/browsers/chromium/source/default.nix b/pkgs/applications/networking/browsers/chromium/source/default.nix
index c075cc36f16..d7ccc412fa4 100644
--- a/pkgs/applications/networking/browsers/chromium/source/default.nix
+++ b/pkgs/applications/networking/browsers/chromium/source/default.nix
@@ -41,7 +41,7 @@ stdenv.mkDerivation {
 
   outputs = [ "out" "sandbox" "bundled" "main" ];
   installPhase = ''
-    ensureDir "$out" "$sandbox" "$bundled" "$main"
+    mkdir -p "$out" "$sandbox" "$bundled" "$main"
 
     header "copying browser main sources to $main"
     find . -mindepth 1 -maxdepth 1 \
diff --git a/pkgs/applications/networking/dropbox-cli/default.nix b/pkgs/applications/networking/dropbox-cli/default.nix
index 5262c121bb2..51f3ae2ac8d 100644
--- a/pkgs/applications/networking/dropbox-cli/default.nix
+++ b/pkgs/applications/networking/dropbox-cli/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation {
   phases = "unpackPhase installPhase";
 
   installPhase = ''
-    ensureDir "$out/bin/" "$out/share/applications"
+    mkdir -p "$out/bin/" "$out/share/applications"
     cp data/dropbox.desktop "$out/share/applications"
     substitute "dropbox.in" "$out/bin/dropbox" \
       --replace '@PACKAGE_VERSION@' ${version} \
diff --git a/pkgs/applications/networking/dropbox/default.nix b/pkgs/applications/networking/dropbox/default.nix
index 62dce4c4212..55b7bd7486b 100644
--- a/pkgs/applications/networking/dropbox/default.nix
+++ b/pkgs/applications/networking/dropbox/default.nix
@@ -70,9 +70,9 @@ in stdenv.mkDerivation {
   '';
 
   installPhase = ''
-    ensureDir "$out/${appdir}"
+    mkdir -p "$out/${appdir}"
     cp -r ".dropbox-dist/"* "$out/${appdir}/"
-    ensureDir "$out/bin"
+    mkdir -p "$out/bin"
     ln -s "$out/${appdir}/dropbox" "$out/bin/dropbox"
 
     patchelf --set-interpreter ${stdenv.glibc}/lib/${interpreter} \
@@ -83,7 +83,7 @@ in stdenv.mkDerivation {
     find "$out/${appdir}" -type f -a -perm +0100 \
       -print -exec patchelf --force-rpath --set-rpath "$RPATH" {} \;
 
-    ensureDir "$out/share/applications"
+    mkdir -p "$out/share/applications"
     cp "${desktopItem}/share/applications/"* $out/share/applications
   '';
 
diff --git a/pkgs/applications/networking/instant-messengers/pidgin-plugins/skype4pidgin/default.nix b/pkgs/applications/networking/instant-messengers/pidgin-plugins/skype4pidgin/default.nix
index 6402e7154de..a83589bf75e 100644
--- a/pkgs/applications/networking/instant-messengers/pidgin-plugins/skype4pidgin/default.nix
+++ b/pkgs/applications/networking/instant-messengers/pidgin-plugins/skype4pidgin/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
   buildPhase  = "make libskype.so libskype_dbus.so";
 
   installPhase = ''
-    ensureDir $out/pixmaps/pidgin/protocols/{16,22,48} $out/bin $out/lib/pidgin
+    mkdir -p $out/pixmaps/pidgin/protocols/{16,22,48} $out/bin $out/lib/pidgin
     cp icons/16/skypeout.png $out/pixmaps/pidgin/protocols/16
     cp icons/22/skypeout.png $out/pixmaps/pidgin/protocols/22
     cp icons/48/skypeout.png $out/pixmaps/pidgin/protocols/48
diff --git a/pkgs/applications/networking/irc/irssi/fish/default.nix b/pkgs/applications/networking/irc/irssi/fish/default.nix
index eb21f34838e..64e3d216ac0 100644
--- a/pkgs/applications/networking/irc/irssi/fish/default.nix
+++ b/pkgs/applications/networking/irc/irssi/fish/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/lib/irssi/modules
+    mkdir -p $out/lib/irssi/modules
     cp src/.libs/libfish.so $out/lib/irssi/modules
   '';
   
diff --git a/pkgs/applications/networking/p2p/freenet/default.nix b/pkgs/applications/networking/p2p/freenet/default.nix
index 013694d259c..4e705711677 100644
--- a/pkgs/applications/networking/p2p/freenet/default.nix
+++ b/pkgs/applications/networking/p2p/freenet/default.nix
@@ -34,7 +34,7 @@ stdenv.mkDerivation {
   buildPhase = "ant package-only";
 
   installPhase = ''
-    ensureDir $out/share/freenet $out/bin
+    mkdir -p $out/share/freenet $out/bin
     cp lib/bcprov.jar $out/share/freenet
     cp lib/freenet/freenet-ext.jar $out/share/freenet
     cp dist/freenet.jar $out/share/freenet
diff --git a/pkgs/applications/networking/syncthing/default.nix b/pkgs/applications/networking/syncthing/default.nix
index 8f169180dd5..226b7f6d097 100644
--- a/pkgs/applications/networking/syncthing/default.nix
+++ b/pkgs/applications/networking/syncthing/default.nix
@@ -31,7 +31,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp -r ./bin $out
   '';
 
diff --git a/pkgs/applications/office/zotero/default.nix b/pkgs/applications/office/zotero/default.nix
index f0f7d801d8f..b6636cef641 100644
--- a/pkgs/applications/office/zotero/default.nix
+++ b/pkgs/applications/office/zotero/default.nix
@@ -23,10 +23,10 @@ stdenv.mkDerivation {
 
   inherit bash xulrunner;
   installPhase = ''
-    ensureDir "$out/libexec/zotero"
+    mkdir -p "$out/libexec/zotero"
     cp -vR * "$out/libexec/zotero/"
 
-    ensureDir "$out/bin"
+    mkdir -p "$out/bin"
     substituteAll "${./zotero.sh}" "$out/bin/zotero"
     chmod +x "$out/bin/zotero"
   '';
diff --git a/pkgs/applications/science/logic/twelf/default.nix b/pkgs/applications/science/logic/twelf/default.nix
index 1079c378321..c6c7e4d9c1a 100644
--- a/pkgs/applications/science/logic/twelf/default.nix
+++ b/pkgs/applications/science/logic/twelf/default.nix
@@ -17,15 +17,15 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     rsync -av bin/* $out/bin/
 
-    ensureDir $out/share/emacs/site-lisp/twelf/
+    mkdir -p $out/share/emacs/site-lisp/twelf/
     rsync -av emacs/ $out/share/emacs/site-lisp/twelf/
 
-    ensureDir $out/share/twelf/examples
+    mkdir -p $out/share/twelf/examples
     rsync -av examples/ $out/share/twelf/examples/
-    ensureDir $out/share/twelf/vim
+    mkdir -p $out/share/twelf/vim
     rsync -av vim/ $out/share/twelf/vim/
   '';
 
diff --git a/pkgs/applications/science/math/gap/default.nix b/pkgs/applications/science/math/gap/default.nix
index 74fff2390a3..0700251c3a8 100644
--- a/pkgs/applications/science/math/gap/default.nix
+++ b/pkgs/applications/science/math/gap/default.nix
@@ -38,7 +38,7 @@ rec {
   phaseNames = ["doConfigure" "doMake" "doDeploy"];
 
   doDeploy = a.fullDepEntry ''
-    ensureDir "$out/bin" "$out/share/gap/"
+    mkdir -p "$out/bin" "$out/share/gap/"
 
     cp -r . "$out/share/gap/build-dir"
 
diff --git a/pkgs/applications/version-management/git-and-tools/git-bz/default.nix b/pkgs/applications/version-management/git-and-tools/git-bz/default.nix
index 3a2270cf972..4c4ff62901e 100644
--- a/pkgs/applications/version-management/git-and-tools/git-bz/default.nix
+++ b/pkgs/applications/version-management/git-and-tools/git-bz/default.nix
@@ -21,8 +21,8 @@ stdenv.mkDerivation {
   '';
 
   installPhase = ''
-    ensureDir $out
-    ensureDir $out/bin
+    mkdir -p $out
+    mkdir -p $out/bin
     cp git-bz $out/bin
     wrapProgram $out/bin/git-bz \
       --prefix PYTHONPATH : "$(toPythonPath $python):$(toPythonPath $pysqlite)"
diff --git a/pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix b/pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix
index c44f2dbcbb6..94c819e711b 100644
--- a/pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix
+++ b/pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp svn-all-fast-export $out/bin
   '';
 
diff --git a/pkgs/applications/video/makemkv/builder.sh b/pkgs/applications/video/makemkv/builder.sh
index 0e1898a4556..e4cfcf3d906 100644
--- a/pkgs/applications/video/makemkv/builder.sh
+++ b/pkgs/applications/video/makemkv/builder.sh
@@ -30,9 +30,9 @@ for i in ${bin} ; do
     ${i}
 done 
 
-ensureDir $out/bin
-ensureDir $out/lib
-ensureDir $out/share/MakeMKV
+mkdir -p $out/bin
+mkdir -p $out/lib
+mkdir -p $out/share/MakeMKV
 cp ${lib} ${out}/lib
 cp ${bin} ${out}/bin
 cp makemkv-bin-${ver}/src/share/* $out/share/MakeMKV
diff --git a/pkgs/applications/video/omxplayer/default.nix b/pkgs/applications/video/omxplayer/default.nix
index 811fb7a78db..3add2646ad9 100644
--- a/pkgs/applications/video/omxplayer/default.nix
+++ b/pkgs/applications/video/omxplayer/default.nix
@@ -71,7 +71,7 @@ stdenv.mkDerivation rec {
     export INCLUDES="-I${raspberrypifw}/include/interface/vcos/pthreads -I${raspberrypifw}/include/interface/vmcs_host/linux/"
   '';
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp omxplayer.bin $out/bin
   '';
   buildInputs = [ raspberrypifw ffmpeg pcre boostHeaders freetype zlib ];
diff --git a/pkgs/build-support/cabal/default.nix b/pkgs/build-support/cabal/default.nix
index 6c806c4bf1f..69423004d65 100644
--- a/pkgs/build-support/cabal/default.nix
+++ b/pkgs/build-support/cabal/default.nix
@@ -248,12 +248,12 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
 
               ./Setup copy
 
-              ensureDir $out/bin # necessary to get it added to PATH
+              mkdir -p $out/bin # necessary to get it added to PATH
 
               local confDir=$out/lib/ghc-${ghc.ghc.version}/package.conf.d
               local installedPkgConf=$confDir/${self.fname}.installedconf
               local pkgConf=$confDir/${self.fname}.conf
-              ensureDir $confDir
+              mkdir -p $confDir
               ./Setup register --gen-pkg-config=$pkgConf
               if test -f $pkgConf; then
                 echo '[]' > $installedPkgConf
@@ -265,7 +265,7 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
               fi
 
               ${optionalString (self.enableSharedExecutables && self.isExecutable && self.stdenv.isDarwin) ''
-                for exe in $out/bin/* ; do
+                for exe in "$out/bin/"* ; do
                   install_name_tool -add_rpath \
                     $out/lib/${ghc.ghc.name}/${self.pname}-${self.version} $exe
                 done
diff --git a/pkgs/build-support/clang-wrapper/add-flags b/pkgs/build-support/clang-wrapper/add-flags
index 3b064547153..7a9711290aa 100644
--- a/pkgs/build-support/clang-wrapper/add-flags
+++ b/pkgs/build-support/clang-wrapper/add-flags
@@ -21,4 +21,4 @@ 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_CLANG_WRAPPER_FLAGS_SET=1
+export NIX_GCC_WRAPPER_FLAGS_SET=1
diff --git a/pkgs/build-support/clang-wrapper/clang-wrapper.sh b/pkgs/build-support/clang-wrapper/clang-wrapper.sh
index b39aa2d721e..57715274f1e 100644
--- a/pkgs/build-support/clang-wrapper/clang-wrapper.sh
+++ b/pkgs/build-support/clang-wrapper/clang-wrapper.sh
@@ -1,10 +1,10 @@
 #! @shell@ -e
 
-if test -n "$NIX_CLANG_WRAPPER_START_HOOK"; then
-    source "$NIX_CLANG_WRAPPER_START_HOOK"
+if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then
+    source "$NIX_GCC_WRAPPER_START_HOOK"
 fi
 
-if test -z "$NIX_CLANG_WRAPPER_FLAGS_SET"; then
+if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
     source @out@/nix-support/add-flags.sh
 fi
 
diff --git a/pkgs/build-support/clang-wrapper/default.nix b/pkgs/build-support/clang-wrapper/default.nix
index 4b2a5a1182e..7a5d87127d9 100644
--- a/pkgs/build-support/clang-wrapper/default.nix
+++ b/pkgs/build-support/clang-wrapper/default.nix
@@ -29,8 +29,8 @@ stdenv.mkDerivation {
   builder = ./builder.sh;
   setupHook = ./setup-hook.sh;
   clangWrapper = ./clang-wrapper.sh;
-  ldWrapper = ./ld-wrapper.sh;
-  utils = ./utils.sh;
+  ldWrapper = ../gcc-wrapper/ld-wrapper.sh;
+  utils = ../gcc-wrapper/utils.sh;
   addFlags = ./add-flags;
 
   inherit nativeTools nativeLibc nativePrefix clang clangVersion libcxx;
diff --git a/pkgs/build-support/clang-wrapper/ld-wrapper.sh b/pkgs/build-support/clang-wrapper/ld-wrapper.sh
deleted file mode 100644
index ae45c62d460..00000000000
--- a/pkgs/build-support/clang-wrapper/ld-wrapper.sh
+++ /dev/null
@@ -1,164 +0,0 @@
-#! @shell@ -e
-
-if test -n "$NIX_LD_WRAPPER_START_HOOK"; then
-    source "$NIX_LD_WRAPPER_START_HOOK"
-fi
-
-if test -z "$NIX_CLANG_WRAPPER_FLAGS_SET"; then
-    source @out@/nix-support/add-flags.sh
-fi
-
-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_CLANG" -o -z "$NIX_LDFLAGS_SET" \); 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" = "-rpath" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        elif test "$p" = "-dynamic-linker" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        elif test "${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
-            # Our ld is not built with sysroot support (Can we fix that?)
-            :
-        else
-            rest=("${rest[@]}" "$p")
-        fi
-        n=$((n + 1))
-    done
-    params=("${rest[@]}")
-fi
-
-
-extra=()
-extraBefore=()
-
-if test -z "$NIX_LDFLAGS_SET"; then
-    extra=(${extra[@]} $NIX_LDFLAGS)
-    extraBefore=(${extraBefore[@]} $NIX_LDFLAGS_BEFORE)
-fi
-
-
-# Add all used dynamic libraries to the rpath.
-if test "$NIX_DONT_SET_RPATH" != "1"; then
-
-    libPath=""
-    addToLibPath() {
-        local path="$1"
-        if test "${path:0:1}" != "/"; then return 0; fi
-        case "$path" in
-            *..*|*./*|*/.*|*//*)
-                local path2
-                if path2=$(readlink -f "$path"); then
-                    path="$path2"
-                fi
-                ;;
-        esac
-        case $libPath in
-            *\ $path\ *) return 0 ;;
-        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
-        case $rpath in
-            *\ $1\ *) return 0 ;;
-        esac
-        rpath="$rpath $1 "
-    }
-
-    libs=""
-    addToLibs() {
-        libs="$libs $1"
-    }
-
-    rpath=""
-
-    # First, find all -L... switches.
-    allParams=("${params[@]}" ${extra[@]})
-    n=0
-    while test $n -lt ${#allParams[*]}; do
-        p=${allParams[n]}
-        p2=${allParams[$((n+1))]}
-        if test "${p:0:3}" = "-L/"; then
-            addToLibPath ${p:2}
-        elif test "$p" = "-L"; then
-            addToLibPath ${p2}
-            n=$((n + 1))
-        elif test "$p" = "-l"; then
-            addToLibs ${p2}
-            n=$((n + 1))
-        elif test "${p:0:2}" = "-l"; then
-            addToLibs ${p:2}
-        elif test "$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))
-        elif [[ "$p" =~ ^[^-].*\.so($|\.) ]]; then
-            # This is a direct reference to a shared library, so add
-            # its directory to the rpath.
-            path="$(dirname "$p")";
-            addToRPath "${path}"
-        fi
-        n=$((n + 1))
-    done
-
-    # Second, for each directory in the library search path (-L...),
-    # see if it contains a dynamic library used by a -l... flag.  If
-    # 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
-                addToRPath $i
-                break
-            fi
-        done
-    done
-    
-
-    # Finally, add `-rpath' switches.
-    for i in $rpath; do
-        extra=(${extra[@]} -rpath $i)
-    done
-fi
-
-
-# Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @ld@:" >&2
-  for i in "${params[@]}"; do
-      echo "  $i" >&2
-  done
-  echo "extra flags to @ld@:" >&2
-  for i in ${extra[@]}; do
-      echo "  $i" >&2
-  done
-fi
-
-if test -n "$NIX_LD_WRAPPER_EXEC_HOOK"; then
-    source "$NIX_LD_WRAPPER_EXEC_HOOK"
-fi
-
-exec @ld@ ${extraBefore[@]} "${params[@]}" ${extra[@]}
diff --git a/pkgs/build-support/clang-wrapper/utils.sh b/pkgs/build-support/clang-wrapper/utils.sh
deleted file mode 100644
index 753b3772e95..00000000000
--- a/pkgs/build-support/clang-wrapper/utils.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-skip () {
-    if test "$NIX_DEBUG" = "1"; then
-        echo "skipping impure path $1" >&2
-    fi
-}
-
-
-# Checks whether a path is impure.  E.g., `/lib/foo.so' is impure, but
-# `/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
-    
-    # Otherwise, the path should refer to the store or some temporary
-    # directory (including the build directory).
-    test \
-        "$p" != "/dev/null" -a \
-        "${p:0:${#NIX_STORE}}" != "$NIX_STORE" -a \
-        "${p:0:4}" != "/tmp" -a \
-        "${p:0:${#NIX_BUILD_TOP}}" != "$NIX_BUILD_TOP"
-}
diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
index 2ad7783a442..c53fd44207d 100644
--- a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
@@ -77,6 +77,7 @@ if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
         n=$((n + 1))
     done
     params=("${rest[@]}")
+    NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE --sysroot=/var/empty"
 fi
 
 
diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
index 74b6273848e..822c4a03a21 100644
--- a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
@@ -32,6 +32,9 @@ if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE" \
             # We cannot skip this; barf.
             echo "impure path \`$p' used in link" >&2
             exit 1
+        elif test "${p:0:9}" = "--sysroot"; then
+            # Our ld is not built with sysroot support (Can we fix that?)
+            :
         else
             rest=("${rest[@]}" "$p")
         fi
@@ -45,10 +48,12 @@ extra=()
 extraBefore=()
 
 if test -z "$NIX_LDFLAGS_SET"; then
-    extra=(${extra[@]} $NIX_LDFLAGS)
-    extraBefore=(${extraBefore[@]} $NIX_LDFLAGS_BEFORE)
+    extra+=($NIX_LDFLAGS)
+    extraBefore+=($NIX_LDFLAGS_BEFORE)
 fi
 
+extra+=($NIX_LDFLAGS_AFTER)
+
 
 # Add all used dynamic libraries to the rpath.
 if test "$NIX_DONT_SET_RPATH" != "1"; then
diff --git a/pkgs/build-support/kdewrapper/default.nix b/pkgs/build-support/kdewrapper/default.nix
index 6dcf68a324a..64dfd7d0ca6 100644
--- a/pkgs/build-support/kdewrapper/default.nix
+++ b/pkgs/build-support/kdewrapper/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation {
   inherit libs;
 
   buildCommand = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
 
     KDEDIRS=${program}
     QT_PLUGIN_PATH=${program}/lib/qt4/plugins:${program}/lib/kde4/plugins
diff --git a/pkgs/build-support/make-startupitem/default.nix b/pkgs/build-support/make-startupitem/default.nix
index dc78b8a704e..fad6f00d821 100644
--- a/pkgs/build-support/make-startupitem/default.nix
+++ b/pkgs/build-support/make-startupitem/default.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation {
   priority = 5;
 
   buildCommand = ''
-    ensureDir $out/share/autostart
+    mkdir -p $out/share/autostart
     target=${name}.desktop
     cp ${package}/share/applications/${srcPrefix}${name}.desktop $target
     chmod +rw $target
diff --git a/pkgs/build-support/release/functions.sh b/pkgs/build-support/release/functions.sh
index 9f2d03519c8..8ac67a19672 100644
--- a/pkgs/build-support/release/functions.sh
+++ b/pkgs/build-support/release/functions.sh
@@ -9,6 +9,6 @@ findTarballs() {
 }
 
 propagateImageName() {
-    ensureDir $out/nix-support
+    mkdir -p $out/nix-support
     cat "$diskImage"/nix-support/full-name > $out/nix-support/full-name
 }
diff --git a/pkgs/build-support/vm/windows/bootstrap.nix b/pkgs/build-support/vm/windows/bootstrap.nix
index e3b44d1b6ab..ebea819b191 100644
--- a/pkgs/build-support/vm/windows/bootstrap.nix
+++ b/pkgs/build-support/vm/windows/bootstrap.nix
@@ -69,7 +69,7 @@ in rec {
         -b "${installedVM}/disk.img" \
         -f qcow2 winvm.img
       ${runAndSuspend}
-      ensureDir "$out"
+      mkdir -p "$out"
       cp winvm.img "$out/disk.img"
       cp state.gz "$out/state.gz"
     '';
diff --git a/pkgs/build-support/vm/windows/install/default.nix b/pkgs/build-support/vm/windows/install/default.nix
index 10690bf6b28..fe8e8f61de0 100644
--- a/pkgs/build-support/vm/windows/install/default.nix
+++ b/pkgs/build-support/vm/windows/install/default.nix
@@ -22,7 +22,7 @@ let
   cygwinSshKey = stdenv.mkDerivation {
     name = "snakeoil-ssh-cygwin";
     buildCommand = ''
-      ensureDir "$out"
+      mkdir -p "$out"
       ${openssh}/bin/ssh-keygen -t ecdsa -f "$out/key" -N ""
     '';
   };
@@ -65,7 +65,7 @@ in stdenv.mkDerivation {
   buildCommand = ''
     ${qemu}/bin/qemu-img create -f qcow2 winvm.img 2G
     ${installController}
-    ensureDir "$out"
+    mkdir -p "$out"
     cp winvm.img "$out/disk.img"
   '';
   passthru = {
diff --git a/pkgs/data/misc/tzdata/default.nix b/pkgs/data/misc/tzdata/default.nix
index 332c9de1837..90111cb52e1 100644
--- a/pkgs/data/misc/tzdata/default.nix
+++ b/pkgs/data/misc/tzdata/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
       ln -s . $out/share/zoneinfo/posix
       mv $out/share/zoneinfo-leaps $out/share/zoneinfo/right
 
-      ensureDir "$lib/include"
+      mkdir -p "$lib/include"
       cp tzfile.h "$lib/include/tzfile.h"
     '';
 
diff --git a/pkgs/desktops/e18/enlightenment.nix b/pkgs/desktops/e18/enlightenment.nix
index 52a5dd8f89f..c3cd585e525 100644
--- a/pkgs/desktops/e18/enlightenment.nix
+++ b/pkgs/desktops/e18/enlightenment.nix
@@ -1,4 +1,5 @@
 { stdenv, fetchurl, pkgconfig, e18, xlibs, libffi, pam, alsaLib, luajit, bzip2, set_freqset_setuid ? false }:
+
 stdenv.mkDerivation rec {
   name = "enlightenment-${version}";
   version = "0.18.8";
diff --git a/pkgs/desktops/gnome-3/3.10/core/at-spi2-atk/default.nix b/pkgs/desktops/gnome-3/3.10/core/at-spi2-atk/default.nix
deleted file mode 100644
index fc0c4f2a6bc..00000000000
--- a/pkgs/desktops/gnome-3/3.10/core/at-spi2-atk/default.nix
+++ /dev/null
@@ -1,21 +0,0 @@
-{ stdenv, fetchurl, python, pkgconfig, popt, atk, libX11, libICE, xlibs, libXi
-, intltool, dbus_glib, at_spi2_core, libSM }:
-
-stdenv.mkDerivation rec {
-  versionMajor = "2.12";
-  versionMinor = "0";
-  moduleName   = "at-spi2-atk";
-  name = "${moduleName}-${versionMajor}.${versionMinor}";
-
-  src = fetchurl {
-    url = "mirror://gnome/sources/${moduleName}/${versionMajor}/${name}.tar.xz";
-    sha256 = "0crn3k6qvn6fjvgm68dj5ska1ppfgmdkaia2db1jp0b9y74nfm1v";
-  };
-
-  buildInputs = [ python pkgconfig popt atk libX11 libICE xlibs.libXtst libXi
-                  intltool dbus_glib at_spi2_core libSM ];
-
-  meta = with stdenv.lib; {
-    platforms = platforms.linux;
-  };
-}
diff --git a/pkgs/desktops/gnome-3/3.10/core/caribou/default.nix b/pkgs/desktops/gnome-3/3.10/core/caribou/default.nix
index 41a997c1f71..ba5dc7e7b90 100644
--- a/pkgs/desktops/gnome-3/3.10/core/caribou/default.nix
+++ b/pkgs/desktops/gnome-3/3.10/core/caribou/default.nix
@@ -1,5 +1,5 @@
 { fetchurl, stdenv, pkgconfig, gnome3, clutter, dbus, pythonPackages, libxml2
-, libxklavier, libXtst, gtk2, intltool, libxslt }:
+, libxklavier, libXtst, gtk2, intltool, libxslt, at_spi2_core }:
 
 
 stdenv.mkDerivation rec {
diff --git a/pkgs/desktops/gnome-3/3.10/core/gnome-shell/default.nix b/pkgs/desktops/gnome-3/3.10/core/gnome-shell/default.nix
index d468e06d429..2b5ff4cc5a2 100644
--- a/pkgs/desktops/gnome-3/3.10/core/gnome-shell/default.nix
+++ b/pkgs/desktops/gnome-3/3.10/core/gnome-shell/default.nix
@@ -1,5 +1,5 @@
 { fetchurl, stdenv, pkgconfig, gnome3, json_glib, libcroco, intltool, libsecret
-, python, libsoup, polkit, clutter, networkmanager, docbook_xsl, docbook_xsl_ns
+, python, libsoup, polkit, clutter, networkmanager, docbook_xsl, docbook_xsl_ns, at_spi2_core
 , libstartup_notification, telepathy_glib, telepathy_logger, libXtst, p11_kit, unzip
 , pulseaudio, libical, libtool, nss, gobjectIntrospection, gstreamer, makeWrapper
 , accountsservice, gdk_pixbuf, gdm, upower, ibus, networkmanagerapplet, librsvg }:
diff --git a/pkgs/desktops/gnome-3/3.10/default.nix b/pkgs/desktops/gnome-3/3.10/default.nix
index 4376493c95b..89e16490df9 100644
--- a/pkgs/desktops/gnome-3/3.10/default.nix
+++ b/pkgs/desktops/gnome-3/3.10/default.nix
@@ -10,10 +10,6 @@ rec {
 
 #### Core (http://ftp.acc.umu.se/pub/GNOME/core/)
 
-  at_spi2_atk = callPackage ./core/at-spi2-atk { };
-
-  at_spi2_core = callPackage ./core/at-spi2-core { };
-
   baobab = callPackage ./core/baobab { };
 
   caribou = callPackage ./core/caribou { };
diff --git a/pkgs/desktops/gnome-3/3.12/core/at-spi2-core/default.nix b/pkgs/desktops/gnome-3/3.12/core/at-spi2-core/default.nix
deleted file mode 100644
index d60a0ff7480..00000000000
--- a/pkgs/desktops/gnome-3/3.12/core/at-spi2-core/default.nix
+++ /dev/null
@@ -1,32 +0,0 @@
-{ stdenv, fetchurl, python, pkgconfig, popt, intltool, dbus_glib
-, libX11, xextproto, libSM, libICE, libXtst, libXi, gobjectIntrospection }:
-
-stdenv.mkDerivation (rec {
-  versionMajor = "2.12";
-  versionMinor = "0";
-  moduleName   = "at-spi2-core";
-  name = "${moduleName}-${versionMajor}.${versionMinor}";
-
-  src = fetchurl {
-    url = "mirror://gnome/sources/${moduleName}/${versionMajor}/${name}.tar.xz";
-    sha256 = "12gvsgdaxnxskndlhlmdkc50cfqgmzfc4n8la9944fz5k3fhwmfv";
-  };
-
-  buildInputs = [
-    python pkgconfig popt  intltool dbus_glib
-    libX11 xextproto libSM libICE libXtst libXi
-    gobjectIntrospection
-  ];
-
-  # ToDo: on non-NixOS we create a symlink from there?
-  configureFlags = "--with-dbus-daemondir=/run/current-system/sw/bin/";
-
-  meta = with stdenv.lib; {
-    platforms = platforms.linux;
-  };
-}
-  // stdenv.lib.optionalAttrs stdenv.isDarwin {
-    NIX_LDFLAGS = "-lintl";
-  }
-)
-
diff --git a/pkgs/desktops/gnome-3/3.12/core/caribou/default.nix b/pkgs/desktops/gnome-3/3.12/core/caribou/default.nix
index 4d2f390c042..3a6c3f0dd35 100644
--- a/pkgs/desktops/gnome-3/3.12/core/caribou/default.nix
+++ b/pkgs/desktops/gnome-3/3.12/core/caribou/default.nix
@@ -1,5 +1,5 @@
 { fetchurl, stdenv, pkgconfig, gnome3, clutter, dbus, pythonPackages, libxml2
-, libxklavier, libXtst, gtk2, intltool, libxslt }:
+, libxklavier, libXtst, gtk2, intltool, libxslt, at_spi2_core }:
 
 
 stdenv.mkDerivation rec {
diff --git a/pkgs/desktops/gnome-3/3.12/core/gnome-shell/default.nix b/pkgs/desktops/gnome-3/3.12/core/gnome-shell/default.nix
index 9663d131762..002e8e7f7ff 100644
--- a/pkgs/desktops/gnome-3/3.12/core/gnome-shell/default.nix
+++ b/pkgs/desktops/gnome-3/3.12/core/gnome-shell/default.nix
@@ -1,5 +1,5 @@
 { fetchurl, stdenv, pkgconfig, gnome3, json_glib, libcroco, intltool, libsecret
-, python, libsoup, polkit, clutter, networkmanager, docbook_xsl, docbook_xsl_ns
+, python, libsoup, polkit, clutter, networkmanager, docbook_xsl, docbook_xsl_ns, at_spi2_core
 , libstartup_notification, telepathy_glib, telepathy_logger, libXtst, p11_kit, unzip
 , pulseaudio, libical, libtool, nss, gobjectIntrospection, gstreamer, makeWrapper
 , accountsservice, gdk_pixbuf, gdm, upower, ibus, networkmanagerapplet, librsvg }:
diff --git a/pkgs/desktops/gnome-3/3.12/default.nix b/pkgs/desktops/gnome-3/3.12/default.nix
index b1d06d75187..ee1724e1e25 100644
--- a/pkgs/desktops/gnome-3/3.12/default.nix
+++ b/pkgs/desktops/gnome-3/3.12/default.nix
@@ -16,10 +16,6 @@ rec {
 
 #### Core (http://ftp.acc.umu.se/pub/GNOME/core/)
 
-  at_spi2_atk = callPackage ./core/at-spi2-atk { };
-
-  at_spi2_core = callPackage ./core/at-spi2-core { };
-
   baobab = callPackage ./core/baobab { };
 
   caribou = callPackage ./core/caribou { };
diff --git a/pkgs/development/compilers/gcc/4.2-apple64/default.nix b/pkgs/development/compilers/gcc/4.2-apple64/default.nix
index 229f68fd841..f5496cb5ef7 100644
--- a/pkgs/development/compilers/gcc/4.2-apple64/default.nix
+++ b/pkgs/development/compilers/gcc/4.2-apple64/default.nix
@@ -44,4 +44,6 @@ stdenv.mkDerivation rec {
   langC = true;
 
   buildInputs = stdenv.lib.optionals langF77 [ gmp mpfr bison flex ];
+
+  meta.broken = true;
 }
diff --git a/pkgs/development/compilers/gcc/4.8/builder.sh b/pkgs/development/compilers/gcc/4.8/builder.sh
index 7c9b9420dda..3d24d34a2f2 100644
--- a/pkgs/development/compilers/gcc/4.8/builder.sh
+++ b/pkgs/development/compilers/gcc/4.8/builder.sh
@@ -109,13 +109,11 @@ if test "$noSysDirs" = "1"; then
         fi
     fi
 
-
     # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find
     # the startfiles.
     # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx
     # for the startfiles.
-    makeFlagsArray=( \
-        "${makeFlagsArray[@]}" \
+    makeFlagsArray+=( \
         NATIVE_SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \
         SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \
         CFLAGS_FOR_BUILD="$EXTRA_FLAGS $EXTRA_LDFLAGS" \
@@ -128,8 +126,7 @@ if test "$noSysDirs" = "1"; then
         )
 
     if test -z "$targetConfig"; then
-        makeFlagsArray=( \
-            "${makeFlagsArray[@]}" \
+        makeFlagsArray+=( \
             BOOT_CFLAGS="$EXTRA_FLAGS $EXTRA_LDFLAGS" \
             BOOT_LDFLAGS="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \
             )
@@ -138,13 +135,11 @@ if test "$noSysDirs" = "1"; then
     if test -n "$targetConfig" -a "$crossStageStatic" == 1; then
         # We don't want the gcc build to assume there will be a libc providing
         # limits.h in this stagae
-        makeFlagsArray=( \
-            "${makeFlagsArray[@]}" \
+        makeFlagsArray+=( \
             LIMITS_H_TEST=false \
             )
     else
-        makeFlagsArray=( \
-            "${makeFlagsArray[@]}" \
+        makeFlagsArray+=( \
             LIMITS_H_TEST=true \
             )
     fi
@@ -163,6 +158,7 @@ preConfigure() {
         # Patch to get armvt5el working:
         sed -i -e 's/ arm)/ arm*)/' newlib/configure.host
     fi
+
     # Bug - they packaged zlib
     if test -d "zlib"; then
         # This breaks the build without-headers, which should build only
@@ -189,8 +185,8 @@ preConfigure() {
     fi
 
     # Eval the preConfigure script from nix expression.
-    eval $providedPreConfigure;
-    env;
+    eval "$providedPreConfigure"
+
     # Perform the build in a different directory.
     mkdir ../build
     cd ../build
@@ -204,6 +200,15 @@ postConfigure() {
 }
 
 
+preInstall() {
+    # Make ‘lib64’ a symlink to ‘lib’.
+    if [ -n "$is64bit" -a -z "$enableMultilib" ]; then
+        mkdir -p $out/lib
+        ln -s lib $out/lib64
+    fi
+}
+
+
 postInstall() {
     # Remove precompiled headers for now.  They are very big and
     # probably not very useful yet.
diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix
index 62dbad74758..2fb8f9d73b5 100644
--- a/pkgs/development/compilers/gcc/4.8/default.nix
+++ b/pkgs/development/compilers/gcc/4.8/default.nix
@@ -67,7 +67,6 @@ let version = "4.8.3";
     patches = []
       ++ optional enableParallelBuilding ./parallel-bconfig.patch
       ++ optional (cross != null) ./libstdc++-target.patch
-      # ++ optional noSysDirs ./no-sys-dirs.patch
       # The GNAT Makefiles did not pay attention to CFLAGS_FOR_TARGET for its
       # target libraries and tools.
       ++ optional langAda ./gnat-cflags.patch
@@ -304,14 +303,21 @@ stdenv.mkDerivation ({
         "\"--with-host-libstdcxx=-Wl,-rpath,\$prefix/lib/amd64 -lstdc++\"
          \"--with-boot-ldflags=-L../prev-x86_64-pc-solaris2.11/libstdc++-v3/src/.libs\""}
     );
-    ${stdenv.lib.optionalString (stdenv.isSunOS && stdenv.is64bit)
-      ''
-        export NIX_LDFLAGS=`echo $NIX_LDFLAGS | sed -e s~$prefix/lib~$prefix/lib/amd64~g`
-        export LDFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $LDFLAGS_FOR_TARGET"
-        export CXXFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CXXFLAGS_FOR_TARGET"
-        export CFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CFLAGS_FOR_TARGET"
-      ''}
-    '';
+  '' + stdenv.lib.optionalString (stdenv.isSunOS && stdenv.is64bit) ''
+    export NIX_LDFLAGS=`echo $NIX_LDFLAGS | sed -e s~$prefix/lib~$prefix/lib/amd64~g`
+    export LDFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $LDFLAGS_FOR_TARGET"
+    export CXXFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CXXFLAGS_FOR_TARGET"
+    export CFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CFLAGS_FOR_TARGET"
+  '' + stdenv.lib.optionalString stdenv.isDarwin ''
+    if SDKROOT=$(/usr/bin/xcrun --show-sdk-path); then
+      configureFlagsArray+=(--with-native-system-header-dir=$SDKROOT/usr/include)
+      makeFlagsArray+=( \
+       CFLAGS_FOR_BUILD=-F$SDKROOT/System/Library/Frameworks \
+       CFLAGS_FOR_TARGET=-F$SDKROOT/System/Library/Frameworks \
+       FLAGS_FOR_TARGET=-F$SDKROOT/System/Library/Frameworks \
+      )
+    fi
+  '';
 
   dontDisableStatic = true;
 
@@ -494,9 +500,11 @@ stdenv.mkDerivation ({
     else null;
 
   passthru =
-    { inherit langC langCC langObjC langObjCpp langAda langFortran langVhdl langGo enableMultilib version; };
+    { inherit langC langCC langObjC langObjCpp langAda langFortran langVhdl langGo version; };
+
+  inherit enableParallelBuilding enableMultilib;
 
-  inherit enableParallelBuilding;
+  inherit (stdenv) is64bit;
 
   meta = {
     homepage = http://gcc.gnu.org/;
diff --git a/pkgs/development/compilers/gcc/4.8/no-sys-dirs.patch b/pkgs/development/compilers/gcc/4.8/no-sys-dirs.patch
deleted file mode 100644
index 79901703cb8..00000000000
--- a/pkgs/development/compilers/gcc/4.8/no-sys-dirs.patch
+++ /dev/null
@@ -1,41 +0,0 @@
-diff -ru gcc-4.3.1-orig/gcc/cppdefault.c gcc-4.3.1/gcc/cppdefault.c
---- gcc-4.3.1-orig/gcc/cppdefault.c	2007-07-26 10:37:01.000000000 +0200
-+++ gcc-4.3.1/gcc/cppdefault.c	2008-06-25 17:48:23.000000000 +0200
-@@ -41,6 +41,10 @@
- # undef CROSS_INCLUDE_DIR
- #endif
- 
-+#undef LOCAL_INCLUDE_DIR
-+#undef SYSTEM_INCLUDE_DIR
-+#undef STANDARD_INCLUDE_DIR
-+
- const struct default_include cpp_include_defaults[]
- #ifdef INCLUDE_DEFAULTS
- = INCLUDE_DEFAULTS;
-diff -ru gcc-4.3.1-orig/gcc/gcc.c gcc-4.3.1/gcc/gcc.c
---- gcc-4.3.1-orig/gcc/gcc.c	2008-03-02 23:55:19.000000000 +0100
-+++ gcc-4.3.1/gcc/gcc.c	2008-06-25 17:52:53.000000000 +0200
-@@ -1478,10 +1478,10 @@
- /* Default prefixes to attach to command names.  */
- 
- #ifndef STANDARD_STARTFILE_PREFIX_1
--#define STANDARD_STARTFILE_PREFIX_1 "/lib/"
-+#define STANDARD_STARTFILE_PREFIX_1 ""
- #endif
- #ifndef STANDARD_STARTFILE_PREFIX_2
--#define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/"
-+#define STANDARD_STARTFILE_PREFIX_2 ""
- #endif
- 
- #ifdef CROSS_DIRECTORY_STRUCTURE  /* Don't use these prefixes for a cross compiler.  */
---- gcc-4.3.1-orig/gcc/Makefile.in	2008-05-11 20:54:15.000000000 +0200
-+++ gcc-4.3.1/gcc/Makefile.in	2008-06-25 17:48:23.000000000 +0200
-@@ -3277,7 +3281,7 @@
-   -DGPLUSPLUS_INCLUDE_DIR=\"$(gcc_gxx_include_dir)\" \
-   -DGPLUSPLUS_TOOL_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/$(target_noncanonical)\" \
-   -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/backward\" \
--  -DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
-+  -DLOCAL_INCLUDE_DIR=\"/no-such-dir\" \
-   -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
-   -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
-   -DPREFIX=\"$(prefix)/\" \
diff --git a/pkgs/development/compilers/ghdl/default.nix b/pkgs/development/compilers/ghdl/default.nix
index 8b14dbc5cbf..7b2e03f8d57 100644
--- a/pkgs/development/compilers/ghdl/default.nix
+++ b/pkgs/development/compilers/ghdl/default.nix
@@ -34,14 +34,14 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp ghdl_mcode $out/bin
 
-    ensureDir $out/share/ghdl_mcode/translate
+    mkdir -p $out/share/ghdl_mcode/translate
     cp -R ../lib $out/share/ghdl_mcode/translate
     cp -R ../../libraries $out/share/ghdl_mcode
 
-    ensureDir $out/share/man/man1
+    mkdir -p $out/share/man/man1
     cp ../../doc/ghdl.1 $out/share/man/man1/ghdl_mcode.1
 
     # Ghdl has some timestamps checks, storing file timestamps in '.cf' files.
diff --git a/pkgs/development/compilers/go/1.3.nix b/pkgs/development/compilers/go/1.3.nix
index b9178d5e61c..fafa045e562 100644
--- a/pkgs/development/compilers/go/1.3.nix
+++ b/pkgs/development/compilers/go/1.3.nix
@@ -69,7 +69,7 @@ stdenv.mkDerivation {
     # http://lists.science.uu.nl/pipermail/nix-dev/2013-October/011891.html
     # Fix for "libgcc_s.so.1 must be installed for pthread_cancel to work"
     # during tests:
-    export LD_LIBRARY_PATH="$(dirname $(echo ${stdenv.gcc.gcc}/lib*/libgcc_s.so))"
+    export LD_LIBRARY_PATH="$(dirname $(echo ${stdenv.gcc.gcc}/lib/libgcc_s.so))"
 
     mkdir -p "$out/bin"
     export GOROOT="$(pwd)/"
diff --git a/pkgs/development/compilers/go/gox.nix b/pkgs/development/compilers/go/gox.nix
index 705cb6e5c28..da40b7570fe 100644
--- a/pkgs/development/compilers/go/gox.nix
+++ b/pkgs/development/compilers/go/gox.nix
@@ -40,7 +40,7 @@ stdenv.mkDerivation rec {
   propagatedBuildInputs = [ go ];
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     export GOPATH=$src
     go build -v -o $out/bin/gox github.com/mitchellh/gox
   '';
diff --git a/pkgs/development/compilers/gwt/2.4.0.nix b/pkgs/development/compilers/gwt/2.4.0.nix
index 65208b062c2..f0dc9378c4f 100644
--- a/pkgs/development/compilers/gwt/2.4.0.nix
+++ b/pkgs/development/compilers/gwt/2.4.0.nix
@@ -11,7 +11,7 @@ stdenv.mkDerivation {
   buildInputs = [ unzip ];
 
   installPhase = ''
-    ensureDir $out
+    mkdir -p $out
     unzip $src
     mv gwt-2.4.0 $out/bin
   '';
diff --git a/pkgs/development/compilers/mercury/default.nix b/pkgs/development/compilers/mercury/default.nix
index 5ea922a371a..21af582c594 100644
--- a/pkgs/development/compilers/mercury/default.nix
+++ b/pkgs/development/compilers/mercury/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
   '';
 
   preConfigure = ''
-    ensureDir $out/lib/mercury/cgi-bin ;
+    mkdir -p $out/lib/mercury/cgi-bin ;
     configureFlags="--enable-deep-profiler=$out/lib/mercury/cgi-bin";
   '';
 
diff --git a/pkgs/development/compilers/ocaml/3.11.2.nix b/pkgs/development/compilers/ocaml/3.11.2.nix
index cffd7c3f54a..64cf8a9f9f7 100644
--- a/pkgs/development/compilers/ocaml/3.11.2.nix
+++ b/pkgs/development/compilers/ocaml/3.11.2.nix
@@ -37,7 +37,7 @@ stdenv.mkDerivation rec {
     patch -p0 < ${./mips64.patch}
   '';
   postBuild = ''
-    ensureDir $out/include
+    mkdir -p $out/include
     ln -sv $out/lib/ocaml/caml $out/include/caml
   '';
 
diff --git a/pkgs/development/compilers/openjdk-darwin/default.nix b/pkgs/development/compilers/openjdk-darwin/default.nix
index 68708726c85..8d3cbef75d4 100644
--- a/pkgs/development/compilers/openjdk-darwin/default.nix
+++ b/pkgs/development/compilers/openjdk-darwin/default.nix
@@ -1,16 +1,18 @@
-{ stdenv, fetchurl, setJavaClassPath }:
+{ stdenv, fetchurl, unzip, setJavaClassPath }:
 let
   jdk = stdenv.mkDerivation {
-    name = "openjdk6-b16-24_apr_2009-r1";
+    name = "openjdk-7u60b30";
 
+    # From https://github.com/alexkasko/openjdk-unofficial-builds
     src = fetchurl {
-      url = http://landonf.bikemonkey.org/static/soylatte/bsd-dist/openjdk6_darwin/openjdk6-b16-24_apr_2009-r1.tar.bz2;
-      sha256 = "14pbv6jjk95k7hbgiwyvjdjv8pccm7m8a130k0q7mjssf4qmpx1v";
+      url = https://bitbucket.org/alexkasko/openjdk-unofficial-builds/downloads/openjdk-1.7.0-u60-unofficial-macosx-x86_64-bundle.zip;
+      sha256 = "af510a4d566712d82c17054bb39f91d98c69a85586e244c6123669a0bd4b7401";
     };
 
+    buildInputs = [ unzip ];
+
     installPhase = ''
-      mkdir -p $out
-      cp -vR * $out/
+      mv */Contents/Home $out
 
       # jni.h expects jni_md.h to be in the header search path.
       ln -s $out/include/darwin/*_md.h $out/include/
diff --git a/pkgs/development/compilers/pakcs/default.nix b/pkgs/development/compilers/pakcs/default.nix
index 60071a8f6fa..1fb4318ebb9 100644
--- a/pkgs/development/compilers/pakcs/default.nix
+++ b/pkgs/development/compilers/pakcs/default.nix
@@ -54,13 +54,13 @@ stdenv.mkDerivation rec {
     export LC_ALL=en_US.UTF-8
 
     # Set up link to cymake, which has been built already.
-    ensureDir bin/.local
+    mkdir -p bin/.local
     ln -s ${curryFront}/bin/cymake bin/.local/
   '';
 
   installPhase = ''
     # Prepare PAKCSHOME directory.
-    ensureDir $out/pakcs
+    mkdir -p $out/pakcs
     for d in bin curry2prolog currytools lib tools cpns include www examples docs ; do
       cp -r $d $out/pakcs ;
     done
@@ -80,7 +80,7 @@ stdenv.mkDerivation rec {
     (cd $out/pakcs/www ; make)
 
     # Install bin.
-    ensureDir $out/bin
+    mkdir -p $out/bin
     for b in makecurrycgi .makesavedstate pakcs parsecurry cleancurry \
              addtypes cass currybrowse currycreatemake currydoc currytest \
              dataToXml erd2curry ; do
@@ -88,7 +88,7 @@ stdenv.mkDerivation rec {
     done
 
     # Place emacs lisp files in expected locations.
-    ensureDir $out/share/emacs/site-lisp/curry-pakcs
+    mkdir -p $out/share/emacs/site-lisp/curry-pakcs
     for e in "tools/emacs/"*.el ; do
       cp $e $out/share/emacs/site-lisp/curry-pakcs/ ;
     done
diff --git a/pkgs/development/compilers/sbcl/bootstrap.nix b/pkgs/development/compilers/sbcl/bootstrap.nix
index c3335ea6d22..015d7dd95da 100644
--- a/pkgs/development/compilers/sbcl/bootstrap.nix
+++ b/pkgs/development/compilers/sbcl/bootstrap.nix
@@ -15,9 +15,9 @@ stdenv.mkDerivation rec {
     };
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp -p src/runtime/sbcl $out/bin
-    ensureDir $out/share/sbcl
+    mkdir -p $out/share/sbcl
     cp -p output/sbcl.core $out/share/sbcl
   '';
 
diff --git a/pkgs/development/compilers/sbcl/default.nix b/pkgs/development/compilers/sbcl/default.nix
index 7f7a76060bd..d3892d43d15 100644
--- a/pkgs/development/compilers/sbcl/default.nix
+++ b/pkgs/development/compilers/sbcl/default.nix
@@ -51,7 +51,7 @@ stdenv.mkDerivation rec {
 
   preBuild = ''
     export INSTALL_ROOT=$out
-    ensureDir test-home
+    mkdir -p test-home
     export HOME=$PWD/test-home
   '';
 
diff --git a/pkgs/development/compilers/smlnj/bootstrap.nix b/pkgs/development/compilers/smlnj/bootstrap.nix
index 27fdf75cc25..39a1bbd0df3 100644
--- a/pkgs/development/compilers/smlnj/bootstrap.nix
+++ b/pkgs/development/compilers/smlnj/bootstrap.nix
@@ -22,10 +22,10 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     rsync -av bin/ $out/bin/
 
-    ensureDir $out/lib
+    mkdir -p $out/lib
     rsync -av lib/ $out/lib/
   '';
 
diff --git a/pkgs/development/eclipse/ecj/default.nix b/pkgs/development/eclipse/ecj/default.nix
index 786fcdba18a..0f52e879863 100644
--- a/pkgs/development/eclipse/ecj/default.nix
+++ b/pkgs/development/eclipse/ecj/default.nix
@@ -54,6 +54,6 @@ stdenv.mkDerivation rec {
     # http://www.eclipse.org/legal/epl-v10.html (free software, copyleft)
     license = "EPLv1.0";
 
-    platforms = stdenv.lib.platforms.linux;
+    platforms = stdenv.lib.platforms.linux ++ stdenv.lib.platforms.darwin;
   };
 }
diff --git a/pkgs/development/interpreters/perl/5.16/default.nix b/pkgs/development/interpreters/perl/5.16/default.nix
index bbd9e003b2c..600884db5e6 100644
--- a/pkgs/development/interpreters/perl/5.16/default.nix
+++ b/pkgs/development/interpreters/perl/5.16/default.nix
@@ -64,29 +64,5 @@ stdenv.mkDerivation rec {
 
   setupHook = ./setup-hook.sh;
 
-  doCheck = !stdenv.isDarwin;
-
-  # some network-related tests don't work, mostly probably due to our sandboxing
-  testsToSkip = ''
-    lib/Net/hostent.t \
-    dist/IO/t/{io_multihomed.t,io_sock.t} \
-    dist/Net-Ping/t/*.t \
-    cpan/autodie/t/truncate.t \
-    t/porting/{maintainers.t,regen.t} \
-    cpan/Socket/t/get{name,addr}info.t \
-  '' + optionalString stdenv.isFreeBSD ''
-    cpan/CPANPLUS/t/04_CPANPLUS-Module.t \
-    cpan/CPANPLUS/t/20_CPANPLUS-Dist-MM.t \
-  '' + " ";
-
-  postPatch = optionalString (!stdenv.isDarwin) /* this failed on Darwin, no idea why */ ''
-    for test in ${testsToSkip}; do
-      echo "Removing test" $test
-      rm "$test"
-      pat=`echo "$test" | sed 's,/,\\\\/,g'` # just escape slashes
-      sed "/^$pat/d" -i MANIFEST
-    done
-  '';
-
   passthru.libPrefix = "lib/perl5/site_perl";
 }
diff --git a/pkgs/development/libraries/aacskeys/default.nix b/pkgs/development/libraries/aacskeys/default.nix
index 088f2cc4b1e..0b20d8a41ea 100644
--- a/pkgs/development/libraries/aacskeys/default.nix
+++ b/pkgs/development/libraries/aacskeys/default.nix
@@ -25,7 +25,7 @@ stdenv.mkDerivation {
   buildInputs = [openssl jdk premake3];
 
   installPhase = ''
-    ensureDir $out/{bin,lib,share/${baseName}}
+    mkdir -p $out/{bin,lib,share/${baseName}}
 
     # Install lib
     install -Dm444 lib/linux/libaacskeys.so $out/lib
diff --git a/pkgs/development/libraries/apache-activemq/default.nix b/pkgs/development/libraries/apache-activemq/default.nix
index d55ff9049ed..2f2792dec14 100644
--- a/pkgs/development/libraries/apache-activemq/default.nix
+++ b/pkgs/development/libraries/apache-activemq/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
   phases = [ "unpackPhase" "installPhase" ];
 
   installPhase = ''
-    ensureDir $out
+    mkdir -p $out
     mv * $out/
     for j in `find $out/lib -name "*.jar"`; do
       cp="''${cp:+"$cp:"}$j";
diff --git a/pkgs/desktops/gnome-3/3.12/core/at-spi2-atk/default.nix b/pkgs/development/libraries/at-spi2-atk/default.nix
index 416a33b09a2..416a33b09a2 100644
--- a/pkgs/desktops/gnome-3/3.12/core/at-spi2-atk/default.nix
+++ b/pkgs/development/libraries/at-spi2-atk/default.nix
diff --git a/pkgs/desktops/gnome-3/3.10/core/at-spi2-core/default.nix b/pkgs/development/libraries/at-spi2-core/default.nix
index d60a0ff7480..d60a0ff7480 100644
--- a/pkgs/desktops/gnome-3/3.10/core/at-spi2-core/default.nix
+++ b/pkgs/development/libraries/at-spi2-core/default.nix
diff --git a/pkgs/development/libraries/boost/1.55.nix b/pkgs/development/libraries/boost/1.55.nix
index df29b2402f8..bf355f7169c 100644
--- a/pkgs/development/libraries/boost/1.55.nix
+++ b/pkgs/development/libraries/boost/1.55.nix
@@ -75,6 +75,7 @@ stdenv.mkDerivation {
     ./b2 -j$NIX_BUILD_CORES -sEXPAT_INCLUDE=${expat}/include -sEXPAT_LIBPATH=${expat}/lib --layout=${layout} variant=${variant} threading=${threading} link=${link} ${cflags} install${withToolset}
     rm $out/bin/bjam
     ln -s $out/bin/b2 $out/bin/bjam
+    rm -rf $out/share/boost-build/example
   '';
 
   crossAttrs = rec {
diff --git a/pkgs/development/libraries/bwidget/default.nix b/pkgs/development/libraries/bwidget/default.nix
index 81f4f9a287e..0d1913bc8e7 100644
--- a/pkgs/development/libraries/bwidget/default.nix
+++ b/pkgs/development/libraries/bwidget/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
   dontBuild = true;
 
   installPhase = ''
-    ensureDir "$out/lib/${passthru.libPrefix}"
+    mkdir -p "$out/lib/${passthru.libPrefix}"
     cp -R *.tcl lang images "$out/lib/${passthru.libPrefix}"
   '';
 
diff --git a/pkgs/development/libraries/fontconfig/default.nix b/pkgs/development/libraries/fontconfig/default.nix
index 5e211c74d5e..f0c4da75567 100644
--- a/pkgs/development/libraries/fontconfig/default.nix
+++ b/pkgs/development/libraries/fontconfig/default.nix
@@ -20,6 +20,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ pkgconfig expat ];
 
   configureFlags = [
+    "--sysconfdir=/etc"
     "--with-cache-dir=/var/cache/fontconfig"
     "--disable-docs"
     "--with-default-fonts="
@@ -39,7 +40,7 @@ stdenv.mkDerivation rec {
   doCheck = true;
 
   # Don't try to write to /var/cache/fontconfig at install time.
-  installFlags = "fc_cachedir=$(TMPDIR)/dummy RUN_FC_CACHE_TEST=false";
+  installFlags = "sysconfdir=$(out)/etc fc_cachedir=$(TMPDIR)/dummy RUN_FC_CACHE_TEST=false";
 
   postInstall = ''
     cd "$out/etc/fonts" && tar xvf ${infinality_patch}
diff --git a/pkgs/development/libraries/gdk-pixbuf/setup-hook.sh b/pkgs/development/libraries/gdk-pixbuf/setup-hook.sh
index c983f9f6a61..06e820633b8 100644
--- a/pkgs/development/libraries/gdk-pixbuf/setup-hook.sh
+++ b/pkgs/development/libraries/gdk-pixbuf/setup-hook.sh
@@ -1,6 +1,6 @@
 findGdkPixbufLoaders() {
 
-	if [ -z "$IN_NIX_SHELL" ]; then
+	if [ -n "$out" ] && [ -z "$IN_NIX_SHELL" ]; then
 
 		# set pixbuf loaders.cache for this package
 
diff --git a/pkgs/development/libraries/glib/darwin-compilation.patch b/pkgs/development/libraries/glib/darwin-compilation.patch
new file mode 100644
index 00000000000..f215eef798a
--- /dev/null
+++ b/pkgs/development/libraries/glib/darwin-compilation.patch
@@ -0,0 +1,24 @@
+Fix compilation on Mac OS X with gcc 4.8.
+
+diff -ru glib-2.40.0-orig/gio/gdummyfile.c glib-2.40.0/gio/gdummyfile.c
+--- glib-2.40.0-orig/gio/gdummyfile.c   2014-02-03 18:40:41.000000000 +0100
++++ glib-2.40.0/gio/gdummyfile.c        2014-07-15 10:58:31.000000000 +0200
+@@ -454,7 +454,8 @@
+   result = g_malloc (escaped_string_end - escaped_string + 1);
+        
+   out = result;
+-  for (in = escaped_string; in < escaped_string_end; in++) 
++  in = escaped_string;
++  for (; in < escaped_string_end; in++) 
+     {
+       character = *in;
+       if (*in == '%') 
+@@ -551,6 +552,7 @@
+   
+   decoded->scheme = g_malloc (p - uri);
+   out = decoded->scheme;
+-  for (in = uri; in < p - 1; in++)
++  in = uri;
++  for (; in < p - 1; in++)
+     *out++ = g_ascii_tolower (*in);
+   *out = 0;
diff --git a/pkgs/development/libraries/glib/default.nix b/pkgs/development/libraries/glib/default.nix
index 9a592d4f954..14e72495968 100644
--- a/pkgs/development/libraries/glib/default.nix
+++ b/pkgs/development/libraries/glib/default.nix
@@ -49,6 +49,8 @@ stdenv.mkDerivation rec {
     sha256 = "1d98mbqjmc34s8095lkw1j1bwvnnkw9581yfvjaikjvfjsaz29qd";
   };
 
+  patches = optional stdenv.isDarwin ./darwin-compilation.patch;
+
   setupHook = ./setup-hook.sh;
 
   buildInputs = [ libelf ]
@@ -67,6 +69,11 @@ stdenv.mkDerivation rec {
   NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin " -lintl"
     + optionalString stdenv.isSunOS " -DBSD_COMP";
 
+  preBuild = optionalString stdenv.isDarwin
+    ''
+      export MACOSX_DEPLOYMENT_TARGET=
+    '';
+
   enableParallelBuilding = true;
 
   inherit doCheck;
diff --git a/pkgs/development/libraries/glibc/2.19/common.nix b/pkgs/development/libraries/glibc/2.19/common.nix
index 43ba2a9ca11..cd1ba747d7c 100644
--- a/pkgs/development/libraries/glibc/2.19/common.nix
+++ b/pkgs/development/libraries/glibc/2.19/common.nix
@@ -58,6 +58,8 @@ stdenv.mkDerivation ({
       ./fix_path_attribute_in_getconf.patch
 
       ./fix-math.patch
+
+      ./cve-2014-0475.patch
     ];
 
   postPatch = ''
diff --git a/pkgs/development/libraries/glibc/2.19/cve-2014-0475.patch b/pkgs/development/libraries/glibc/2.19/cve-2014-0475.patch
new file mode 100644
index 00000000000..a4f983de8f6
--- /dev/null
+++ b/pkgs/development/libraries/glibc/2.19/cve-2014-0475.patch
@@ -0,0 +1,170 @@
+Picked from upstream commits, but excluding changes to news and tests:
+d183645616b0533 and 4e8f95a0df7c2
+Also see https://sourceware.org/bugzilla/show_bug.cgi?id=17137
+
+diff --git a/locale/setlocale.c b/locale/setlocale.c
+index 9458468..6455b8b 100644
+--- a/locale/setlocale.c
++++ b/locale/setlocale.c
+@@ -272,6 +272,8 @@ setlocale (int category, const char *locale)
+ 	 of entries of the form `CATEGORY=VALUE'.  */
+       const char *newnames[__LC_LAST];
+       struct __locale_data *newdata[__LC_LAST];
++      /* Copy of the locale argument, for in-place splitting.  */
++      char *locale_copy = NULL;
+ 
+       /* Set all name pointers to the argument name.  */
+       for (category = 0; category < __LC_LAST; ++category)
+@@ -281,7 +283,13 @@ setlocale (int category, const char *locale)
+       if (__glibc_unlikely (strchr (locale, ';') != NULL))
+ 	{
+ 	  /* This is a composite name.  Make a copy and split it up.  */
+-	  char *np = strdupa (locale);
++	  locale_copy = strdup (locale);
++	  if (__glibc_unlikely (locale_copy == NULL))
++	    {
++	      __libc_rwlock_unlock (__libc_setlocale_lock);
++	      return NULL;
++	    }
++	  char *np = locale_copy;
+ 	  char *cp;
+ 	  int cnt;
+ 
+@@ -299,6 +307,7 @@ setlocale (int category, const char *locale)
+ 		{
+ 		error_return:
+ 		  __libc_rwlock_unlock (__libc_setlocale_lock);
++		  free (locale_copy);
+ 
+ 		  /* Bogus category name.  */
+ 		  ERROR_RETURN;
+@@ -391,8 +400,9 @@ setlocale (int category, const char *locale)
+       /* Critical section left.  */
+       __libc_rwlock_unlock (__libc_setlocale_lock);
+ 
+-      /* Free the resources (the locale path variable).  */
++      /* Free the resources.  */
+       free (locale_path);
++      free (locale_copy);
+ 
+       return composite;
+     }
+diff --git a/locale/findlocale.c b/locale/findlocale.c
+index bbaf708..22e8b53 100644
+--- a/locale/findlocale.c
++++ b/locale/findlocale.c
+@@ -17,6 +17,7 @@
+    <http://www.gnu.org/licenses/>.  */
+ 
+ #include <assert.h>
++#include <errno.h>
+ #include <locale.h>
+ #include <stdlib.h>
+ #include <string.h>
+@@ -57,6 +58,45 @@ struct loaded_l10nfile *_nl_locale_file_list[__LC_LAST];
+ 
+ const char _nl_default_locale_path[] attribute_hidden = LOCALEDIR;
+ 
++/* Checks if the name is actually present, that is, not NULL and not
++   empty.  */
++static inline int
++name_present (const char *name)
++{
++  return name != NULL && name[0] != '\0';
++}
++
++/* Checks that the locale name neither extremely long, nor contains a
++   ".." path component (to prevent directory traversal).  */
++static inline int
++valid_locale_name (const char *name)
++{
++  /* Not set.  */
++  size_t namelen = strlen (name);
++  /* Name too long.  The limit is arbitrary and prevents stack overflow
++     issues later.  */
++  if (__glibc_unlikely (namelen > 255))
++    return 0;
++  /* Directory traversal attempt.  */
++  static const char slashdot[4] = {'/', '.', '.', '/'};
++  if (__glibc_unlikely (memmem (name, namelen,
++				slashdot, sizeof (slashdot)) != NULL))
++    return 0;
++  if (namelen == 2 && __glibc_unlikely (name[0] == '.' && name [1] == '.'))
++    return 0;
++  if (namelen >= 3
++      && __glibc_unlikely (((name[0] == '.'
++			     && name[1] == '.'
++			     && name[2] == '/')
++			    || (name[namelen - 3] == '/'
++				&& name[namelen - 2] == '.'
++				&& name[namelen - 1] == '.'))))
++    return 0;
++  /* If there is a slash in the name, it must start with one.  */
++  if (__glibc_unlikely (memchr (name, '/', namelen) != NULL) && name[0] != '/')
++    return 0;
++  return 1;
++}
+ 
+ struct __locale_data *
+ internal_function
+@@ -65,7 +105,7 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
+ {
+   int mask;
+   /* Name of the locale for this category.  */
+-  char *loc_name;
++  char *loc_name = (char *) *name;
+   const char *language;
+   const char *modifier;
+   const char *territory;
+@@ -73,31 +113,39 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
+   const char *normalized_codeset;
+   struct loaded_l10nfile *locale_file;
+ 
+-  if ((*name)[0] == '\0')
++  if (loc_name[0] == '\0')
+     {
+       /* The user decides which locale to use by setting environment
+ 	 variables.  */
+-      *name = getenv ("LC_ALL");
+-      if (*name == NULL || (*name)[0] == '\0')
+-	*name = getenv (_nl_category_names.str
++      loc_name = getenv ("LC_ALL");
++      if (!name_present (loc_name))
++	loc_name = getenv (_nl_category_names.str
+ 			+ _nl_category_name_idxs[category]);
+-      if (*name == NULL || (*name)[0] == '\0')
+-	*name = getenv ("LANG");
++      if (!name_present (loc_name))
++	loc_name = getenv ("LANG");
++      if (!name_present (loc_name))
++	loc_name = (char *) _nl_C_name;
+     }
+ 
+-  if (*name == NULL || (*name)[0] == '\0'
+-      || (__builtin_expect (__libc_enable_secure, 0)
+-	  && strchr (*name, '/') != NULL))
+-    *name = (char *) _nl_C_name;
++  /* We used to fall back to the C locale if the name contains a slash
++     character '/', but we now check for directory traversal in
++     valid_locale_name, so this is no longer necessary.  */
+ 
+-  if (__builtin_expect (strcmp (*name, _nl_C_name), 1) == 0
+-      || __builtin_expect (strcmp (*name, _nl_POSIX_name), 1) == 0)
++  if (__builtin_expect (strcmp (loc_name, _nl_C_name), 1) == 0
++      || __builtin_expect (strcmp (loc_name, _nl_POSIX_name), 1) == 0)
+     {
+       /* We need not load anything.  The needed data is contained in
+ 	 the library itself.  */
+       *name = (char *) _nl_C_name;
+       return _nl_C[category];
+     }
++  else if (!valid_locale_name (loc_name))
++    {
++      __set_errno (EINVAL);
++      return NULL;
++    }
++
++  *name = loc_name;
+ 
+   /* We really have to load some data.  First we try the archive,
+      but only if there was no LOCPATH environment variable specified.  */
diff --git a/pkgs/development/libraries/haskell/ghc-heap-view/default.nix b/pkgs/development/libraries/haskell/ghc-heap-view/default.nix
index c32d3be5308..1df6885280c 100644
--- a/pkgs/development/libraries/haskell/ghc-heap-view/default.nix
+++ b/pkgs/development/libraries/haskell/ghc-heap-view/default.nix
@@ -8,7 +8,7 @@ cabal.mkDerivation (self: {
   sha256 = "1qi7f3phj2j63x1wd2cvk36945cxd84s12zs03hlrn49wzx2pf1n";
   buildDepends = [ binary transformers ];
   postInstall = ''
-    ensureDir "$out/share/ghci"
+    mkdir -p "$out/share/ghci"
     ln -s "$out/share/$pname-$version/ghci" "$out/share/ghci/$pname"
   '';
   meta = {
diff --git a/pkgs/development/libraries/haskell/ghc-mod/default.nix b/pkgs/development/libraries/haskell/ghc-mod/default.nix
index f876fb5aba8..a9c06e80f8a 100644
--- a/pkgs/development/libraries/haskell/ghc-mod/default.nix
+++ b/pkgs/development/libraries/haskell/ghc-mod/default.nix
@@ -26,7 +26,7 @@ cabal.mkDerivation (self: {
     make
     rm Makefile
     cd ..
-    ensureDir "$out/share/emacs"
+    mkdir -p "$out/share/emacs"
     mv $pname-$version emacs/site-lisp
     mv $out/bin/ghc-mod $out/bin/.ghc-mod-wrapped
     cat - > $out/bin/ghc-mod <<EOF
diff --git a/pkgs/development/libraries/haskell/ghc-vis/default.nix b/pkgs/development/libraries/haskell/ghc-vis/default.nix
index bfcc3e70472..2a4badd91e3 100644
--- a/pkgs/development/libraries/haskell/ghc-vis/default.nix
+++ b/pkgs/development/libraries/haskell/ghc-vis/default.nix
@@ -14,7 +14,7 @@ cabal.mkDerivation (self: {
   ];
   jailbreak = true;
   postInstall = ''
-    ensureDir "$out/share/ghci"
+    mkdir -p "$out/share/ghci"
     ln -s "$out/share/$pname-$version/ghci" "$out/share/ghci/$pname"
   '';
   meta = {
diff --git a/pkgs/development/libraries/haskell/hoogle/local.nix b/pkgs/development/libraries/haskell/hoogle/local.nix
index 67f38f260e0..eebfd0224d2 100644
--- a/pkgs/development/libraries/haskell/hoogle/local.nix
+++ b/pkgs/development/libraries/haskell/hoogle/local.nix
@@ -65,7 +65,7 @@ cabal.mkDerivation (self: rec {
         exit 1
     fi
 
-    ensureDir $out/share/hoogle/doc
+    mkdir -p $out/share/hoogle/doc
     export HOOGLE_DOC_PATH=$out/share/hoogle/doc
 
     cd $out/share/hoogle
diff --git a/pkgs/development/libraries/java/junixsocket/default.nix b/pkgs/development/libraries/java/junixsocket/default.nix
index e49e626aa00..317ba601cfb 100644
--- a/pkgs/development/libraries/java/junixsocket/default.nix
+++ b/pkgs/development/libraries/java/junixsocket/default.nix
@@ -14,9 +14,6 @@ stdenv.mkDerivation rec {
 
   preConfigure =
     ''
-      substituteInPlace build.xml \
-        --replace /usr/bin/ "" \
-        --replace macosx darwin
       substituteInPlace src/main/org/newsclub/net/unix/NativeUnixSocketConfig.java \
         --replace /opt/newsclub/lib-native $out/lib
     '';
@@ -25,7 +22,7 @@ stdenv.mkDerivation rec {
 
   ANT_ARGS =
     # Note that our OpenJDK on Darwin is currently 32-bit, so we have to build a 32-bit dylib.
-    (if stdenv.is64bit && !stdenv.isDarwin then [ "-Dskip32=true" ] else [ "-Dskip64=true" ])
+    (if stdenv.is64bit then [ "-Dskip32=true" ] else [ "-Dskip64=true" ])
     ++ [ "-Dgcc=cc" "-Dant.build.javac.source=1.6" ]
     ++ stdenv.lib.optional stdenv.isDarwin "-DisMac=true";
 
diff --git a/pkgs/development/libraries/libav/default.nix b/pkgs/development/libraries/libav/default.nix
index 247c3666e15..679b091ce72 100644
--- a/pkgs/development/libraries/libav/default.nix
+++ b/pkgs/development/libraries/libav/default.nix
@@ -28,7 +28,7 @@ let
   result = {
     libav_0_8 = libavFun "0.8.13" "1fr3rzykrlm1cla0csm9hqa3gcqp19hf5rgn70nyb9w92r67v685";
     libav_9   = libavFun   "9.14" "07gn4lbqx6wfhb2h2ddj88hcsacwmzb4syalg211m55xmp1g1fp4";
-    libav_10  = libavFun  "10.2"  "06wvk51cnllw6367qagc90sva4jr5d0r6jx8183wcwzwzgv01w29";
+    libav_10  = libavFun  "10.3"  "1fq83rc5534fjqjlhkw5i9k54dmyqn2pgvyillm6pws8rkn9yb5r";
   };
 
   libavFun = version : sha256 : stdenv.mkDerivation rec {
diff --git a/pkgs/development/libraries/libsamplerate/default.nix b/pkgs/development/libraries/libsamplerate/default.nix
index 708d8989304..85d51d0ad71 100644
--- a/pkgs/development/libraries/libsamplerate/default.nix
+++ b/pkgs/development/libraries/libsamplerate/default.nix
@@ -15,10 +15,14 @@ stdenv.mkDerivation rec {
   #--disable-fftw          disable usage of FFTW
   #--disable-cpu-clip      disable tricky cpu specific clipper
 
-  # need headers from the Carbon.framework in /System/Library/Frameworks to
-  # compile this on darwin -- not sure how to handle
-  NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin
-    "-I/System/Library/Frameworks/Carbon.framework/Versions/A/Headers";
+  postConfigure = stdenv.lib.optionalString stdenv.isDarwin
+    ''
+      # need headers from the Carbon.framework in /System/Library/Frameworks to
+      # compile this on darwin -- not sure how to handle
+      NIX_CFLAGS_COMPILE+=" -I$SDKROOT/System/Library/Frameworks/Carbon.framework/Versions/A/Headers"
+
+      substituteInPlace examples/Makefile --replace "-fpascal-strings" ""
+    '';
 
   meta = with stdenv.lib; {
     description = "Sample Rate Converter for audio";
diff --git a/pkgs/development/libraries/libsndfile/default.nix b/pkgs/development/libraries/libsndfile/default.nix
index 8b0eeeb8e57..74140d5f335 100644
--- a/pkgs/development/libraries/libsndfile/default.nix
+++ b/pkgs/development/libraries/libsndfile/default.nix
@@ -12,8 +12,13 @@ stdenv.mkDerivation rec {
 
   # need headers from the Carbon.framework in /System/Library/Frameworks to
   # compile this on darwin -- not sure how to handle
-  NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin
-    "-I/System/Library/Frameworks/Carbon.framework/Versions/A/Headers";
+  preConfigure = stdenv.lib.optionalString stdenv.isDarwin
+    ''
+      NIX_CFLAGS_COMPILE+=" -I$SDKROOT/System/Library/Frameworks/Carbon.framework/Versions/A/Headers"
+    '';
+
+  # Needed on Darwin.
+  NIX_CFLAGS_LINK = "-logg -lvorbis";
 
   meta = with stdenv.lib; {
     description = "A C library for reading and writing files containing sampled sound";
diff --git a/pkgs/development/libraries/mesa/default.nix b/pkgs/development/libraries/mesa/default.nix
index 5695967bc3d..bbad10898bf 100644
--- a/pkgs/development/libraries/mesa/default.nix
+++ b/pkgs/development/libraries/mesa/default.nix
@@ -24,7 +24,7 @@ else
 */
 
 let
-  version = "10.2.4";
+  version = "10.2.5";
   # this is the default search path for DRI drivers
   driverLink = "/run/opengl-driver" + stdenv.lib.optionalString stdenv.isi686 "-32";
 in
@@ -35,7 +35,7 @@ stdenv.mkDerivation {
 
   src =  fetchurl {
     url = "ftp://ftp.freedesktop.org/pub/mesa/${version}/MesaLib-${version}.tar.bz2";
-    sha256 = "06l18j9vshq2xzhnp6zd6pw0dlfy0qg1cw4zyn1w51gb8h9398h6";
+    sha256 = "039is15p8pkhf8m0yiyb72zybl63xb9ckqzcg3xwi8zlyw5ryidl";
   };
 
   prePatch = "patchShebangs .";
diff --git a/pkgs/development/libraries/ncurses/default.nix b/pkgs/development/libraries/ncurses/default.nix
index 7627fb79e99..87953c1158d 100644
--- a/pkgs/development/libraries/ncurses/default.nix
+++ b/pkgs/development/libraries/ncurses/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl, unicode ? true}:
+{ lib, stdenv, fetchurl, unicode ? true }:
 
 let
   /* C++ bindings fail to build on `i386-pc-solaris2.11' with GCC 3.4.3:
@@ -10,7 +10,7 @@ let
      So disable them for now.  */
   cxx = !stdenv.isSunOS;
 in
-stdenv.mkDerivation (rec {
+stdenv.mkDerivation rec {
   name = "ncurses-5.9";
 
   src = fetchurl {
@@ -18,13 +18,7 @@ stdenv.mkDerivation (rec {
     sha256 = "0fsn7xis81za62afan0vvm38bvgzg5wfmv1m86flqcj0nj7jjilh";
   };
 
-  clangPatch = fetchurl {
-    # Patch referenced from https://github.com/Homebrew/homebrew-dupes/issues/43
-    url = "http://lists.gnu.org/archive/html/bug-ncurses/2011-04/txtkWQqiQvcZe.txt";
-    sha256 = "03lrwqvb0r2qgi8hz7ayd3g26d6xilr3c92j8li3b77kdc0w0rlv";
-  };
-
-  patches = [ ./patch-ac ] ++ stdenv.lib.optional stdenv.isDarwin clangPatch;
+  patches = [ ./patch-ac ];
 
   configureFlags = ''
     --with-shared --without-debug --enable-pc-files --enable-symlinks
@@ -41,6 +35,8 @@ 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;
@@ -50,8 +46,8 @@ stdenv.mkDerivation (rec {
   preBuild =
     # On Darwin, we end up using the native `sed' during bootstrap, and it
     # fails to run this command, which isn't needed anyway.
-    stdenv.lib.optionalString (!stdenv.isDarwin)
-    ''sed -e "s@\([[:space:]]\)sh @\1''${SHELL} @" -i */Makefile Makefile'';
+    lib.optionalString (!stdenv.isDarwin)
+      ''sed -e "s@\([[:space:]]\)sh @\1''${SHELL} @" -i */Makefile Makefile'';
 
   # When building a wide-character (Unicode) build, create backward
   # compatibility links from the the "normal" libraries to the
@@ -71,6 +67,8 @@ stdenv.mkDerivation (rec {
     ln -svf ncursesw5-config $out/bin/ncurses5-config
   '' else "";
 
+  postFixup = lib.optionalString stdenv.isDarwin "rm $out/lib/*.so";
+
   meta = {
     description = "GNU Ncurses, a free software emulation of curses in SVR4 and more";
 
@@ -90,9 +88,9 @@ stdenv.mkDerivation (rec {
 
     homepage = http://www.gnu.org/software/ncurses/;
 
-    license = stdenv.lib.licenses.mit;
+    license = lib.licenses.mit;
 
-    maintainers = [ stdenv.lib.maintainers.ludo ];
-    platforms = stdenv.lib.platforms.all;
+    maintainers = [ lib.maintainers.ludo ];
+    platforms = lib.platforms.all;
   };
-} // ( if stdenv.isDarwin then { postFixup = "rm $out/lib/*.so"; } else { } ) )
+}
diff --git a/pkgs/development/libraries/opencv/default.nix b/pkgs/development/libraries/opencv/default.nix
index ea858417b2f..7dafcfce948 100644
--- a/pkgs/development/libraries/opencv/default.nix
+++ b/pkgs/development/libraries/opencv/default.nix
@@ -1,5 +1,6 @@
-{ stdenv, fetchurl, cmake, gtk, libjpeg, libpng, libtiff, jasper, ffmpeg
-, pkgconfig, gstreamer, xineLib, glib, python27, python27Packages }:
+{ lib, stdenv, fetchurl, cmake, gtk, libjpeg, libpng, libtiff, jasper, ffmpeg
+, pkgconfig, gstreamer, xineLib, glib, python27, python27Packages
+, enableBloat ? false }:
 
 let v = "2.4.7"; in
 
@@ -11,8 +12,9 @@ stdenv.mkDerivation rec {
     sha256 = "0hravl3yhyv4r4n7vb055d4qnp893q2hc0fcmmncfh7sbdrnr3f4";
   };
 
-  buildInputs = [ gtk glib libjpeg libpng libtiff jasper ffmpeg xineLib gstreamer
-    python27 python27Packages.numpy ];
+  buildInputs =
+    [ libjpeg libpng libtiff ]
+    ++ lib.optionals enableBloat [ gtk glib jasper ffmpeg xineLib gstreamer python27 python27Packages.numpy ];
 
   nativeBuildInputs = [ cmake pkgconfig ];
 
diff --git a/pkgs/development/libraries/openssl/default.nix b/pkgs/development/libraries/openssl/default.nix
index 93f7cbe1a1f..8c88df984f0 100644
--- a/pkgs/development/libraries/openssl/default.nix
+++ b/pkgs/development/libraries/openssl/default.nix
@@ -2,7 +2,7 @@
 , withCryptodev ? false, cryptodevHeaders }:
 
 let
-  name = "openssl-1.0.1h";
+  name = "openssl-1.0.1i";
 
   opensslCrossSystem = stdenv.lib.attrByPath [ "openssl" "system" ]
     (throw "openssl needs its platform name cross building" null)
@@ -43,7 +43,7 @@ stdenv.mkDerivation {
       "http://www.openssl.org/source/${name}.tar.gz"
       "http://openssl.linux-mirror.org/source/${name}.tar.gz"
     ];
-    sha256 = "14yhsgag5as7nhxnw7f0vklwjwa3pmn1i15nmp3f4qxa6sc8l74x";
+    sha256 = "1izwv1wzqdw8aqnvb70jcqpqp0rvkcm22w5c1dm9l1kpr939y5rw";
   };
 
   patches = patchesCross false;
@@ -65,7 +65,7 @@ stdenv.mkDerivation {
   makeFlags = "MANDIR=$(out)/share/man";
 
   # Parallel building is broken in OpenSSL.
-  #enableParallelBuilding = true;
+  enableParallelBuilding = false;
 
   postInstall =
     ''
diff --git a/pkgs/development/libraries/readline/no-arch_only-6.3.patch b/pkgs/development/libraries/readline/no-arch_only-6.3.patch
new file mode 100644
index 00000000000..7c46dbad962
--- /dev/null
+++ b/pkgs/development/libraries/readline/no-arch_only-6.3.patch
@@ -0,0 +1,13 @@
+diff -ru -x '*~' readline-6.3-orig/support/shobj-conf readline-6.3/support/shobj-conf
+--- support/shobj-conf	2014-02-24 03:06:29.000000000 +0100
++++ support/shobj-conf	2014-07-22 11:18:52.000000000 +0200
+@@ -194,9 +194,6 @@
+ 	# Darwin 8 == Mac OS X 10.4; Mac OS X 10.N == Darwin N+4
+ 	*)
+ 		case "${host_os}" in
+-		darwin[89]*|darwin1[012]*)
+-			SHOBJ_ARCHFLAGS='-arch_only `/usr/bin/arch`'
+-			;;
+ 		 *) 	# Mac OS X 10.9 (Mavericks) and later
+ 			SHOBJ_ARCHFLAGS=
+ 			# for 32 and 64bit universal library
diff --git a/pkgs/development/libraries/readline/no-arch_only.patch b/pkgs/development/libraries/readline/no-arch_only.patch
new file mode 100644
index 00000000000..b23eab5d9d7
--- /dev/null
+++ b/pkgs/development/libraries/readline/no-arch_only.patch
@@ -0,0 +1,14 @@
+diff -ru -x '*~' readline-6.2-orig/support/shobj-conf readline-6.2/support/shobj-conf
+--- support/shobj-conf	2009-10-28 14:20:21.000000000 +0100
++++ support/shobj-conf	2014-07-01 13:03:28.000000000 +0200
+@@ -168,8 +168,8 @@
+ 	SHLIB_LIBVERSION='$(SHLIB_MAJOR)$(SHLIB_MINOR).$(SHLIB_LIBSUFF)'
+ 	SHLIB_LIBSUFF='dylib'
+ 
+-	SHOBJ_LDFLAGS='-dynamiclib -dynamic -undefined dynamic_lookup -arch_only `/usr/bin/arch`'
+-	SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v'
++	SHOBJ_LDFLAGS='-dynamiclib -dynamic -undefined dynamic_lookup'
++	SHLIB_XLDFLAGS='-dynamiclib -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v'
+ 
+ 	SHLIB_LIBS='-lncurses'	# see if -lcurses works on MacOS X 10.1 
+ 	;;
diff --git a/pkgs/development/libraries/readline/readline6.3.nix b/pkgs/development/libraries/readline/readline6.3.nix
index dd39804983a..9f5c9f7b581 100644
--- a/pkgs/development/libraries/readline/readline6.3.nix
+++ b/pkgs/development/libraries/readline/readline6.3.nix
@@ -13,7 +13,9 @@ stdenv.mkDerivation (rec {
   patchFlags = "-p0";
 
   patches =
-    [ ./link-against-ncurses.patch ];
+    [ ./link-against-ncurses.patch
+      ./no-arch_only-6.3.patch
+    ];
 
   meta = {
     description = "GNU Readline, a library for interactive line editing";
diff --git a/pkgs/development/libraries/readline/readline6.nix b/pkgs/development/libraries/readline/readline6.nix
index 05500f345ac..0559113285c 100644
--- a/pkgs/development/libraries/readline/readline6.nix
+++ b/pkgs/development/libraries/readline/readline6.nix
@@ -12,7 +12,9 @@ stdenv.mkDerivation (rec {
 
   patchFlags = "-p0";
   patches =
-    [ ./link-against-ncurses.patch ]
+    [ ./link-against-ncurses.patch
+      ./no-arch_only.patch
+    ]
     ++
     (let
        patch = nr: sha256:
diff --git a/pkgs/development/mobile/androidenv/androidsdk.nix b/pkgs/development/mobile/androidenv/androidsdk.nix
index 1a2124754a2..3c9327f1c59 100644
--- a/pkgs/development/mobile/androidenv/androidsdk.nix
+++ b/pkgs/development/mobile/androidenv/androidsdk.nix
@@ -178,7 +178,7 @@ stdenv.mkDerivation rec {
     
     # Create wrappers to the most important tools and platform tools so that we can run them if the SDK is in our PATH
     
-    ensureDir $out/bin
+    mkdir -p $out/bin
 
     for i in $out/libexec/android-sdk-*/tools/*
     do
diff --git a/pkgs/development/mobile/xcodeenv/simulate-app.nix b/pkgs/development/mobile/xcodeenv/simulate-app.nix
index d25ef0f8e43..c999497d8c0 100644
--- a/pkgs/development/mobile/xcodeenv/simulate-app.nix
+++ b/pkgs/development/mobile/xcodeenv/simulate-app.nix
@@ -10,7 +10,7 @@ in
 stdenv.mkDerivation {
   name = stdenv.lib.replaceChars [" "] [""] name;
   buildCommand = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cat > $out/bin/run-test-simulator << "EOF"
     #! ${stdenv.shell} -e
 
diff --git a/pkgs/development/mobile/xcodeenv/xcodewrapper.nix b/pkgs/development/mobile/xcodeenv/xcodewrapper.nix
index 71e34ee5127..fd375d6213c 100644
--- a/pkgs/development/mobile/xcodeenv/xcodewrapper.nix
+++ b/pkgs/development/mobile/xcodeenv/xcodewrapper.nix
@@ -3,7 +3,7 @@
 stdenv.mkDerivation {
   name = "xcode-wrapper-"+version;
   buildCommand = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cd $out/bin
     ln -s /usr/bin/xcode-select
     ln -s /usr/bin/xcodebuild
diff --git a/pkgs/development/ocaml-modules/ocamlmake/default.nix b/pkgs/development/ocaml-modules/ocamlmake/default.nix
index 0170119d94e..3f91901d9b6 100644
--- a/pkgs/development/ocaml-modules/ocamlmake/default.nix
+++ b/pkgs/development/ocaml-modules/ocamlmake/default.nix
@@ -14,7 +14,7 @@ in stdenv.mkDerivation {
   };
 
   installPhase = ''
-    ensureDir "$out/include/"
+    mkdir -p "$out/include/"
     cp OCamlMakefile "$out/include/"
   '';
 
diff --git a/pkgs/development/tools/apktool/default.nix b/pkgs/development/tools/apktool/default.nix
index a415ffd152d..23941653575 100644
--- a/pkgs/development/tools/apktool/default.nix
+++ b/pkgs/development/tools/apktool/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
 
   installPhase = ''
     install -D apktool.jar "$out/libexec/apktool/apktool.jar"
-    ensureDir "$out/bin"
+    mkdir -p "$out/bin"
     makeWrapper "${jre}/bin/java" "$out/bin/apktool" \
         --add-flags "-jar $out/libexec/apktool/apktool.jar" \
         --prefix PATH : "${buildTools}/build-tools/android-4.3/"
diff --git a/pkgs/development/tools/etcdctl/default.nix b/pkgs/development/tools/etcdctl/default.nix
index a37ef26f541..5e6438d0f5f 100644
--- a/pkgs/development/tools/etcdctl/default.nix
+++ b/pkgs/development/tools/etcdctl/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     mv etcdctl $out/bin
   '';
 
diff --git a/pkgs/development/tools/gocode/default.nix b/pkgs/development/tools/gocode/default.nix
index 6057c288cf6..30e4b79ee38 100644
--- a/pkgs/development/tools/gocode/default.nix
+++ b/pkgs/development/tools/gocode/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     mv gocode $out/bin
   '';
 
diff --git a/pkgs/development/tools/literate-programming/noweb/default.nix b/pkgs/development/tools/literate-programming/noweb/default.nix
index 291bc29e1b7..4f8691c40ad 100644
--- a/pkgs/development/tools/literate-programming/noweb/default.nix
+++ b/pkgs/development/tools/literate-programming/noweb/default.nix
@@ -9,7 +9,7 @@ stdenv.mkDerivation {
     sha256 = "10hdd6mrk26kyh4bnng4ah5h1pnanhsrhqa7qwqy6dyv3rng44y9";
   };
   preBuild = ''
-    ensureDir $out/lib/noweb
+    mkdir -p $out/lib/noweb
     cd src
     makeFlags="BIN=$out/bin LIB=$out/lib/noweb MAN=$out/share/man TEXINPUTS=$out/share/texmf/tex/latex"
   '';
diff --git a/pkgs/development/tools/misc/autoconf/default.nix b/pkgs/development/tools/misc/autoconf/default.nix
index 38fe289d29a..4dca332722b 100644
--- a/pkgs/development/tools/misc/autoconf/default.nix
+++ b/pkgs/development/tools/misc/autoconf/default.nix
@@ -14,7 +14,8 @@ stdenv.mkDerivation rec {
   # http://thread.gmane.org/gmane.comp.sysutils.autoconf.bugs/6822 for
   # details.
   # There are many test failures on `i386-pc-solaris2.11'.
-  doCheck = ((!stdenv.isCygwin) && (!stdenv.isSunOS));
+  #doCheck = ((!stdenv.isCygwin) && (!stdenv.isSunOS));
+  doCheck = false;
 
   # Don't fixup "#! /bin/sh" in Autoconf, otherwise it will use the
   # "fixed" path in generated files!
diff --git a/pkgs/development/tools/misc/distcc/masq.nix b/pkgs/development/tools/misc/distcc/masq.nix
index 117480670c3..753c35b5d3a 100644
--- a/pkgs/development/tools/misc/distcc/masq.nix
+++ b/pkgs/development/tools/misc/distcc/masq.nix
@@ -5,7 +5,7 @@ stdenv.mkDerivation {
 
   phases = [ "installPhase" ];
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
 
     bin=${gccRaw}/bin
 
diff --git a/pkgs/development/tools/misc/grafana/default.nix b/pkgs/development/tools/misc/grafana/default.nix
index 346c7fb6ad2..b1566684cf0 100644
--- a/pkgs/development/tools/misc/grafana/default.nix
+++ b/pkgs/development/tools/misc/grafana/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
 
   phases = ["unpackPhase" "installPhase"];
   installPhase = ''
-    ensureDir $out && cp -R * $out
+    mkdir -p $out && cp -R * $out
     ${optionalString (conf!=null) ''cp ${conf} $out/config.js''}
   '';
 
diff --git a/pkgs/development/tools/misc/opengrok/default.nix b/pkgs/development/tools/misc/opengrok/default.nix
index 8f77b3d7283..d38c862ecfb 100644
--- a/pkgs/development/tools/misc/opengrok/default.nix
+++ b/pkgs/development/tools/misc/opengrok/default.nix
@@ -11,7 +11,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ makeWrapper ];
 
   installPhase = ''
-    ensureDir $out
+    mkdir -p $out
     cp -a * $out/
     substituteInPlace $out/bin/OpenGrok --replace /bin/uname ${coreutils}/bin/uname
     wrapProgram $out/bin/OpenGrok \
diff --git a/pkgs/development/tools/node-webkit/default.nix b/pkgs/development/tools/node-webkit/default.nix
index 04ee2962173..1f101776064 100644
--- a/pkgs/development/tools/node-webkit/default.nix
+++ b/pkgs/development/tools/node-webkit/default.nix
@@ -33,8 +33,8 @@ in stdenv.mkDerivation rec {
   installPhase = let
     LD_LIBRARY_PATH = "${nwEnv}/lib:${nwEnv}/lib64:$out/share/node-webkit";
   in ''
-    ensureDir $out/bin
-    ensureDir $out/share/node-webkit
+    mkdir -p $out/bin
+    mkdir -p $out/share/node-webkit
     cp -R * $out/share/node-webkit
 
     ln -s ${udev}/lib/libudev.so $out/share/node-webkit/libudev.so.0
diff --git a/pkgs/development/tools/ocaml/deriving/default.nix b/pkgs/development/tools/ocaml/deriving/default.nix
index d53f41b5da5..55bbf3748ea 100644
--- a/pkgs/development/tools/ocaml/deriving/default.nix
+++ b/pkgs/development/tools/ocaml/deriving/default.nix
@@ -52,7 +52,7 @@ versionedDerivation "ocaml-deriving" version {
     # not all tests compile !?
     # (cd tests; make)
 
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp -a lib $out/
     cp -a syntax $out
 
diff --git a/pkgs/development/tools/packer/default.nix b/pkgs/development/tools/packer/default.nix
index 5cea753dd9c..073de5137f8 100644
--- a/pkgs/development/tools/packer/default.nix
+++ b/pkgs/development/tools/packer/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
     XC_ARCH=$(go env GOARCH)
     XC_OS=$(go env GOOS)
 
-    ensureDir $out/bin
+    mkdir -p $out/bin
 
     cd $src/src/github.com/mitchellh/packer
     gox \
diff --git a/pkgs/development/tools/yuicompressor/default.nix b/pkgs/development/tools/yuicompressor/default.nix
index 5dcc30811e2..1a5485af541 100644
--- a/pkgs/development/tools/yuicompressor/default.nix
+++ b/pkgs/development/tools/yuicompressor/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
   };
 
   buildCommand = ''
-    ensureDir $out/lib
+    mkdir -p $out/lib
     ln -s $src $out/lib/yuicompressor.jar
   '';
 }
diff --git a/pkgs/games/0ad/default.nix b/pkgs/games/0ad/default.nix
index c0dfe723c81..78b76f1ac36 100644
--- a/pkgs/games/0ad/default.nix
+++ b/pkgs/games/0ad/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, stdenvType, callPackage, fetchurl, python27
+{ stdenv, callPackage, fetchurl, python27
 , pkgconfig, spidermonkey_24, boost, icu, libxml2, libpng
 , libjpeg, zlib, curl, libogg, libvorbis, enet, miniupnpc
 , openalSoft, mesa, xproto, libX11, libXcursor, nspr, SDL
@@ -16,8 +16,8 @@ let
   zeroadData = callPackage ./data.nix { inherit version releaseType; };
 
   archForPremake =
-    if stdenv.lib.hasPrefix "x86_64-" stdenvType then "x64" else
-    if stdenv.lib.hasPrefix "i686-" stdenvType then "x32" else "ERROR";
+    if stdenv.lib.hasPrefix "x86_64-" stdenv.system then "x64" else
+    if stdenv.lib.hasPrefix "i686-" stdenv.system then "x32" else "ERROR";
 
 in
 stdenv.mkDerivation rec {
diff --git a/pkgs/games/andyetitmoves/default.nix b/pkgs/games/andyetitmoves/default.nix
index 6f5fc2add3a..ae04c57aa26 100644
--- a/pkgs/games/andyetitmoves/default.nix
+++ b/pkgs/games/andyetitmoves/default.nix
@@ -38,7 +38,7 @@ stdenv.mkDerivation rec {
   phases = "unpackPhase installPhase";
 
   installPhase = ''
-    ensureDir $out/{opt/andyetitmoves,bin}
+    mkdir -p $out/{opt/andyetitmoves,bin}
     cp -r * $out/opt/andyetitmoves/
 
     fullPath=${stdenv.gcc.gcc}/lib64
diff --git a/pkgs/games/crafty/default.nix b/pkgs/games/crafty/default.nix
index 54deae2ecfe..0e2796df22d 100644
--- a/pkgs/games/crafty/default.nix
+++ b/pkgs/games/crafty/default.nix
@@ -621,10 +621,10 @@ stdenv.mkDerivation rec {
            else "make";
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp -p ./crafty $out/bin
 
-    ensureDir $out/share/crafty
+    mkdir -p $out/share/crafty
     cd $out/share/crafty
 
     $out/bin/crafty "books create ${startPgn} 60"
@@ -635,7 +635,7 @@ stdenv.mkDerivation rec {
         $out/bin/crafty "book create enormous.pgn 60"
         rm -f *.001 enormous.pgn
         
-        ensureDir $out/share/crafty/TB
+        mkdir -p $out/share/crafty/TB
         ${stdenv.lib.fold
           (tb: acc: acc + "\nln -s "
                         + toString tb
diff --git a/pkgs/games/gsb/default.nix b/pkgs/games/gsb/default.nix
index 52c3830c22a..757d3cf7681 100644
--- a/pkgs/games/gsb/default.nix
+++ b/pkgs/games/gsb/default.nix
@@ -32,8 +32,8 @@ stdenv.mkDerivation rec {
     + ":" + stdenv.gcc.gcc + "/lib64";
 
   installPhase = ''
-    ensureDir $out/libexec/positech/GSB/
-    ensureDir $out/bin
+    mkdir -p $out/libexec/positech/GSB/
+    mkdir -p $out/bin
 
     patchelf \
       --interpreter "$(cat $NIX_GCC/nix-support/dynamic-linker)" \
diff --git a/pkgs/games/minecraft/default.nix b/pkgs/games/minecraft/default.nix
index b4ec7eb311f..9f79dd70c6a 100644
--- a/pkgs/games/minecraft/default.nix
+++ b/pkgs/games/minecraft/default.nix
@@ -1,6 +1,8 @@
-{stdenv, fetchurl, jre, libX11, libXext, libXcursor, libXrandr, libXxf86vm
+{ stdenv, fetchurl, jre, libX11, libXext, libXcursor, libXrandr, libXxf86vm
 , mesa, openal, alsaOss }:
 
+assert jre ? architecture;
+
 stdenv.mkDerivation {
   name = "minecraft-2013.07.01";
 
diff --git a/pkgs/games/openlierox/default.nix b/pkgs/games/openlierox/default.nix
index b031cb3f0dd..2dc4dece75f 100644
--- a/pkgs/games/openlierox/default.nix
+++ b/pkgs/games/openlierox/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation {
   '';
 
   installPhase = ''
-    ensureDir $out/bin $out/share/OpenLieroX
+    mkdir -p $out/bin $out/share/OpenLieroX
     cp bin/* $out/bin
     cp -R ../share/gamedir/* $out/share/OpenLieroX
   '';
diff --git a/pkgs/games/opentyrian/default.nix b/pkgs/games/opentyrian/default.nix
index 6b9c4847367..cfae6a4bb3e 100644
--- a/pkgs/games/opentyrian/default.nix
+++ b/pkgs/games/opentyrian/default.nix
@@ -22,9 +22,9 @@ stdenv.mkDerivation rec {
   ";
   buildPhase = "make release";
   installPhase = "
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp ./opentyrian $out/bin
-    ensureDir $out/share/opentyrian/data
+    mkdir -p $out/share/opentyrian/data
     unzip -j $data -d $out/share/opentyrian/data
   ";
 
diff --git a/pkgs/games/vessel/default.nix b/pkgs/games/vessel/default.nix
index 9b9dd6c1f43..8a92490b6e0 100644
--- a/pkgs/games/vessel/default.nix
+++ b/pkgs/games/vessel/default.nix
@@ -24,8 +24,8 @@ stdenv.mkDerivation rec {
     + ":" + stdenv.lib.makeLibraryPath [ SDL pulseaudio alsaLib ] ;
 
   installPhase = ''
-    ensureDir $out/libexec/strangeloop/vessel/
-    ensureDir $out/bin
+    mkdir -p $out/libexec/strangeloop/vessel/
+    mkdir -p $out/bin
 
     # allow scripting of the mojoinstaller
     gcc -fPIC -shared -o isatty.so $ld_preload
diff --git a/pkgs/games/worldofgoo/default.nix b/pkgs/games/worldofgoo/default.nix
index 13e7e487c8f..c39ffb1de05 100644
--- a/pkgs/games/worldofgoo/default.nix
+++ b/pkgs/games/worldofgoo/default.nix
@@ -50,8 +50,8 @@ stdenv.mkDerivation rec {
     + ":" + stdenv.gcc.gcc + "/lib64";
 
   installPhase = ''
-    ensureDir $out/libexec/2dboy/WorldOfGoo/
-    ensureDir $out/bin
+    mkdir -p $out/libexec/2dboy/WorldOfGoo/
+    mkdir -p $out/bin
 
     patchelf --interpreter "$(cat $NIX_GCC/nix-support/dynamic-linker)" --set-rpath $libPath ./WorldOfGoo.bin64
 
diff --git a/pkgs/misc/emulators/bsod/default.nix b/pkgs/misc/emulators/bsod/default.nix
index d15e873422e..526ea25a04e 100644
--- a/pkgs/misc/emulators/bsod/default.nix
+++ b/pkgs/misc/emulators/bsod/default.nix
@@ -11,7 +11,7 @@ stdenv.mkDerivation {
   buildInputs = [ ncurses ];
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp bsod $out/bin
   '';
 
diff --git a/pkgs/misc/vim-plugins/default.nix b/pkgs/misc/vim-plugins/default.nix
index 4142bce3b37..87014a9c714 100644
--- a/pkgs/misc/vim-plugins/default.nix
+++ b/pkgs/misc/vim-plugins/default.nix
@@ -89,7 +89,7 @@ let vimHelpTags = ''
 
     installPhase = ''
       target=$out/share/vim-plugins/${path}
-      ensureDir $out/share/vim-plugins
+      mkdir -p $out/share/vim-plugins
       cp -r . $target
       ${vimHelpTags}
       vimHelpTags $target
@@ -408,7 +408,7 @@ in rec
     };
     unpackPhase = ":";
     installPhase = ''
-      ensureDir $out/share/vim-plugins/vim-a
+      mkdir -p $out/share/vim-plugins/vim-a
       cp ${src} $out/share/vim-plugins/vim-a/a.vim
     '';
   };
diff --git a/pkgs/os-specific/darwin/xcode/default.nix b/pkgs/os-specific/darwin/xcode/default.nix
index 73585d59c0b..2a48590154e 100644
--- a/pkgs/os-specific/darwin/xcode/default.nix
+++ b/pkgs/os-specific/darwin/xcode/default.nix
@@ -31,12 +31,12 @@ in stdenv.mkDerivation rec {
   patches = optional (osxVersion == "10.9") ./gcc-fix-enum-attributes.patch;
 
   installPhase = ''
-    ensureDir "$out/share/sysroot"
+    mkdir -p "$out/share/sysroot"
     cp -a * "$out/share/sysroot/"
     ln -s "$out/share/sysroot/usr/lib" "$out/lib"
     ln -s "$out/share/sysroot/usr/include" "$out/include"
 
-    ensureDir "$toolchain"
+    mkdir -p "$toolchain"
     pushd "$toolchain"
     ${xpwn}/bin/hfsplus "$(dirs +1)/../main.hfs" extractall \
       Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr \
diff --git a/pkgs/os-specific/linux/apparmor/default.nix b/pkgs/os-specific/linux/apparmor/default.nix
index 12173e20f3f..8048419a93b 100644
--- a/pkgs/os-specific/linux/apparmor/default.nix
+++ b/pkgs/os-specific/linux/apparmor/default.nix
@@ -48,7 +48,7 @@ stdenv.mkDerivation rec {
     make
     make check
     make install
-    ensureDir $out/lib/perl5/site_perl/
+    mkdir -p $out/lib/perl5/site_perl/
     cp swig/perl/LibAppArmor.pm $out/lib/perl5/site_perl/
     cp swig/perl/LibAppArmor.bs $out/lib/perl5/site_perl/
     # this is automatically copied elsewhere....
diff --git a/pkgs/os-specific/linux/bbswitch/default.nix b/pkgs/os-specific/linux/bbswitch/default.nix
index e12c80e0886..6c7d6d5330e 100644
--- a/pkgs/os-specific/linux/bbswitch/default.nix
+++ b/pkgs/os-specific/linux/bbswitch/default.nix
@@ -22,10 +22,10 @@ stdenv.mkDerivation {
   '';
 
   installPhase = ''
-    ensureDir $out/lib/modules/${kernel.modDirVersion}/misc
+    mkdir -p $out/lib/modules/${kernel.modDirVersion}/misc
     cp bbswitch.ko $out/lib/modules/${kernel.modDirVersion}/misc
 
-    ensureDir $out/bin
+    mkdir -p $out/bin
     tee $out/bin/discrete_vga_poweroff << EOF
     #!/bin/sh
 
diff --git a/pkgs/os-specific/linux/frandom/default.nix b/pkgs/os-specific/linux/frandom/default.nix
index 20419fe816d..80ad483b367 100644
--- a/pkgs/os-specific/linux/frandom/default.nix
+++ b/pkgs/os-specific/linux/frandom/default.nix
@@ -20,10 +20,10 @@ stdenv.mkDerivation rec {
  
   installPhase = ''
     kernelVersion=${kernel.modDirVersion}
-    ensureDir $out/lib/modules/$kernelVersion/misc
+    mkdir -p $out/lib/modules/$kernelVersion/misc
     cp frandom.ko $out/lib/modules/$kernelVersion/misc
 
-    ensureDir $out/lib/udev/rules.d
+    mkdir -p $out/lib/udev/rules.d
     tee $out/lib/udev/rules.d/10-frandom.rules <<-EOF
     #
     # These are the rules for the frandom devices. In theory, we could let
diff --git a/pkgs/os-specific/linux/gogoclient/default.nix b/pkgs/os-specific/linux/gogoclient/default.nix
index 09a449bbede..a627a8cbcc9 100644
--- a/pkgs/os-specific/linux/gogoclient/default.nix
+++ b/pkgs/os-specific/linux/gogoclient/default.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
   buildInputs = [openssl];
 
   preFixup = ''
-    ensureDir $out/share/${name}
+    mkdir -p $out/share/${name}
     chmod 444 $out/bin/gogoc.conf
     mv $out/bin/gogoc.conf $out/share/${name}/gogoc.conf.sample
     rm $out/bin/gogoc.conf.sample
diff --git a/pkgs/os-specific/linux/google-authenticator/default.nix b/pkgs/os-specific/linux/google-authenticator/default.nix
index e2a5cb37c94..0e38d94e1ed 100644
--- a/pkgs/os-specific/linux/google-authenticator/default.nix
+++ b/pkgs/os-specific/linux/google-authenticator/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin $out/lib/security
+    mkdir -p $out/bin $out/lib/security
     cp pam_google_authenticator.so $out/lib/security
     cp google-authenticator $out/bin
   '';
diff --git a/pkgs/os-specific/linux/i7z/default.nix b/pkgs/os-specific/linux/i7z/default.nix
index 1aa10648861..1fe1f48f4ef 100644
--- a/pkgs/os-specific/linux/i7z/default.nix
+++ b/pkgs/os-specific/linux/i7z/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/sbin
+    mkdir -p $out/sbin
     make install prefix=$out
     install -Dm755 GUI/i7z_GUI $out/sbin/i7z-gui
   '';
diff --git a/pkgs/os-specific/linux/iomelt/default.nix b/pkgs/os-specific/linux/iomelt/default.nix
index df267d304c1..fccf7b6b1cd 100644
--- a/pkgs/os-specific/linux/iomelt/default.nix
+++ b/pkgs/os-specific/linux/iomelt/default.nix
@@ -9,8 +9,8 @@ in stdenv.mkDerivation {
   };
 
   preBuild = ''
-    ensureDir $out/bin
-    ensureDir $out/share/man/man1
+    mkdir -p $out/bin
+    mkdir -p $out/share/man/man1
 
     substituteInPlace Makefile \
       --replace /usr $out
diff --git a/pkgs/os-specific/linux/mcelog/default.nix b/pkgs/os-specific/linux/mcelog/default.nix
index 5c36bb09781..463722d2c96 100644
--- a/pkgs/os-specific/linux/mcelog/default.nix
+++ b/pkgs/os-specific/linux/mcelog/default.nix
@@ -26,7 +26,7 @@ in stdenv.mkDerivation {
   makeFlags = "prefix=$(out) etcprefix=$(out) DOCDIR=$(out)/share/doc";
 
   preInstall = ''
-    ensureDir $out/share/doc
+    mkdir -p $out/share/doc
   '';
 
   meta = {
diff --git a/pkgs/os-specific/linux/microcode/converter.nix b/pkgs/os-specific/linux/microcode/converter.nix
index 49babc6ca57..da4d9677217 100644
--- a/pkgs/os-specific/linux/microcode/converter.nix
+++ b/pkgs/os-specific/linux/microcode/converter.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation {
   '';
 
   installPhase = ''
-    ensureDir "$out/bin"
+    mkdir -p "$out/bin"
     cp intel-microcode2ucode "$out/bin/"
   '';
 
diff --git a/pkgs/os-specific/linux/netatop/default.nix b/pkgs/os-specific/linux/netatop/default.nix
index e843658dfc2..c77faa6a9e7 100644
--- a/pkgs/os-specific/linux/netatop/default.nix
+++ b/pkgs/os-specific/linux/netatop/default.nix
@@ -22,8 +22,8 @@ stdenv.mkDerivation {
   '';
 
   preInstall = ''
-    ensureDir $out/bin $out/sbin $out/share/man/man{4,8}
-    ensureDir $out/lib/modules/${kernel.modDirVersion}/extra
+    mkdir -p $out/bin $out/sbin $out/share/man/man{4,8}
+    mkdir -p $out/lib/modules/${kernel.modDirVersion}/extra
   '';
       
   meta = {
diff --git a/pkgs/os-specific/linux/otpw/default.nix b/pkgs/os-specific/linux/otpw/default.nix
index 2cf375c8368..27d0510a657 100644
--- a/pkgs/os-specific/linux/otpw/default.nix
+++ b/pkgs/os-specific/linux/otpw/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin $out/lib/security $out/share/man/man{1,8}
+    mkdir -p $out/bin $out/lib/security $out/share/man/man{1,8}
     cp pam_*.so $out/lib/security
     cp otpw-gen $out/bin
     cp *.1 $out/share/man/man1
diff --git a/pkgs/os-specific/linux/rfkill/udev.nix b/pkgs/os-specific/linux/rfkill/udev.nix
index 6cf6e4adfa0..054ed471eaa 100644
--- a/pkgs/os-specific/linux/rfkill/udev.nix
+++ b/pkgs/os-specific/linux/rfkill/udev.nix
@@ -31,12 +31,12 @@ stdenv.mkDerivation {
   dontBuild = true;
 
   installPhase = ''
-    ensureDir "$out/etc/udev/rules.d/";
+    mkdir -p "$out/etc/udev/rules.d/";
     cat > "$out/etc/udev/rules.d/90-rfkill.rules" << EOF
       SUBSYSTEM=="rfkill", ATTR{type}=="wlan", RUN+="$out/bin/rfkill-hook.sh" 
     EOF
 
-    ensureDir "$out/bin/";
+    mkdir -p "$out/bin/";
     cp ${./rfkill-hook.sh} "$out/bin/rfkill-hook.sh"
     chmod +x "$out/bin/rfkill-hook.sh";
   '';
diff --git a/pkgs/os-specific/linux/util-linux/default.nix b/pkgs/os-specific/linux/util-linux/default.nix
index cdc384f3ee8..1dd7c0c089f 100644
--- a/pkgs/os-specific/linux/util-linux/default.nix
+++ b/pkgs/os-specific/linux/util-linux/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchurl, zlib, ncurses ? null, perl ? null, pam }:
 
 stdenv.mkDerivation rec {
-  name = "util-linux-2.24.1";
+  name = "util-linux-2.24.2";
 
   src = fetchurl {
     url = "http://www.kernel.org/pub/linux/utils/util-linux/v2.24/${name}.tar.xz";
-    sha256 = "0444xhfm9525v3aagyfbp38mp7xsw2fn9zg4ya713c7s5hivcpl3";
+    sha256 = "1w0g8q5aj5pjdf8l52g0mxyvlk62f4dch51q9jm3hnqwgz0dchqj";
   };
 
   crossAttrs = {
diff --git a/pkgs/os-specific/linux/x86info/default.nix b/pkgs/os-specific/linux/x86info/default.nix
index 6cd2a431a60..eaec63f98bf 100644
--- a/pkgs/os-specific/linux/x86info/default.nix
+++ b/pkgs/os-specific/linux/x86info/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ pciutils python ];
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp x86info lsmsr $out/bin
   '';
 
diff --git a/pkgs/servers/dict/dictd-wiktionary.nix b/pkgs/servers/dict/dictd-wiktionary.nix
index 9e9c05d2f91..370bfd39137 100644
--- a/pkgs/servers/dict/dictd-wiktionary.nix
+++ b/pkgs/servers/dict/dictd-wiktionary.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
   builder = writeScript "wiktionary-builder.sh" ''
     source $stdenv/setup
 
-    ensureDir $out/share/dictd/
+    mkdir -p $out/share/dictd/
     cd $out/share/dictd
 
     export LOCALE_ARCHIVE=${glibcLocales}/lib/locale/locale-archive
diff --git a/pkgs/servers/dict/dictd-wordnet.nix b/pkgs/servers/dict/dictd-wordnet.nix
index 063868ddc6e..b6680e8b21c 100644
--- a/pkgs/servers/dict/dictd-wordnet.nix
+++ b/pkgs/servers/dict/dictd-wordnet.nix
@@ -9,7 +9,7 @@ stdenv.mkDerivation rec {
 
   builder = writeScript "builder.sh" ''
     . ${stdenv}/setup
-    ensureDir $out/share/dictd/
+    mkdir -p $out/share/dictd/
     cd $out/share/dictd
 
     for i in ${wordnet}/dict/data.*; do
diff --git a/pkgs/servers/etcd/default.nix b/pkgs/servers/etcd/default.nix
index 1fb21f2b8ab..8b4903c8602 100644
--- a/pkgs/servers/etcd/default.nix
+++ b/pkgs/servers/etcd/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     mv etcd $out/bin/etcd
   '';
 
diff --git a/pkgs/servers/fleet/default.nix b/pkgs/servers/fleet/default.nix
index 627c1ff0cf9..e3a53c85052 100644
--- a/pkgs/servers/fleet/default.nix
+++ b/pkgs/servers/fleet/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     mv fleet $out/bin
   '';
 
diff --git a/pkgs/servers/http/thttpd/default.nix b/pkgs/servers/http/thttpd/default.nix
index e03183cbe49..0bb3d96b37b 100644
--- a/pkgs/servers/http/thttpd/default.nix
+++ b/pkgs/servers/http/thttpd/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
   '';
 
   preInstall = ''
-    ensureDir "$out/man/man1"
+    mkdir -p "$out/man/man1"
     sed -i -e 's/-o bin -g bin *//' Makefile
     sed -i -e '/chgrp/d' extras/Makefile
   '';
diff --git a/pkgs/servers/monitoring/seyren/default.nix b/pkgs/servers/monitoring/seyren/default.nix
index 541c377c404..e6e15129568 100644
--- a/pkgs/servers/monitoring/seyren/default.nix
+++ b/pkgs/servers/monitoring/seyren/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ makeWrapper jre src ];
 
   installPhase = ''
-    ensureDir "$out"/bin
+    mkdir -p "$out"/bin
     makeWrapper "${jre}/bin/java" "$out"/bin/seyren --add-flags "-jar $src"
   '';
 
diff --git a/pkgs/servers/nosql/influxdb/default.nix b/pkgs/servers/nosql/influxdb/default.nix
index fa9c48c6ea9..77852b6d2ed 100644
--- a/pkgs/servers/nosql/influxdb/default.nix
+++ b/pkgs/servers/nosql/influxdb/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
     wrapProgram "$out/bin/influxdb" \
         --prefix LD_LIBRARY_PATH : "${stdenv.gcc.gcc}/lib:${stdenv.gcc.gcc}/lib64"
 
-    ensureDir $out/share/influxdb
+    mkdir -p $out/share/influxdb
     cp -R admin scripts config.toml $out/share/influxdb
   '';
 
diff --git a/pkgs/servers/nsq/default.nix b/pkgs/servers/nsq/default.nix
index b1570d96c7b..4d32c3203c7 100644
--- a/pkgs/servers/nsq/default.nix
+++ b/pkgs/servers/nsq/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     mv build/* $out/bin
   '';
 
diff --git a/pkgs/servers/serfdom/default.nix b/pkgs/servers/serfdom/default.nix
index 92ab3bd780a..48e5f2cea22 100644
--- a/pkgs/servers/serfdom/default.nix
+++ b/pkgs/servers/serfdom/default.nix
@@ -16,12 +16,12 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     mv serf $out/bin/serf
   '';
 
   meta = with stdenv.lib; {
-    description = "Serf is a service discovery and orchestration tool that is decentralized, highly available, and fault tolerant";
+    description = "A service discovery and orchestration tool that is decentralized, highly available, and fault tolerant";
     homepage = http://www.serfdom.io/;
     license = licenses.mpl20;
     maintainers = with maintainers; [ msackman cstrahan ];
diff --git a/pkgs/shells/bash/bash-4.2-patches.nix b/pkgs/shells/bash/bash-4.2-patches.nix
index ac6e9e97f18..567ec3c551c 100644
--- a/pkgs/shells/bash/bash-4.2-patches.nix
+++ b/pkgs/shells/bash/bash-4.2-patches.nix
@@ -46,4 +46,6 @@ patch: [
 (patch "043" "0mswgjk3z80qm1mb93jmbql27nbczxk86cw5byf0m29y1y2869nw")
 (patch "044" "1rk6jywzfvg1crvhib1zk37rsps73minhr7l4vcb3vfdkin2vlqh")
 (patch "045" "0vcqn9rb26bahhrarbwhpa0ny0nrf4vyrzh97d44lfcxypqfzdyx")
+(patch "046" "0vc1ngkxkamwr022ww3vjp9ww9c647az4pjn175c1v60d0xk5hcm")
+(patch "047" "0ymgimqz65sx2izg1dvm1h5cc01arl3j9j5137212l1ls00r55y1")
 ]
diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix
index a2723f5575c..47d1fb6d9f7 100644
--- a/pkgs/stdenv/default.nix
+++ b/pkgs/stdenv/default.nix
@@ -5,14 +5,7 @@
 # Posix utilities, the GNU C compiler, and so on.  On other systems,
 # we use the native C library.
 
-
-# stdenvType exists to support multiple kinds of stdenvs on the same
-# system, e.g., cygwin and mingw builds on i686-cygwin.  Most people
-# can ignore it.
-
-{ system, stdenvType ? system, allPackages ? import ../.., platform, config }:
-
-assert system != "i686-cygwin" -> system == stdenvType;
+{ system, allPackages ? import ../.., platform, config }:
 
 
 rec {
@@ -45,23 +38,16 @@ rec {
   stdenvLinux = (import ./linux { inherit system allPackages platform config;}).stdenvLinux;
 
 
-  # MinGW/MSYS standard environment.
-  stdenvMinGW = import ./mingw {
-    inherit system;
-  };
-
-
   # Select the appropriate stdenv for the platform `system'.
   stdenv =
-    if stdenvType == "i686-linux" then stdenvLinux else
-    if stdenvType == "x86_64-linux" then stdenvLinux else
-    if stdenvType == "armv5tel-linux" then stdenvLinux else
-    if stdenvType == "armv6l-linux" then stdenvLinux else
-    if stdenvType == "armv7l-linux" then stdenvLinux else
-    if stdenvType == "mips64el-linux" then stdenvLinux else
-    if stdenvType == "powerpc-linux" then /* stdenvLinux */ stdenvNative else
-    if stdenvType == "i686-mingw" then stdenvMinGW else
-    if stdenvType == "x86_64-darwin" then stdenvNix else
-    if stdenvType == "x86_64-solaris" then stdenvNix else
+    if system == "i686-linux" then stdenvLinux else
+    if system == "x86_64-linux" then stdenvLinux else
+    if system == "armv5tel-linux" then stdenvLinux else
+    if system == "armv6l-linux" then stdenvLinux else
+    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-solaris" then stdenvNix else
     stdenvNative;
 }
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index 6047ecf853c..0d8355e89cc 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -55,8 +55,6 @@ let
 
       propagatedUserEnvPkgs = [gcc] ++
         lib.filter lib.isDerivation initialPath;
-
-      __ignoreNulls = true;
     }
 
     // rec {
@@ -103,6 +101,7 @@ let
               stdenv = result;
               system = result.system;
               userHook = config.stdenv.userHook or null;
+              __ignoreNulls = true;
 
               # Inputs built by the cross compiler.
               buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs);
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index ce83b1f6961..c3b9033b49a 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -103,6 +103,7 @@ fi
 
 # Execute the pre-hook.
 export SHELL=@shell@
+export CONFIG_SHELL="$SHELL"
 if [ -z "$shell" ]; then export shell=@shell@; fi
 runHook preHook
 
@@ -120,6 +121,7 @@ fi
 
 # Ensure that the given directories exists.
 ensureDir() {
+    echo "warning: ‘ensureDir’ is deprecated; use ‘mkdir’ instead" >&2
     local dir
     for dir in "$@"; do
         if ! [ -x "$dir" ]; then mkdir -p "$dir"; fi
diff --git a/pkgs/stdenv/linux/make-bootstrap-tools-crosspi.nix b/pkgs/stdenv/linux/make-bootstrap-tools-crosspi.nix
index 9ea63a46be3..3abffc46926 100644
--- a/pkgs/stdenv/linux/make-bootstrap-tools-crosspi.nix
+++ b/pkgs/stdenv/linux/make-bootstrap-tools-crosspi.nix
@@ -116,7 +116,7 @@ rec {
 
       buildCommand = ''
 	set -x
-        ensureDir $out/bin $out/lib $out/libexec
+        mkdir -p $out/bin $out/lib $out/libexec
 
         # Copy what we need of Glibc.
         cp -d ${glibc}/lib/ld-*.so* $out/lib
diff --git a/pkgs/stdenv/mingw/builder.sh b/pkgs/stdenv/mingw/builder.sh
deleted file mode 100755
index 5a9f9749a4f..00000000000
--- a/pkgs/stdenv/mingw/builder.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-# the other stdenv could change the SHELL variable,
-# so we have to remember its value.
-origShell=$SHELL
-origGcc=$GCC
-
-source $STDENV/setup
-
-mkdir $OUT
-
-SHELL=$origShell
-GCC=$origGcc
-
-export NIX_BUILD_TOP=$(pwd)
-
-substitute "$SETUP" "$OUT/setup" \
-    --subst-var INITIALPATH \
-    --subst-var GCC \
-    --subst-var SHELL
diff --git a/pkgs/stdenv/mingw/cygpath/builder.sh b/pkgs/stdenv/mingw/cygpath/builder.sh
deleted file mode 100755
index 3061900ee0c..00000000000
--- a/pkgs/stdenv/mingw/cygpath/builder.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-source $stdenv/setup
-
-mkdir $out
-result="$(cygpath --mixed $path)"
-echo "\"$result\"" > $out/default.nix
diff --git a/pkgs/stdenv/mingw/cygpath/default.nix b/pkgs/stdenv/mingw/cygpath/default.nix
deleted file mode 100644
index a0554c1d41d..00000000000
--- a/pkgs/stdenv/mingw/cygpath/default.nix
+++ /dev/null
@@ -1,9 +0,0 @@
-{stdenv}: path :
-
-import (
-  stdenv.mkDerivation {
-    name = "cygpath";
-    builder = ./builder.sh;
-    inherit path;
-  }
-)
diff --git a/pkgs/stdenv/mingw/default-builder.sh b/pkgs/stdenv/mingw/default-builder.sh
deleted file mode 100755
index 422699971ed..00000000000
--- a/pkgs/stdenv/mingw/default-builder.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-source $STDENV/setup
-genericBuild
diff --git a/pkgs/stdenv/mingw/default.nix b/pkgs/stdenv/mingw/default.nix
deleted file mode 100644
index 947db5f10a8..00000000000
--- a/pkgs/stdenv/mingw/default.nix
+++ /dev/null
@@ -1,233 +0,0 @@
-{system} :
-
-let {
-  body =
-    stdenvFinal;
-
-  /**
-   * Initial standard environment based on native Cygwin tools.
-   * GCC is not required.
-   * Required (approx): bash, mkdir, gnu tar, curl.
-   */
-  stdenvInit1 =
-    import ./simple-stdenv {
-      inherit system;
-      name = "stdenv-init1-mingw";
-      shell = "/bin/bash.exe";
-      path = ["/usr/bin" "/bin" "/usr/local/bin"];
-    };
-
-  /**
-   * Initial standard environment based on MSYS tools.
-   */
-  stdenvInit2 =
-    import ./simple-stdenv {
-      inherit system;
-      name = "stdenv-init2-mingw";
-      shell = msysShell;
-      path = [(msys + "/bin")];
-    };
-
-  /**
-   * Initial standard environment with the most basic MinGW packages.
-   */
-  stdenvInit3 =
-    (import ./simple-stdenv) {
-      inherit system;
-      name = "stdenv-init3-mingw";
-      shell = msysShell;
-      path = [
-        (make + "/bin")
-        (tar + "/bin")
-        (binutils + "/bin")
-        (gccFull + "/bin")
-        (mingwRuntimeBin + "/bin")
-        (w32apiBin + "/bin")
-        (msys + "/bin")
-      ];
-
-      extraEnv = {
-        C_INCLUDE_PATH = mingwRuntimeBin + "/include" + ":" + w32apiBin + "/include";
-        LIBRARY_PATH = mingwRuntimeBin + "/lib" + ":" + w32apiBin + "/lib";
-      };
-    };
-
-  /**
-   * Final standard environment, based on generic stdenv.
-   * It would be better to make the generic stdenv usable on
-   * MINGW (i.e. make all environment variables CAPS).
-   */
-  stdenvFinal =
-    let {
-      body =
-        stdenv // mkDerivationFun // {
-          inherit fetchurl;
-          overrides.pkgconfig = pkgconfigBin;
-        };
-
-      shell =
-        msys + "/bin/sh.exe";
-
-      stdenv =
-        stdenvInit2.mkDerivation {
-          name = "stdenv-mingw";
-          builder = ./builder.sh;
-          setup = ./setup.sh;
-
-          /**
-           * binutils is on the path because it contains dlltool, which
-           * is invoked on the PATH by some packages.
-           */
-          initialPath = [make tar binutils gccFull mingwRuntimeSrc w32apiSrc msys];
-          gcc = gccFull;
-          shell = msysShell;
-          inherit curl;
-          isDarwin = false;
-          isMinGW = true;
-        };
-
-      mkDerivationFun = {
-        mkDerivation = attrs:
-          (derivation (
-            (removeAttrs attrs ["meta"])
-            //
-            {
-              builder =
-                if attrs ? realBuilder then attrs.realBuilder else shell;
-              args =
-                if attrs ? args then
-                  attrs.args
-                 else
-                  ["-e"] ++ (
-                    if attrs ? builder then
-                      [./fix-builder.sh attrs.builder]
-                    else
-                      [./fix-builder.sh ./default-builder.sh]
-                    );
-              inherit stdenv system;
-              C_INCLUDE_PATH = mingwRuntimeSrc + "/include" + ":" + w32apiSrc + "/include";
-              CPLUS_INCLUDE_PATH = mingwRuntimeSrc + "/include" + ":" + w32apiSrc + "/include";
-              LIBRARY_PATH = mingwRuntimeSrc + "/lib" + ":" + w32apiSrc + "/lib";
-            })
-          )
-          // { meta = if attrs ? meta then attrs.meta else {}; };
-       };
-     };
-
-  /**
-   * fetchurl
-   */
-  fetchurlInit1 =
-    import ../../build-support/fetchurl {
-      stdenv = stdenvInit1;
-      curl =
-        (import ./pkgs).curl {
-          stdenv = stdenvInit1;
-        };
-    };
-
-  cygpath =
-    import ./cygpath {
-      stdenv = stdenvInit1;
-    };
-
-  /**
-   * Hack: we need the cygpath of the Cygwin chmod.
-   */
-  fetchurl =
-    import ./fetchurl {
-      stdenv = stdenvInit2;
-      curl = curl + "/bin/curl.exe";
-      chmod = cygpath "/usr/bin/chmod";
-    };
-
-  /**
-   * MSYS, installed using stdenvInit1
-   *
-   * @todo Maybe remove the make of msys?
-   */
-  msys =
-    stdenvInit1.mkDerivation {
-      name = "msys-1.0.11";
-      builder = ./msys-builder.sh;
-      src =
-        fetchurlInit1 {
-          url = ftp://ftp.strategoxt.org/pub/mingw/msys-1.0.11.tar.gz;
-          sha256 = "08qp4jk279i66q6ngksg58fx3cfv1r6p5n394h2kfrs56qs9zvz4";
-        };
-    };
-
-  msysShell = 
-    msys + "/bin/sh.exe";
-
-  /**
-   * Binary packages, based on stdenvInit2
-   */
-  curl =
-    (import ./pkgs).curl {
-      stdenv = stdenvInit2;
-    };
-
-  gccFull =
-    (import ./pkgs).gccFull {
-      stdenv = stdenvInit2;
-      inherit fetchurl;
-    };
-
-  make =
-   (import ./pkgs).make {
-     stdenv = stdenvInit2;
-     inherit fetchurl;
-   };
-
-  tar =
-   (import ./pkgs).tar {
-     stdenv = stdenvInit2;
-     inherit fetchurl;
-   };
-
-  binutils =
-   (import ./pkgs).binutils {
-     stdenv = stdenvInit2;
-     inherit fetchurl;
-    };
-
-  mingwRuntimeBin =
-    (import ./pkgs).mingwRuntimeBin {
-      stdenv = stdenvInit2;
-      inherit fetchurl;
-    };
-
-  w32apiBin =
-    (import ./pkgs).w32apiBin {
-      stdenv = stdenvInit2;
-      inherit fetchurl;
-    };
-
-  pkgconfigBin =
-    (import ./pkgs).pkgconfigBin {
-      stdenv = stdenvInit3;
-      inherit fetchurl;
-    };
-
-  /**
-   * Source packages, based on stdenvInit3
-   */
-  mingwRuntimeSrc =
-    (import ./pkgs).mingwRuntimeSrc {
-      stdenv = stdenvInit3;
-      inherit fetchurl;
-    };
-
-  w32apiSrc =
-    (import ./pkgs).w32apiSrc {
-      stdenv = stdenvInit3;
-      inherit fetchurl;
-    };
-
-  replace =
-    (import ./pkgs).replace {
-      stdenv = stdenvInit3;
-      inherit fetchurl;
-    };
-}
diff --git a/pkgs/stdenv/mingw/fetchurl/builder.sh b/pkgs/stdenv/mingw/fetchurl/builder.sh
deleted file mode 100755
index e9f2669a097..00000000000
--- a/pkgs/stdenv/mingw/fetchurl/builder.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-if test -z "$out"; then
-  stdenv="$STDENV"
-  url="$URL"
-  id="$ID"
-  outputHashAlgo="$OUTPUTHASHALGO"
-  outputHash="$OUTPUTHASH"
-  chmod=$CHMOD
-  curl=$CURL
-fi
-
-source $stdenv/setup
-
-if test -z "$out"; then
-  out="$OUT"
-fi
-
-header "downloading $out from $url"
-$curl --fail --location --max-redirs 20 "$url" > "$out"
-
-if test "$NIX_OUTPUT_CHECKED" != "1"; then
-    if test "$outputHashAlgo" != "md5"; then
-        echo "hashes other than md5 are unsupported in Nix <= 0.7, upgrade to Nix 0.8"
-        exit 1
-    fi
-    actual=$(md5sum -b "$out" | cut -c1-32)
-    if test "$actual" != "$id"; then
-        echo "hash is $actual, expected $id"
-        exit 1
-    fi
-fi
-
-$chmod a-x $out
-
-stopNest
diff --git a/pkgs/stdenv/mingw/fetchurl/default.nix b/pkgs/stdenv/mingw/fetchurl/default.nix
deleted file mode 100644
index b4d278b2686..00000000000
--- a/pkgs/stdenv/mingw/fetchurl/default.nix
+++ /dev/null
@@ -1,28 +0,0 @@
-{stdenv, curl, chmod}:
-
-{url, outputHash ? "", outputHashAlgo ? "", md5 ? "", sha1 ? "", sha256 ? ""}:
-
-assert (outputHash != "" && outputHashAlgo != "")
-    || md5 != "" || sha1 != "" || sha256 != "";
-
-stdenv.mkDerivation {
-  name = baseNameOf (toString url);
-  builder = ./builder.sh;
-
-  # Compatibility with Nix <= 0.7.
-  id = md5;
-
-  # New-style output content requirements.
-  outputHashAlgo = if outputHashAlgo != "" then outputHashAlgo else
-      if sha256 != "" then "sha256" else if sha1 != "" then "sha1" else "md5";
-  outputHash = if outputHash != "" then outputHash else
-      if sha256 != "" then sha256 else if sha1 != "" then sha1 else md5;
-  
-  inherit url chmod curl;
-
-  # We borrow these environment variables from the caller to allow
-  # easy proxy configuration.  This is impure, but a fixed-output
-  # derivation like fetchurl is allowed to do so since its result is
-  # by definition pure.
-  impureEnvVars = ["http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy"];
-}
diff --git a/pkgs/stdenv/mingw/fix-builder.sh b/pkgs/stdenv/mingw/fix-builder.sh
deleted file mode 100755
index 09d933bd17b..00000000000
--- a/pkgs/stdenv/mingw/fix-builder.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-# Workaround MSYS shell problem
-
-if test -z "$out"; then
-  buildInputs=$BUILDINPUTS
-  buildUtilities=$BUILDUTILITIES
-  configureFlags=$CONFIGUREFLAGS
-  doCheck=$DOCHECK
-  doCoverageAnalysis=$DOCOVERAGEANALYSIS
-  dontInstall=$DONTINSTALL
-  dontLogThroughTee=$DONTLOGTHROUGHTEE
-  lcov=$LCOV
-  logPhases=$LOGPHASES
-  out=$OUT
-  patches=$PATCHES
-  propagatedBuildInputs=$PROPAGATEDBUILDINPUTS
-  stdenv=$STDENV
-  src=$SRC
-  srcs=$SRCS
-  succeedOnFailure=$SUCCEEDONFAILURE
-  system=$SYSTEM
-fi
-
-source $@
diff --git a/pkgs/stdenv/mingw/msys-builder.sh b/pkgs/stdenv/mingw/msys-builder.sh
deleted file mode 100644
index a801e7fbcab..00000000000
--- a/pkgs/stdenv/mingw/msys-builder.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-source $stdenv/setup
-
-mkdir $out
-cd $out
-tar zxvf $src
-
-# Make the Nix store available to MSYS.
-# Hack: we are assuming that the stdenv is based on Cygwin.
-
-nixdir="$(cygpath --windows /nix)"
-mkdir $out/nix
-cat > $out/etc/fstab <<EOF
-#Win32_Path      Mount_Point
-$nixdir          /nix
-EOF
diff --git a/pkgs/stdenv/mingw/pkgs/bin-builder.sh b/pkgs/stdenv/mingw/pkgs/bin-builder.sh
deleted file mode 100644
index f4f21d50a45..00000000000
--- a/pkgs/stdenv/mingw/pkgs/bin-builder.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-source $STDENV/setup
-
-mkdir $OUT
-cd $OUT
-tar zxvf $SRC
diff --git a/pkgs/stdenv/mingw/pkgs/curl.exe b/pkgs/stdenv/mingw/pkgs/curl.exe
deleted file mode 100755
index 0a02fa0af5c..00000000000
--- a/pkgs/stdenv/mingw/pkgs/curl.exe
+++ /dev/null
Binary files differdiff --git a/pkgs/stdenv/mingw/pkgs/default.nix b/pkgs/stdenv/mingw/pkgs/default.nix
deleted file mode 100644
index 5add5b6546e..00000000000
--- a/pkgs/stdenv/mingw/pkgs/default.nix
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * MinGW packages.
- */
-rec {
-
-  /**
-   * Curl, binary
-   */
-  curl =  {stdenv} :
-    stdenv.mkDerivation {
-      name = "curl-7.15.4";
-      exename = "curl.exe";
-      builder = ./single-exe-builder.sh;
-      src = ./curl.exe;
-    };
-
-  /**
-   * Make. Binary.
-   */
-  make = {stdenv, fetchurl} :
-    stdenv.mkDerivation {
-      name = "mingw-make-3.81";
-      builder = ./bin-builder.sh;
-      src = 
-        fetchurl {
-          url = http://surfnet.dl.sourceforge.net/sourceforge/mingw/mingw32-make-3.81-1.tar.gz;
-          md5 = "74c2f44ecc699b318edeb07d838feae5";
-        };
-    };
-
-  /**
-   * Tar
-   */
-  tar = {stdenv, fetchurl} :
-    stdenv.mkDerivation {
-      name = "mingw-tar";
-      builder = ./bin-builder.sh;
-      src = 
-        fetchurl {
-          url = ftp://ftp.strategoxt.org/pub/mingw/tar-1.22-1-msys-1.0.11-bin.tar.gz;
-          sha256 = "17rbv159g56q3bp8rh5vzv8hw8clxs7vk731cgqg0vy1fzls6yfq";
-        };
-    };
-
-  /**
-   * GCC. Binary
-   */
-  gccFull =  {stdenv, fetchurl} :
-    stdenv.mkDerivation {
-      name = "gcc-full-4.4.0-mingw32";
-      builder = ./bin-builder.sh;
-      src = 
-        fetchurl {
-          url = ftp://ftp.strategoxt.org/pub/mingw/gcc-full-4.4.0-mingw32-bin-2.tar.gz;
-          sha256= "6c5a125591837817c940f4c66140cd7393b3f5837dd738c7ed315157e6270a60";
-        };
-    };
-
-  /**
-   * binutils. Binary.
-   */
-  binutils =  {stdenv, fetchurl} :
-    stdenv.mkDerivation {
-      name = "binutils-2.19.1-mingw32";
-      builder = ./bin-builder.sh;
-      src = 
-        fetchurl {
-          url = http://surfnet.dl.sourceforge.net/sourceforge/mingw/files/GNU%20Binutils/Current%20Release_%20GNU%20binutils-2.19.1/binutils-2.19.1-mingw32-bin.tar.gz;
-          sha256 = "037vh2n9iv2vccvplk48vd3al91p7yhc73p5nkfsrb6sg977shj2";
-        };
-    };
-
-  mingwRuntimeBin = {stdenv, fetchurl} :
-    stdenv.mkDerivation {
-      name = "mingwrt-3.16";
-      builder = ./bin-builder.sh;
-      src = 
-        fetchurl {
-          url = http://surfnet.dl.sourceforge.net/sourceforge/mingw/files/MinGW%20Runtime/mingwrt-3.16/mingwrt-3.16-mingw32-dev.tar.gz;
-          sha256 = "1xqpp7lvsj88grs6jlk0fnlkvis2y4avcqrpwsaxxrpjlg5bwzci";
-        };
-    };
-
-  mingwRuntimeSrc = {stdenv, fetchurl} :
-    stdenv.mkDerivation {
-      name = "mingwrt-3.16-mingw32";
-      builder = ./src-builder.sh;
-      src =
-        fetchurl {
-          url = http://surfnet.dl.sourceforge.net/sourceforge/mingw/files/MinGW%20Runtime/mingwrt-3.16/mingwrt-3.16-mingw32-src.tar.gz;
-          sha256 = "0rljw3v94z9wzfa63b7lvyprms5l5jgf11lws8vm8z7x7q7h1k38";
-        };
-    };
-
-  w32apiBin = {stdenv, fetchurl} :
-    stdenv.mkDerivation {
-      name = "w32api-3.13-mingw32";
-      builder = ./bin-builder.sh;
-      src = 
-        fetchurl {
-          url = http://surfnet.dl.sourceforge.net/sourceforge/mingw/files/MinGW%20API%20for%20MS-Windows/Current%20Release_%20w32api-3.13/w32api-3.13-mingw32-dev.tar.gz;
-          sha256 = "19jm2hdym5ixi9b874xmmilixlpxvfdpi5y3bx0bs88fdah03gvx";
-        };
-    };
-
-  w32apiSrc = {stdenv, fetchurl} :
-    stdenv.mkDerivation {
-      name = "w32api-3.13-mingw32";
-      builder = ./src-builder.sh;
-      src = 
-        fetchurl {
-          url = http://surfnet.dl.sourceforge.net/sourceforge/mingw/files/MinGW%20API%20for%20MS-Windows/Current%20Release_%20w32api-3.13/w32api-3.13-mingw32-src.tar.gz;
-          sha256 = "1i1gpwilfc21s3yr4sx39i0w4g7lbij427wwxa34gjfgz0awdkh2";
-        };
-    };
-
-  /**
-   * We need a binary pkg-config to bootstrap the compilation of
-   * glib and pkg-config: pkg-config needs glib, glib needs pkg-config.
-   *
-   * This tarball contains pkg-config and all its dependencies. Once we
-   * have bootstrapped pkg-config we really need to use a statically linked
-   * pkg-config (and provide this .exe at the web: it is really missing
-   * on the web).
-   */
-  pkgconfigBin =  {stdenv, fetchurl} :
-    stdenv.mkDerivation {
-      name = "pkgconfig-0.23";
-      builder = ./pkgconfig-builder.sh;
-      setupHook = ../../../development/tools/misc/pkgconfig/setup-hook.sh;
-      src =
-        fetchurl {
-          url = ftp://ftp.strategoxt.org/pub/mingw/pkg-config-0.23.tar.gz;
-          sha256 = "1vab3rdnw16nhma1bln41bbrn6phbpcv9wiz79map8y5znaiv6mq";
-        };
-    };
-
-  replace = {stdenv, fetchurl} :
-    import ../../../tools/text/replace {
-      inherit fetchurl stdenv;
-    };
-
-  /*
-  pkgs.coreutils
-  pkgs.findutils
-  pkgs.diffutils
-  pkgs.gnused
-  pkgs.gnugrep
-  pkgs.gawk
-  pkgs.gnutar
-  pkgs.gzip
-  pkgs.bzip2
-  pkgs.gnumake
-  pkgs.bash
-  pkgs.patch
-  */
-}
diff --git a/pkgs/stdenv/mingw/pkgs/pkgconfig-builder.sh b/pkgs/stdenv/mingw/pkgs/pkgconfig-builder.sh
deleted file mode 100644
index c7f456951e3..00000000000
--- a/pkgs/stdenv/mingw/pkgs/pkgconfig-builder.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-source $STDENV/setup
-
-mkdir $OUT
-cd $OUT
-tar zxvf $SRC
-
-test -x $OUT/nix-support || mkdir $OUT/nix-support
-cp $SETUPHOOK $OUT/nix-support/setup-hook
diff --git a/pkgs/stdenv/mingw/pkgs/single-exe-builder.sh b/pkgs/stdenv/mingw/pkgs/single-exe-builder.sh
deleted file mode 100644
index 660f8175afc..00000000000
--- a/pkgs/stdenv/mingw/pkgs/single-exe-builder.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-if test -z "$out"; then
-  stdenv=$STDENV
-  out=$OUT
-  src=$SRC
-  exename=$EXENAME
-fi
-
-source $stdenv/setup
-
-mkdir $out
-mkdir $out/bin
-cp $src $out/bin/$exename
diff --git a/pkgs/stdenv/mingw/pkgs/src-builder.sh b/pkgs/stdenv/mingw/pkgs/src-builder.sh
deleted file mode 100644
index 09dbb152772..00000000000
--- a/pkgs/stdenv/mingw/pkgs/src-builder.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-source $STDENV/setup
-
-tar zxvf $SRC
-cd $NAME
-./configure --prefix=$OUT
-make
-make install
diff --git a/pkgs/stdenv/mingw/setup.sh b/pkgs/stdenv/mingw/setup.sh
deleted file mode 100755
index c757eb7ae54..00000000000
--- a/pkgs/stdenv/mingw/setup.sh
+++ /dev/null
@@ -1,759 +0,0 @@
-# Run the named hook, either by calling the function with that name or
-# by evaluating the variable with that name.  This allows convenient
-# setting of hooks both from Nix expressions (as attributes /
-# environment variables) and from shell scripts (as functions). 
-runHook() {
-    local hookName="$1"
-    if test "$(type -t $hookName)" = function; then
-        $hookName
-    else
-        eval "${!hookName}"
-    fi
-}
-
-
-exitHandler() {
-    exitCode=$?
-    set +e
-
-    closeNest
-
-    if test -n "$showBuildStats"; then
-        times > "$NIX_BUILD_TOP/.times"
-        local -a times=($(cat "$NIX_BUILD_TOP/.times"))
-        # Print the following statistics:
-        # - user time for the shell
-        # - system time for the shell
-        # - user time for all child processes
-        # - system time for all child processes
-        echo "build time elapsed: " ${times[*]}
-    fi
-    
-    if test $exitCode != 0; then
-        runHook failureHook
-    
-        # If the builder had a non-zero exit code and
-        # $succeedOnFailure is set, create the file
-        # `$out/nix-support/failed' to signal failure, and exit
-        # normally.  Otherwise, return the original exit code.
-        if test -n "$succeedOnFailure"; then
-            echo "build failed with exit code $exitCode (ignored)"
-            mkdir -p "$out/nix-support"
-            echo -n $exitCode > "$out/nix-support/failed"
-            exit 0
-        fi
-        
-    else
-        runHook exitHook
-    fi
-    
-    exit $exitCode
-}
-
-trap "exitHandler" EXIT
-
-
-######################################################################
-# Helper functions that might be useful in setup hooks.
-
-
-addToSearchPathWithCustomDelimiter() {
-    local delimiter=$1
-    local varName=$2
-    local dir=$3
-    if [ -d "$dir" ]; then
-        eval export ${varName}=${!varName}${!varName:+$delimiter}${dir}
-    fi
-}
-
-PATH_DELIMITER=':'
-
-addToSearchPath() {
-    addToSearchPathWithCustomDelimiter "${PATH_DELIMITER}" "$@"
-}
-
-
-######################################################################
-# Initialisation.
-
-set -e
-
-test -z $NIX_GCC && NIX_GCC=@GCC@
-
-
-# Wildcard expansions that don't match should expand to an empty list.
-# This ensures that, for instance, "for i in *; do ...; done" does the
-# right thing.
-shopt -s nullglob
-
-
-# Set up the initial path.
-PATH=
-for i in $NIX_GCC @INITIALPATH@; do
-    if test "$i" = /; then i=; fi
-    addToSearchPath PATH $i/bin
-done
-
-# Hack: the /tmp of Cygwin is different from the /tmp in MSYS
-if test -d $NIX_BUILD_TOP; then
-  echo "Nix build top already exists. Strange."
-else
-  mkdir $NIX_BUILD_TOP
-  cd $NIX_BUILD_TOP
-fi
-
-if test "$NIX_DEBUG" = "1"; then
-    echo "initial path: $PATH"
-fi
-
-
-# Execute the pre-hook.
-export SHELL=@SHELL@
-if test -z "$shell"; then
-    export shell=@SHELL@
-fi
-
-# Check that the pre-hook initialised SHELL.
-if test -z "$SHELL"; then echo "SHELL not set"; exit 1; fi
-
-
-# Hack: run gcc's setup hook.
-envHooks=()
-if test -f $NIX_GCC/nix-support/setup-hook; then
-    source $NIX_GCC/nix-support/setup-hook
-fi
-
-
-# Ensure that the given directories exists.
-ensureDir() {
-    local dir
-    for dir in "$@"; do
-        if ! test -x "$dir"; then mkdir -p "$dir"; fi
-    done
-}
-
-installBin() {
-    mkdir -p $out/bin
-    cp "$@" $out/bin
-}
-
-
-# Allow the caller to augment buildInputs (it's not always possible to
-# do this before the call to setup.sh, since the PATH is empty at that
-# point; here we have a basic Unix environment).
-runHook addInputsHook
-
-
-# Recursively find all build inputs.
-findInputs() {
-    local pkg=$1
-
-    case $pkgs in
-        *\ $pkg\ *)
-            return 0
-            ;;
-    esac
-
-    pkgs="$pkgs $pkg "
-
-    if test -f $pkg/nix-support/setup-hook; then
-        source $pkg/nix-support/setup-hook
-    fi
-
-    if test -f $pkg/nix-support/propagated-build-inputs; then
-        for i in $(cat $pkg/nix-support/propagated-build-inputs); do
-            findInputs $i
-        done
-    fi
-}
-
-pkgs=""
-for i in $buildInputs $propagatedBuildInputs; do
-    findInputs $i
-done
-
-
-# Set the relevant environment variables to point to the build inputs
-# found above.
-addToEnv() {
-    local pkg=$1
-
-    if test -d $1/bin; then
-        addToSearchPath _PATH $1/bin
-    fi
-
-    # Run the package-specific hooks set by the setup-hook scripts.
-    for i in "${envHooks[@]}"; do
-        $i $pkg
-    done
-}
-
-for i in $pkgs; do
-    addToEnv $i
-done
-
-
-# Add the output as an rpath.
-if test "$NIX_NO_SELF_RPATH" != "1"; then
-    export NIX_LDFLAGS="-rpath $out/lib $NIX_LDFLAGS"
-    if test -n "$NIX_LIB64_IN_SELF_RPATH"; then
-        export NIX_LDFLAGS="-rpath $out/lib64 $NIX_LDFLAGS"
-    fi
-fi
-
-
-# Set the TZ (timezone) environment variable, otherwise commands like
-# `date' will complain (e.g., `Tue Mar 9 10:01:47 Local time zone must
-# be set--see zic manual page 2004').
-export TZ=UTC
-
-
-# Set the prefix.  This is generally $out, but it can be overriden,
-# for instance if we just want to perform a test build/install to a
-# temporary location and write a build report to $out.
-if test -z "$prefix"; then
-    prefix="$out";
-fi
-
-if test "$useTempPrefix" = "1"; then
-    prefix="$NIX_BUILD_TOP/tmp_prefix";
-fi
-
-
-PATH=$_PATH${_PATH:+:}$PATH
-if test "$NIX_DEBUG" = "1"; then
-    echo "final path: $PATH"
-fi
-
-
-# Make GNU Make produce nested output.
-export NIX_INDENT_MAKE=1
-
-
-######################################################################
-# Misc. helper functions.
-
-
-stripDirs() {
-    local dirs="$1"
-    local stripFlags="$2"
-    local dirsNew=
-
-    for d in ${dirs}; do
-        if test -d "$prefix/$d"; then
-            dirsNew="${dirsNew} $prefix/$d "
-        fi
-    done
-    dirs=${dirsNew}
-
-    if test -n "${dirs}"; then
-        header "stripping (with flags $stripFlags) in $dirs"
-        find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $stripFlags || true
-        stopNest
-    fi
-}
-
-
-######################################################################
-# Textual substitution functions.
-
-
-substitute() {
-    local input="$1"
-    local output="$2"
-
-    local -a params=("$@")
-    local -a args=()
-
-    local n p pattern replacement varName
-
-    for ((n = 2; n < ${#params[*]}; n += 1)); do
-        p=${params[$n]}
-
-        if test "$p" = "--replace"; then
-            pattern="${params[$((n + 1))]}"
-            replacement="${params[$((n + 2))]}"
-            n=$((n + 2))
-        fi
-
-        if test "$p" = "--subst-var"; then
-            varName="${params[$((n + 1))]}"
-            pattern="@$varName@"
-            replacement="${!varName}"
-            n=$((n + 1))
-        fi
-
-        if test "$p" = "--subst-var-by"; then
-            pattern="@${params[$((n + 1))]}@"
-            replacement="${params[$((n + 2))]}"
-            n=$((n + 2))
-        fi
-
-        if test ${#args[@]} != 0; then
-            args[${#args[@]}]="-a"
-        fi
-        args[${#args[@]}]="$pattern"
-        args[${#args[@]}]="$replacement"
-    done
-
-    replace-literal -e -s -- "${args[@]}" < "$input" > "$output".tmp
-    if test -x "$output"; then
-        chmod +x "$output".tmp
-    fi
-    mv -f "$output".tmp "$output"
-}
-
-
-substituteInPlace() {
-    local fileName="$1"
-    shift
-    substitute "$fileName" "$fileName" "$@"
-}
-
-
-substituteAll() {
-    local input="$1"
-    local output="$2"
-
-    # Select all environment variables that start with a lowercase character.
-    for envVar in $(env | sed "s/^[^a-z].*//" | sed "s/^\([^=]*\)=.*/\1/"); do
-        if test "$NIX_DEBUG" = "1"; then
-            echo "$envVar -> ${!envVar}"
-        fi
-        args="$args --subst-var $envVar"
-    done
-
-    substitute "$input" "$output" $args
-}
-
-
-######################################################################
-# What follows is the generic builder.
-
-
-nestingLevel=0
-
-startNest() {
-    nestingLevel=$(($nestingLevel + 1))
-    echo -en "\e[$1p"
-}
-
-stopNest() {
-    nestingLevel=$(($nestingLevel - 1))
-    echo -en "\e[q"
-}
-
-header() {
-    startNest "$2"
-    echo "$1"
-}
-
-# Make sure that even when we exit abnormally, the original nesting
-# level is properly restored.
-closeNest() {
-    while test $nestingLevel -gt 0; do
-        stopNest
-    done
-}
-
-
-# This function is useful for debugging broken Nix builds.  It dumps
-# all environment variables to a file `env-vars' in the build
-# directory.  If the build fails and the `-K' option is used, you can
-# then go to the build directory and source in `env-vars' to reproduce
-# the environment used for building.
-dumpVars() {  
-    echo  "Dumping env-vars to $NIX_BUILD_TOP/env-vars"
-    if test "$noDumpEnvVars" != "1"; then
-        export > "$NIX_BUILD_TOP/env-vars"
-    fi
-}
-
-
-# Utility function: return the base name of the given path, with the
-# prefix `HASH-' removed, if present.
-stripHash() {
-    strippedName=$(basename $1);
-    if echo "$strippedName" | grep -q '^[a-z0-9]\{32\}-'; then
-        strippedName=$(echo "$strippedName" | cut -c34-)
-    fi
-}
-
-
-unpackFile() {
-    curSrc="$1"
-    local cmd
-
-    header "unpacking source archive $curSrc" 3
-
-    case "$curSrc" in
-        *.tar)
-            tar xvf $curSrc
-            ;;
-        *.tar.gz | *.tgz | *.tar.Z)
-            gzip -d < $curSrc | tar xvf -
-            ;;
-        *.tar.bz2 | *.tbz2)
-            bzip2 -d < $curSrc | tar xvf -
-            ;;
-        *.zip)
-            unzip $curSrc
-            ;;
-        *)
-            if test -d "$curSrc"; then
-                stripHash $curSrc
-                cp -prvd $curSrc $strippedName
-            else
-                if test -z "$unpackCmd"; then
-                    echo "source archive $curSrc has unknown type"
-                    exit 1
-                fi
-                runHook unpackCmd
-            fi
-            ;;
-    esac
-
-    stopNest
-}
-
-
-unpackPhase() {
-    runHook preUnpack
-    
-    if test -z "$srcs"; then
-        if test -z "$src"; then
-            echo 'variable $src or $srcs should point to the source'
-            exit 1
-        fi
-        srcs="$src"
-    fi
-
-    # To determine the source directory created by unpacking the
-    # source archives, we record the contents of the current
-    # directory, then look below which directory got added.  Yeah,
-    # it's rather hacky.
-    local dirsBefore=""
-    for i in *; do
-        if test -d "$i"; then
-            dirsBefore="$dirsBefore $i "
-        fi
-    done
-
-    # Unpack all source archives.
-    for i in $srcs; do
-        unpackFile $i
-    done
-
-    # Find the source directory.
-    if test -n "$setSourceRoot"; then
-        runHook setSourceRoot
-    elif test -z "$sourceRoot"; then
-        sourceRoot=
-        for i in *; do
-            if test -d "$i"; then
-                case $dirsBefore in
-                    *\ $i\ *)
-                        ;;
-                    *)
-                        if test -n "$sourceRoot"; then
-                            echo "unpacker produced multiple directories"
-                            exit 1
-                        fi
-                        sourceRoot="$i"
-                        ;;
-                esac
-            fi
-        done
-    fi
-
-    if test -z "$sourceRoot"; then
-        echo "unpacker appears to have produced no directories"
-        exit 1
-    fi
-
-    echo "source root is $sourceRoot"
-
-    # By default, add write permission to the sources.  This is often
-    # necessary when sources have been copied from other store
-    # locations.
-    if test "$dontMakeSourcesWritable" != 1; then
-        chmod -R u+w "$sourceRoot"
-    fi
-
-    runHook postUnpack
-}
-
-
-patchPhase() {
-    runHook prePatch
-
-    for i in $patches; do
-        header "applying patch $i" 3
-        local uncompress=cat
-        case $i in
-            *.gz)
-                uncompress="gzip -d"
-                ;;
-            *.bz2)
-                uncompress="bzip2 -d"
-                ;;
-        esac
-        $uncompress < $i | patch ${patchFlags:--p1}
-        stopNest
-    done
-
-    runHook postPatch
-}
-
-
-configurePhase() {
-    runHook preConfigure
-
-    if test -z "$configureScript"; then
-        configureScript=./configure
-        if ! test -x $configureScript; then
-            echo "no configure script, doing nothing"
-            return
-        fi
-    fi
-
-    if test -z "$dontAddPrefix"; then
-        configureFlags="${prefixKey:---prefix=}$prefix $configureFlags"
-    fi
-
-    # Add --disable-dependency-tracking to speed up some builds.
-    if test -z "$dontAddDisableDepTrack"; then
-        if grep -q dependency-tracking $configureScript; then
-            configureFlags="--disable-dependency-tracking $configureFlags"
-        fi
-    fi
-
-    # By default, disable static builds.
-    if test -z "$dontDisableStatic"; then
-        if grep -q enable-static $configureScript; then
-            configureFlags="--disable-static $configureFlags"
-        fi
-    fi
-
-    echo "configure flags: $configureFlags ${configureFlagsArray[@]}"
-    $configureScript $configureFlags "${configureFlagsArray[@]}"
-
-    runHook postConfigure
-}
-
-
-buildPhase() {
-    runHook preBuild
-
-    if test -z "$makeFlags" && ! test -n "$makefile" -o -e "Makefile" -o -e "makefile" -o -e "GNUmakefile"; then
-        echo "no Makefile, doing nothing"
-        return
-    fi
-
-    echo "make flags: $makeFlags ${makeFlagsArray[@]} $buildFlags ${buildFlagsArray[@]}"
-    make ${makefile:+-f $makefile} \
-        $makeFlags "${makeFlagsArray[@]}" \
-        $buildFlags "${buildFlagsArray[@]}"
-
-    runHook postBuild
-}
-
-
-checkPhase() {
-    runHook preCheck
-
-    echo "check flags: $makeFlags ${makeFlagsArray[@]} $checkFlags ${checkFlagsArray[@]}"
-    make ${makefile:+-f $makefile} \
-        $makeFlags "${makeFlagsArray[@]}" \
-        $checkFlags "${checkFlagsArray[@]}" ${checkTarget:-check}
-
-    runHook postCheck
-}
-
-
-patchELF() {
-    # Patch all ELF executables and shared libraries.
-    header "patching ELF executables and libraries"
-    if test -e "$prefix"; then
-        find "$prefix" \( \
-            \( -type f -a -name "*.so*" \) -o \
-            \( -type f -a -perm +0100 \) \
-            \) -print -exec patchelf --shrink-rpath {} \;
-    fi
-    stopNest
-}
-
-
-patchShebangs() {
-    # Rewrite all script interpreter file names (`#! /path') under the
-    # specified  directory tree to paths found in $PATH.  E.g.,
-    # /bin/sh will be rewritten to /nix/store/<hash>-some-bash/bin/sh.
-    # Interpreters that are already in the store are left untouched.
-    header "patching script interpreter paths"
-    local dir="$1"
-    local f
-    for f in $(find "$dir" -type f -perm +0100); do
-        local oldPath=$(sed -ne '1 s,^#![ ]*\([^ ]*\).*$,\1,p' "$f")
-        if test -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE"; then
-            local newPath=$(type -P $(basename $oldPath) || true)
-            if test -n "$newPath" -a "$newPath" != "$oldPath"; then
-                echo "$f: interpreter changed from $oldPath to $newPath"
-                sed -i -e "1 s,$oldPath,$newPath," "$f"
-            fi
-        fi
-    done
-    stopNest
-}
-
-
-installPhase() {
-    runHook preInstall
-
-    mkdir -p "$prefix"
-
-    installTargets=${installTargets:-install}
-    echo "install flags: $installTargets $makeFlags ${makeFlagsArray[@]} $installFlags ${installFlagsArray[@]}"
-    make ${makefile:+-f $makefile} $installTargets \
-        $makeFlags "${makeFlagsArray[@]}" \
-        $installFlags "${installFlagsArray[@]}"
-
-    runHook postInstall
-}
-
-
-# The fixup phase performs generic, package-independent, Nix-related
-# stuff, like running patchelf and setting the
-# propagated-build-inputs.  It should rarely be overriden.
-fixupPhase() {
-    runHook preFixup
-
-    # Put man/doc/info under $out/share.
-    forceShare=${forceShare:=man doc info}
-    if test -n "$forceShare"; then
-        for d in $forceShare; do
-            if test -d "$prefix/$d"; then
-                if test -d "$prefix/share/$d"; then
-                    echo "both $d/ and share/$d/ exists!"
-                else
-                    echo "fixing location of $d/ subdirectory"
-                    mkdir -p $prefix/share
-                    if test -w $prefix/share; then
-                        mv -v $prefix/$d $prefix/share
-                        ln -sv $prefix/share/$d $prefix/$d
-                    fi
-                fi
-            fi
-        done;
-    fi
-
-    # TODO: strip _only_ ELF executables, and return || fail here...
-    if test -z "$dontStrip"; then
-        stripDebugList=${stripDebugList:-lib lib64 libexec bin sbin}
-        if test -n "$stripDebugList"; then
-            stripDirs "$stripDebugList" "${stripDebugFlags:--S}"
-        fi
-        
-        stripAllList=${stripAllList:-}
-        if test -n "$stripAllList"; then
-            stripDirs "$stripAllList" "${stripAllFlags:--s}"
-        fi
-    fi
-
-    if test "$havePatchELF" = 1 -a -z "$dontPatchELF"; then
-        patchELF "$prefix"
-    fi
-
-    if test -z "$dontPatchShebangs"; then
-        patchShebangs "$prefix"
-    fi
-
-    if test -n "$propagatedBuildInputs"; then
-        mkdir -p "$out/nix-support"
-        echo "$propagatedBuildInputs" > "$out/nix-support/propagated-build-inputs"
-    fi
-
-    if test -n "$setupHook"; then
-        mkdir -p "$out/nix-support"
-        substituteAll "$setupHook" "$out/nix-support/setup-hook"
-    fi
-
-    runHook postFixup
-}
-
-
-distPhase() {
-    runHook preDist
-
-    echo "dist flags: $distFlags ${distFlagsArray[@]}"
-    make ${makefile:+-f $makefile} $distFlags "${distFlagsArray[@]}" ${distTarget:-dist}
-
-    if test "$dontCopyDist" != 1; then
-        mkdir -p "$out/tarballs"
-
-        # Note: don't quote $tarballs, since we explicitly permit
-        # wildcards in there.
-        cp -pvd ${tarballs:-*.tar.gz} $out/tarballs
-    fi
-
-    runHook postDist
-}
-
-
-showPhaseHeader() {
-    local phase="$1"
-    case $phase in
-        unpackPhase) header "unpacking sources";;
-        patchPhase) header "patching sources";;
-        configurePhase) header "configuring";;
-        buildPhase) header "building";;
-        checkPhase) header "running tests";;
-        installPhase) header "installing";;
-        fixupPhase) header "post-installation fixup";;
-        *) header "$phase";;
-    esac
-}
-
-
-genericBuild() {
-    header "building $out"
-
-    if test -n "$buildCommand"; then
-        eval "$buildCommand"
-        return
-    fi
-
-    if test -z "$phases"; then
-        phases="$prePhases unpackPhase patchPhase $preConfigurePhases \
-            configurePhase $preBuildPhases buildPhase checkPhase \
-            $preInstallPhases installPhase $preFixupPhases fixupPhase \
-            $preDistPhases distPhase $postPhases";
-    fi
-
-    for curPhase in $phases; do
-        if test "$curPhase" = buildPhase -a -n "$dontBuild"; then continue; fi
-        if test "$curPhase" = checkPhase -a -z "$doCheck"; then continue; fi
-        if test "$curPhase" = installPhase -a -n "$dontInstall"; then continue; fi
-        if test "$curPhase" = fixupPhase -a -n "$dontFixup"; then continue; fi
-        if test "$curPhase" = distPhase -a -z "$doDist"; then continue; fi
-        
-        showPhaseHeader "$curPhase"
-        dumpVars
-        
-        # Evaluate the variable named $curPhase if it exists, otherwise the
-        # function named $curPhase.
-        eval "${!curPhase:-$curPhase}"
-
-        if test "$curPhase" = unpackPhase; then
-            cd "${sourceRoot:-.}"
-        fi
-        
-        stopNest
-    done
-
-    stopNest
-}
-
-
-
-
-dumpVars
diff --git a/pkgs/stdenv/mingw/simple-stdenv/builder.sh b/pkgs/stdenv/mingw/simple-stdenv/builder.sh
deleted file mode 100644
index 0cbc13e4fab..00000000000
--- a/pkgs/stdenv/mingw/simple-stdenv/builder.sh
+++ /dev/null
@@ -1,80 +0,0 @@
-if test -z "$out"; then
-  out="$OUT"
-  initialPath="$INITIALPATH"
-  shell="$SHELL"
-fi
-
-setupPath=
-for i in $initialPath; do
-  setupPath=$setupPath${setupPath:+:}$i
-done
-
-PATH=$setupPath
-export PATH
-
-mkdir $out
-
-cat > $out/setup <<EOF
-PATH=$setupPath
-export PATH
-
-SHELL=$shell
-export SHELL
-
-# make fetchurl usable
-header() {
-  echo "\$1"
-}
-
-stopNest() {
-  echo "Nothing to do"
-}
-
-# !!! Awful copy&paste.
-substitute() {
-    local input="\$1"
-    local output="\$2"
-
-    local -a params=("\$@")
-
-    local sedScript=\$NIX_BUILD_TOP/.sedargs
-    rm -f \$sedScript
-    touch \$sedScript
-
-    local n p pattern replacement varName
-    
-    for ((n = 2; n < \${#params[*]}; n += 1)); do
-        p=\${params[\$n]}
-
-        if test "\$p" = "--replace"; then
-            pattern=\${params[\$((n + 1))]}
-            replacement=\${params[\$((n + 2))]}
-            n=\$((n + 2))
-            echo "s^\$pattern^\$replacement^g" >> \$sedScript
-            sedArgs=("\${sedArgs[@]}" "-e" )
-        fi
-
-        if test "\$p" = "--subst-var"; then
-            varName=\${params[\$((n + 1))]}
-            n=\$((n + 1))
-            echo "s^@\${varName}@^\${!varName}^g" >> \$sedScript
-        fi
-
-        if test "\$p" = "--subst-var-by"; then
-            varName=\${params[\$((n + 1))]}
-            replacement=\${params[\$((n + 2))]}
-            n=\$((n + 2))
-            echo "s^@\${varName}@^\$replacement^g" >> \$sedScript
-        fi
-
-    done
-
-    sed -f \$sedScript < "\$input" > "\$output".tmp
-    if test -x "\$output"; then
-        chmod +x "\$output".tmp
-    fi
-    mv -f "\$output".tmp "\$output"
-}
-EOF
-
-chmod +x $out/setup
diff --git a/pkgs/stdenv/mingw/simple-stdenv/default.nix b/pkgs/stdenv/mingw/simple-stdenv/default.nix
deleted file mode 100644
index 379cda0a598..00000000000
--- a/pkgs/stdenv/mingw/simple-stdenv/default.nix
+++ /dev/null
@@ -1,31 +0,0 @@
-{ system
-, name
-, shell
-, path
-, extraEnv ? {}
-, extraShellOptions ? []
-}:
-
-let {
-  body = 
-    derivation ({
-      inherit system name;
-      initialPath = path;
-      builder = shell;
-      args = extraShellOptions ++ ["-e" ./builder.sh];
-    } // extraEnv)
-
-    // {
-      mkDerivation = attrs:
-        derivation ((removeAttrs attrs ["meta"]) // {
-          builder = shell;
-          args = extraShellOptions ++ ["-e" ] ++ [attrs.builder]; # (if attrs ? builder then [attrs.builder] else [ ../fix-builder.sh ../default-builder.sh] ) ;
-          stdenv = body;
-          system = body.system;
-        }
-
-        // extraEnv);
-
-      inherit shell;
-    };
-}
diff --git a/pkgs/stdenv/nix/default.nix b/pkgs/stdenv/nix/default.nix
index 78e5b84a841..a496a819a6d 100644
--- a/pkgs/stdenv/nix/default.nix
+++ b/pkgs/stdenv/nix/default.nix
@@ -7,16 +7,18 @@ import ../generic rec {
     ''
       export NIX_ENFORCE_PURITY=1
       export NIX_IGNORE_LD_THROUGH_GCC=1
-
-      if [ "$system" = "i686-darwin" -o "$system" = "powerpc-darwin" -o "$system" = "x86_64-darwin" ]; then
-        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=" "
-      fi
-    '';
+    '' + (if stdenv.isDarwin then ''
+      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"
+    '' else "");
 
   initialPath = (import ../common-path.nix) {pkgs = pkgs;};
 
diff --git a/pkgs/tools/backup/store-backup/default.nix b/pkgs/tools/backup/store-backup/default.nix
index e9b98fec710..c986adeafdc 100644
--- a/pkgs/tools/backup/store-backup/default.nix
+++ b/pkgs/tools/backup/store-backup/default.nix
@@ -26,7 +26,7 @@ stdenv.mkDerivation {
   };
 
   installPhase = ''
-    ensureDir $out/scripts
+    mkdir -p $out/scripts
     mv * $out
     mv $out/_ATTENTION_ $out/doc
     mv $out/{correct.sh,cron-storebackup} $out/scripts
diff --git a/pkgs/tools/filesystems/unionfs-fuse/default.nix b/pkgs/tools/filesystems/unionfs-fuse/default.nix
index bff5aaf242b..23340f88376 100644
--- a/pkgs/tools/filesystems/unionfs-fuse/default.nix
+++ b/pkgs/tools/filesystems/unionfs-fuse/default.nix
@@ -25,7 +25,7 @@ stdenv.mkDerivation rec {
   # This must be done in preConfigure because the build process removes
   # helper from the source directory during the build.
   preConfigure = ''
-    ensureDir $out/sbin
+    mkdir -p $out/sbin
     cp -a mount.unionfs $out/sbin/mount.unionfs-fuse
     substituteInPlace $out/sbin/mount.unionfs-fuse --replace mount.fuse ${fuse}/sbin/mount.fuse
     substituteInPlace $out/sbin/mount.unionfs-fuse --replace unionfs $out/bin/unionfs
diff --git a/pkgs/tools/misc/debootstrap/default.nix b/pkgs/tools/misc/debootstrap/default.nix
index d37febcf506..16b1858e91d 100644
--- a/pkgs/tools/misc/debootstrap/default.nix
+++ b/pkgs/tools/misc/debootstrap/default.nix
@@ -20,7 +20,7 @@ let
     ];
     # TODO install man
     installPhase = ''
-      ensureDir $out/sbin
+      mkdir -p $out/sbin
       ls -l
       t=$out/sbin/MAKEDEV
       cp MAKEDEV $t
@@ -78,7 +78,7 @@ stdenv.mkDerivation {
       functions
 
     d=$out/share/debootstrap
-    ensureDir $out/{share/debootstrap,bin}
+    mkdir -p $out/{share/debootstrap,bin}
 
     ${fakeroot}/bin/fakeroot -- make devices.tar.gz MAKEDEV=${makedev}/sbin/MAKEDEV
 
@@ -94,7 +94,7 @@ stdenv.mkDerivation {
     EOF
     chmod +x $out/bin/debootstrap
 
-    ensureDir $out/man/man8
+    mkdir -p $out/man/man8
     mv debootstrap.8 $out/man/man8
   '';
 
diff --git a/pkgs/tools/misc/logstash/default.nix b/pkgs/tools/misc/logstash/default.nix
index 15c99fff54c..7f43ccdb625 100644
--- a/pkgs/tools/misc/logstash/default.nix
+++ b/pkgs/tools/misc/logstash/default.nix
@@ -15,11 +15,11 @@ stdenv.mkDerivation rec {
   dontPatchShebangs = true;
 
   installPhase = ''
-    ensureDir $out/bin
-    ensureDir $out/vendor
-    ensureDir $out/lib
-    ensureDir $out/locales
-    ensureDir $out/patterns
+    mkdir -p $out/bin
+    mkdir -p $out/vendor
+    mkdir -p $out/lib
+    mkdir -p $out/locales
+    mkdir -p $out/patterns
     cp -a bin $out
     cp -a vendor $out
     cp -a lib $out
diff --git a/pkgs/tools/misc/megacli/default.nix b/pkgs/tools/misc/megacli/default.nix
index 82650999b73..7fd6ce966d6 100644
--- a/pkgs/tools/misc/megacli/default.nix
+++ b/pkgs/tools/misc/megacli/default.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation rec {
        [ stdenv.gcc.gcc stdenv.gcc.libc ncurses ];
 
   buildCommand = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cd $out
     unzip ${src}
     rpm2cpio linux/MegaCli-8.07.07-1.noarch.rpm | cpio -idmv
diff --git a/pkgs/tools/misc/multitail/default.nix b/pkgs/tools/misc/multitail/default.nix
index a81df014f0d..f3f90143bda 100644
--- a/pkgs/tools/misc/multitail/default.nix
+++ b/pkgs/tools/misc/multitail/default.nix
@@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
   makeFlags = stdenv.lib.optionalString stdenv.isDarwin "-f makefile.macosx";
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp multitail $out/bin
   '';
 
diff --git a/pkgs/tools/misc/picocom/default.nix b/pkgs/tools/misc/picocom/default.nix
index 6b4a0e3018f..303fdb3dbe0 100644
--- a/pkgs/tools/misc/picocom/default.nix
+++ b/pkgs/tools/misc/picocom/default.nix
@@ -11,7 +11,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ makeWrapper ];
 
   installPhase = ''
-    ensureDir $out/bin $out/share/man/man8
+    mkdir -p $out/bin $out/share/man/man8
     cp picocom $out/bin
     cp picocom.8 $out/share/man/man8
 
diff --git a/pkgs/tools/misc/rkflashtool/default.nix b/pkgs/tools/misc/rkflashtool/default.nix
index c985183c1c0..6b74f9ac5d3 100644
--- a/pkgs/tools/misc/rkflashtool/default.nix
+++ b/pkgs/tools/misc/rkflashtool/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp rkunpack rkcrc rkflashtool $out/bin
   '';
 
diff --git a/pkgs/tools/misc/sl/default.nix b/pkgs/tools/misc/sl/default.nix
index 7880b3e883f..a2dab4e0eb8 100644
--- a/pkgs/tools/misc/sl/default.nix
+++ b/pkgs/tools/misc/sl/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation {
   buildInputs = [ ncurses ];
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp sl $out/bin
   '';
 
diff --git a/pkgs/tools/networking/connect/default.nix b/pkgs/tools/networking/connect/default.nix
index c6291efad31..8723c53c322 100644
--- a/pkgs/tools/networking/connect/default.nix
+++ b/pkgs/tools/networking/connect/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   '';
 
   buildPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     gcc -o $out/bin/connect connect.c
   '';
 
diff --git a/pkgs/tools/networking/filegive/default.nix b/pkgs/tools/networking/filegive/default.nix
index 35cd6676132..d7d867cc8df 100644
--- a/pkgs/tools/networking/filegive/default.nix
+++ b/pkgs/tools/networking/filegive/default.nix
@@ -35,7 +35,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp filegive $out/bin
   '';
 
diff --git a/pkgs/tools/networking/reaver-wps/default.nix b/pkgs/tools/networking/reaver-wps/default.nix
index 0c290db78a7..afce95fbd44 100644
--- a/pkgs/tools/networking/reaver-wps/default.nix
+++ b/pkgs/tools/networking/reaver-wps/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   '';
 
   preInstall = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
   '';
 
   meta = {
diff --git a/pkgs/tools/networking/udptunnel/default.nix b/pkgs/tools/networking/udptunnel/default.nix
index 36fdbfac723..b12ce573d1c 100644
--- a/pkgs/tools/networking/udptunnel/default.nix
+++ b/pkgs/tools/networking/udptunnel/default.nix
@@ -9,7 +9,7 @@ stdenv.mkDerivation {
   };
 
   installPhase = ''
-    ensureDir $out/bin $out/share/udptunnel
+    mkdir -p $out/bin $out/share/udptunnel
     cp udptunnel $out/bin
     cp README COPYING* $out/share/udptunnel
   '';
diff --git a/pkgs/tools/security/fprot/default.nix b/pkgs/tools/security/fprot/default.nix
index 2a8531a1795..b43ea402f6d 100644
--- a/pkgs/tools/security/fprot/default.nix
+++ b/pkgs/tools/security/fprot/default.nix
@@ -11,10 +11,10 @@ stdenv.mkDerivation rec {
   };
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp fpscan $out/bin
 
-    ensureDir $out/opt/f-prot
+    mkdir -p $out/opt/f-prot
     cp fpupdate $out/opt/f-prot
     cp product.data.default $out/opt/f-prot/product.data
     cp license.key $out/opt/f-prot/
@@ -23,12 +23,12 @@ stdenv.mkDerivation rec {
 
     patchelf --interpreter "$(cat $NIX_GCC/nix-support/dynamic-linker)" $out/opt/f-prot/fpupdate
 
-    ensureDir $out/share/man/
-    ensureDir $out/share/man/man1
+    mkdir -p $out/share/man/
+    mkdir -p $out/share/man/man1
     cp doc/man/fpscan.1 $out/share/man/man1
-    ensureDir $out/share/man/man5
+    mkdir -p $out/share/man/man5
     cp doc/man/f-prot.conf.5 $out/share/man/man5
-    ensureDir $out/share/man/man8
+    mkdir -p $out/share/man/man8
     cp doc/man/fpupdate.8 $out/share/man/man8
   '';
 
diff --git a/pkgs/tools/security/meo/default.nix b/pkgs/tools/security/meo/default.nix
index 0a96dbadff7..be678b18dda 100644
--- a/pkgs/tools/security/meo/default.nix
+++ b/pkgs/tools/security/meo/default.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp tools/{meo,p11} $out/bin
     cp meo-gui/meo-gui $out/bin
     cp meo-gui/meo-gui $out/bin
diff --git a/pkgs/tools/security/tor/torbrowser.nix b/pkgs/tools/security/tor/torbrowser.nix
index 7be7c79888e..f220a46bddc 100644
--- a/pkgs/tools/security/tor/torbrowser.nix
+++ b/pkgs/tools/security/tor/torbrowser.nix
@@ -45,8 +45,8 @@ in stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/share/tor-browser
-    ensureDir $out/bin
+    mkdir -p $out/share/tor-browser
+    mkdir -p $out/bin
     cp -R * $out/share/tor-browser
 
     cat > "$out/bin/tor-browser" << EOF
diff --git a/pkgs/tools/system/storebrowse/default.nix b/pkgs/tools/system/storebrowse/default.nix
index dc30c601750..041dd96e1ca 100644
--- a/pkgs/tools/system/storebrowse/default.nix
+++ b/pkgs/tools/system/storebrowse/default.nix
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp storebrowse $out/bin
   '';
 
diff --git a/pkgs/tools/system/vboot_reference/default.nix b/pkgs/tools/system/vboot_reference/default.nix
index e1c4734bbda..087a3212fc2 100644
--- a/pkgs/tools/system/vboot_reference/default.nix
+++ b/pkgs/tools/system/vboot_reference/default.nix
@@ -31,7 +31,7 @@ stdenv.mkDerivation rec {
   '';
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp build/cgpt/cgpt $out/bin
     cp build/utility/vbutil_kernel $out/bin
     cp build/utility/vbutil_key $out/bin
diff --git a/pkgs/tools/text/enscript/default.nix b/pkgs/tools/text/enscript/default.nix
index df49e5788eb..fe11ec59246 100644
--- a/pkgs/tools/text/enscript/default.nix
+++ b/pkgs/tools/text/enscript/default.nix
@@ -8,6 +8,13 @@ stdenv.mkDerivation rec {
     sha256 = "1fy0ymvzrrvs889zanxcaxjfcxarm2d3k43c9frmbl1ld7dblmkd";
   };
 
+  preBuild =
+    ''
+      # Fix building on Darwin with GCC.
+      substituteInPlace compat/regex.c --replace \
+         __private_extern__  '__attribute__ ((visibility ("hidden")))'
+    '';
+
   buildInputs = [ gettext ];
 
   doCheck = true;
diff --git a/pkgs/tools/text/gawk/default.nix b/pkgs/tools/text/gawk/default.nix
index e8c5472d2cb..8866888a736 100644
--- a/pkgs/tools/text/gawk/default.nix
+++ b/pkgs/tools/text/gawk/default.nix
@@ -8,8 +8,6 @@ stdenv.mkDerivation rec {
     sha256 = "0hin2hswbbd6kd6i4zzvgciwpl5fba8d2s524z8y5qagyz3x010q";
   };
 
-  patches = [];
-
   doCheck = !stdenv.isCygwin; # XXX: `test-dup2' segfaults on Cygwin 6.1
 
   buildInputs = [ libsigsegv ]
@@ -20,6 +18,8 @@ stdenv.mkDerivation rec {
       # only darwin where reported, seems OK on non-chrooted Fedora (don't rebuild stdenv)
     ++ stdenv.lib.optional (!readlineSupport && stdenv.isDarwin) "--without-readline";
 
+  postInstall = "rm $out/bin/gawk-*";
+
   meta = {
     homepage = http://www.gnu.org/software/gawk/;
     description = "GNU implementation of the Awk programming language";
diff --git a/pkgs/tools/typesetting/djvu2pdf/default.nix b/pkgs/tools/typesetting/djvu2pdf/default.nix
index c7729ac676f..5455df5f106 100644
--- a/pkgs/tools/typesetting/djvu2pdf/default.nix
+++ b/pkgs/tools/typesetting/djvu2pdf/default.nix
@@ -13,9 +13,9 @@ stdenv.mkDerivation rec {
   propagatedUserEnvPkgs = [ djvulibre ghostscript ];
 
   installPhase = ''
-    ensureDir $out/bin
+    mkdir -p $out/bin
     cp -p djvu2pdf $out/bin
-    ensureDir $out/man/man1
+    mkdir -p $out/man/man1
     cp -p djvu2pdf.1.gz $out/man/man1
   '';
 
diff --git a/pkgs/tools/typesetting/tex/pgfplots/default.nix b/pkgs/tools/typesetting/tex/pgfplots/default.nix
index bc47244a5fa..67739350c6f 100644
--- a/pkgs/tools/typesetting/tex/pgfplots/default.nix
+++ b/pkgs/tools/typesetting/tex/pgfplots/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation {
   buildPhase = "true";
   
   installPhase = "
-    ensureDir $out/share/texmf-nix
+    mkdir -p $out/share/texmf-nix
     cp -prd * $out/share/texmf-nix
   ";
 }
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 30f7acb9360..3e77a1231bf 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -8,15 +8,6 @@
 { # The system (e.g., `i686-linux') for which to build the packages.
   system ? builtins.currentSystem
 
-  # Usually, the system type uniquely determines the stdenv and thus
-  # how to build the packages.  But on some platforms we have
-  # different stdenvs, leading to different ways to build the
-  # packages.  For instance, on Windows we support both Cygwin and
-  # Mingw builds.  In both cases, `system' is `i686-cygwin'.  The
-  # attribute `stdenvType' is used to select the specific kind of
-  # stdenv to use, e.g., `i686-mingw'.
-, stdenvType ? system
-
 , # The standard environment to use.  Only used for bootstrapping.  If
   # null, the default standard environment is used.
   bootStdenv ? null
@@ -137,7 +128,7 @@ let
     self_ = with self; helperFunctions // {
 
   # Make some arguments passed to all-packages.nix available
-  inherit system stdenvType platform;
+  inherit system platform;
 
   # Allow callPackage to fill in the pkgs argument
   inherit pkgs;
@@ -214,7 +205,7 @@ let
 
 
   allStdenvs = import ../stdenv {
-    inherit system stdenvType platform config;
+    inherit system platform config;
     allPackages = args: import ./all-packages.nix ({ inherit config system; } // args);
   };
 
@@ -977,12 +968,7 @@ let
 
   encfs = callPackage ../tools/filesystems/encfs { };
 
-  enscript = callPackage ../tools/text/enscript {
-    # fix syntax errors
-    stdenv = if stdenv.isDarwin
-      then clangStdenv
-      else stdenv;
-  };
+  enscript = callPackage ../tools/text/enscript { };
 
   ethtool = callPackage ../tools/misc/ethtool { };
 
@@ -4266,15 +4252,15 @@ let
 
   attr = callPackage ../development/libraries/attr { };
 
+  at_spi2_core = callPackage ../development/libraries/at-spi2-core { };
+
+  at_spi2_atk = callPackage ../development/libraries/at-spi2-atk { };
+
   aqbanking = callPackage ../development/libraries/aqbanking { };
 
   aubio = callPackage ../development/libraries/aubio { };
 
-  audiofile = callPackage ../development/libraries/audiofile {
-    stdenv = if stdenv.isDarwin
-      then overrideGCC stdenv gccApple
-      else stdenv;
-  };
+  audiofile = callPackage ../development/libraries/audiofile { };
 
   axis = callPackage ../development/libraries/axis { };
 
@@ -4816,11 +4802,7 @@ let
       gtkmm;
   };
 
-  glib = callPackage ../development/libraries/glib {
-    stdenv = if stdenv.isDarwin
-      then overrideGCC stdenv gccApple
-      else stdenv;
-  };
+  glib = callPackage ../development/libraries/glib { };
   glib-tested = glib.override { doCheck = true; }; # checked version separate to break cycles
   glibmm = callPackage ../development/libraries/glibmm { };
 
@@ -4853,9 +4835,7 @@ let
     cupsSupport = config.gtk2.cups or stdenv.isLinux;
   };
 
-  gtk3 = callPackage ../development/libraries/gtk+/3.x.nix {
-    inherit (gnome3) at_spi2_atk;
-  };
+  gtk3 = callPackage ../development/libraries/gtk+/3.x.nix { };
 
   gtk = pkgs.gtk2;
 
@@ -5284,11 +5264,7 @@ let
 
   librevisa = callPackage ../development/libraries/librevisa { };
 
-  libsamplerate = callPackage ../development/libraries/libsamplerate {
-    stdenv = if stdenv.isDarwin
-      then overrideGCC stdenv gccApple
-      else stdenv;
-  };
+  libsamplerate = callPackage ../development/libraries/libsamplerate { };
 
   libspectre = callPackage ../development/libraries/libspectre { };
 
@@ -5483,11 +5459,7 @@ let
   # To bootstrap SBCL, I need CLisp 2.44.1; it needs libsigsegv 2.5
   libsigsegv_25 = callPackage ../development/libraries/libsigsegv/2.5.nix { };
 
-  libsndfile = callPackage ../development/libraries/libsndfile {
-    stdenv = if stdenv.isDarwin
-      then overrideGCC stdenv gccApple
-      else stdenv;
-  };
+  libsndfile = callPackage ../development/libraries/libsndfile { };
 
   libsodium = callPackage ../development/libraries/libsodium { };
 
@@ -5782,13 +5754,6 @@ let
 
   ncurses = callPackage ../development/libraries/ncurses {
     unicode = system != "i686-cygwin";
-    stdenv =
-      # On Darwin, NCurses uses `-no-cpp-precomp', which is specific to
-      # Apple-GCC.  Since NCurses is part of stdenv, always use
-      # `stdenvNative' to build it.
-      if stdenv.isDarwin
-      then allStdenvs.stdenvNative
-      else stdenv;
   };
 
   neon = callPackage ../development/libraries/neon {
@@ -6066,23 +6031,9 @@ let
 
   readline5 = callPackage ../development/libraries/readline/readline5.nix { };
 
-  readline6 = callPackage ../development/libraries/readline/readline6.nix {
-    stdenv =
-      # On Darwin, Readline uses `-arch_only', which is specific to
-      # Apple-GCC.  So give it what it expects.
-      if stdenv.isDarwin
-      then overrideGCC stdenv gccApple
-      else stdenv;
-  };
+  readline6 = callPackage ../development/libraries/readline/readline6.nix { };
 
-  readline63 = callPackage ../development/libraries/readline/readline6.3.nix {
-    stdenv =
-      # On Darwin, Readline uses `-arch_only', which is specific to
-      # Apple-GCC.  So give it what it expects.
-      if stdenv.isDarwin
-      then overrideGCC stdenv gccApple
-      else stdenv;
-  };
+  readline63 = callPackage ../development/libraries/readline/readline6.3.nix { };
 
   librdf_raptor = callPackage ../development/libraries/librdf/raptor.nix { };
 
@@ -9788,7 +9739,6 @@ let
 
   thunderbird-bin = callPackage ../applications/networking/mailreaders/thunderbird-bin {
     gconf = pkgs.gnome.GConf;
-    inherit (pkgs.gnome3) at_spi2_atk;
     inherit (pkgs.gnome) libgnome libgnomeui;
     inherit (pkgs.xlibs) libX11 libXScrnSaver libXext
       libXinerama libXrender libXt;
diff --git a/pkgs/top-level/mingw.nix b/pkgs/top-level/mingw.nix
deleted file mode 100644
index 6c744bfd861..00000000000
--- a/pkgs/top-level/mingw.nix
+++ /dev/null
@@ -1,27 +0,0 @@
-let {
-  pkgs =
-    import ./all-packages.nix {
-      stdenvType = "i686-mingw";
-    };
-
-  body = {
-    inherit (pkgs)
-      aterm
-      getopt
-      pkgconfig
-      realCurl
-      strategoLibraries
-      zlib;
-#    inherit profileTest;
-  };
-
-#  profileTest =
-#    pkgs.stdenv.mkDerivation {
-#      name = "profile-test";
-#      src = ./char-test.c;
-#      builder = ./profile-builder.sh;
-#      strlib = pkgs.strategoLibraries;
-#      aterm = pkgs.aterm;
-#      buildInputs = [pkgs.aterm pkgs.strategoLibraries];
-#    };
-}