summary refs log tree commit diff
path: root/pkgs/development
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development')
-rw-r--r--pkgs/development/compilers/gcc-arm-embedded/default.nix4
-rw-r--r--pkgs/development/compilers/gcc/4.6/builder.sh25
-rw-r--r--pkgs/development/compilers/gcc/4.6/default.nix10
-rw-r--r--pkgs/development/compilers/gcc/4.8/default.nix12
-rw-r--r--pkgs/development/compilers/gcc/4.9/default.nix12
-rw-r--r--pkgs/development/compilers/gcc/5/default.nix13
-rw-r--r--pkgs/development/compilers/gcc/builder.sh41
-rw-r--r--pkgs/development/compilers/ghc/6.10.2-binary.nix10
-rw-r--r--pkgs/development/compilers/ghc/6.10.4.nix4
-rw-r--r--pkgs/development/compilers/ghc/6.12.3.nix8
-rw-r--r--pkgs/development/compilers/ghc/7.0.4-binary.nix6
-rw-r--r--pkgs/development/compilers/ghc/7.0.4.nix8
-rw-r--r--pkgs/development/compilers/ghc/7.10.2.nix10
-rw-r--r--pkgs/development/compilers/ghc/7.2.2.nix8
-rw-r--r--pkgs/development/compilers/ghc/7.4.2-binary.nix2
-rw-r--r--pkgs/development/compilers/ghc/7.4.2.nix8
-rw-r--r--pkgs/development/compilers/ghc/7.6.3.nix8
-rw-r--r--pkgs/development/compilers/ghc/7.8.3.nix8
-rw-r--r--pkgs/development/compilers/ghc/7.8.4.nix8
-rw-r--r--pkgs/development/compilers/ghc/head.nix10
-rw-r--r--pkgs/development/compilers/ghc/nokinds.nix10
-rw-r--r--pkgs/development/compilers/ghcjs/default.nix6
-rw-r--r--pkgs/development/compilers/go/1.1.nix101
-rw-r--r--pkgs/development/compilers/go/1.2.nix91
-rw-r--r--pkgs/development/compilers/go/1.3.nix113
-rw-r--r--pkgs/development/compilers/go/1.4.nix2
-rw-r--r--pkgs/development/compilers/go/default.nix95
-rw-r--r--pkgs/development/compilers/llvm/3.7/llvm.nix2
-rw-r--r--pkgs/development/compilers/mentor/default.nix2
-rw-r--r--pkgs/development/compilers/mkcl/default.nix4
-rw-r--r--pkgs/development/compilers/mlton/default.nix10
-rw-r--r--pkgs/development/compilers/nim/default.nix2
-rw-r--r--pkgs/development/compilers/nvidia-cg-toolkit/default.nix2
-rw-r--r--pkgs/development/compilers/openjdk/7.nix6
-rw-r--r--pkgs/development/compilers/openjdk/8.nix4
-rw-r--r--pkgs/development/compilers/openjdk/bootstrap.nix8
-rw-r--r--pkgs/development/compilers/orc/default.nix15
-rw-r--r--pkgs/development/compilers/path64/default.nix4
-rw-r--r--pkgs/development/compilers/rustc/generic.nix8
-rw-r--r--pkgs/development/compilers/tinycc/default.nix6
-rw-r--r--pkgs/development/compilers/urweb/default.nix6
-rw-r--r--pkgs/development/interpreters/elixir/default.nix2
-rw-r--r--pkgs/development/interpreters/guile/default.nix2
-rw-r--r--pkgs/development/interpreters/love/default.nix2
-rw-r--r--pkgs/development/interpreters/lua-5/expat.nix2
-rw-r--r--pkgs/development/interpreters/luajit/default.nix2
-rw-r--r--pkgs/development/interpreters/perl/5.20/default.nix18
-rw-r--r--pkgs/development/interpreters/perl/5.22/default.nix36
-rw-r--r--pkgs/development/interpreters/php/default.nix12
-rw-r--r--pkgs/development/interpreters/pypy/default.nix10
-rw-r--r--pkgs/development/interpreters/python/2.6/default.nix14
-rw-r--r--pkgs/development/interpreters/python/2.7/default.nix13
-rw-r--r--pkgs/development/interpreters/python/3.2/default.nix4
-rw-r--r--pkgs/development/interpreters/python/3.3/default.nix4
-rw-r--r--pkgs/development/interpreters/python/3.4/default.nix4
-rw-r--r--pkgs/development/interpreters/python/3.5/default.nix4
-rw-r--r--pkgs/development/interpreters/ruby/bundler-env/default-gem-config.nix20
-rw-r--r--pkgs/development/interpreters/ruby/patches.nix4
-rw-r--r--pkgs/development/interpreters/spidermonkey/1.8.0-rc1.nix2
-rw-r--r--pkgs/development/interpreters/spidermonkey/17.0.nix12
-rw-r--r--pkgs/development/interpreters/spidermonkey/185-1.0.0.nix2
-rw-r--r--pkgs/development/interpreters/spidermonkey/24.2.nix12
-rw-r--r--pkgs/development/libraries/SDL/default.nix7
-rw-r--r--pkgs/development/libraries/SDL2/default.nix2
-rw-r--r--pkgs/development/libraries/aalib/default.nix16
-rw-r--r--pkgs/development/libraries/acl/default.nix2
-rw-r--r--pkgs/development/libraries/apr-util/default.nix12
-rw-r--r--pkgs/development/libraries/apr/default.nix14
-rw-r--r--pkgs/development/libraries/at-spi2-core/default.nix2
-rw-r--r--pkgs/development/libraries/atk/default.nix6
-rw-r--r--pkgs/development/libraries/attr/default.nix2
-rw-r--r--pkgs/development/libraries/boehm-gc/default.nix9
-rw-r--r--pkgs/development/libraries/boost/generic.nix7
-rw-r--r--pkgs/development/libraries/cairo/default.nix24
-rw-r--r--pkgs/development/libraries/cogl/1.20.nix2
-rw-r--r--pkgs/development/libraries/cogl/1.22.nix2
-rw-r--r--pkgs/development/libraries/cogl/default.nix2
-rw-r--r--pkgs/development/libraries/cyrus-sasl/default.nix8
-rw-r--r--pkgs/development/libraries/dbus-glib/default.nix5
-rw-r--r--pkgs/development/libraries/dbus/default.nix125
-rw-r--r--pkgs/development/libraries/dbus/no-create-dirs.patch26
-rw-r--r--pkgs/development/libraries/dbus/ucred-dirty-hack.patch18
-rw-r--r--pkgs/development/libraries/epoxy/default.nix2
-rw-r--r--pkgs/development/libraries/expat/default.nix4
-rw-r--r--pkgs/development/libraries/ffmpeg/generic.nix9
-rw-r--r--pkgs/development/libraries/fftw/default.nix3
-rw-r--r--pkgs/development/libraries/fontconfig/2.10.nix2
-rw-r--r--pkgs/development/libraries/fontconfig/default.nix4
-rw-r--r--pkgs/development/libraries/fontconfig/make-fonts-conf.nix6
-rw-r--r--pkgs/development/libraries/freetype/default.nix8
-rw-r--r--pkgs/development/libraries/gdk-pixbuf/default.nix18
-rw-r--r--pkgs/development/libraries/gettext/default.nix2
-rw-r--r--pkgs/development/libraries/gettext/expat.nix2
-rw-r--r--pkgs/development/libraries/git2/default.nix2
-rw-r--r--pkgs/development/libraries/glib-networking/default.nix4
-rw-r--r--pkgs/development/libraries/glib/default.nix26
-rw-r--r--pkgs/development/libraries/glib/setup-hook.sh19
-rw-r--r--pkgs/development/libraries/glibc/builder.sh17
-rw-r--r--pkgs/development/libraries/glibc/common.nix5
-rw-r--r--pkgs/development/libraries/glibc/default.nix2
-rw-r--r--pkgs/development/libraries/glibc/info.nix2
-rw-r--r--pkgs/development/libraries/glibc/locales.nix4
-rw-r--r--pkgs/development/libraries/glibc/multi.nix36
-rw-r--r--pkgs/development/libraries/gmime/default.nix4
-rw-r--r--pkgs/development/libraries/gmp/5.1.x.nix2
-rw-r--r--pkgs/development/libraries/gmp/6.x.nix13
-rw-r--r--pkgs/development/libraries/gnutls/generic.nix12
-rw-r--r--pkgs/development/libraries/gobject-introspection/default.nix21
-rw-r--r--pkgs/development/libraries/gobject-introspection/setup-hook.sh7
-rw-r--r--pkgs/development/libraries/gpgme/default.nix11
-rw-r--r--pkgs/development/libraries/gstreamer/default.nix7
-rw-r--r--pkgs/development/libraries/gstreamer/legacy/gst-plugins-good/default.nix7
-rw-r--r--pkgs/development/libraries/gstreamer/vaapi/default.nix8
-rw-r--r--pkgs/development/libraries/gtk+/2.x.nix11
-rw-r--r--pkgs/development/libraries/gtk+/3.x.nix29
-rw-r--r--pkgs/development/libraries/gtk+/setup-hook.sh10
-rw-r--r--pkgs/development/libraries/gupnp/default.nix2
-rw-r--r--pkgs/development/libraries/gvfs/default.nix2
-rw-r--r--pkgs/development/libraries/harfbuzz/default.nix37
-rw-r--r--pkgs/development/libraries/hunspell/default.nix6
-rw-r--r--pkgs/development/libraries/icu/default.nix5
-rw-r--r--pkgs/development/libraries/jasper/default.nix11
-rw-r--r--pkgs/development/libraries/json-c/default.nix6
-rw-r--r--pkgs/development/libraries/lame/default.nix3
-rw-r--r--pkgs/development/libraries/lcms/default.nix2
-rw-r--r--pkgs/development/libraries/lcms2/default.nix11
-rw-r--r--pkgs/development/libraries/libao/default.nix2
-rw-r--r--pkgs/development/libraries/libarchive/default.nix2
-rw-r--r--pkgs/development/libraries/libassuan/default.nix5
-rw-r--r--pkgs/development/libraries/libav/default.nix14
-rw-r--r--pkgs/development/libraries/libcaca/default.nix7
-rw-r--r--pkgs/development/libraries/libcanberra/default.nix2
-rw-r--r--pkgs/development/libraries/libdbi-drivers/default.nix6
-rw-r--r--pkgs/development/libraries/libdrm/default.nix2
-rw-r--r--pkgs/development/libraries/libedit/default.nix2
-rw-r--r--pkgs/development/libraries/libelf/default.nix16
-rw-r--r--pkgs/development/libraries/libevent/default.nix8
-rw-r--r--pkgs/development/libraries/libextractor/default.nix2
-rw-r--r--pkgs/development/libraries/libffi/default.nix20
-rw-r--r--pkgs/development/libraries/libgcrypt/1.5.nix4
-rw-r--r--pkgs/development/libraries/libgcrypt/default.nix9
-rw-r--r--pkgs/development/libraries/libgpg-error/default.nix11
-rw-r--r--pkgs/development/libraries/libguestfs/default.nix2
-rw-r--r--pkgs/development/libraries/libidn/default.nix2
-rw-r--r--pkgs/development/libraries/libjpeg-turbo/default.nix8
-rw-r--r--pkgs/development/libraries/libjpeg/default.nix2
-rw-r--r--pkgs/development/libraries/libmbim/default.nix2
-rw-r--r--pkgs/development/libraries/libmicrohttpd/default.nix2
-rw-r--r--pkgs/development/libraries/libmng/default.nix11
-rw-r--r--pkgs/development/libraries/libmpc/default.nix2
-rw-r--r--pkgs/development/libraries/libmtp/default.nix14
-rw-r--r--pkgs/development/libraries/libogg/default.nix2
-rw-r--r--pkgs/development/libraries/liboil/default.nix7
-rw-r--r--pkgs/development/libraries/libopensc-dnie/default.nix2
-rw-r--r--pkgs/development/libraries/libopus/default.nix2
-rw-r--r--pkgs/development/libraries/libpng/12.nix4
-rw-r--r--pkgs/development/libraries/libpng/default.nix7
-rw-r--r--pkgs/development/libraries/libproxy/default.nix2
-rw-r--r--pkgs/development/libraries/libqmi/default.nix2
-rw-r--r--pkgs/development/libraries/libraw/default.nix2
-rw-r--r--pkgs/development/libraries/librsvg/default.nix4
-rw-r--r--pkgs/development/libraries/libsamplerate/default.nix8
-rw-r--r--pkgs/development/libraries/libsndfile/default.nix4
-rw-r--r--pkgs/development/libraries/libsodium/default.nix4
-rw-r--r--pkgs/development/libraries/libsoup/default.nix4
-rw-r--r--pkgs/development/libraries/libssh/default.nix2
-rw-r--r--pkgs/development/libraries/libssh2/default.nix2
-rw-r--r--pkgs/development/libraries/libtasn1/default.nix3
-rw-r--r--pkgs/development/libraries/libtheora/default.nix3
-rw-r--r--pkgs/development/libraries/libtiff/default.nix2
-rw-r--r--pkgs/development/libraries/libtoxcore/new-api/default.nix4
-rw-r--r--pkgs/development/libraries/libtoxcore/old-api/default.nix4
-rw-r--r--pkgs/development/libraries/libunwind/default.nix4
-rw-r--r--pkgs/development/libraries/libusb/default.nix3
-rw-r--r--pkgs/development/libraries/libusb1/default.nix8
-rw-r--r--pkgs/development/libraries/libva/default.nix13
-rw-r--r--pkgs/development/libraries/libvdpau/default.nix2
-rw-r--r--pkgs/development/libraries/libvirt/default.nix6
-rw-r--r--pkgs/development/libraries/libvorbis/default.nix3
-rw-r--r--pkgs/development/libraries/libvpx/default.nix5
-rw-r--r--pkgs/development/libraries/libvpx/git.nix5
-rw-r--r--pkgs/development/libraries/libwnck/3.x.nix3
-rw-r--r--pkgs/development/libraries/libwnck/default.nix3
-rw-r--r--pkgs/development/libraries/libxkbcommon/default.nix2
-rw-r--r--pkgs/development/libraries/libxklavier/default.nix2
-rw-r--r--pkgs/development/libraries/libxml2/default.nix41
-rw-r--r--pkgs/development/libraries/libxslt/default.nix15
-rw-r--r--pkgs/development/libraries/mailcore2/default.nix3
-rw-r--r--pkgs/development/libraries/mesa/default.nix59
-rw-r--r--pkgs/development/libraries/mesa/dlopen-absolute-paths.diff2
-rw-r--r--pkgs/development/libraries/mpfr/default.nix2
-rw-r--r--pkgs/development/libraries/ncurses/default.nix41
-rw-r--r--pkgs/development/libraries/nettle/generic.nix5
-rw-r--r--pkgs/development/libraries/newt/default.nix10
-rw-r--r--pkgs/development/libraries/nspr/default.nix4
-rw-r--r--pkgs/development/libraries/nss/default.nix18
-rw-r--r--pkgs/development/libraries/nss_wrapper/default.nix3
-rw-r--r--pkgs/development/libraries/openldap/default.nix9
-rw-r--r--pkgs/development/libraries/openssl/default.nix19
-rw-r--r--pkgs/development/libraries/p11-kit/default.nix3
-rw-r--r--pkgs/development/libraries/pango/default.nix14
-rw-r--r--pkgs/development/libraries/pcre/default.nix26
-rw-r--r--pkgs/development/libraries/pdf2xml/default.nix4
-rw-r--r--pkgs/development/libraries/phonon-backend-gstreamer/qt5/old.nix2
-rw-r--r--pkgs/development/libraries/policykit/default.nix2
-rw-r--r--pkgs/development/libraries/polkit/default.nix2
-rw-r--r--pkgs/development/libraries/poppler/default.nix2
-rw-r--r--pkgs/development/libraries/portaudio/default.nix2
-rw-r--r--pkgs/development/libraries/qt-3/default.nix6
-rw-r--r--pkgs/development/libraries/qt-4.x/4.8/default.nix19
-rw-r--r--pkgs/development/libraries/qt-5/5.4/0008-dlopen-webkit-udev.patch4
-rw-r--r--pkgs/development/libraries/qt-5/5.4/0009-dlopen-serialport-udev.patch4
-rw-r--r--pkgs/development/libraries/qt-5/5.4/0014-mkspecs-libgl.patch4
-rw-r--r--pkgs/development/libraries/qt-5/5.4/default.nix19
-rw-r--r--pkgs/development/libraries/qt-5/5.4/qtbase.nix24
-rw-r--r--pkgs/development/libraries/qt-5/5.5/qtbase/0010-mkspecs-libgl.patch4
-rw-r--r--pkgs/development/libraries/qt-5/5.5/qtbase/default.nix25
-rw-r--r--pkgs/development/libraries/qt-5/5.5/qtserialport/0001-dlopen-serialport-udev.patch4
-rw-r--r--pkgs/development/libraries/qt-5/5.5/qtserialport/default.nix9
-rw-r--r--pkgs/development/libraries/qt-5/5.5/qtwebkit/0003-dlopen-webkit-udev.patch4
-rw-r--r--pkgs/development/libraries/qt-5/5.5/qtwebkit/default.nix9
-rw-r--r--pkgs/development/libraries/rdkafka/default.nix2
-rw-r--r--pkgs/development/libraries/readline/6.3.nix2
-rw-r--r--pkgs/development/libraries/schroedinger/default.nix16
-rw-r--r--pkgs/development/libraries/scmccid/default.nix2
-rw-r--r--pkgs/development/libraries/slang/default.nix23
-rw-r--r--pkgs/development/libraries/smpeg/default.nix2
-rw-r--r--pkgs/development/libraries/socket_wrapper/default.nix1
-rw-r--r--pkgs/development/libraries/speex/default.nix6
-rw-r--r--pkgs/development/libraries/speexdsp/default.nix2
-rw-r--r--pkgs/development/libraries/sqlite/default.nix2
-rw-r--r--pkgs/development/libraries/uid_wrapper/default.nix1
-rw-r--r--pkgs/development/libraries/webkitgtk/2.4.nix4
-rw-r--r--pkgs/development/libraries/webkitgtk/default.nix4
-rw-r--r--pkgs/development/libraries/wildmidi/default.nix2
-rw-r--r--pkgs/development/libraries/wxGTK-2.8/default.nix6
-rw-r--r--pkgs/development/libraries/x264/default.nix2
-rw-r--r--pkgs/development/libraries/x265/default.nix2
-rw-r--r--pkgs/development/libraries/zlib/default.nix34
-rw-r--r--pkgs/development/mobile/androidenv/androidndk.nix4
-rw-r--r--pkgs/development/mobile/androidenv/androidndk_r8e.nix2
-rw-r--r--pkgs/development/mobile/androidenv/androidsdk.nix24
-rw-r--r--pkgs/development/mobile/androidenv/build-tools.nix4
-rw-r--r--pkgs/development/mobile/androidenv/platform-tools.nix2
-rw-r--r--pkgs/development/mobile/titaniumenv/titaniumsdk-3.1.nix4
-rw-r--r--pkgs/development/mobile/titaniumenv/titaniumsdk-3.2.nix4
-rw-r--r--pkgs/development/mobile/titaniumenv/titaniumsdk-3.3.nix4
-rw-r--r--pkgs/development/mobile/titaniumenv/titaniumsdk-3.4.nix4
-rw-r--r--pkgs/development/mobile/titaniumenv/titaniumsdk-3.5.nix4
-rw-r--r--pkgs/development/ocaml-modules/expat/default.nix4
-rw-r--r--pkgs/development/perl-modules/DBD-SQLite/default.nix4
-rw-r--r--pkgs/development/perl-modules/DBD-SQLite/external-sqlite.patch72
-rw-r--r--pkgs/development/perl-modules/generic/builder.sh1
-rw-r--r--pkgs/development/perl-modules/generic/default.nix10
-rw-r--r--pkgs/development/python-modules/pygobject/default.nix2
-rw-r--r--pkgs/development/r-modules/default.nix2
-rw-r--r--pkgs/development/tools/build-managers/cargo/snapshot.nix2
-rw-r--r--pkgs/development/tools/build-managers/cmake/2.8.nix5
-rw-r--r--pkgs/development/tools/build-managers/cmake/default.nix42
-rw-r--r--pkgs/development/tools/build-managers/cmake/search-path-3.2.patch8
-rw-r--r--pkgs/development/tools/build-managers/gnumake/4.1/default.nix2
-rw-r--r--pkgs/development/tools/misc/autogen/default.nix13
-rw-r--r--pkgs/development/tools/misc/binutils/default.nix4
-rw-r--r--pkgs/development/tools/misc/drush/default.nix2
-rw-r--r--pkgs/development/tools/misc/eggdbus/default.nix2
-rw-r--r--pkgs/development/tools/misc/global/default.nix2
-rw-r--r--pkgs/development/tools/misc/libtool/libtool2.nix3
-rw-r--r--pkgs/development/tools/misc/patchelf/default.nix2
-rw-r--r--pkgs/development/tools/misc/pkgconfig/default.nix31
-rw-r--r--pkgs/development/tools/misc/texinfo/5.2.nix4
-rw-r--r--pkgs/development/tools/node-webkit/nw11.nix4
-rw-r--r--pkgs/development/tools/node-webkit/nw12.nix4
-rw-r--r--pkgs/development/tools/node-webkit/nw9.nix4
-rw-r--r--pkgs/development/tools/phantomjs/default.nix19
-rw-r--r--pkgs/development/tools/selenium/chromedriver/default.nix4
-rw-r--r--pkgs/development/tools/vagrant/default.nix16
-rw-r--r--pkgs/development/web/nodejs/v4.nix8
277 files changed, 1816 insertions, 930 deletions
diff --git a/pkgs/development/compilers/gcc-arm-embedded/default.nix b/pkgs/development/compilers/gcc-arm-embedded/default.nix
index b6f6ac51ba2..3f9a2a1f2fb 100644
--- a/pkgs/development/compilers/gcc-arm-embedded/default.nix
+++ b/pkgs/development/compilers/gcc-arm-embedded/default.nix
@@ -30,8 +30,8 @@ stdenv.mkDerivation {
 
     for f in $(find $out); do
       if [ -f "$f" ] && patchelf "$f" 2> /dev/null; then
-        patchelf --set-interpreter ${glibc}/lib/ld-linux.so.2 \
-                 --set-rpath $out/lib:${gcc}/lib:${ncurses}/lib \
+        patchelf --set-interpreter ${glibc.out}/lib/ld-linux.so.2 \
+                 --set-rpath $out/lib:${gcc.lib or gcc}/lib:${ncurses.lib}/lib \
                  "$f" || true
       fi
     done
diff --git a/pkgs/development/compilers/gcc/4.6/builder.sh b/pkgs/development/compilers/gcc/4.6/builder.sh
index af2e97b1e4e..af36ec33b70 100644
--- a/pkgs/development/compilers/gcc/4.6/builder.sh
+++ b/pkgs/development/compilers/gcc/4.6/builder.sh
@@ -8,9 +8,10 @@ mkdir $NIX_FIXINC_DUMMY
 if test "$staticCompiler" = "1"; then
     EXTRA_LDFLAGS="-static"
 else
-    EXTRA_LDFLAGS=""
+    EXTRA_LDFLAGS="-Wl,-rpath,$lib/lib"
 fi
 
+
 # GCC interprets empty paths as ".", which we don't want.
 if test -z "$CPATH"; then unset CPATH; fi
 if test -z "$LIBRARY_PATH"; then unset LIBRARY_PATH; fi
@@ -29,7 +30,7 @@ if test "$noSysDirs" = "1"; then
         # Use *real* header files, otherwise a limits.h is generated
         # that does not include Glibc's limits.h (notably missing
         # SSIZE_MAX, which breaks the build).
-        export NIX_FIXINC_DUMMY=$(cat $NIX_CC/nix-support/orig-libc)/include
+        export NIX_FIXINC_DUMMY=$libc_dev/include
 
         # The path to the Glibc binaries such as `crti.o'.
         glibc_libdir="$(cat $NIX_CC/nix-support/orig-libc)/lib"
@@ -50,10 +51,10 @@ if test "$noSysDirs" = "1"; then
     # bootstrap compiler are optimized and (optionally) contain
     # debugging information (info "(gccinstall) Building").
     if test -n "$dontStrip"; then
-	extraFlags="-O2 -g $extraFlags"
+        extraFlags="-O2 -g $extraFlags"
     else
-	# Don't pass `-g' at all; this saves space while building.
-	extraFlags="-O2 $extraFlags"
+        # Don't pass `-g' at all; this saves space while building.
+        extraFlags="-O2 $extraFlags"
     fi
 
     EXTRA_FLAGS="$extraFlags"
@@ -170,9 +171,8 @@ preConfigure() {
         # Patch the configure script so it finds glibc headers.  It's
         # important for example in order not to get libssp built,
         # because its functionality is in glibc already.
-        glibc_headers="$(cat $NIX_CC/nix-support/orig-libc)/include"
         sed -i \
-            -e "s,glibc_header_dir=/usr/include,glibc_header_dir=$glibc_headers", \
+            -e "s,glibc_header_dir=/usr/include,glibc_header_dir=$libc_dev/include", \
             gcc/configure
     fi
 
@@ -206,6 +206,14 @@ preInstall() {
 
 
 postInstall() {
+    # Move runtime libraries to $lib.
+    mkdir -p $lib/lib
+    ln -s lib $lib/lib64
+    mv -v $out/lib/lib*.so $out/lib/lib*.so.*[0-9] $out/lib/*.la $lib/lib/
+    for i in $lib/lib/*.la; do
+        substituteInPlace $i --replace $out $lib
+    done
+
     # Remove precompiled headers for now.  They are very big and
     # probably not very useful yet.
     find $out/include -name "*.gch" -exec rm -rf {} \; -prune
@@ -217,6 +225,7 @@ postInstall() {
 
     # More dependencies with the previous gcc or some libs (gccbug stores the build command line)
     rm -rf $out/bin/gccbug
+
     # Take out the bootstrap-tools from the rpath, as it's not needed at all having $out
     for i in $out/libexec/gcc/*/*/*; do
         if PREV_RPATH=`patchelf --print-rpath $i`; then
@@ -225,7 +234,7 @@ postInstall() {
     done
 
     # Get rid of some "fixed" header files
-    rm -rf $out/lib/gcc/*/*/include/root
+    rm -rfv $out/lib/gcc/*/*/include-fixed/{root,linux}
 
     # Replace hard links for i686-pc-linux-gnu-gcc etc. with symlinks.
     for i in $out/bin/*-gcc*; do
diff --git a/pkgs/development/compilers/gcc/4.6/default.nix b/pkgs/development/compilers/gcc/4.6/default.nix
index b3caad11b71..bc968d1f66e 100644
--- a/pkgs/development/compilers/gcc/4.6/default.nix
+++ b/pkgs/development/compilers/gcc/4.6/default.nix
@@ -170,7 +170,7 @@ let version = "4.6.4";
       "-stage-final";
     crossNameAddon = if cross != null then "-${cross.config}" + stageNameAddon else "";
 
-  bootstrap = cross == null && !stdenv.isArm && !stdenv.isMips;
+    bootstrap = cross == null && !stdenv.isArm && !stdenv.isMips;
 
 in
 
@@ -182,13 +182,19 @@ stdenv.mkDerivation ({
 
   builder = ./builder.sh;
 
-  src = (import ./sources.nix) {
+  srcs = (import ./sources.nix) {
     inherit fetchurl optional version;
     inherit langC langCC langFortran langJava langAda langGo;
   };
 
+  outputs = [ "out" "lib" ];
+
+  setOutputFlags = false;
+
   inherit patches enableMultilib;
 
+  libc_dev = stdenv.cc.libc_dev;
+
   postPatch =
     if (stdenv.isGNU
         || (libcCross != null                  # e.g., building `gcc.crossDrv'
diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix
index fd80f4ec8c5..09e3751580c 100644
--- a/pkgs/development/compilers/gcc/4.8/default.nix
+++ b/pkgs/development/compilers/gcc/4.8/default.nix
@@ -197,7 +197,7 @@ let version = "4.8.5";
     stageNameAddon = if crossStageStatic then "-stage-static" else "-stage-final";
     crossNameAddon = if cross != null then "-${cross.config}" + stageNameAddon else "";
 
-  bootstrap = cross == null && !stdenv.isArm && !stdenv.isMips;
+    bootstrap = cross == null && !stdenv.isArm && !stdenv.isMips;
 
 in
 
@@ -209,8 +209,6 @@ stdenv.mkDerivation ({
 
   builder = ../builder.sh;
 
-  outputs = [ "out" "info" ];
-
   src = fetchurl {
     url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2";
     sha256 = "08yggr18v373a1ihj0rg2vd6psnic42b518xcgp3r9k81xz1xyr2";
@@ -218,6 +216,12 @@ stdenv.mkDerivation ({
 
   inherit patches;
 
+  outputs = [ "out" "lib" "doc" ];
+  setOutputFlags = false;
+  NIX_NO_SELF_RPATH = true;
+
+  libc_dev = stdenv.cc.libc_dev;
+
   postPatch =
     if (stdenv.isGNU
         || (libcCross != null                  # e.g., building `gcc.crossDrv'
@@ -358,7 +362,7 @@ stdenv.mkDerivation ({
       )
     }
     ${if (stdenv ? glibc && cross == null)
-      then " --with-native-system-header-dir=${stdenv.glibc}/include"
+      then " --with-native-system-header-dir=${stdenv.glibc.dev}/include"
       else ""}
     ${if langAda then " --enable-libada" else ""}
     ${if cross == null && stdenv.isi686 then "--with-arch=i686" else ""}
diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix
index fecdd85cd41..2b87c8ac430 100644
--- a/pkgs/development/compilers/gcc/4.9/default.nix
+++ b/pkgs/development/compilers/gcc/4.9/default.nix
@@ -196,7 +196,7 @@ let version = "4.9.3";
     stageNameAddon = if crossStageStatic then "-stage-static" else "-stage-final";
     crossNameAddon = if cross != null then "-${cross.config}" + stageNameAddon else "";
 
-  bootstrap = cross == null && !stdenv.isArm && !stdenv.isMips;
+  bootstrap = cross == null;
 
 in
 
@@ -208,8 +208,6 @@ stdenv.mkDerivation ({
 
   builder = ../builder.sh;
 
-  outputs = [ "out" "info" ];
-
   src = fetchurl {
     url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2";
     sha256 = "0zmnm00d2a1hsd41g34bhvxzvxisa2l584q3p447bd91lfjv4ci3";
@@ -217,6 +215,12 @@ stdenv.mkDerivation ({
 
   inherit patches;
 
+  outputs = [ "out" "lib" "doc" ];
+  setOutputFlags = false;
+  NIX_NO_SELF_RPATH = true;
+
+  libc_dev = stdenv.cc.libc_dev;
+
   postPatch =
     if (stdenv.isGNU
         || (libcCross != null                  # e.g., building `gcc.crossDrv'
@@ -357,7 +361,7 @@ stdenv.mkDerivation ({
       )
     }
     ${if (stdenv ? glibc && cross == null)
-      then " --with-native-system-header-dir=${stdenv.glibc}/include"
+      then " --with-native-system-header-dir=${stdenv.glibc.dev}/include"
       else ""}
     ${if langAda then " --enable-libada" else ""}
     ${if cross == null && stdenv.isi686 then "--with-arch=i686" else ""}
diff --git a/pkgs/development/compilers/gcc/5/default.nix b/pkgs/development/compilers/gcc/5/default.nix
index 6decc4c8cc3..6b54d31cb01 100644
--- a/pkgs/development/compilers/gcc/5/default.nix
+++ b/pkgs/development/compilers/gcc/5/default.nix
@@ -34,6 +34,7 @@
 , stripped ? true
 , gnused ? null
 , binutils ? null
+, cloog # unused; just for compat with gcc4, as we override the parameter on some places
 }:
 
 assert langJava     -> zip != null && unzip != null
@@ -196,7 +197,7 @@ let version = "5.2.0";
     stageNameAddon = if crossStageStatic then "-stage-static" else "-stage-final";
     crossNameAddon = if cross != null then "-${cross.config}" + stageNameAddon else "";
 
-  bootstrap = cross == null && !stdenv.isArm && !stdenv.isMips;
+  bootstrap = cross == null;
 
 in
 
@@ -208,8 +209,6 @@ stdenv.mkDerivation ({
 
   builder = ../builder.sh;
 
-  outputs = [ "out" "info" ];
-
   src = fetchurl {
     url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2";
     sha256 = "1bccp8a106xwz3wkixn65ngxif112vn90qf95m6lzpgpnl25p0sz";
@@ -217,6 +216,12 @@ stdenv.mkDerivation ({
 
   inherit patches;
 
+  outputs = [ "out" "lib" "man" "info" ];
+  setOutputFlags = false;
+  NIX_NO_SELF_RPATH = true;
+
+  libc_dev = stdenv.cc.libc_dev;
+
   postPatch =
     if (stdenv.isGNU
         || (libcCross != null                  # e.g., building `gcc.crossDrv'
@@ -357,7 +362,7 @@ stdenv.mkDerivation ({
       )
     }
     ${if (stdenv ? glibc && cross == null)
-      then " --with-native-system-header-dir=${stdenv.glibc}/include"
+      then " --with-native-system-header-dir=${stdenv.glibc.dev}/include"
       else ""}
     ${if langAda then " --enable-libada" else ""}
     ${if cross == null && stdenv.isi686 then "--with-arch=i686" else ""}
diff --git a/pkgs/development/compilers/gcc/builder.sh b/pkgs/development/compilers/gcc/builder.sh
index dd77c67a023..8d33f88de17 100644
--- a/pkgs/development/compilers/gcc/builder.sh
+++ b/pkgs/development/compilers/gcc/builder.sh
@@ -8,9 +8,10 @@ mkdir $NIX_FIXINC_DUMMY
 if test "$staticCompiler" = "1"; then
     EXTRA_LDFLAGS="-static"
 else
-    EXTRA_LDFLAGS=""
+    EXTRA_LDFLAGS="-Wl,-rpath,$lib/lib"
 fi
 
+
 # GCC interprets empty paths as ".", which we don't want.
 if test -z "$CPATH"; then unset CPATH; fi
 if test -z "$LIBRARY_PATH"; then unset LIBRARY_PATH; fi
@@ -29,7 +30,7 @@ if test "$noSysDirs" = "1"; then
         # Use *real* header files, otherwise a limits.h is generated
         # that does not include Glibc's limits.h (notably missing
         # SSIZE_MAX, which breaks the build).
-        export NIX_FIXINC_DUMMY=$(cat $NIX_CC/nix-support/orig-libc)/include
+        export NIX_FIXINC_DUMMY=$libc_dev/include
 
         # The path to the Glibc binaries such as `crti.o'.
         glibc_libdir="$(cat $NIX_CC/nix-support/orig-libc)/lib"
@@ -171,9 +172,8 @@ preConfigure() {
         # Patch the configure script so it finds glibc headers.  It's
         # important for example in order not to get libssp built,
         # because its functionality is in glibc already.
-        glibc_headers="$(cat $NIX_CC/nix-support/orig-libc)/include"
         sed -i \
-            -e "s,glibc_header_dir=/usr/include,glibc_header_dir=$glibc_headers", \
+            -e "s,glibc_header_dir=/usr/include,glibc_header_dir=$libc_dev/include", \
             gcc/configure
     fi
 
@@ -210,9 +210,15 @@ preInstall() {
 
 
 postInstall() {
-    # Remove precompiled headers for now.  They are very big and
-    # probably not very useful yet.
-    find $out/include -name "*.gch" -exec rm -rf {} \; -prune
+    # Move runtime libraries to $lib.
+    moveToOutput "lib/lib*.so*" "$lib"
+    moveToOutput "lib/lib*.la"  "$lib"
+    ln -s lib "$lib/lib64" # for *.la
+    moveToOutput "share/gcc-*/python" "$lib"
+
+    for i in "$lib"/lib/*.{la,py}; do
+        substituteInPlace "$i" --replace "$out" "$lib"
+    done
 
     # Remove `fixincl' to prevent a retained dependency on the
     # previous gcc.
@@ -221,15 +227,23 @@ postInstall() {
 
     # More dependencies with the previous gcc or some libs (gccbug stores the build command line)
     rm -rf $out/bin/gccbug
+
     # Take out the bootstrap-tools from the rpath, as it's not needed at all having $out
-    for i in $out/libexec/gcc/*/*/*; do
-        if PREV_RPATH=`patchelf --print-rpath $i`; then
-            patchelf --set-rpath `echo $PREV_RPATH | sed 's,:[^:]*bootstrap-tools/lib,,'` $i
-        fi
+    for i in $(find "$out"/libexec/gcc/*/*/* -type f -a \! -name '*.la'); do
+        PREV_RPATH=`patchelf --print-rpath "$i"`
+        NEW_RPATH=`echo "$PREV_RPATH" | sed 's,:[^:]*bootstrap-tools/lib,,g'`
+        patchelf --set-rpath "$NEW_RPATH" "$i" && echo OK
+    done
+
+    # For some reason the libs retain RPATH to $out
+    for i in "$lib"/lib/{libtsan,libasan,libubsan}.so.*.*.*; do
+        PREV_RPATH=`patchelf --print-rpath "$i"`
+        NEW_RPATH=`echo "$PREV_RPATH" | sed "s,:${out}[^:]*,,g"`
+        patchelf --set-rpath "$NEW_RPATH" "$i" && echo OK
     done
 
     # Get rid of some "fixed" header files
-    rm -rf $out/lib/gcc/*/*/include/root
+    rm -rfv $out/lib/gcc/*/*/include-fixed/{root,linux}
 
     # Replace hard links for i686-pc-linux-gnu-gcc etc. with symlinks.
     for i in $out/bin/*-gcc*; do
@@ -250,6 +264,9 @@ postInstall() {
     paxmark r $out/libexec/gcc/*/*/{cc1,cc1plus}
 
     eval "$postInstallGhdl"
+
+    # Two identical man pages are shipped (moving and compressing is done later)
+    ln -sf gcc.1 "$out"/share/man/man1/g++.1
 }
 
 genericBuild
diff --git a/pkgs/development/compilers/ghc/6.10.2-binary.nix b/pkgs/development/compilers/ghc/6.10.2-binary.nix
index 96ec4e6c114..5a3ddc97587 100644
--- a/pkgs/development/compilers/ghc/6.10.2-binary.nix
+++ b/pkgs/development/compilers/ghc/6.10.2-binary.nix
@@ -40,14 +40,14 @@ stdenv.mkDerivation rec {
     (if stdenv.isLinux then ''
       find . -type f -perm -0100 \
           -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-          --set-rpath "${libedit}/lib:${ncurses}/lib:${gmp}/lib" {} \;
+          --set-rpath "${libedit}/lib:${ncurses.lib}/lib:${gmp.out}/lib" {} \;
       for prog in ld ar gcc strip ranlib; do
         find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
       done
      '' else "");
 
   configurePhase = ''
-    ./configure --prefix=$out --with-gmp-libraries=${gmp}/lib --with-gmp-includes=${gmp}/include
+    ./configure --prefix=$out --with-gmp-libraries=${gmp.out}/lib --with-gmp-includes=${gmp.dev}/include
   '';
 
   # Stripping combined with patchelf breaks the executables (they die
@@ -65,8 +65,8 @@ stdenv.mkDerivation rec {
     (if stdenv.isDarwin then
       ''
         mkdir -p $out/frameworks/GMP.framework/Versions/A
-        ln -s ${gmp}/lib/libgmp.dylib $out/frameworks/GMP.framework/GMP
-        ln -s ${gmp}/lib/libgmp.dylib $out/frameworks/GMP.framework/Versions/A/GMP
+        ln -s ${gmp.out}/lib/libgmp.dylib $out/frameworks/GMP.framework/GMP
+        ln -s ${gmp.out}/lib/libgmp.dylib $out/frameworks/GMP.framework/Versions/A/GMP
         # !!! fix this
         mkdir -p $out/frameworks/GNUeditline.framework/Versions/A
         ln -s ${libedit}/lib/libeditline.dylib $out/frameworks/GNUeditline.framework/GNUeditline
@@ -83,7 +83,7 @@ stdenv.mkDerivation rec {
     +
       ''
         # bah, the passing gmp doesn't work, so let's add it to the final package.conf in a quick but dirty way
-        sed -i "s@^\(.*pkgName = PackageName \"rts\".*\libraryDirs = \\[\)\(.*\)@\\1\"${gmp}/lib\",\2@" $out/lib/ghc-${version}/package.conf
+        sed -i "s@^\(.*pkgName = PackageName \"rts\".*\libraryDirs = \\[\)\(.*\)@\\1\"${gmp.out}/lib\",\2@" $out/lib/ghc-${version}/package.conf
 
         # Sanity check, can ghc create executables?
         cd $TMP
diff --git a/pkgs/development/compilers/ghc/6.10.4.nix b/pkgs/development/compilers/ghc/6.10.4.nix
index d8157673fbc..d8d25ef8082 100644
--- a/pkgs/development/compilers/ghc/6.10.4.nix
+++ b/pkgs/development/compilers/ghc/6.10.4.nix
@@ -13,8 +13,8 @@ stdenv.mkDerivation rec {
   buildInputs = [ghc libedit perl gmp];
 
   configureFlags = [
-    "--with-gmp-libraries=${gmp}/lib"
-    "--with-gmp-includes=${gmp}/include"
+    "--with-gmp-libraries=${gmp.out}/lib"
+    "--with-gmp-includes=${gmp.dev}/include"
     "--with-gcc=${stdenv.cc}/bin/gcc"
   ];
 
diff --git a/pkgs/development/compilers/ghc/6.12.3.nix b/pkgs/development/compilers/ghc/6.12.3.nix
index f6beaf3a006..e8e9b55a885 100644
--- a/pkgs/development/compilers/ghc/6.12.3.nix
+++ b/pkgs/development/compilers/ghc/6.12.3.nix
@@ -13,10 +13,10 @@ stdenv.mkDerivation rec {
   buildInputs = [ghc perl gmp ncurses];
 
   buildMK = ''
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp}/lib"
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.lib}/lib"
   '';
 
   preConfigure = ''
diff --git a/pkgs/development/compilers/ghc/7.0.4-binary.nix b/pkgs/development/compilers/ghc/7.0.4-binary.nix
index 31df7f1fa35..874cf627864 100644
--- a/pkgs/development/compilers/ghc/7.0.4-binary.nix
+++ b/pkgs/development/compilers/ghc/7.0.4-binary.nix
@@ -52,7 +52,7 @@ stdenv.mkDerivation rec {
     # We have to patch the GMP paths for the integer-gmp package.
      ''
       find . -name integer-gmp.buildinfo \
-          -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${gmp}/lib@" {} \;
+          -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${gmp.out}/lib@" {} \;
      '' + stdenv.lib.optionalString stdenv.isDarwin ''
       find . -name base.buildinfo \
           -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${libiconv}/lib@" {} \;
@@ -62,7 +62,7 @@ stdenv.mkDerivation rec {
     stdenv.lib.optionalString stdenv.isLinux ''
       find . -type f -perm -0100 \
           -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-          --set-rpath "${ncurses}/lib:${gmp}/lib" {} \;
+          --set-rpath "${ncurses.lib}/lib:${gmp.out}/lib" {} \;
       sed -i "s|/usr/bin/perl|perl\x00        |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
       sed -i "s|/usr/bin/gcc|gcc\x00        |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
       for prog in ld ar gcc strip ranlib; do
@@ -89,7 +89,7 @@ stdenv.mkDerivation rec {
 
   configurePhase = ''
     ./configure --prefix=$out \
-      --with-gmp-libraries=${gmp}/lib --with-gmp-includes=${gmp}/include \
+      --with-gmp-libraries=${gmp.out}/lib --with-gmp-includes=${gmp}/include \
       ${stdenv.lib.optionalString stdenv.isDarwin "--with-gcc=${./gcc-clang-wrapper.sh}"}
   '';
 
diff --git a/pkgs/development/compilers/ghc/7.0.4.nix b/pkgs/development/compilers/ghc/7.0.4.nix
index 281e5ca66a2..79b5f654ae9 100644
--- a/pkgs/development/compilers/ghc/7.0.4.nix
+++ b/pkgs/development/compilers/ghc/7.0.4.nix
@@ -14,10 +14,10 @@ stdenv.mkDerivation rec {
   buildInputs = [ ghc perl gmp ncurses ];
 
   buildMK = ''
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp}/lib"
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.lib}/lib"
     ${stdenv.lib.optionalString stdenv.isDarwin ''
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-libraries="${libiconv}/lib"
diff --git a/pkgs/development/compilers/ghc/7.10.2.nix b/pkgs/development/compilers/ghc/7.10.2.nix
index 73fcd788c74..7a1f7ec8c6b 100644
--- a/pkgs/development/compilers/ghc/7.10.2.nix
+++ b/pkgs/development/compilers/ghc/7.10.2.nix
@@ -5,10 +5,10 @@
 let
 
   buildMK = ''
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp}/lib"
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.lib}/lib"
     ${stdenv.lib.optionalString stdenv.isDarwin ''
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-libraries="${libiconv}/lib"
@@ -41,7 +41,7 @@ stdenv.mkDerivation rec {
 
   configureFlags = [
     "--with-gcc=${stdenv.cc}/bin/cc"
-    "--with-gmp-includes=${gmp}/include" "--with-gmp-libraries=${gmp}/lib"
+    "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
   ];
 
   # required, because otherwise all symbols from HSffi.o are stripped, and
diff --git a/pkgs/development/compilers/ghc/7.2.2.nix b/pkgs/development/compilers/ghc/7.2.2.nix
index 7276f413967..20d80753afa 100644
--- a/pkgs/development/compilers/ghc/7.2.2.nix
+++ b/pkgs/development/compilers/ghc/7.2.2.nix
@@ -14,10 +14,10 @@ stdenv.mkDerivation rec {
   buildInputs = [ ghc perl gmp ncurses ];
 
   buildMK = ''
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp}/lib"
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.lib}/lib"
     ${stdenv.lib.optionalString stdenv.isDarwin ''
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-libraries="${libiconv}/lib"
diff --git a/pkgs/development/compilers/ghc/7.4.2-binary.nix b/pkgs/development/compilers/ghc/7.4.2-binary.nix
index 03dd4dcd35b..a57aff4d864 100644
--- a/pkgs/development/compilers/ghc/7.4.2-binary.nix
+++ b/pkgs/development/compilers/ghc/7.4.2-binary.nix
@@ -61,7 +61,7 @@ stdenv.mkDerivation rec {
     # find editline/gmp.
     stdenv.lib.optionalString stdenv.isLinux ''
       mkdir -p "$out/lib"
-      ln -sv "${ncurses}/lib/libncurses.so" "$out/lib/libncurses${stdenv.lib.optionalString stdenv.is64bit "w"}.so.5"
+      ln -sv "${ncurses.lib}/lib/libncurses.so" "$out/lib/libncurses${stdenv.lib.optionalString stdenv.is64bit "w"}.so.5"
       find . -type f -perm -0100 \
           -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
           --set-rpath "$out/lib:${gmp}/lib" {} \;
diff --git a/pkgs/development/compilers/ghc/7.4.2.nix b/pkgs/development/compilers/ghc/7.4.2.nix
index b2abcb08ec3..46855e86d33 100644
--- a/pkgs/development/compilers/ghc/7.4.2.nix
+++ b/pkgs/development/compilers/ghc/7.4.2.nix
@@ -15,10 +15,10 @@ stdenv.mkDerivation rec {
   buildInputs = [ ghc perl gmp ncurses ];
 
   buildMK = ''
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp}/lib"
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.lib}/lib"
     ${stdenv.lib.optionalString stdenv.isDarwin ''
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-libraries="${libiconv}/lib"
diff --git a/pkgs/development/compilers/ghc/7.6.3.nix b/pkgs/development/compilers/ghc/7.6.3.nix
index 366c0044a67..8e630641abf 100644
--- a/pkgs/development/compilers/ghc/7.6.3.nix
+++ b/pkgs/development/compilers/ghc/7.6.3.nix
@@ -22,10 +22,10 @@ in stdenv.mkDerivation rec {
   buildInputs = [ ghc perl gmp ncurses ];
 
   buildMK = ''
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp}/lib"
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.lib}/lib"
     ${stdenv.lib.optionalString stdenv.isDarwin ''
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-libraries="${libiconv}/lib"
diff --git a/pkgs/development/compilers/ghc/7.8.3.nix b/pkgs/development/compilers/ghc/7.8.3.nix
index 2e0f5ba07e4..5d74af99dca 100644
--- a/pkgs/development/compilers/ghc/7.8.3.nix
+++ b/pkgs/development/compilers/ghc/7.8.3.nix
@@ -14,10 +14,10 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = true;
 
   buildMK = ''
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp}/lib"
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.lib}/lib"
     DYNAMIC_BY_DEFAULT = NO
     ${stdenv.lib.optionalString stdenv.isDarwin ''
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
diff --git a/pkgs/development/compilers/ghc/7.8.4.nix b/pkgs/development/compilers/ghc/7.8.4.nix
index 4323341dc4a..9020df2f053 100644
--- a/pkgs/development/compilers/ghc/7.8.4.nix
+++ b/pkgs/development/compilers/ghc/7.8.4.nix
@@ -14,10 +14,10 @@ stdenv.mkDerivation (rec {
   enableParallelBuilding = true;
 
   buildMK = ''
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp}/lib"
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.lib}/lib"
     DYNAMIC_BY_DEFAULT = NO
     ${stdenv.lib.optionalString stdenv.isDarwin ''
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix
index fe0d0b37371..43c32538b1a 100644
--- a/pkgs/development/compilers/ghc/head.nix
+++ b/pkgs/development/compilers/ghc/head.nix
@@ -3,10 +3,10 @@
 let
 
   buildMK = ''
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp}/lib"
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.lib}/lib"
     DYNAMIC_BY_DEFAULT = NO
     ${stdenv.lib.optionalString stdenv.isDarwin ''
       libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
@@ -47,7 +47,7 @@ stdenv.mkDerivation rec {
 
   configureFlags = [
     "--with-gcc=${stdenv.cc}/bin/cc"
-    "--with-gmp-includes=${gmp}/include" "--with-gmp-libraries=${gmp}/lib"
+    "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
   ];
 
   enableParallelBuilding = true;
diff --git a/pkgs/development/compilers/ghc/nokinds.nix b/pkgs/development/compilers/ghc/nokinds.nix
index 6334759496f..cad827060ad 100644
--- a/pkgs/development/compilers/ghc/nokinds.nix
+++ b/pkgs/development/compilers/ghc/nokinds.nix
@@ -3,10 +3,10 @@
 let
 
   buildMK = ''
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp}/lib"
-    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses}/include"
-    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
+    libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
+    libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.lib}/lib"
     DYNAMIC_BY_DEFAULT = NO
     SRC_HC_OPTS        = -H64m -O -fasm
     GhcLibHcOpts       = -O -dcore-lint
@@ -57,7 +57,7 @@ stdenv.mkDerivation rec {
 
   configureFlags = [
     "--with-gcc=${stdenv.cc}/bin/cc"
-    "--with-gmp-includes=${gmp}/include" "--with-gmp-libraries=${gmp}/lib"
+    "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
   ];
 
   enableParallelBuilding = true;
diff --git a/pkgs/development/compilers/ghcjs/default.nix b/pkgs/development/compilers/ghcjs/default.nix
index 5ddfdc41917..91570752380 100644
--- a/pkgs/development/compilers/ghcjs/default.nix
+++ b/pkgs/development/compilers/ghcjs/default.nix
@@ -101,12 +101,12 @@ mkDerivation (rec {
     done
   '';
   postInstall = ''
-    PATH=$out/bin:$PATH LD_LIBRARY_PATH=${gmp}/lib:${stdenv.cc}/lib64:$LD_LIBRARY_PATH \
+    PATH=$out/bin:$PATH LD_LIBRARY_PATH=${gmp.out}/lib:${stdenv.cc}/lib64:$LD_LIBRARY_PATH \
       env -u GHC_PACKAGE_PATH $out/bin/ghcjs-boot \
         --dev \
         --with-cabal ${cabal-install}/bin/cabal \
-        --with-gmp-includes ${gmp}/include \
-        --with-gmp-libraries ${gmp}/lib
+        --with-gmp-includes ${gmp.dev}/include \
+        --with-gmp-libraries ${gmp.out}/lib
   '';
   passthru = {
     isGhcjs = true;
diff --git a/pkgs/development/compilers/go/1.1.nix b/pkgs/development/compilers/go/1.1.nix
new file mode 100644
index 00000000000..0c6d4126414
--- /dev/null
+++ b/pkgs/development/compilers/go/1.1.nix
@@ -0,0 +1,101 @@
+{ stdenv, fetchurl, bison, glibc, bash, coreutils, makeWrapper, tzdata, iana_etc
+, removeGodocExternals ? false }:
+
+let
+  loader386 = "${glibc.out}/lib/ld-linux.so.2";
+  loaderAmd64 = "${glibc.out}/lib/ld-linux-x86-64.so.2";
+  loaderArm = "${glibc.out}/lib/ld-linux.so.3";
+in
+
+stdenv.mkDerivation {
+  name = "go-1.1.2";
+
+  src = fetchurl {
+    url = http://go.googlecode.com/files/go1.1.2.src.tar.gz;
+    sha256 = "0w7bchhb4b053az3wjp6z342rs9lp9nxf4w2mnfd1b89d6sb7izz";
+  };
+
+  buildInputs = [ bison glibc bash makeWrapper ];
+
+  NIX_CFLAGS_COMPILE = "-Wno-error=cpp";
+
+  # I'm not sure what go wants from its 'src', but the go installation manual
+  # describes an installation keeping the src.
+  preUnpack = ''
+    mkdir -p $out/share
+    cd $out/share
+  '';
+
+  prePatch = ''
+    cd ..
+    if [ ! -d go ]; then
+      mv * go
+    fi
+    cd go
+
+    patchShebangs ./ # replace /bin/bash
+    # !!! substituteInPlace does not seems to be effective.
+    sed -i 's,/lib/ld-linux.so.2,${loader386},' src/cmd/8l/asm.c
+    sed -i 's,/lib64/ld-linux-x86-64.so.2,${loaderAmd64},' src/cmd/6l/asm.c
+    sed -i 's,/lib64/ld-linux-x86-64.so.3,${loaderArm},' src/cmd/5l/asm.c
+    sed -i 's,/usr/share/zoneinfo/,${tzdata}/share/zoneinfo/,' src/pkg/time/zoneinfo_unix.go
+    sed -i 's,/etc/protocols,${iana_etc}/etc/protocols,' src/pkg/net/lookup_unix.go
+
+    #sed -i -e 's,/bin/cat,${coreutils}/bin/cat,' \
+    #  -e 's,/bin/echo,${coreutils}/bin/echo,' \
+    #  src/pkg/exec/exec_test.go
+
+    # Disabling the 'os/http/net' tests (they want files not available in
+    # chroot builds)
+    rm src/pkg/net/{multicast_test.go,parse_test.go,port_test.go}
+    # The os test wants to read files in an existing path. Just it don't be /usr/bin.
+    sed -i 's,/usr/bin,'"`pwd`", src/pkg/os/os_test.go
+    sed -i 's,/bin/pwd,'"`type -P pwd`", src/pkg/os/os_test.go
+    # Disable the hostname test
+    sed -i '/TestHostname/areturn' src/pkg/os/os_test.go
+    # ParseInLocation fails the test
+    sed -i '/TestParseInSydney/areturn' src/pkg/time/time_test.go
+  '' + stdenv.lib.optionalString removeGodocExternals ''
+    sed -i -e '/googleapi/d' -e '/javascript">$/,+6d' lib/godoc/godoc.html 
+  '';
+
+  patches = [ ./cacert.patch ];
+
+  GOOS = "linux";
+  GOARCH = if stdenv.system == "i686-linux" then "386"
+          else if stdenv.system == "x86_64-linux" then "amd64"
+          else if stdenv.system == "armv5tel-linux" then "arm"
+          else throw "Unsupported system";
+  GOARM = stdenv.lib.optionalString (stdenv.system == "armv5tel-linux") "5";
+
+  installPhase = ''
+    mkdir -p "$out/bin"
+    export GOROOT="$(pwd)/"
+    export GOBIN="$out/bin"
+    export PATH="$GOBIN:$PATH"
+    cd ./src
+    ./all.bash
+    cd -
+
+    # Wrap the tools to define the location of the
+    # libraries.
+    for a in go gofmt godoc; do
+	    wrapProgram "$out/bin/$a" \
+	      --set "GOROOT" $out/share/go \
+        ${if stdenv.system == "armv5tel-linux" then "--set GOARM $GOARM" else ""}
+    done
+
+    # Copy the emacs configuration for Go files.
+    mkdir -p "$out/share/emacs/site-lisp"
+    cp ./misc/emacs/* $out/share/emacs/site-lisp/
+  '';
+
+  meta = {
+    branch = "1.1";
+    homepage = http://golang.org/;
+    description = "The Go Programming language";
+    license = "BSD";
+    maintainers = with stdenv.lib.maintainers; [ pierron viric ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/pkgs/development/compilers/go/1.2.nix b/pkgs/development/compilers/go/1.2.nix
new file mode 100644
index 00000000000..0454ea96d89
--- /dev/null
+++ b/pkgs/development/compilers/go/1.2.nix
@@ -0,0 +1,91 @@
+{ stdenv, fetchurl, bison, glibc, bash, coreutils, makeWrapper, tzdata, iana_etc }:
+
+let
+  loader386 = "${glibc.out}/lib/ld-linux.so.2";
+  loaderAmd64 = "${glibc.out}/lib/ld-linux-x86-64.so.2";
+  loaderArm = "${glibc.out}/lib/ld-linux.so.3";
+in
+
+stdenv.mkDerivation {
+  name = "go-1.2.2";
+
+  src = fetchurl {
+    url = https://storage.googleapis.com/golang/go1.2.2.src.tar.gz;
+    sha1 = "3ce0ac4db434fc1546fec074841ff40dc48c1167";
+  };
+
+  buildInputs = [ bison glibc bash makeWrapper ];
+
+  NIX_CFLAGS_COMPILE = "-Wno-error=cpp";
+
+  # I'm not sure what go wants from its 'src', but the go installation manual
+  # describes an installation keeping the src.
+  preUnpack = ''
+    mkdir -p $out/share
+    cd $out/share
+  '';
+
+  prePatch = ''
+    cd ..
+    if [ ! -d go ]; then
+      mv * go
+    fi
+    cd go
+
+    patchShebangs ./ # replace /bin/bash
+    # !!! substituteInPlace does not seems to be effective.
+    sed -i 's,/lib/ld-linux.so.2,${loader386},' src/cmd/8l/asm.c
+    sed -i 's,/lib64/ld-linux-x86-64.so.2,${loaderAmd64},' src/cmd/6l/asm.c
+    sed -i 's,/lib64/ld-linux-x86-64.so.3,${loaderArm},' src/cmd/5l/asm.c
+    sed -i 's,/usr/share/zoneinfo/,${tzdata}/share/zoneinfo/,' src/pkg/time/zoneinfo_unix.go
+    sed -i 's,/etc/protocols,${iana_etc}/etc/protocols,' src/pkg/net/lookup_unix.go
+
+    #sed -i -e 's,/bin/cat,${coreutils}/bin/cat,' \
+    #  -e 's,/bin/echo,${coreutils}/bin/echo,' \
+    #  src/pkg/exec/exec_test.go
+
+    # Disabling the 'os/http/net' tests (they want files not available in
+    # chroot builds)
+    rm src/pkg/net/{multicast_test.go,parse_test.go,port_test.go}
+    # The os test wants to read files in an existing path. Just it don't be /usr/bin.
+    sed -i 's,/usr/bin,'"`pwd`", src/pkg/os/os_test.go
+    sed -i 's,/bin/pwd,'"`type -P pwd`", src/pkg/os/os_test.go
+    # Disable the hostname test
+    sed -i '/TestHostname/areturn' src/pkg/os/os_test.go
+    # ParseInLocation fails the test
+    sed -i '/TestParseInSydney/areturn' src/pkg/time/time_test.go
+  '';
+
+  patches = [ ./cacert-1.2.patch ];
+
+  GOOS = "linux";
+  GOARCH = if stdenv.system == "i686-linux" then "386"
+          else if stdenv.system == "x86_64-linux" then "amd64"
+          else if stdenv.system == "armv5tel-linux" then "arm"
+          else throw "Unsupported system";
+  GOARM = stdenv.lib.optionalString (stdenv.system == "armv5tel-linux") "5";
+  GO386 = 387; # from Arch: don't assume sse2 on i686
+
+  installPhase = ''
+    mkdir -p "$out/bin"
+    export GOROOT="$(pwd)/"
+    export GOBIN="$out/bin"
+    export PATH="$GOBIN:$PATH"
+    cd ./src
+    ./all.bash
+    cd -
+
+    # Copy the emacs configuration for Go files.
+    mkdir -p "$out/share/emacs/site-lisp"
+    cp ./misc/emacs/* $out/share/emacs/site-lisp/
+  '';
+
+  meta = {
+    branch = "1.2";
+    homepage = http://golang.org/;
+    description = "The Go Programming language";
+    license = "BSD";
+    maintainers = with stdenv.lib.maintainers; [ pierron viric ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/pkgs/development/compilers/go/1.3.nix b/pkgs/development/compilers/go/1.3.nix
new file mode 100644
index 00000000000..a9a3c10584b
--- /dev/null
+++ b/pkgs/development/compilers/go/1.3.nix
@@ -0,0 +1,113 @@
+{ stdenv, lib, fetchurl, fetchhg, bison, glibc, bash, coreutils, makeWrapper, tzdata, iana_etc, perl }:
+
+let
+  loader386 = "${glibc.out}/lib/ld-linux.so.2";
+  loaderAmd64 = "${glibc.out}/lib/ld-linux-x86-64.so.2";
+  loaderArm = "${glibc.out}/lib/ld-linux.so.3";
+  srcs = {
+    golang = fetchurl {
+      url = https://storage.googleapis.com/golang/go1.3.3.src.tar.gz;
+      sha1 = "b54b7deb7b7afe9f5d9a3f5dd830c7dede35393a";
+    };
+    tools = fetchhg {
+      url = https://code.google.com/p/go.tools/;
+      rev = "e1c276c4e679";
+      sha256 = "0x62njflwkd99i2ixbksg6mjppl1wfg86f0g3swn350l1h0xzp76";
+    };
+  };
+in
+
+stdenv.mkDerivation {
+  name = "go-1.3.3";
+
+  src = srcs.golang;
+
+  # perl is used for testing go vet
+  buildInputs = [ bison bash makeWrapper perl ] ++ lib.optionals stdenv.isLinux [ glibc ] ;
+
+  # I'm not sure what go wants from its 'src', but the go installation manual
+  # describes an installation keeping the src.
+  preUnpack = ''
+    mkdir -p $out/share
+    cd $out/share
+  '';
+  postUnpack = ''
+    mkdir -p $out/share/go/src/pkg/code.google.com/p/
+    cp -rv --no-preserve=mode,ownership ${srcs.tools} $out/share/go/src/pkg/code.google.com/p/go.tools
+  '';
+
+  prePatch = ''
+    # Ensure that the source directory is named go
+    cd ..
+    if [ ! -d go ]; then
+      mv * go
+    fi
+    cd go
+    patchShebangs ./ # replace /bin/bash
+
+    # Disabling the 'os/http/net' tests (they want files not available in
+    # chroot builds)
+    rm src/pkg/net/{multicast_test.go,parse_test.go,port_test.go}
+    # !!! substituteInPlace does not seems to be effective.
+    # The os test wants to read files in an existing path. Just don't let it be /usr/bin.
+    sed -i 's,/usr/bin,'"`pwd`", src/pkg/os/os_test.go
+    sed -i 's,/bin/pwd,'"`type -P pwd`", src/pkg/os/os_test.go
+    # Disable the unix socket test
+    sed -i '/TestShutdownUnix/areturn' src/pkg/net/net_test.go
+    # Disable the hostname test
+    sed -i '/TestHostname/areturn' src/pkg/os/os_test.go
+    sed -i 's,/etc/protocols,${iana_etc}/etc/protocols,' src/pkg/net/lookup_unix.go
+    # ParseInLocation fails the test
+    sed -i '/TestParseInSydney/areturn' src/pkg/time/format_test.go
+  '' + lib.optionalString stdenv.isLinux ''
+    sed -i 's,/usr/share/zoneinfo/,${tzdata}/share/zoneinfo/,' src/pkg/time/zoneinfo_unix.go
+    sed -i 's,/lib/ld-linux.so.3,${loaderArm},' src/cmd/5l/asm.c
+    sed -i 's,/lib64/ld-linux-x86-64.so.2,${loaderAmd64},' src/cmd/6l/asm.c
+    sed -i 's,/lib/ld-linux.so.2,${loader386},' src/cmd/8l/asm.c
+  '';
+
+  patches = [ ./cacert-1.2.patch ];
+
+  GOOS = if stdenv.isDarwin then "darwin" else "linux";
+  GOARCH = if stdenv.isDarwin then "amd64"
+           else if stdenv.system == "i686-linux" then "386"
+           else if stdenv.system == "x86_64-linux" then "amd64"
+           else if stdenv.system == "armv5tel-linux" then "arm"
+           else throw "Unsupported system";
+  GOARM = stdenv.lib.optionalString (stdenv.system == "armv5tel-linux") "5";
+  GO386 = 387; # from Arch: don't assume sse2 on i686
+  CGO_ENABLED = if stdenv.isDarwin then 0 else 1;
+
+  installPhase = ''
+    export CC=cc
+    mkdir -p "$out/bin"
+    unset GOPATH
+    export GOROOT="$(pwd)/"
+    export GOBIN="$out/bin"
+    export PATH="$GOBIN:$PATH"
+    cd ./src
+    ./all.bash
+    cd -
+
+    # Build extra tooling
+    # TODO: Fix godoc tests
+    TOOL_ROOT=code.google.com/p/go.tools/cmd
+    go install -v $TOOL_ROOT/cover $TOOL_ROOT/vet $TOOL_ROOT/godoc
+    go test -v    $TOOL_ROOT/cover $TOOL_ROOT/vet # $TOOL_ROOT/godoc
+
+    # Copy the emacs configuration for Go files.
+    mkdir -p "$out/share/emacs/site-lisp"
+    cp ./misc/emacs/* $out/share/emacs/site-lisp/
+  '';
+
+  setupHook = ./setup-hook.sh;
+
+  meta = {
+    branch = "1.3";
+    homepage = http://golang.org/;
+    description = "The Go Programming language";
+    license = "BSD";
+    maintainers = with stdenv.lib.maintainers; [ cstrahan ];
+    platforms = stdenv.lib.platforms.linux ++ stdenv.lib.platforms.darwin;
+  };
+}
diff --git a/pkgs/development/compilers/go/1.4.nix b/pkgs/development/compilers/go/1.4.nix
index d2500169744..a31ef704e6a 100644
--- a/pkgs/development/compilers/go/1.4.nix
+++ b/pkgs/development/compilers/go/1.4.nix
@@ -56,7 +56,7 @@ stdenv.mkDerivation rec {
     sed -i 's,/usr/share/zoneinfo/,${tzdata}/share/zoneinfo/,' src/time/zoneinfo_unix.go
 
     # Find the loader dynamically
-    LOADER="$(find ${libc}/lib -name ld-linux\* | head -n 1)"
+    LOADER="$(find ${libc.out or libc}/lib -name ld-linux\* | head -n 1)"
 
     # Replace references to the loader
     find src/cmd -name asm.c -exec sed -i "s,/lib/ld-linux.*\.so\.[0-9],$LOADER," {} \;
diff --git a/pkgs/development/compilers/go/default.nix b/pkgs/development/compilers/go/default.nix
new file mode 100644
index 00000000000..c684d7d5ee5
--- /dev/null
+++ b/pkgs/development/compilers/go/default.nix
@@ -0,0 +1,95 @@
+{ stdenv, fetchurl, bison, glibc, bash, coreutils, makeWrapper, tzdata}:
+
+let
+  loader386 = "${glibc.out}/lib/ld-linux.so.2";
+  loaderAmd64 = "${glibc.out}/lib/ld-linux-x86-64.so.2";
+  loaderArm = "${glibc.out}/lib/ld-linux.so.3";
+in
+
+stdenv.mkDerivation {
+  name = "go-1.0.3";
+
+  src = fetchurl {
+    url = http://go.googlecode.com/files/go1.0.3.src.tar.gz;
+    sha256 = "1pz31az3icwqfqfy3avms05jnqr0qrbrx9yqsclkdwbjs4rkbfkz";
+  };
+
+  buildInputs = [ bison glibc bash makeWrapper ];
+
+  # I'm not sure what go wants from its 'src', but the go installation manual
+  # describes an installation keeping the src.
+  preUnpack = ''
+    mkdir -p $out/share
+    cd $out/share
+  '';
+
+  prePatch = ''
+    cd ..
+    if [ ! -d go ]; then
+      mv * go
+    fi
+    cd go
+
+    patchShebangs ./ # replace /bin/bash
+    # !!! substituteInPlace does not seems to be effective.
+    sed -i 's,/lib/ld-linux.so.2,${loader386},' src/cmd/8l/asm.c
+    sed -i 's,/lib64/ld-linux-x86-64.so.2,${loaderAmd64},' src/cmd/6l/asm.c
+    sed -i 's,/lib64/ld-linux-x86-64.so.3,${loaderArm},' src/cmd/5l/asm.c
+    sed -i 's,/usr/share/zoneinfo/,${tzdata}/share/zoneinfo/,' src/pkg/time/zoneinfo_unix.go
+
+    #sed -i -e 's,/bin/cat,${coreutils}/bin/cat,' \
+    #  -e 's,/bin/echo,${coreutils}/bin/echo,' \
+    #  src/pkg/exec/exec_test.go
+
+    # Disabling the 'os/http/net' tests (they want files not available in
+    # chroot builds)
+    rm src/pkg/net/{multicast_test.go,parse_test.go,port_test.go}
+    # The os test wants to read files in an existing path. Just it don't be /usr/bin.
+    sed -i 's,/usr/bin,'"`pwd`", src/pkg/os/os_test.go
+    sed -i 's,/bin/pwd,'"`type -P pwd`", src/pkg/os/os_test.go
+    # Disable the hostname test
+    sed -i '/TestHostname/areturn' src/pkg/os/os_test.go
+  '';
+
+  patches = [ ./cacert.patch ./1_0-opt-error.patch ./1_0-gcc-bug.patch ];
+
+  GOOS = "linux";
+  GOARCH = if stdenv.system == "i686-linux" then "386"
+          else if stdenv.system == "x86_64-linux" then "amd64"
+          else if stdenv.system == "armv5tel-linux" then "arm"
+          else throw "Unsupported system";
+  GOARM = stdenv.lib.optionalString (stdenv.system == "armv5tel-linux") "5";
+
+  NIX_CFLAGS_COMPILE = "-Wno-error=cpp";
+
+  installPhase = ''
+    mkdir -p "$out/bin"
+    export GOROOT="$(pwd)/"
+    export GOBIN="$out/bin"
+    export PATH="$GOBIN:$PATH"
+    cd ./src
+    ./all.bash
+    cd -
+
+    # Wrap the tools to define the location of the
+    # libraries.
+    for a in go gofmt godoc; do
+	    wrapProgram "$out/bin/$a" \
+	      --set "GOROOT" $out/share/go \
+        ${if stdenv.system == "armv5tel-linux" then "--set GOARM $GOARM" else ""}
+    done
+
+    # Copy the emacs configuration for Go files.
+    mkdir -p "$out/share/emacs/site-lisp"
+    cp ./misc/emacs/* $out/share/emacs/site-lisp/
+  '';
+
+  meta = {
+    branch = "1.0";
+    homepage = http://golang.org/;
+    description = "The Go Programming language";
+    license = "BSD";
+    maintainers = with stdenv.lib.maintainers; [ pierron viric ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/pkgs/development/compilers/llvm/3.7/llvm.nix b/pkgs/development/compilers/llvm/3.7/llvm.nix
index 060c0f3e867..045d2e4951a 100644
--- a/pkgs/development/compilers/llvm/3.7/llvm.nix
+++ b/pkgs/development/compilers/llvm/3.7/llvm.nix
@@ -56,6 +56,8 @@ in stdenv.mkDerivation rec {
     "-DCAN_TARGET_i386=false"
   ];
 
+  NIX_LDFLAGS = "-lpthread"; # no idea what's the problem
+
   postBuild = ''
     rm -fR $out
 
diff --git a/pkgs/development/compilers/mentor/default.nix b/pkgs/development/compilers/mentor/default.nix
index 7ff013b2344..573bf821031 100644
--- a/pkgs/development/compilers/mentor/default.nix
+++ b/pkgs/development/compilers/mentor/default.nix
@@ -34,7 +34,7 @@ let
 
             # GDB needs ncurses
             case "$file" in
-              *gdb) patchelf --set-rpath "${ncurses}/lib" "$file";;
+              *gdb) patchelf --set-rpath "${ncurses.lib}/lib" "$file";;
             esac
         done
 
diff --git a/pkgs/development/compilers/mkcl/default.nix b/pkgs/development/compilers/mkcl/default.nix
index f6ab05bd29b..af1ebd6a196 100644
--- a/pkgs/development/compilers/mkcl/default.nix
+++ b/pkgs/development/compilers/mkcl/default.nix
@@ -14,8 +14,8 @@ stdenv.mkDerivation rec {
   propagatedBuildInputs = [ gmp ];
 
   configureFlags = [
-    "GMP_CFLAGS=-I${gmp}/include"
-    "GMP_LDFLAGS=-L${gmp}/lib"
+    "GMP_CFLAGS=-I${gmp.dev}/include"
+    "GMP_LDFLAGS=-L${gmp.out}/lib"
   ];
 
   postInstall = ''
diff --git a/pkgs/development/compilers/mlton/default.nix b/pkgs/development/compilers/mlton/default.nix
index 381941acc20..c4890c1ca88 100644
--- a/pkgs/development/compilers/mlton/default.nix
+++ b/pkgs/development/compilers/mlton/default.nix
@@ -6,8 +6,8 @@ let
   usr_prefix = if stdenv.isDarwin then "usr/local" else "usr";
 
   dynamic_linker =
-    if stdenv.isx86_64 then "${stdenv.glibc}/lib/ld-linux-x86-64.so.2"
-                       else "${stdenv.glibc}/lib/ld-linux.so.2";
+    if stdenv.isx86_64 then "${stdenv.glibc.out}/lib/ld-linux-x86-64.so.2"
+                       else "${stdenv.glibc.out}/lib/ld-linux.so.2";
 in
 
 stdenv.mkDerivation rec {
@@ -73,7 +73,7 @@ stdenv.mkDerivation rec {
     chmod u+x $(pwd)/../${usr_prefix}/bin/mlton
 
     # So the builder runs the binary compiler with gmp.
-    export LD_LIBRARY_PATH=${gmp}/lib:$LD_LIBRARY_PATH
+    export LD_LIBRARY_PATH=${gmp.out}/lib:$LD_LIBRARY_PATH
 
   '' + stdenv.lib.optionalString stdenv.isLinux ''
     # Patch ELF interpreter.
@@ -92,10 +92,10 @@ stdenv.mkDerivation rec {
     substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace '/${usr_prefix}/lib/mlton' $out/lib/mlton
 
     # Path to libgmp.
-    substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "-link-opt '-lm -lgmp'" "-link-opt '-lm -lgmp -L${gmp}/lib'"
+    substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "-link-opt '-lm -lgmp'" "-link-opt '-lm -lgmp -L${gmp.out}/lib'"
 
     # Path to gmp.h.
-    substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "-cc-opt '-O1 -fno-common'" "-cc-opt '-O1 -fno-common -I${gmp}/include'"
+    substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "-cc-opt '-O1 -fno-common'" "-cc-opt '-O1 -fno-common -I${gmp.dev}/include'"
 
     # Path to the same cc used in the build; needed at runtime.
     substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "gcc='gcc'" "gcc='"$(type -p cc)"'"
diff --git a/pkgs/development/compilers/nim/default.nix b/pkgs/development/compilers/nim/default.nix
index 6e552959fdb..cfa725d3d31 100644
--- a/pkgs/development/compilers/nim/default.nix
+++ b/pkgs/development/compilers/nim/default.nix
@@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
   buildPhase   = "sh build.sh";
   installPhase =
     ''
-      installBin bin/nim
+      install -Dt "$out/bin" bin/nim
       substituteInPlace install.sh --replace '$1/nim' "$out"
       sh install.sh $out
     '';
diff --git a/pkgs/development/compilers/nvidia-cg-toolkit/default.nix b/pkgs/development/compilers/nvidia-cg-toolkit/default.nix
index 9c6d07c4681..ab71090b358 100644
--- a/pkgs/development/compilers/nvidia-cg-toolkit/default.nix
+++ b/pkgs/development/compilers/nvidia-cg-toolkit/default.nix
@@ -25,7 +25,7 @@ stdenv.mkDerivation rec {
   installPhase = ''
     for b in cgc cgfxcat cginfo
     do
-        patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux*.so.? "bin/$b"
+        patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux*.so.? "bin/$b"
     done
     # FIXME: cgfxcat and cginfo need more patchelf
     mkdir -p "$out/bin/"
diff --git a/pkgs/development/compilers/openjdk/7.nix b/pkgs/development/compilers/openjdk/7.nix
index 97ffbf9f099..de803a5d90c 100644
--- a/pkgs/development/compilers/openjdk/7.nix
+++ b/pkgs/development/compilers/openjdk/7.nix
@@ -106,9 +106,9 @@ let
 
     makeFlags = [
       "SORT=${coreutils}/bin/sort"
-      "ALSA_INCLUDE=${alsaLib}/include/alsa/version.h"
-      "FREETYPE_HEADERS_PATH=${freetype}/include"
-      "FREETYPE_LIB_PATH=${freetype}/lib"
+      "ALSA_INCLUDE=${alsaLib.dev}/include/alsa/version.h"
+      "FREETYPE_HEADERS_PATH=${freetype.dev}/include"
+      "FREETYPE_LIB_PATH=${freetype.out}/lib"
       "MILESTONE=${update}"
       "BUILD_NUMBER=b${build}"
       "USRBIN_PATH="
diff --git a/pkgs/development/compilers/openjdk/8.nix b/pkgs/development/compilers/openjdk/8.nix
index bbbae38f6b8..48d7dd5dffb 100644
--- a/pkgs/development/compilers/openjdk/8.nix
+++ b/pkgs/development/compilers/openjdk/8.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, cpio, file, which, unzip, zip, xorg, cups, freetype
+{ stdenv, fetchurl, cpio, pkgconfig, file, which, unzip, zip, xorg, cups, freetype
 , alsaLib, bootjdk, cacert, perl, liberation_ttf, fontconfig, zlib
 , setJavaClassPath
 , minimal ? false
@@ -63,6 +63,7 @@ let
 
     outputs = [ "out" "jre" ];
 
+    nativeBuildInputs = [ pkgconfig ];
     buildInputs = [
       cpio file which unzip zip
       xorg.libX11 xorg.libXt xorg.libXext xorg.libXrender xorg.libXtst
@@ -93,7 +94,6 @@ let
     '';
 
     configureFlags = [
-      "--with-freetype=${freetype}"
       "--with-boot-jdk=${bootjdk.home}"
       "--with-update-version=${update}"
       "--with-build-number=${build}"
diff --git a/pkgs/development/compilers/openjdk/bootstrap.nix b/pkgs/development/compilers/openjdk/bootstrap.nix
index a9ca7673dfe..48a22638813 100644
--- a/pkgs/development/compilers/openjdk/bootstrap.nix
+++ b/pkgs/development/compilers/openjdk/bootstrap.nix
@@ -40,13 +40,13 @@ let
     LIBDIRS="$(find $out -name \*.so\* -exec dirname {} \; | sort | uniq | tr '\n' ':')"
 
     for i in $out/bin/*; do
-      patchelf --set-interpreter ${glibc}/lib/ld-linux*.so.2 $i || true
-      patchelf --set-rpath "${glibc}/lib:$LIBDIRS" $i || true
+      patchelf --set-interpreter ${glibc.out}/lib/ld-linux*.so.2 $i || true
+      patchelf --set-rpath "${glibc.out}/lib:$LIBDIRS" $i || true
     done
 
     find $out -name \*.so\* | while read lib; do
-      patchelf --set-interpreter ${glibc}/lib/ld-linux*.so.2 $lib || true
-      patchelf --set-rpath "${glibc}/lib:${stdenv.cc.cc}/lib:$LIBDIRS" $lib || true
+      patchelf --set-interpreter ${glibc.out}/lib/ld-linux*.so.2 $lib || true
+      patchelf --set-rpath "${glibc.out}/lib:${stdenv.cc.cc.lib}/lib:$LIBDIRS" $lib || true
     done
 
     # Temporarily, while NixOS's OpenJDK bootstrap tarball doesn't have PaX markings:
diff --git a/pkgs/development/compilers/orc/default.nix b/pkgs/development/compilers/orc/default.nix
index 3b8916c67e9..22fb400a1ea 100644
--- a/pkgs/development/compilers/orc/default.nix
+++ b/pkgs/development/compilers/orc/default.nix
@@ -8,20 +8,25 @@ stdenv.mkDerivation rec {
     sha256 = "1ryz1gfgrxcj806cakcblxf0bcwq8p2mw8k86fs3f5wlwayawzkn";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "dev" "out" ];
+  outputBin = "dev"; # compilation tools
+
+  postInstall = ''
+    sed "/^toolsdir=/ctoolsdir=$dev/bin" -i "$dev"/lib/pkgconfig/orc*.pc
+  '';
 
   # building memcpy_speed.log
   # ../test-driver: line 107:  4495 Segmentation fault      "$@" > $log_file 2>&1
   # FAIL: memcpy_speed
   doCheck = false; # see https://bugzilla.gnome.org/show_bug.cgi?id=728129#c7
 
-  meta = {
+  meta = with stdenv.lib; {
     description = "The Oil Runtime Compiler";
     homepage = "http://code.entropywave.com/orc/";
     # The source code implementing the Marsenne Twister algorithm is licensed
     # under the 3-clause BSD license. The rest is 2-clause BSD license.
-    license = stdenv.lib.licenses.bsd3;
-    platforms = stdenv.lib.platforms.unix;
-    maintainers = with stdenv.lib.maintainers; [ fuuzetsu ];
+    license = licenses.bsd3;
+    platforms = platforms.unix;
+    maintainers = [ maintainers.fuuzetsu ];
   };
 }
diff --git a/pkgs/development/compilers/path64/default.nix b/pkgs/development/compilers/path64/default.nix
index d6112dcdfc4..694bdc8990f 100644
--- a/pkgs/development/compilers/path64/default.nix
+++ b/pkgs/development/compilers/path64/default.nix
@@ -13,7 +13,7 @@ stdenv.mkDerivation {
 
   patchPhase = ''
     sed -i s,/usr/bin/ld,$(type -P ld), src/driver/phases.c
-    sed -i s,/lib64/ld-linux-x86-64.so.2,${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2, src/include/main_defs.h.in
+    sed -i s,/lib64/ld-linux-x86-64.so.2,${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2, src/include/main_defs.h.in
   '';
 
   cmakeFlags = ''
@@ -22,7 +22,7 @@ stdenv.mkDerivation {
     -DPATH64_ENABLE_PSCRUNTIME=OFF
     -DPATH64_ENABLE_PROFILING=OFF -DPATH64_ENABLE_TARGETS=x8664 
     -DCMAKE_BUILD_TYPE=Debug -DPATH64_ENABLE_FORTRAN=OFF
-    -DPSC_CRT_PATH=${stdenv.cc.libc}/lib
+    -DPSC_CRT_PATH=${stdenv.cc.libc.out}/lib
   '';
 
   makeFlags = "-j4";
diff --git a/pkgs/development/compilers/rustc/generic.nix b/pkgs/development/compilers/rustc/generic.nix
index d578facad69..b88782517d7 100644
--- a/pkgs/development/compilers/rustc/generic.nix
+++ b/pkgs/development/compilers/rustc/generic.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchurl, fetchgit, fetchzip, file, python2, tzdata, procps
-, llvmPackages_37, jemalloc, ncurses
+, llvmPackages_37, jemalloc, ncurses, binutils
 
 , shortVersion, isRelease
 , forceBundledLLVM ? false
@@ -112,8 +112,8 @@ with stdenv.lib; stdenv.mkDerivation {
       mkdir -p "$out"
       cp -r bin "$out/bin"
     '' + optionalString stdenv.isLinux ''
-      patchelf --interpreter "${stdenv.glibc}/lib/${stdenv.cc.dynamicLinker}" \
-               --set-rpath "${stdenv.cc.cc}/lib/:${stdenv.cc.cc}/lib64/" \
+      patchelf --interpreter "${stdenv.glibc.out}/lib/${stdenv.cc.dynamicLinker}" \
+               --set-rpath "${stdenv.cc.cc.lib}/lib/:${stdenv.cc.cc.lib}/lib64/" \
                "$out/bin/rustc"
     '';
   };
@@ -121,7 +121,7 @@ with stdenv.lib; stdenv.mkDerivation {
   configureFlags = configureFlags
                 ++ [ "--enable-local-rust" "--local-rust-root=$snapshot" "--enable-rpath" ]
                 # ++ [ "--jemalloc-root=${jemalloc}/lib"
-                ++ [ "--default-linker=${stdenv.cc}/bin/cc" "--default-ar=${stdenv.cc.binutils}/bin/ar" ]
+                ++ [ "--default-linker=${stdenv.cc}/bin/cc" "--default-ar=${binutils}/bin/ar" ]
                 ++ optional (stdenv.cc.cc ? isClang) "--enable-clang"
                 ++ optional (!forceBundledLLVM) "--llvm-root=${llvmShared}";
 
diff --git a/pkgs/development/compilers/tinycc/default.nix b/pkgs/development/compilers/tinycc/default.nix
index c9378451d1f..9da1ef0dd9a 100644
--- a/pkgs/development/compilers/tinycc/default.nix
+++ b/pkgs/development/compilers/tinycc/default.nix
@@ -19,9 +19,9 @@ stdenv.mkDerivation rec {
 
   preConfigure = ''
     configureFlagsArray+=("--elfinterp=$(cat $NIX_CC/nix-support/dynamic-linker)")
-    configureFlagsArray+=("--crtprefix=${stdenv.glibc}/lib")
-    configureFlagsArray+=("--sysincludepaths=${stdenv.glibc}/include:{B}/include")
-    configureFlagsArray+=("--libpaths=${stdenv.glibc}/lib")
+    configureFlagsArray+=("--crtprefix=${stdenv.glibc.out}/lib")
+    configureFlagsArray+=("--sysincludepaths=${stdenv.glibc.dev}/include:{B}/include")
+    configureFlagsArray+=("--libpaths=${stdenv.glibc.out}/lib")
   '';
 
   doCheck = true;
diff --git a/pkgs/development/compilers/urweb/default.nix b/pkgs/development/compilers/urweb/default.nix
index 3e4b0bcae5b..c53cddc0ad1 100644
--- a/pkgs/development/compilers/urweb/default.nix
+++ b/pkgs/development/compilers/urweb/default.nix
@@ -22,12 +22,12 @@ stdenv.mkDerivation rec {
   preConfigure = ''
     export PGHEADER="${postgresql}/include/libpq-fe.h";
     export MSHEADER="${mysql.lib}/include/mysql/mysql.h";
-    export SQHEADER="${sqlite}/include/sqlite3.h";
+    export SQHEADER="${sqlite.dev}/include/sqlite3.h";
 
     export CCARGS="-I$out/include \
                    -L${mysql.lib}/lib/mysql \
-                   -L${postgresql}/lib \
-                   -L${sqlite}/lib";
+                   -L${postgresql.lib}/lib \
+                   -L${sqlite.out}/lib";
   '';
 
   # Be sure to keep the statically linked libraries
diff --git a/pkgs/development/interpreters/elixir/default.nix b/pkgs/development/interpreters/elixir/default.nix
index 380da51da77..21523899b92 100644
--- a/pkgs/development/interpreters/elixir/default.nix
+++ b/pkgs/development/interpreters/elixir/default.nix
@@ -30,7 +30,7 @@ stdenv.mkDerivation {
      b=$(basename $f)
       if [ $b == "mix" ]; then continue; fi
       wrapProgram $f \
-        --prefix PATH ":" "${erlang}/bin:${coreutils}/bin:${curl}/bin:${bash}/bin" \
+        --prefix PATH ":" "${erlang}/bin:${coreutils}/bin:${curl.bin}/bin:${bash}/bin" \
         --set CURL_CA_BUNDLE /etc/ssl/certs/ca-certificates.crt
     done
 
diff --git a/pkgs/development/interpreters/guile/default.nix b/pkgs/development/interpreters/guile/default.nix
index c4634de5d3f..bb0ef7594a4 100644
--- a/pkgs/development/interpreters/guile/default.nix
+++ b/pkgs/development/interpreters/guile/default.nix
@@ -49,7 +49,7 @@
     sed -i "$out/lib/pkgconfig/guile-2.0.pc"    \
         -e 's|-lunistring|-L${libunistring}/lib -lunistring|g ;
             s|^Cflags:\(.*\)$|Cflags: -I${libunistring}/include \1|g ;
-            s|-lltdl|-L${libtool}/lib -lltdl|g'
+            s|-lltdl|-L${libtool.lib}/lib -lltdl|g'
   '';
 
   # make check doesn't work on darwin
diff --git a/pkgs/development/interpreters/love/default.nix b/pkgs/development/interpreters/love/default.nix
index fc1f01cb373..b12c2c40578 100644
--- a/pkgs/development/interpreters/love/default.nix
+++ b/pkgs/development/interpreters/love/default.nix
@@ -36,7 +36,7 @@ stdenv.mkDerivation rec {
   '';
 
   NIX_CFLAGS_COMPILE = ''
-    -I${SDL}/include/SDL
+    -I${SDL.dev}/include/SDL
     -I${freetype}include/freetype2
   '';
 
diff --git a/pkgs/development/interpreters/lua-5/expat.nix b/pkgs/development/interpreters/lua-5/expat.nix
index 0dbbaf8a161..243abae331a 100644
--- a/pkgs/development/interpreters/lua-5/expat.nix
+++ b/pkgs/development/interpreters/lua-5/expat.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
     makeFlagsArray=(
       LUA_LDIR="$out/share/lua/${lua5.luaversion}"
       LUA_INC="-I${lua5}/include" LUA_CDIR="$out/lib/lua/${lua5.luaversion}"
-      EXPAT_INC="-I${expat}/include");
+      EXPAT_INC="-I${expat.dev}/include");
   '';
 
   meta = {
diff --git a/pkgs/development/interpreters/luajit/default.nix b/pkgs/development/interpreters/luajit/default.nix
index 8e148f1189c..0d4a5ef2d6a 100644
--- a/pkgs/development/interpreters/luajit/default.nix
+++ b/pkgs/development/interpreters/luajit/default.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
   '' + stdenv.lib.optionalString (stdenv.cc.libc != null)
   ''
     substituteInPlace Makefile \
-      --replace ldconfig ${stdenv.cc.libc}/sbin/ldconfig
+      --replace ldconfig ${stdenv.cc.libc.bin}/bin/ldconfig
   '';
 
   configurePhase = false;
diff --git a/pkgs/development/interpreters/perl/5.20/default.nix b/pkgs/development/interpreters/perl/5.20/default.nix
index 05d64e9c511..eacf8620f7b 100644
--- a/pkgs/development/interpreters/perl/5.20/default.nix
+++ b/pkgs/development/interpreters/perl/5.20/default.nix
@@ -28,8 +28,11 @@ stdenv.mkDerivation rec {
     sha256 = "17cvplgpxbm1hshxlkra2fldn4da1iap1lsnb04hdm8ply93k95i";
   };
 
+  # TODO: Add a "dev" output containing the header files.
   outputs = [ "out" "man" ];
 
+  setOutputFlags = false;
+
   patches =
     [ # Do not look in /usr etc. for dependencies.
       ./no-sys-dirs.patch
@@ -63,8 +66,8 @@ stdenv.mkDerivation rec {
       "-Uinstallusrbinperl"
       "-Dinstallstyle=lib/perl5"
       "-Duseshrplib"
-      "-Dlocincpth=${libc}/include"
-      "-Dloclibpth=${libc}/lib"
+      "-Dlocincpth=${libc.dev or libc}/include"
+      "-Dloclibpth=${libc.out or libc}/lib"
     ]
     ++ optional stdenv.isSunOS "-Dcc=gcc"
     ++ optional enableThreading "-Dusethreads";
@@ -92,6 +95,17 @@ stdenv.mkDerivation rec {
       substituteInPlace dist/PathTools/Cwd.pm --replace "'/bin/pwd'" "'$(type -tP pwd)'"
     '';
 
+  postInstall =
+    ''
+      # Remove dependency between "out" and "man" outputs.
+      rm $out/lib/perl5/*/*/.packlist
+
+      # Remove dependencies on glibc.dev and coreutils.
+      substituteInPlace $out/lib/perl5/*/*/Config_heavy.pl \
+        --replace ${stdenv.glibc.dev or "/blabla"} /no-such-path \
+        --replace $man /no-such-path
+    ''; # */
+
   setupHook = ./setup-hook.sh;
 
   passthru.libPrefix = "lib/perl5/site_perl";
diff --git a/pkgs/development/interpreters/perl/5.22/default.nix b/pkgs/development/interpreters/perl/5.22/default.nix
index 53e777c19a1..99ae93c77b5 100644
--- a/pkgs/development/interpreters/perl/5.22/default.nix
+++ b/pkgs/development/interpreters/perl/5.22/default.nix
@@ -15,7 +15,8 @@ assert enableThreading -> (stdenv ? glibc);
 let
 
   libc = if stdenv.cc.libc or null != null then stdenv.cc.libc else "/usr";
-
+  libcInc = libc.dev or libc;
+  libcLib = libc.out or libc;
 in
 
 with stdenv.lib;
@@ -28,7 +29,8 @@ stdenv.mkDerivation rec {
     sha256 = "0g5bl8sdpzx9gx2g5jq3py4bj07z2ylk7s1qn0fvsss2yl3hhs8c";
   };
 
-  outputs = [ "out" "man" ];
+  outputs = [ "out" "man" "docdev" ];
+  setOutputFlags = false;
 
   patches =
     [ # Do not look in /usr etc. for dependencies.
@@ -48,8 +50,8 @@ stdenv.mkDerivation rec {
       "-Uinstallusrbinperl"
       "-Dinstallstyle=lib/perl5"
       "-Duseshrplib"
-      "-Dlocincpth=${libc}/include"
-      "-Dloclibpth=${libc}/lib"
+      "-Dlocincpth=${libcInc}/include"
+      "-Dloclibpth=${libcLib}/lib"
     ]
     ++ optional stdenv.isSunOS "-Dcc=gcc"
     ++ optional enableThreading "-Dusethreads";
@@ -69,10 +71,8 @@ stdenv.mkDerivation rec {
   preConfigure =
     ''
       configureFlags="$configureFlags -Dprefix=$out -Dman1dir=$out/share/man/man1 -Dman3dir=$out/share/man/man3"
-
-      ${optionalString stdenv.isArm ''
-        configureFlagsArray=(-Dldflags="-lm -lrt")
-      ''}
+    '' + optionalString stdenv.isArm ''
+      configureFlagsArray=(-Dldflags="-lm -lrt")
     '' + optionalString stdenv.isDarwin ''
       substituteInPlace hints/darwin.sh --replace "env MACOSX_DEPLOYMENT_TARGET=10.3" ""
     '' + optionalString (!enableThreading) ''
@@ -92,9 +92,9 @@ stdenv.mkDerivation rec {
 
   preCheck = ''
     # Try and setup a local hosts file
-    if [ -f "${libc}/lib/libnss_files.so" ]; then
+    if [ -f "${libcLib}/lib/libnss_files.so" ]; then
       mkdir $TMPDIR/fakelib
-      cp "${libc}/lib/libnss_files.so" $TMPDIR/fakelib
+      cp "${libcLib}/lib/libnss_files.so" $TMPDIR/fakelib
       sed -i 's,/etc/hosts,/dev/fd/3,g' $TMPDIR/fakelib/libnss_files.so
       export LD_LIBRARY_PATH=$TMPDIR/fakelib
     fi
@@ -104,6 +104,22 @@ stdenv.mkDerivation rec {
     unset LD_LIBRARY_PATH
   '';
 
+  # TODO: it seems like absolute paths to some coreutils is required.
+  postInstall =
+    ''
+      # Remove dependency between "out" and "man" outputs.
+      rm "$out"/lib/perl5/*/*/.packlist
+
+      # Remove dependencies on glibc and gcc
+      sed "/ *libpth =>/c    libpth => ' '," \
+        -i "$out"/lib/perl5/*/*/Config.pm
+      # TODO: removing those paths would be cleaner than overwriting with nonsense.
+      substituteInPlace "$out"/lib/perl5/*/*/Config_heavy.pl \
+        --replace "${libcInc}" /no-such-path \
+        --replace "${stdenv.cc.cc or "/no-such-path"}" /no-such-path \
+        --replace "$man" /no-such-path
+    ''; # */
+
   meta = {
     homepage = https://www.perl.org/;
     description = "The standard implementation of the Perl 5 programmming language";
diff --git a/pkgs/development/interpreters/php/default.nix b/pkgs/development/interpreters/php/default.nix
index 2c554648290..bde21afea9d 100644
--- a/pkgs/development/interpreters/php/default.nix
+++ b/pkgs/development/interpreters/php/default.nix
@@ -44,7 +44,13 @@ let
         };
 
         ldap = {
-          configureFlags = ["--with-ldap=${openldap}"];
+          configureFlags = [
+            "--with-ldap"
+            "LDAP_DIR=${openldap.dev}"
+            "LDAP_INCDIR=${openldap.dev}/include"
+            "LDAP_LIBDIR=${openldap.out}/lib"
+            "--with-ldap-sasl=${cyrus_sasl.dev}"
+            ];
           buildInputs = [openldap cyrus_sasl openssl];
         };
 
@@ -69,7 +75,7 @@ let
 
         libxml2 = {
           configureFlags = [
-            "--with-libxml-dir=${libxml2}"
+            "--with-libxml-dir=${libxml2.dev}"
             ];
           buildInputs = [ libxml2 ];
         };
@@ -148,7 +154,7 @@ let
         };
 
         openssl = {
-          configureFlags = ["--with-openssl=${openssl}"];
+          configureFlags = ["--enable-openssl"];
           buildInputs = [openssl];
         };
 
diff --git a/pkgs/development/interpreters/pypy/default.nix b/pkgs/development/interpreters/pypy/default.nix
index d9501844387..2b74aaa9441 100644
--- a/pkgs/development/interpreters/pypy/default.nix
+++ b/pkgs/development/interpreters/pypy/default.nix
@@ -43,9 +43,9 @@ let
 
       # hint pypy to find nix ncurses
       substituteInPlace pypy/module/_minimal_curses/fficurses.py \
-        --replace "/usr/include/ncurses/curses.h" "${ncurses}/include/curses.h" \
-        --replace "ncurses/curses.h" "${ncurses}/include/curses.h" \
-        --replace "ncurses/term.h" "${ncurses}/include/term.h" \
+        --replace "/usr/include/ncurses/curses.h" "${ncurses.dev}/include/curses.h" \
+        --replace "ncurses/curses.h" "${ncurses.dev}/include/curses.h" \
+        --replace "ncurses/term.h" "${ncurses.dev}/include/term.h" \
         --replace "libraries=['curses']" "libraries=['ncurses']"
 
       # tkinter hints
@@ -54,7 +54,7 @@ let
         --replace "linklibs = ['tcl' + _ver, 'tk' + _ver]" "linklibs=['${tcl.libPrefix}', '${tk.libPrefix}']" \
         --replace "libdirs = []" "libdirs = ['${tk}/lib', '${tcl}/lib']"
 
-      sed -i "s@libraries=\['sqlite3'\]\$@libraries=['sqlite3'], include_dirs=['${sqlite}/include'], library_dirs=['${sqlite}/lib']@" lib_pypy/_sqlite3_build.py
+      sed -i "s@libraries=\['sqlite3'\]\$@libraries=['sqlite3'], include_dirs=['${sqlite.dev}/include'], library_dirs=['${sqlite.out}/lib']@" lib_pypy/_sqlite3_build.py
     '';
 
     setupHook = ./setup-hook.sh;
@@ -72,7 +72,7 @@ let
 
     doCheck = true;
     checkPhase = ''
-       export TERMINFO="${ncurses}/share/terminfo/";
+       export TERMINFO="${ncurses.out}/share/terminfo/";
        export TERM="xterm";
        export HOME="$TMPDIR";
        # disable shutils because it assumes gid 0 exists
diff --git a/pkgs/development/interpreters/python/2.6/default.nix b/pkgs/development/interpreters/python/2.6/default.nix
index 32974778168..96b44ddc17f 100644
--- a/pkgs/development/interpreters/python/2.6/default.nix
+++ b/pkgs/development/interpreters/python/2.6/default.nix
@@ -52,6 +52,10 @@ let
     [ bzip2 openssl ]++ optionals includeModules [ db openssl ncurses gdbm readline xlibsWrapper tcl tk sqlite ]
     ++ optional zlibSupport zlib;
 
+  mkPaths = paths: {
+    C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p.dev or p}/include") paths);
+    LIBRARY_PATH = concatStringsSep ":" (map (p: "${p.lib or (p.out or p)}/lib") paths);
+  };
 
   # Build the basic Python interpreter without modules that have
   # external dependencies.
@@ -62,8 +66,7 @@ let
     inherit majorVersion version src patches buildInputs preConfigure
             configureFlags;
 
-    C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs);
-    LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs);
+    inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
 
     NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2";
 
@@ -83,9 +86,9 @@ let
         ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb${majorVersion}
         mv $out/share/man/man1/{python.1,python2.6.1}
         ln -s $out/share/man/man1/{python2.6.1,python.1}
-        
+
         paxmark E $out/bin/python${majorVersion}
-        
+
         ${ optionalString includeModules "$out/bin/python ./setup.py build_ext"}
       '';
 
@@ -139,8 +142,7 @@ let
 
       buildInputs = [ python ] ++ deps;
 
-      C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs);
-      LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs);
+      inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
 
       buildPhase =
         ''
diff --git a/pkgs/development/interpreters/python/2.7/default.nix b/pkgs/development/interpreters/python/2.7/default.nix
index a2c059da060..1bcb0777e85 100644
--- a/pkgs/development/interpreters/python/2.7/default.nix
+++ b/pkgs/development/interpreters/python/2.7/default.nix
@@ -101,6 +101,11 @@ let
 
   propagatedBuildInputs = optional stdenv.isDarwin configd;
 
+  mkPaths = paths: {
+    C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p.dev or p}/include") paths);
+    LIBRARY_PATH = concatStringsSep ":" (map (p: "${p.lib or (p.out or p)}/lib") paths);
+  };
+
   # Build the basic Python interpreter without modules that have
   # external dependencies.
   python = stdenv.mkDerivation {
@@ -111,8 +116,7 @@ let
             preConfigure configureFlags;
 
     LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
-    C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs);
-    LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs);
+    inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
 
     NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2";
     DETERMINISTIC_BUILD = 1;
@@ -138,6 +142,8 @@ let
         paxmark E $out/bin/python${majorVersion}
 
         ${ optionalString includeModules "$out/bin/python ./setup.py build_ext"}
+
+        rm "$out"/lib/python*/plat-linux2/regen # refers to glibc.dev
       '';
 
     passthru = rec {
@@ -186,8 +192,7 @@ let
 
       buildInputs = [ python ] ++ deps;
 
-      C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs);
-      LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs);
+      inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
 
       # non-python gdbm has a libintl dependency on i686-cygwin, not on x86_64-cygwin
       buildPhase = (if (stdenv.system == "i686-cygwin" && moduleName == "gdbm") then ''
diff --git a/pkgs/development/interpreters/python/3.2/default.nix b/pkgs/development/interpreters/python/3.2/default.nix
index f4103662316..c0b5d3401dd 100644
--- a/pkgs/development/interpreters/python/3.2/default.nix
+++ b/pkgs/development/interpreters/python/3.2/default.nix
@@ -44,8 +44,8 @@ stdenv.mkDerivation {
     ${optionalString stdenv.isDarwin ''export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -msse2"''}
 
     configureFlagsArray=( --enable-shared --with-threads --with-wide-unicode
-                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${p}/include") buildInputs)}"
-                          LDFLAGS="${concatStringsSep " " (map (p: "-L${p}/lib") buildInputs)}"
+                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${p.dev or p}/include") buildInputs)}"
+                          LDFLAGS="${concatStringsSep " " (map (p: "-L${p.lib or (p.out or p)}/lib") buildInputs)}"
                           LIBS="${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"
                         )
   '';
diff --git a/pkgs/development/interpreters/python/3.3/default.nix b/pkgs/development/interpreters/python/3.3/default.nix
index a8953f38245..a46ef7c056b 100644
--- a/pkgs/development/interpreters/python/3.3/default.nix
+++ b/pkgs/development/interpreters/python/3.3/default.nix
@@ -46,8 +46,8 @@ stdenv.mkDerivation {
     ${optionalString stdenv.isDarwin ''export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -msse2"''}
 
     configureFlagsArray=( --enable-shared --with-threads
-                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${p}/include") buildInputs)}"
-                          LDFLAGS="${concatStringsSep " " (map (p: "-L${p}/lib") buildInputs)}"
+                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${p.dev or p}/include") buildInputs)}"
+                          LDFLAGS="${concatStringsSep " " (map (p: "-L${p.lib or (p.out or p)}/lib") buildInputs)}"
                           LIBS="${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"
                         )
   '';
diff --git a/pkgs/development/interpreters/python/3.4/default.nix b/pkgs/development/interpreters/python/3.4/default.nix
index 570c7cc35d1..7c979b0ebe9 100644
--- a/pkgs/development/interpreters/python/3.4/default.nix
+++ b/pkgs/development/interpreters/python/3.4/default.nix
@@ -58,8 +58,8 @@ stdenv.mkDerivation {
      ''}
 
     configureFlagsArray=( --enable-shared --with-threads
-                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${p}/include") buildInputs)}"
-                          LDFLAGS="${concatStringsSep " " (map (p: "-L${p}/lib") buildInputs)}"
+                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${p.dev or p}/include") buildInputs)}"
+                          LDFLAGS="${concatStringsSep " " (map (p: "-L${p.lib or (p.out or p)}/lib") buildInputs)}"
                           LIBS="${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"
                         )
   '';
diff --git a/pkgs/development/interpreters/python/3.5/default.nix b/pkgs/development/interpreters/python/3.5/default.nix
index 0f4b6e744ac..4bc39f4c2b3 100644
--- a/pkgs/development/interpreters/python/3.5/default.nix
+++ b/pkgs/development/interpreters/python/3.5/default.nix
@@ -58,8 +58,8 @@ stdenv.mkDerivation {
      ''}
 
     configureFlagsArray=( --enable-shared --with-threads
-                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${p}/include") buildInputs)}"
-                          LDFLAGS="${concatStringsSep " " (map (p: "-L${p}/lib") buildInputs)}"
+                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${p.dev or p}/include") buildInputs)}"
+                          LDFLAGS="${concatStringsSep " " (map (p: "-L${p.lib or (p.out or p)}/lib") buildInputs)}"
                           LIBS="${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"
                         )
   '';
diff --git a/pkgs/development/interpreters/ruby/bundler-env/default-gem-config.nix b/pkgs/development/interpreters/ruby/bundler-env/default-gem-config.nix
index 36925bcdf55..8032ce0145f 100644
--- a/pkgs/development/interpreters/ruby/bundler-env/default-gem-config.nix
+++ b/pkgs/development/interpreters/ruby/bundler-env/default-gem-config.nix
@@ -54,8 +54,8 @@ in
   ncursesw = attrs: {
     buildInputs = [ ncurses ];
     buildFlags = [
-      "--with-cflags=-I${ncurses}/include"
-      "--with-ldflags=-L${ncurses}/lib"
+      "--with-cflags=-I${ncurses.dev}/include"
+      "--with-ldflags=-L${ncurses.lib}/lib"
     ];
   };
 
@@ -63,12 +63,12 @@ in
     buildFlags = [
       "--use-system-libraries"
       "--with-zlib-dir=${zlib}"
-      "--with-xml2-lib=${libxml2}/lib"
-      "--with-xml2-include=${libxml2}/include/libxml2"
-      "--with-xslt-lib=${libxslt}/lib"
-      "--with-xslt-include=${libxslt}/include"
-      "--with-exslt-lib=${libxslt}/lib"
-      "--with-exslt-include=${libxslt}/include"
+      "--with-xml2-lib=${libxml2.out}/lib"
+      "--with-xml2-include=${libxml2.dev}/include/libxml2"
+      "--with-xslt-lib=${libxslt.out}/lib"
+      "--with-xslt-include=${libxslt.dev}/include"
+      "--with-exslt-lib=${libxslt.out}/lib"
+      "--with-exslt-include=${libxslt.dev}/include"
     ] ++ lib.optional stdenv.isDarwin "--with-iconv-dir=${libiconv}";
     buildInputs = lib.optional stdenv.isDarwin darwin.libobjc;
   };
@@ -89,8 +89,8 @@ in
 
   sqlite3 = attrs: {
     buildFlags = [
-      "--with-sqlite3-include=${sqlite}/include"
-      "--with-sqlite3-lib=${sqlite}/lib"
+      "--with-sqlite3-include=${sqlite.dev}/include"
+      "--with-sqlite3-lib=${sqlite.out}/lib"
     ];
   };
 
diff --git a/pkgs/development/interpreters/ruby/patches.nix b/pkgs/development/interpreters/ruby/patches.nix
index 0cc477c991e..be79c5c957a 100644
--- a/pkgs/development/interpreters/ruby/patches.nix
+++ b/pkgs/development/interpreters/ruby/patches.nix
@@ -82,8 +82,8 @@ in
   nokogiri = {
     buildInputs = [ libxml2 ];
     buildFlags =
-      [ "--with-xml2-dir=${libxml2} --with-xml2-include=${libxml2}/include/libxml2"
-        "--with-xslt-dir=${libxslt}  --use-system-libraries"
+      [ "--with-xml2-dir=${libxml2.out} --with-xml2-include=${libxml2.dev}/include/libxml2"
+        "--with-xslt-dir=${libxslt.out}  --use-system-libraries"
         libiconv
       ];
   };
diff --git a/pkgs/development/interpreters/spidermonkey/1.8.0-rc1.nix b/pkgs/development/interpreters/spidermonkey/1.8.0-rc1.nix
index ecaed507712..99f66199d93 100644
--- a/pkgs/development/interpreters/spidermonkey/1.8.0-rc1.nix
+++ b/pkgs/development/interpreters/spidermonkey/1.8.0-rc1.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
     '';
 
   preConfigure = ''
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${nspr}/include/nspr"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${nspr.dev}/include/nspr"
   '';
 
   makeFlags = "-f ${makefile} JS_DIST=\${out} BUILD_OPT=1 JS_READLINE=1 JS_THREADSAFE=1";
diff --git a/pkgs/development/interpreters/spidermonkey/17.0.nix b/pkgs/development/interpreters/spidermonkey/17.0.nix
index 7573b546164..5cc71b59d51 100644
--- a/pkgs/development/interpreters/spidermonkey/17.0.nix
+++ b/pkgs/development/interpreters/spidermonkey/17.0.nix
@@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
     sha256 = "1fig2wf4f10v43mqx67y68z6h77sy900d1w0pz9qarrqx57rc7ij";
   };
 
+  outputs = [ "dev" "out" "lib" ];
+
   propagatedBuildInputs = [ nspr ];
 
   buildInputs = [ pkgconfig perl python zip libffi readline ];
@@ -21,11 +23,14 @@ stdenv.mkDerivation rec {
   '';
 
   preConfigure = ''
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${nspr}/include/nspr"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${nspr.dev}/include/nspr"
     export LIBXUL_DIST=$out
   '';
 
+  setOutputFlags = false;
   configureFlags = [
+    "--libdir=$(lib)/lib"
+    "--includedir=$(dev)/include"
     "--enable-threadsafe"
     "--with-system-nspr"
     "--with-system-ffi"
@@ -49,7 +54,10 @@ stdenv.mkDerivation rec {
     paxmark mr jsapi-tests/jsapi-tests
   '';
 
-  postInstall = ''rm "$out"/lib/*.a''; # halve the output size
+  postInstall = ''
+    rm "$lib"/lib/*.a # halve the output size
+    moveToOutput "bin/js*-config" "$dev" # break the cycle
+  '';
 
   meta = with stdenv.lib; {
     description = "Mozilla's JavaScript engine written in C/C++";
diff --git a/pkgs/development/interpreters/spidermonkey/185-1.0.0.nix b/pkgs/development/interpreters/spidermonkey/185-1.0.0.nix
index a036388f15e..94f070d1a91 100644
--- a/pkgs/development/interpreters/spidermonkey/185-1.0.0.nix
+++ b/pkgs/development/interpreters/spidermonkey/185-1.0.0.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
   postUnpack = "sourceRoot=\${sourceRoot}/js/src";
 
   preConfigure = ''
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${nspr}/include/nspr"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${nspr.dev}/include/nspr"
     export LIBXUL_DIST=$out
   '';
 
diff --git a/pkgs/development/interpreters/spidermonkey/24.2.nix b/pkgs/development/interpreters/spidermonkey/24.2.nix
index 3a9bd8ad7a4..5c4fc850815 100644
--- a/pkgs/development/interpreters/spidermonkey/24.2.nix
+++ b/pkgs/development/interpreters/spidermonkey/24.2.nix
@@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
     sha256 = "1n1phk8r3l8icqrrap4czplnylawa0ddc2cc4cgdz46x3lrkybz6";
   };
 
+  outputs = [ "dev" "out" "lib" ];
+
   propagatedBuildInputs = [ nspr ];
 
   buildInputs = [ pkgconfig perl python zip libffi readline ];
@@ -21,11 +23,14 @@ stdenv.mkDerivation rec {
   postUnpack = "sourceRoot=\${sourceRoot}/js/src";
 
   preConfigure = ''
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${nspr}/include/nspr"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${nspr.dev}/include/nspr"
     export LIBXUL_DIST=$out
   '';
 
+  setOutputFlags = false;
   configureFlags = [
+    "--libdir=$(lib)/lib"
+    "--includedir=$(dev)/include"
     "--enable-threadsafe"
     "--with-system-nspr"
     "--with-system-ffi"
@@ -40,6 +45,11 @@ stdenv.mkDerivation rec {
   doCheck = true;
   preCheck = "rm jit-test/tests/sunspider/check-date-format-tofte.js"; # https://bugzil.la/600522
 
+  postInstall = ''
+    rm "$lib"/lib/*.a # halve the output size
+    moveToOutput "bin/js*-config" "$dev" # break the cycle
+  '';
+
   meta = with stdenv.lib; {
     description = "Mozilla's JavaScript engine written in C/C++";
     homepage = https://developer.mozilla.org/en/SpiderMonkey;
diff --git a/pkgs/development/libraries/SDL/default.nix b/pkgs/development/libraries/SDL/default.nix
index 7006eb10f7e..fbc446bcabc 100644
--- a/pkgs/development/libraries/SDL/default.nix
+++ b/pkgs/development/libraries/SDL/default.nix
@@ -27,7 +27,8 @@ stdenv.mkDerivation rec {
     sha256 = "005d993xcac8236fpvd1iawkz4wqjybkpn8dbwaliqz5jfkidlyn";
   };
 
-  outputs = [ "out" "man" ];
+  outputs = [ "dev" "out" ];
+  outputBin = "dev"; # sdl-config
 
   nativeBuildInputs = [ pkgconfig ];
 
@@ -57,7 +58,7 @@ stdenv.mkDerivation rec {
     "--disable-osmesa-shared"
   ] ++ stdenv.lib.optionals (stdenv ? cross) ([
     "--without-x"
-  ] ++ stdenv.lib.optional alsaSupport "--with-alsa-prefix=${alsaLib}/lib");
+  ] ++ stdenv.lib.optional alsaSupport "--with-alsa-prefix=${alsaLib.out}/lib");
 
   # Fix a build failure on OS X Mavericks
   # Ticket: https://bugzilla.libsdl.org/show_bug.cgi?id=2085
@@ -66,6 +67,8 @@ stdenv.mkDerivation rec {
     sha1 = "3137feb503a89a8d606405373905b92dcf7e293b";
   }) ];
 
+  postFixup = ''moveToOutput share/aclocal "$dev" '';
+
   crossAttrs =stdenv.lib.optionalAttrs (stdenv.cross.libc == "libSystem") {
     patches = let
       f = rev: sha256: fetchurl {
diff --git a/pkgs/development/libraries/SDL2/default.nix b/pkgs/development/libraries/SDL2/default.nix
index 529c485930b..1c260c2ba91 100644
--- a/pkgs/development/libraries/SDL2/default.nix
+++ b/pkgs/development/libraries/SDL2/default.nix
@@ -19,7 +19,7 @@ let
   configureFlagsFun = attrs: ''
         --disable-oss --disable-x11-shared
         --disable-pulseaudio-shared --disable-alsa-shared
-        ${if alsaSupport then "--with-alsa-prefix=${attrs.alsaLib}/lib" else ""}
+        ${if alsaSupport then "--with-alsa-prefix=${attrs.alsaLib.out}/lib" else ""}
         ${if (!x11Support) then "--without-x" else ""}
       '';
 in
diff --git a/pkgs/development/libraries/aalib/default.nix b/pkgs/development/libraries/aalib/default.nix
index d7dcbeba330..fb8edd27bf8 100644
--- a/pkgs/development/libraries/aalib/default.nix
+++ b/pkgs/development/libraries/aalib/default.nix
@@ -8,16 +8,30 @@ stdenv.mkDerivation {
     sha256 = "1vkh19gb76agvh4h87ysbrgy82hrw88lnsvhynjf4vng629dmpgv";
   };
 
+  outputs = [ "dev" "out" "bin" "doc" ];
+  setOutputFlags = false; # Doesn't support all the flags
+
+  patches = stdenv.lib.optionals stdenv.isDarwin [ ./darwin.patch ];
+
   # The fuloong2f is not supported by aalib still
   preConfigure = ''
     cp ${automake}/share/automake*/config.{sub,guess} .
+    configureFlagsArray+=(
+      "--bindir=$bin/bin"
+      "--includedir=$dev/include"
+      "--libdir=$out/lib"
+    )
   '';
 
   buildInputs = [ ncurses ];
 
   configureFlags = "--without-x --with-ncurses=${ncurses}";
 
-  patches = stdenv.lib.optionals stdenv.isDarwin [ ./darwin.patch ];
+  postInstall = ''
+    mkdir -p $dev/bin
+    mv $bin/bin/aalib-config $dev/bin/aalib-config
+    substituteInPlace $out/lib/libaa.la --replace "${ncurses.dev}/lib" "${ncurses.lib}/lib"
+  '';
 
   meta = {
     description = "ASCII art graphics library";
diff --git a/pkgs/development/libraries/acl/default.nix b/pkgs/development/libraries/acl/default.nix
index d37d8926fbd..4055708907b 100644
--- a/pkgs/development/libraries/acl/default.nix
+++ b/pkgs/development/libraries/acl/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "08qd9s3wfhv0ajswsylnfwr5h0d7j9d4rgip855nrh400nxp940p";
   };
 
+  outputs = [ "dev" "out" "bin" "doc" ];
+
   nativeBuildInputs = [ gettext ];
   buildInputs = [ attr ];
 
diff --git a/pkgs/development/libraries/apr-util/default.nix b/pkgs/development/libraries/apr-util/default.nix
index c35520f22fd..f1c0807144b 100644
--- a/pkgs/development/libraries/apr-util/default.nix
+++ b/pkgs/development/libraries/apr-util/default.nix
@@ -19,15 +19,20 @@ stdenv.mkDerivation rec {
     sha256 = "0bn81pfscy9yjvbmyx442svf43s6dhrdfcsnkpxz43fai5qk5kx6";
   };
 
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
+
   configureFlags = ''
     --with-apr=${apr} --with-expat=${expat}
     ${optionalString (!stdenv.isCygwin) "--with-crypto"}
-    ${stdenv.lib.optionalString sslSupport "--with-openssl=${openssl}"}
+    ${stdenv.lib.optionalString sslSupport "--with-openssl"}
     ${stdenv.lib.optionalString bdbSupport "--with-berkeley-db=${db}"}
     ${stdenv.lib.optionalString ldapSupport "--with-ldap"}${
       optionalString stdenv.isCygwin "--without-pgsql --without-sqlite2 --without-sqlite3 --without-freetds --without-berkeley-db --without-crypto"}
   '';
 
+  buildInputs = stdenv.lib.optional sslSupport openssl;
+
   propagatedBuildInputs = [ makeWrapper apr expat libiconv ]
     ++ optional sslSupport openssl
     ++ optional bdbSupport db
@@ -35,7 +40,10 @@ stdenv.mkDerivation rec {
 
   # Give apr1 access to sed for runtime invocations
   postInstall = ''
-    wrapProgram $out/bin/apu-1-config --prefix PATH : "${gnused}/bin"
+    for f in $out/lib/*.la $out/lib/apr-util-1/*.la; do
+      substituteInPlace $f --replace "${expat.dev}/lib" "${expat.out}/lib"
+    done
+    wrapProgram $dev/bin/apu-1-config --prefix PATH : "${gnused}/bin"
   '';
 
   enableParallelBuilding = true;
diff --git a/pkgs/development/libraries/apr/default.nix b/pkgs/development/libraries/apr/default.nix
index 08fd1fe4d5f..c6e505f43d2 100644
--- a/pkgs/development/libraries/apr/default.nix
+++ b/pkgs/development/libraries/apr/default.nix
@@ -10,6 +10,14 @@ stdenv.mkDerivation rec {
 
   patches = stdenv.lib.optionals stdenv.isDarwin [ ./is-this-a-compiler-bug.patch ];
 
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
+
+  preConfigure =
+    ''
+      configureFlagsArray+=("--with-installbuilddir=$dev/share/build")
+    '';
+
   configureFlags =
     # Including the Windows headers breaks unistd.h.
     # Based on ftp://sourceware.org/pub/cygwin/release/libapr1/libapr1-1.3.8-2-src.tar.bz2
@@ -17,10 +25,10 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://apr.apache.org/;
     description = "The Apache Portable Runtime library";
-    platforms = stdenv.lib.platforms.all;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
+    platforms = platforms.all;
+    maintainers = [ maintainers.eelco ];
   };
 }
diff --git a/pkgs/development/libraries/at-spi2-core/default.nix b/pkgs/development/libraries/at-spi2-core/default.nix
index b49d1ddb804..a4707ef4334 100644
--- a/pkgs/development/libraries/at-spi2-core/default.nix
+++ b/pkgs/development/libraries/at-spi2-core/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
     sha256 = "0xna0gnlqvzy6209klirywcm7ianazshg6pkk828g07bnrywgvhs";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "dev" "out" ];
 
   buildInputs = [
     python pkgconfig popt  intltool dbus_glib
diff --git a/pkgs/development/libraries/atk/default.nix b/pkgs/development/libraries/atk/default.nix
index dcb90aa16cd..14e2e71c0bd 100644
--- a/pkgs/development/libraries/atk/default.nix
+++ b/pkgs/development/libraries/atk/default.nix
@@ -12,6 +12,10 @@ stdenv.mkDerivation rec {
     sha256 = "ce6c48d77bf951083029d5a396dd552d836fff3c1715d3a7022e917e46d0c92b";
   };
 
+  enableParallelBuilding = true;
+
+  outputs = [ "dev" "out" ];
+
   buildInputs = libintlOrEmpty;
 
   nativeBuildInputs = [ pkgconfig perl ];
@@ -20,8 +24,6 @@ stdenv.mkDerivation rec {
 
   #doCheck = true; # no checks in there (2.10.0)
 
-  postInstall = "rm -rf $out/share/gtk-doc";
-
   meta = {
     description = "Accessibility toolkit";
 
diff --git a/pkgs/development/libraries/attr/default.nix b/pkgs/development/libraries/attr/default.nix
index 8d87e2ee50d..e4e9142b632 100644
--- a/pkgs/development/libraries/attr/default.nix
+++ b/pkgs/development/libraries/attr/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "0nd8y0m6awc9ahv0ciiwf8gy54c8d3j51pw9xg7f7cn579jjyxr5";
   };
 
+  outputs = [ "dev" "out" "bin" "doc" ];
+
   nativeBuildInputs = [ gettext ];
 
   configureFlags = "MAKE=make MSGFMT=msgfmt MSGMERGE=msgmerge XGETTEXT=xgettext ECHO=echo SED=sed AWK=gawk";
diff --git a/pkgs/development/libraries/boehm-gc/default.nix b/pkgs/development/libraries/boehm-gc/default.nix
index 158f4b227dd..4839bedd8bb 100644
--- a/pkgs/development/libraries/boehm-gc/default.nix
+++ b/pkgs/development/libraries/boehm-gc/default.nix
@@ -7,9 +7,10 @@ stdenv.mkDerivation rec {
     url = http://www.hboehm.info/gc/gc_source/gc-7.2f.tar.gz;
     sha256 = "119x7p1cqw40mpwj80xfq879l9m1dkc7vbc1f3bz3kvkf8bf6p16";
   };
-
   patches = if stdenv.isCygwin then [ ./cygwin.patch ] else null;
 
+  outputs = [ "dev" "out" "doc" ];
+
   configureFlags =
     [ "--enable-cplusplus" ]
     ++ lib.optional enableLargeConfig "--enable-large-config";
@@ -19,6 +20,12 @@ stdenv.mkDerivation rec {
   # Don't run the native `strip' when cross-compiling.
   dontStrip = stdenv ? cross;
 
+  postInstall =
+    ''
+      mkdir -p $out/share/doc
+      mv $out/share/gc $out/share/doc/gc
+    '';
+
   meta = {
     description = "The Boehm-Demers-Weiser conservative garbage collector for C and C++";
 
diff --git a/pkgs/development/libraries/boost/generic.nix b/pkgs/development/libraries/boost/generic.nix
index 2a83d7c4142..f933fa6bc3e 100644
--- a/pkgs/development/libraries/boost/generic.nix
+++ b/pkgs/development/libraries/boost/generic.nix
@@ -64,8 +64,8 @@ let
   ] ++ optional (variant == "release") "debug-symbols=off";
 
   nativeB2Flags = [
-    "-sEXPAT_INCLUDE=${expat}/include"
-    "-sEXPAT_LIBPATH=${expat}/lib"
+    "-sEXPAT_INCLUDE=${expat.dev}/include"
+    "-sEXPAT_LIBPATH=${expat.out}/lib"
   ] ++ optional (toolset != null) "toolset=${toolset}"
     ++ optional (mpi != null) "--user-config=user-config.jam";
   nativeB2Args = concatStringsSep " " (genericB2Flags ++ nativeB2Flags);
@@ -148,7 +148,7 @@ stdenv.mkDerivation {
 
   configureScript = "./bootstrap.sh";
   configureFlags = commonConfigureFlags ++ [
-    "--with-icu=${icu}"
+    "--with-icu=${icu.dev}"
     "--with-python=${python.interpreter}"
   ] ++ optional (toolset != null) "--with-toolset=${toolset}";
 
@@ -159,6 +159,7 @@ stdenv.mkDerivation {
   postFixup = fixup;
 
   outputs = [ "out" "dev" "lib" ];
+  setOutputFlags = false;
 
   crossAttrs = rec {
     buildInputs = [ expat.crossDrv zlib.crossDrv bzip2.crossDrv ];
diff --git a/pkgs/development/libraries/cairo/default.nix b/pkgs/development/libraries/cairo/default.nix
index 5add4e45129..5f705ea50a3 100644
--- a/pkgs/development/libraries/cairo/default.nix
+++ b/pkgs/development/libraries/cairo/default.nix
@@ -18,15 +18,18 @@ stdenv.mkDerivation rec {
     sha256 = "05p75r914d809711yg9rapgmmi4hymzbarhd3w0yrfadhiy9rv7n";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputBin = "dev"; # very small
+
   nativeBuildInputs = [ pkgconfig libiconv ] ++ libintlOrEmpty;
 
   propagatedBuildInputs =
-    with xorg; [ xorg.xlibsWrapper fontconfig expat freetype pixman zlib libpng ]
+    with xorg; [ libXext fontconfig expat freetype pixman zlib libpng ]
     ++ optional (!stdenv.isDarwin) libXrender
     ++ optionals xcbSupport [ libxcb xcbutil ]
     ++ optional gobjectSupport glib
-    ++ optionals glSupport [ mesa_noglu ]
-    ;
+    ++ optional glSupport mesa_noglu
+    ; # TODO: maybe liblzo but what would it be for here?
 
   configureFlags = [ "--enable-tee" ]
     ++ optional xcbSupport "--enable-xcb"
@@ -36,29 +39,24 @@ stdenv.mkDerivation rec {
 
   preConfigure =
   # On FreeBSD, `-ldl' doesn't exist.
-    (stdenv.lib.optionalString stdenv.isFreeBSD
+    stdenv.lib.optionalString stdenv.isFreeBSD
        '' for i in "util/"*"/Makefile.in" boilerplate/Makefile.in
           do
             cat "$i" | sed -es/-ldl//g > t
             mv t "$i"
           done
-       '') 
-       +
+       ''
+    +
     ''
     # Work around broken `Requires.private' that prevents Freetype
     # `-I' flags to be propagated.
     sed -i "src/cairo.pc.in" \
-        -es'|^Cflags:\(.*\)$|Cflags: \1 -I${freetype}/include/freetype2 -I${freetype}/include|g'
+        -es'|^Cflags:\(.*\)$|Cflags: \1 -I${freetype.dev}/include/freetype2 -I${freetype.dev}/include|g'
     '';
 
   enableParallelBuilding = true;
 
-  # The default `--disable-gtk-doc' is ignored.
-  postInstall = "rm -rf $out/share/gtk-doc"
-    + stdenv.lib.optionalString stdenv.isDarwin (''
-      #newline
-    '' + glib.flattenInclude
-    );
+  postInstall = stdenv.lib.optionalString stdenv.isDarwin glib.flattenInclude;
 
   meta = with stdenv.lib; {
     description = "A 2D graphics library with support for multiple output devices";
diff --git a/pkgs/development/libraries/cogl/1.20.nix b/pkgs/development/libraries/cogl/1.20.nix
index 5eb12fe2998..ae202b09377 100644
--- a/pkgs/development/libraries/cogl/1.20.nix
+++ b/pkgs/development/libraries/cogl/1.20.nix
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
 
   COGL_PANGO_DEP_CFLAGS
     = stdenv.lib.optionalString (stdenv.isDarwin && pangoSupport)
-      "-I${pango}/include/pango-1.0 -I${cairo}/include/cairo";
+      "-I${pango.dev}/include/pango-1.0 -I${cairo.dev}/include/cairo";
 
   NIX_LDFLAGS = stdenv.lib.optionalString stdenv.isDarwin "-lintl";
 
diff --git a/pkgs/development/libraries/cogl/1.22.nix b/pkgs/development/libraries/cogl/1.22.nix
index ce4fda5bd46..88bb6707749 100644
--- a/pkgs/development/libraries/cogl/1.22.nix
+++ b/pkgs/development/libraries/cogl/1.22.nix
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
 
   COGL_PANGO_DEP_CFLAGS
     = stdenv.lib.optionalString (stdenv.isDarwin && pangoSupport)
-      "-I${pango}/include/pango-1.0 -I${cairo}/include/cairo";
+      "-I${pango.dev}/include/pango-1.0 -I${cairo.dev}/include/cairo";
 
   NIX_LDFLAGS = stdenv.lib.optionalString stdenv.isDarwin "-lintl";
 
diff --git a/pkgs/development/libraries/cogl/default.nix b/pkgs/development/libraries/cogl/default.nix
index a4a20fce023..e4570209066 100644
--- a/pkgs/development/libraries/cogl/default.nix
+++ b/pkgs/development/libraries/cogl/default.nix
@@ -35,7 +35,7 @@ stdenv.mkDerivation rec {
 
   COGL_PANGO_DEP_CFLAGS
     = stdenv.lib.optionalString (stdenv.isDarwin && pangoSupport)
-      "-I${pango}/include/pango-1.0 -I${cairo}/include/cairo";
+      "-I${pango.dev}/include/pango-1.0 -I${cairo.dev}/include/cairo";
 
   NIX_LDFLAGS = stdenv.lib.optionalString stdenv.isDarwin "-lintl";
 
diff --git a/pkgs/development/libraries/cyrus-sasl/default.nix b/pkgs/development/libraries/cyrus-sasl/default.nix
index 2be98f3d5e8..b7155f286c5 100644
--- a/pkgs/development/libraries/cyrus-sasl/default.nix
+++ b/pkgs/development/libraries/cyrus-sasl/default.nix
@@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
     sha256 = "1hvvbcsg21nlncbgs0cgn3iwlnb3vannzwsp6rwvnn9ba4v53g4g";
   };
 
+  outputs = [ "dev" "bin" "out" "man" "docdev" ];
+
   buildInputs =
     [ openssl db gettext kerberos ]
     ++ lib.optional stdenv.isLinux pam
@@ -32,6 +34,12 @@ stdenv.mkDerivation rec {
 
   installFlags = lib.optional stdenv.isDarwin [ "framedir=$(out)/Library/Frameworks/SASL2.framework" ];
 
+  postInstall = ''
+    for f in $out/lib/*.la $out/lib/sasl2/*.la; do
+      substituteInPlace $f --replace "${openssl.dev}/lib" "${openssl.out}/lib"
+    done
+  '';
+
   meta = {
     homepage = "http://cyrusimap.web.cmu.edu/";
     description = "library for adding authentication support to connection-based protocols";
diff --git a/pkgs/development/libraries/dbus-glib/default.nix b/pkgs/development/libraries/dbus-glib/default.nix
index 480dc61897b..59d227f0e86 100644
--- a/pkgs/development/libraries/dbus-glib/default.nix
+++ b/pkgs/development/libraries/dbus-glib/default.nix
@@ -8,13 +8,14 @@ stdenv.mkDerivation rec {
     sha256 = "1xi1v1msz75qs0s4lkyf1psrksdppa3hwkg0mznc6gpw5flg3hdz";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "dev" "out" "docdev" ];
+  outputBin = "dev";
 
   nativeBuildInputs = [ pkgconfig gettext ];
 
   buildInputs = [ expat libiconv ];
 
-  propagatedBuildInputs = [ dbus.libs glib ];
+  propagatedBuildInputs = [ dbus glib ];
 
   doCheck = true;
 
diff --git a/pkgs/development/libraries/dbus/default.nix b/pkgs/development/libraries/dbus/default.nix
index 97eecf78a1a..83635d9739f 100644
--- a/pkgs/development/libraries/dbus/default.nix
+++ b/pkgs/development/libraries/dbus/default.nix
@@ -1,5 +1,4 @@
-{ stdenv, fetchurl, pkgconfig, autoconf, automake, libtool
-, expat, systemd, glib, dbus_glib, python
+{ stdenv, lib, fetchurl, pkgconfig, expat, systemd, glib, dbus_glib, python
 , libX11 ? null, libICE ? null, libSM ? null, x11Support ? (stdenv.isLinux || stdenv.isDarwin) }:
 
 assert x11Support -> libX11 != null
@@ -10,107 +9,77 @@ let
   version = "1.8.20";
   sha256 = "0fkh3d5r57a659hw9lqnw4v0bc5556vx54fsf7l9c732ci6byksw";
 
-  inherit (stdenv) lib;
-
-  buildInputsX = lib.optionals x11Support [ libX11 libICE libSM ];
-
-  # also other parts than "libs" need this statically linked lib
-  makeInternalLib = "(cd dbus && make libdbus-internal.la)";
-
-  systemdOrEmpty = lib.optional stdenv.isLinux systemd;
-
-  # A generic builder for individual parts (subdirs) of D-Bus
-  dbus_drv = name: subdirs: merge: stdenv.mkDerivation (lib.mergeAttrsByFuncDefaultsClean [{
-
-    name = "dbus-${name}-${version}";
+self =  stdenv.mkDerivation {
+    name = "dbus-${version}";
 
     src = fetchurl {
       url = "http://dbus.freedesktop.org/releases/dbus/dbus-${version}.tar.gz";
       inherit sha256;
     };
 
-    patches = [
-        ./ignore-missing-includedirs.patch
-        ./ucred-dirty-hack.patch
-        ./no-create-dirs.patch
-      ]
-      ++ lib.optional (stdenv.isSunOS || stdenv.isLinux) ./implement-getgrouplist.patch
-      ;
-
-    # build only the specified subdirs
-    postPatch = "sed '/SUBDIRS/s/=.*/=" + subdirs + "/' -i Makefile.am\n"
-      # use already packaged libdbus instead of trying to build it again
-      + lib.optionalString (name != "libs") ''
-          for mfile in */Makefile.am; do
-            sed 's,\$(top_builddir)/dbus/\(libdbus-[0-9]\),${libs}/lib/\1,g' -i "$mfile"
-          done
-        '';
+    patches = [ ./ignore-missing-includedirs.patch ]
+      ++ lib.optional stdenv.isSunOS ./implement-getgrouplist.patch;
+    postPatch = ''
+      substituteInPlace tools/Makefile.in \
+        --replace 'install-localstatelibDATA:' 'disabled:' \
+        --replace 'install-data-local:' 'disabled:' \
+        --replace 'installcheck-local:' 'disabled:'
+      substituteInPlace bus/Makefile.in \
+        --replace '$(mkinstalldirs) $(DESTDIR)$(localstatedir)/run/dbus' ':'
+    '' + /* cleanup of runtime references */ ''
+      substituteInPlace ./dbus/dbus-sysdeps-unix.c \
+        --replace 'DBUS_BINDIR "/dbus-launch"' "\"$lib/bin/dbus-launch\""
+      substituteInPlace ./tools/dbus-launch.c \
+        --replace 'DBUS_DAEMONDIR"/dbus-daemon"' '"/run/current-system/sw/bin/dbus-daemon"'
+    '';
+
+    outputs = [ "dev" "out" "lib" "doc" ];
 
     nativeBuildInputs = [ pkgconfig ];
     propagatedBuildInputs = [ expat ];
-    buildInputs = [ autoconf automake libtool ]; # ToDo: optional selinux?
-
-    preConfigure = ''
-      patchShebangs .
-      substituteInPlace tools/Makefile.am --replace 'install-localstatelibDATA:' 'disabled:'
-      autoreconf -fi
-    '';
+    buildInputs = lib.optional stdenv.isLinux systemd
+      ++ lib.optionals x11Support [ libX11 libICE libSM ];
+    # ToDo: optional selinux?
 
     configureFlags = [
       "--localstatedir=/var"
       "--sysconfdir=/etc"
       "--with-session-socket-dir=/tmp"
       "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
+      # this package installs nothing into those dirs and they create a dependency
+      "--datadir=/run/current-system/sw/share"
+      "--libexecdir=$(out)/libexec" # we don't need dbus-daemon-launch-helper
     ] ++ lib.optional (!x11Support) "--without-x";
 
-    enableParallelBuilding = true;
-
-    doCheck = true;
-
-    installFlags = "sysconfdir=$(out)/etc";
-
-  } merge ]);
-
-  libs = dbus_drv "libs" "dbus" {
     # Enable X11 autolaunch support in libdbus. This doesn't actually depend on X11
     # (it just execs dbus-launch in dbus.tools), contrary to what the configure script demands.
-    NIX_CFLAGS_COMPILE = "-DDBUS_ENABLE_X11_AUTOLAUNCH=1";
-    buildInputs = [ systemdOrEmpty ];
-    meta.platforms = stdenv.lib.platforms.all;
-  };
-
-
-  attrs = rec {
-  # If you change much fix indentation
+    # problems building without x11Support so disabled in that case for now
+    NIX_CFLAGS_COMPILE = lib.optionalString x11Support "-DDBUS_ENABLE_X11_AUTOLAUNCH=1";
+    NIX_CFLAGS_LINK = lib.optionalString (!stdenv.isDarwin) "-Wl,--as-needed";
 
-  # This package has been split because most applications only need dbus.lib
-  # which serves as an interface to a *system-wide* daemon,
-  # see e.g. http://en.wikipedia.org/wiki/D-Bus#Architecture .
+    enableParallelBuilding = true;
 
-  inherit libs;
+    doCheck = true;
 
-  tools = dbus_drv "tools" "tools bus" {
-    preBuild = makeInternalLib;
-    buildInputs = buildInputsX ++ systemdOrEmpty ++ [ libs ];
-    NIX_CFLAGS_LINK =
-      stdenv.lib.optionalString (!stdenv.isDarwin && !stdenv.isSunOS) "-Wl,--as-needed "
-      + "-ldbus-1";
+    installFlags = "sysconfdir=$(out)/etc datadir=$(out)/share";
 
-    # don't provide another dbus-1.pc (with incorrect include and link dirs),
-    # also remove useless empty dirs
-    postInstall = ''
-      rm "$out"/lib/pkgconfig/dbus-1.pc
-      rmdir --parents --ignore-fail-on-non-empty "$out"/{lib/pkgconfig,share/dbus-1/*}
+    # it's executed from $lib by absolute path
+    postFixup = ''
+      moveToOutput bin/dbus-launch "$lib"
+      ln -s "$lib/bin/dbus-launch" "$out/bin/"
     '';
 
-    meta.platforms = with stdenv.lib.platforms; allBut darwin;
-  };
-
-  daemon = tools;
+    passthru = {
+      dbus-launch = "${self.lib}/bin/dbus-launch";
+      daemon = self.out;
+    };
 
-  docs = dbus_drv "docs" "doc" {
-    postInstall = ''rm -r "$out/lib"'';
+    meta = with stdenv.lib; {
+      description = "Simple interprocess messaging system";
+      homepage = http://www.freedesktop.org/wiki/Software/dbus/;
+      license = licenses.gpl2Plus; # most is also under AFL-2.1
+      platforms = platforms.unix;
+    };
   };
-};
-in attrs.libs // attrs
+in self
 
diff --git a/pkgs/development/libraries/dbus/no-create-dirs.patch b/pkgs/development/libraries/dbus/no-create-dirs.patch
deleted file mode 100644
index cf10d977599..00000000000
--- a/pkgs/development/libraries/dbus/no-create-dirs.patch
+++ /dev/null
@@ -1,26 +0,0 @@
-diff --git a/bus/Makefile.am b/bus/Makefile.am
-index 6cbc09a..be60bb8 100644
---- a/bus/Makefile.am
-+++ b/bus/Makefile.am
-@@ -212,7 +212,6 @@ clean-local:
- 	/bin/rm *.bb *.bbg *.da *.gcov || true
- 
- install-data-hook:
--	$(mkinstalldirs) $(DESTDIR)$(localstatedir)/run/dbus
- 	$(mkinstalldirs) $(DESTDIR)$(configdir)/system.d
- 	$(mkinstalldirs) $(DESTDIR)$(configdir)/session.d
- 	$(mkinstalldirs) $(DESTDIR)$(datadir)/dbus-1/services
-diff --git a/tools/Makefile.am b/tools/Makefile.am
-index cfd54b8..b6e28f9 100644
---- a/tools/Makefile.am
-+++ b/tools/Makefile.am
-@@ -74,7 +74,7 @@ CLEANFILES = 				\
- 
- # create the /var/lib/dbus directory for dbus-uuidgen
- install-data-local:
--	$(MKDIR_P) $(DESTDIR)$(localstatedir)/lib/dbus
-+	:
- 
- installcheck-local:
--	test -d $(DESTDIR)$(localstatedir)/lib/dbus
-+	:
diff --git a/pkgs/development/libraries/dbus/ucred-dirty-hack.patch b/pkgs/development/libraries/dbus/ucred-dirty-hack.patch
deleted file mode 100644
index a07abcc15fb..00000000000
--- a/pkgs/development/libraries/dbus/ucred-dirty-hack.patch
+++ /dev/null
@@ -1,18 +0,0 @@
-diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
-index b4ecc96..267984a 100644
---- a/dbus/dbus-sysdeps-unix.c
-+++ b/dbus/dbus-sysdeps-unix.c
-@@ -1635,6 +1635,13 @@ write_credentials_byte (int             server_fd,
-     }
- }
- 
-+struct ucred
-+{
-+  pid_t pid;			/* PID of sending process.  */
-+  uid_t uid;			/* UID of sending process.  */
-+  gid_t gid;			/* GID of sending process.  */
-+};
-+
- /**
-  * Reads a single byte which must be nul (an error occurs otherwise),
-  * and reads unix credentials if available. Clears the credentials
diff --git a/pkgs/development/libraries/epoxy/default.nix b/pkgs/development/libraries/epoxy/default.nix
index daffae90b12..00962409660 100644
--- a/pkgs/development/libraries/epoxy/default.nix
+++ b/pkgs/development/libraries/epoxy/default.nix
@@ -13,6 +13,8 @@ stdenv.mkDerivation rec {
     sha256 = "0dfkd4xbp7v5gwsf6qwaraz54yzizf3lj5ymyc0msjn0adq3j5yl";
   };
 
+  outputs = [ "dev" "out" ];
+
   nativeBuildInputs = [ autoreconfHook pkgconfig utilmacros python ];
   buildInputs = [ mesa libX11 ];
 
diff --git a/pkgs/development/libraries/expat/default.nix b/pkgs/development/libraries/expat/default.nix
index 05cfeaee423..082f651a3fc 100644
--- a/pkgs/development/libraries/expat/default.nix
+++ b/pkgs/development/libraries/expat/default.nix
@@ -10,6 +10,10 @@ stdenv.mkDerivation rec {
 
   patches = [ ./CVE-2015-1283.patch ];
 
+  outputs = [ "dev" "out" ]; # TODO: fix referrers
+  outputBin = "dev";
+  outputMan = "dev"; # tiny page for a dev tool
+
   meta = with stdenv.lib; {
     homepage = http://www.libexpat.org/;
     description = "A stream-oriented XML parser library written in C";
diff --git a/pkgs/development/libraries/ffmpeg/generic.nix b/pkgs/development/libraries/ffmpeg/generic.nix
index 1113db5c136..d2da77c7b0d 100644
--- a/pkgs/development/libraries/ffmpeg/generic.nix
+++ b/pkgs/development/libraries/ffmpeg/generic.nix
@@ -69,6 +69,10 @@ stdenv.mkDerivation rec {
 
   patchPhase = ''patchShebangs .'';
 
+  outputs = [ "dev" "out" "bin" ]
+    ++ optional (reqMin "1.0") "doc" ; # just dev-doc
+  setOutputFlags = false; # doesn't accept all and stores configureFlags in libs!
+
   configureFlags = [
     # License
       "--enable-gpl"
@@ -148,6 +152,11 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
+  postFixup = ''
+    moveToOutput bin "$bin"
+    moveToOutput share/ffmpeg/examples "$doc"
+  '';
+
   /* Cross-compilation is untested, consider this an outline, more work
      needs to be done to portions of the build to get it to work correctly */
   crossAttrs = let
diff --git a/pkgs/development/libraries/fftw/default.nix b/pkgs/development/libraries/fftw/default.nix
index dfa4541e34b..a7a02521c69 100644
--- a/pkgs/development/libraries/fftw/default.nix
+++ b/pkgs/development/libraries/fftw/default.nix
@@ -14,6 +14,9 @@ stdenv.mkDerivation rec {
     sha256 = "10h9mzjxnwlsjziah4lri85scc05rlajz39nqf3mbh4vja8dw34g";
   };
 
+  outputs = [ "dev" "out" "doc" ]; # it's dev-doc only
+  outputBin = "dev"; # fftw-wisdom
+
   configureFlags =
     [ "--enable-shared" "--disable-static"
       "--enable-threads"
diff --git a/pkgs/development/libraries/fontconfig/2.10.nix b/pkgs/development/libraries/fontconfig/2.10.nix
index 2951dbb44d4..fea9efde1cf 100644
--- a/pkgs/development/libraries/fontconfig/2.10.nix
+++ b/pkgs/development/libraries/fontconfig/2.10.nix
@@ -16,6 +16,8 @@ stdenv.mkDerivation rec {
       }
     ;
 
+  outputs = [ "dev" "lib" "bin" "out" ]; # $out contains all the config
+
   propagatedBuildInputs = [ freetype ];
   buildInputs = [ pkgconfig expat ];
 
diff --git a/pkgs/development/libraries/fontconfig/default.nix b/pkgs/development/libraries/fontconfig/default.nix
index b03528de2d5..6acf1ebce29 100644
--- a/pkgs/development/libraries/fontconfig/default.nix
+++ b/pkgs/development/libraries/fontconfig/default.nix
@@ -36,6 +36,8 @@ stdenv.mkDerivation rec {
     })
   ];
 
+  outputs = [ "dev" "lib" "bin" "out" ]; # $out contains all the config
+
   propagatedBuildInputs = [ freetype ];
   buildInputs = [ pkgconfig expat ];
 
@@ -65,7 +67,7 @@ stdenv.mkDerivation rec {
   postInstall = ''
     cd "$out/etc/fonts"
     rm conf.d/{50-user,51-local}.conf
-    "${libxslt}/bin/xsltproc" --stringparam fontDirectories "${fontbhttf}" \
+    "${libxslt.bin}/bin/xsltproc" --stringparam fontDirectories "${fontbhttf}" \
       --stringparam fontconfig "$out" \
       --stringparam fontconfigConfigVersion "${configVersion}" \
       --path $out/share/xml/fontconfig \
diff --git a/pkgs/development/libraries/fontconfig/make-fonts-conf.nix b/pkgs/development/libraries/fontconfig/make-fonts-conf.nix
index 2b02e0df7a0..2d0a21ea9dd 100644
--- a/pkgs/development/libraries/fontconfig/make-fonts-conf.nix
+++ b/pkgs/development/libraries/fontconfig/make-fonts-conf.nix
@@ -8,9 +8,9 @@ runCommand "fonts.conf"
   }
   ''
     xsltproc --stringparam fontDirectories "$fontDirectories" \
-      --stringparam fontconfig "${fontconfig}" \
+      --stringparam fontconfig "${fontconfig.out}" \
       --stringparam fontconfigConfigVersion "${fontconfig.configVersion}" \
-      --path ${fontconfig}/share/xml/fontconfig \
-      ${./make-fonts-conf.xsl} ${fontconfig}/etc/fonts/fonts.conf \
+      --path ${fontconfig.out}/share/xml/fontconfig \
+      ${./make-fonts-conf.xsl} ${fontconfig.out}/etc/fonts/fonts.conf \
       > $out
   ''
diff --git a/pkgs/development/libraries/freetype/default.nix b/pkgs/development/libraries/freetype/default.nix
index e9e393075b3..dccde33efcf 100644
--- a/pkgs/development/libraries/freetype/default.nix
+++ b/pkgs/development/libraries/freetype/default.nix
@@ -31,12 +31,16 @@ stdenv.mkDerivation rec {
       (fetch_bohoomil "04-infinality-2.5.4-2014.12.07.patch" "1gph7z9s2221gy5dxn01v3lga0m9yib8yqsaqj5km74bqx1vlalh")
     ];
 
+  outputs = [ "dev" "out" ];
+
   propagatedBuildInputs = [ zlib bzip2 libpng ]; # needed when linking against freetype
   # dependence on harfbuzz is looser than the reverse dependence
   buildInputs = [ pkgconfig which ]
     # FreeType requires GNU Make, which is not part of stdenv on FreeBSD.
     ++ optional (!stdenv.isLinux) gnumake;
 
+  configureFlags = "--disable-static --bindir=$(dev)/bin";
+
   # from Gentoo, see https://bugzilla.redhat.com/show_bug.cgi?id=506840
   NIX_CFLAGS_COMPILE = "-fno-strict-aliasing";
   # The asm for armel is written with the 'asm' keyword.
@@ -47,8 +51,8 @@ stdenv.mkDerivation rec {
   doCheck = true;
 
   # compat hacks
-  postInstall = glib.flattenInclude + ''
-    ln -s . "$out"/include/freetype
+  postFixup = glib.flattenInclude + ''
+    ln -s . "$dev"/include/freetype
   '';
 
   crossAttrs = {
diff --git a/pkgs/development/libraries/gdk-pixbuf/default.nix b/pkgs/development/libraries/gdk-pixbuf/default.nix
index dbd3a679d48..b0f2a5e877e 100644
--- a/pkgs/development/libraries/gdk-pixbuf/default.nix
+++ b/pkgs/development/libraries/gdk-pixbuf/default.nix
@@ -13,12 +13,17 @@ stdenv.mkDerivation rec {
     sha256 = "1g7kjxv67jcdasi14n7jan4icrnnppd1m99wrdmpv32k4m7vfcj4";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputBin = "dev";
+
   setupHook = ./setup-hook.sh;
 
+  enableParallelBuilding = true;
+
   # !!! We might want to factor out the gdk-pixbuf-xlib subpackage.
-  buildInputs = [ libX11 libintlOrEmpty ];
+  buildInputs = [ libX11 gobjectIntrospection ] ++ libintlOrEmpty;
 
-  nativeBuildInputs = [ pkgconfig gobjectIntrospection ];
+  nativeBuildInputs = [ pkgconfig ];
 
   propagatedBuildInputs = [ glib libtiff libjpeg libpng jasper ];
 
@@ -34,12 +39,11 @@ stdenv.mkDerivation rec {
   # The tests take an excessive amount of time (> 1.5 hours) and memory (> 6 GB).
   inherit (doCheck);
 
-  postInstall = "rm -rf $out/share/gtk-doc";
-
-  meta = {
+  meta = with stdenv.lib; {
     description = "A library for image loading and manipulation";
     homepage = http://library.gnome.org/devel/gdk-pixbuf/;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
-    platforms = stdenv.lib.platforms.unix;
+    maintainers = [ maintainers.eelco ];
+    platforms = platforms.unix;
   };
 }
+
diff --git a/pkgs/development/libraries/gettext/default.nix b/pkgs/development/libraries/gettext/default.nix
index 874c767046b..b32b126cfe8 100644
--- a/pkgs/development/libraries/gettext/default.nix
+++ b/pkgs/development/libraries/gettext/default.nix
@@ -41,7 +41,7 @@ stdenv.mkDerivation (rec {
     sed -i -e "s/\(am_libgettextlib_la_OBJECTS = \)error.lo/\\1/" gettext-tools/gnulib-lib/Makefile.in
   '';
 
-  buildInputs = [ xz ] ++ stdenv.lib.optional (!stdenv.isLinux) libiconv;
+  buildInputs = [ xz xz.bin ] ++ stdenv.lib.optional (!stdenv.isLinux) libiconv;
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/development/libraries/gettext/expat.nix b/pkgs/development/libraries/gettext/expat.nix
index fc6116b3916..35d2e1a0950 100644
--- a/pkgs/development/libraries/gettext/expat.nix
+++ b/pkgs/development/libraries/gettext/expat.nix
@@ -5,6 +5,6 @@ runCommand "gettext-expat-${gettext.name}" { buildInputs = [ makeWrapper ]; } ''
   cp -rf ${gettext}/* $out/
   chmod a+w $out/bin
   for p in $out/bin/*; do
-    wrapProgram $p --prefix LD_LIBRARY_PATH : ${expat}/lib
+    wrapProgram $p --prefix LD_LIBRARY_PATH : ${expat.out}/lib
   done
 ''
diff --git a/pkgs/development/libraries/git2/default.nix b/pkgs/development/libraries/git2/default.nix
index 3c433511fc1..4ec2903b900 100644
--- a/pkgs/development/libraries/git2/default.nix
+++ b/pkgs/development/libraries/git2/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl, pkgconfig, cmake, zlib, python, libssh2, openssl, http-parser}:
+{ stdenv, fetchurl, cmake, pkgconfig, zlib, python, libssh2, openssl, http-parser }:
 
 stdenv.mkDerivation rec {
   version = "0.23.2";
diff --git a/pkgs/development/libraries/glib-networking/default.nix b/pkgs/development/libraries/glib-networking/default.nix
index a17b7a21409..869fdcc70a1 100644
--- a/pkgs/development/libraries/glib-networking/default.nix
+++ b/pkgs/development/libraries/glib-networking/default.nix
@@ -13,10 +13,12 @@ stdenv.mkDerivation rec {
     sha256 = "8f8a340d3ba99bfdef38b653da929652ea6640e27969d29f7ac51fbbe11a4346";
   };
 
+  outputs = [ "dev" "out" ]; # to deal with propagatedBuildInputs
+
   configureFlags = "--with-ca-certificates=/etc/ssl/certs/ca-certificates.crt";
 
   preBuild = ''
-    sed -e "s@${glib}/lib/gio/modules@$out/lib/gio/modules@g" -i $(find . -name Makefile)
+    sed -e "s@${glib.out}/lib/gio/modules@$out/lib/gio/modules@g" -i $(find . -name Makefile)
   '';
 
   nativeBuildInputs = [ pkgconfig intltool ];
diff --git a/pkgs/development/libraries/glib/default.nix b/pkgs/development/libraries/glib/default.nix
index e53775464e0..6ce234c3a64 100644
--- a/pkgs/development/libraries/glib/default.nix
+++ b/pkgs/development/libraries/glib/default.nix
@@ -31,12 +31,12 @@ let
   # This is intended to be run in postInstall of any package
   # which has $out/include/ containing just some disjunct directories.
   flattenInclude = ''
-    for dir in "$out"/include/*; do
-      cp -r "$dir"/* "$out/include/"
+    for dir in "''${!outputInclude}"/include/*; do
+      cp -r "$dir"/* "''${!outputInclude}/include/"
       rm -r "$dir"
       ln -s . "$dir"
     done
-    ln -sr -t "$out/include/" "$out"/lib/*/include/* 2>/dev/null || true
+    ln -sr -t "''${!outputInclude}/include/" "''${!outputInclude}"/lib/*/include/* 2>/dev/null || true
   '';
 
   ver_maj = "2.46";
@@ -53,18 +53,22 @@ stdenv.mkDerivation rec {
 
   patches = optional stdenv.isDarwin ./darwin-compilation.patch ++ optional doCheck ./skip-timer-test.patch;
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputBin = "dev";
+
   setupHook = ./setup-hook.sh;
 
-  buildInputs = [ libelf ]
+  buildInputs = [ libelf setupHook pcre ]
     ++ optionals doCheck [ tzdata libxml2 desktop_file_utils shared_mime_info ];
 
   nativeBuildInputs = [ pkgconfig gettext perl python ];
 
-  propagatedBuildInputs = [ pcre zlib libffi libiconv ]
+  propagatedBuildInputs = [ zlib libffi libiconv ]
     ++ libintlOrEmpty;
 
-  configureFlags =
-    optional stdenv.isDarwin "--disable-compile-warnings"
+  # internal pcre would only add <200kB, but it's relatively common
+  configureFlags = [ "--with-pcre=system" ]
+    ++ optional stdenv.isDarwin "--disable-compile-warnings"
     ++ optional stdenv.isSunOS ["--disable-modular-tests" "--with-libiconv"];
 
   NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin " -lintl"
@@ -78,6 +82,12 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = true;
   DETERMINISTIC_BUILD = 1;
 
+  postInstall = ''
+    moveToOutput "share/glib-2.0" "$dev"
+    substituteInPlace "$dev/bin/gdbus-codegen" --replace "$out" "$dev"
+    sed -i "$dev/bin/glib-gettextize" -e "s|^gettext_dir=.*|gettext_dir=$dev/share/glib-2.0/gettext|"
+  '';
+
   inherit doCheck;
   preCheck = optionalString doCheck
     '' export LD_LIBRARY_PATH="$NIX_BUILD_TOP/${name}/glib/.libs:$LD_LIBRARY_PATH"
@@ -99,8 +109,6 @@ stdenv.mkDerivation rec {
        sed -e '/g_subprocess_launcher_set_environ (launcher, envp);/a g_subprocess_launcher_setenv (launcher, "PATH", g_getenv("PATH"), TRUE);' -i gio/tests/gsubprocess.c
     '';
 
-  postInstall = ''rm -rvf $out/share/gtk-doc'';
-
   passthru = {
      gioModuleDir = "lib/gio/modules";
      inherit flattenInclude;
diff --git a/pkgs/development/libraries/glib/setup-hook.sh b/pkgs/development/libraries/glib/setup-hook.sh
index ca7e326bd02..c5cf293902c 100644
--- a/pkgs/development/libraries/glib/setup-hook.sh
+++ b/pkgs/development/libraries/glib/setup-hook.sh
@@ -1,5 +1,3 @@
-# Install gschemas, if any, in a package-specific directory
-installFlagsArray+=("gsettingsschemadir=$out/share/gsettings-schemas/$name/glib-2.0/schemas/")
 
 make_glib_find_gsettings_schemas() {
     # For packages that need gschemas of other packages (e.g. empathy)
@@ -7,17 +5,22 @@ make_glib_find_gsettings_schemas() {
         addToSearchPath GSETTINGS_SCHEMAS_PATH "$1/share/gsettings-schemas/"*
     fi
 }
-
 envHooks+=(make_glib_find_gsettings_schemas)
 
+# Install gschemas, if any, in a package-specific directory
+glibPreInstallPhase() {
+  installFlagsArray+=("gsettingsschemadir=${!outputLib}/share/gsettings-schemas/$name/glib-2.0/schemas/")
+}
+preInstallPhases+=(glibPreInstallPhase)
+
 glibPreFixupPhase() {
     # Move gschemas in case the install flag didn't help
-    if [ -d "$out/share/glib-2.0/schemas" ]; then
-        mkdir -p "$out/share/gsettings-schemas/$name/glib-2.0"
-        mv "$out/share/glib-2.0/schemas" "$out/share/gsettings-schemas/$name/glib-2.0/"
+    if [ -d "${!outputLib}/share/glib-2.0/schemas" ]; then
+        mkdir -p "${!outputLib}/share/gsettings-schemas/$name/glib-2.0"
+        mv "${!outputLib}/share/glib-2.0/schemas" "${!outputLib}/share/gsettings-schemas/$name/glib-2.0/"
     fi
 
-    addToSearchPath GSETTINGS_SCHEMAS_PATH "$out/share/gsettings-schemas/$name"
+    addToSearchPath GSETTINGS_SCHEMAS_PATH "${!outputLib}/share/gsettings-schemas/$name"
 }
+preFixupPhases+=(glibPreFixupPhase)
 
-preFixupPhases="$preFixupPhases glibPreFixupPhase"
diff --git a/pkgs/development/libraries/glibc/builder.sh b/pkgs/development/libraries/glibc/builder.sh
index 2836063e3bf..46f47d9b99c 100644
--- a/pkgs/development/libraries/glibc/builder.sh
+++ b/pkgs/development/libraries/glibc/builder.sh
@@ -12,8 +12,10 @@ postConfigure() {
 
     export NIX_DONT_SET_RPATH=1
     unset CFLAGS
-}
 
+    # Apparently --bindir is not respected.
+    makeFlagsArray+=("bindir=$bin/bin" "sbindir=$bin/sbin" "rootsbindir=$bin/sbin")
+}
 
 postInstall() {
     if test -n "$installLocales"; then
@@ -27,7 +29,7 @@ postInstall() {
     if test -z "$hurdHeaders"; then
         # Include the Linux kernel headers in Glibc, except the `scsi'
         # subdirectory, which Glibc provides itself.
-        (cd $out/include && \
+        (cd $dev/include && \
          ln -sv $(ls -d $kernelHeaders/include/* | grep -v 'scsi$') .)
     fi
 
@@ -48,6 +50,17 @@ postInstall() {
 
     # Get rid of more unnecessary stuff.
     rm -rf $out/var $out/sbin/sln
+
+    # Put libraries for static linking in a separate output.  Note
+    # that libc_nonshared.a and libpthread_nonshared.a are required
+    # for dynamically-linked applications.
+    mkdir -p $static/lib
+    mv $out/lib/*.a $static/lib
+    mv $static/lib/lib*_nonshared.a $out/lib
+
+    # Work around a Nix bug: hard links across outputs cause a build failure.
+    cp $bin/bin/getconf $bin/bin/getconf_
+    mv $bin/bin/getconf_ $bin/bin/getconf
 }
 
 genericBuild
diff --git a/pkgs/development/libraries/glibc/common.nix b/pkgs/development/libraries/glibc/common.nix
index cf356ccefbe..03881a41aa5 100644
--- a/pkgs/development/libraries/glibc/common.nix
+++ b/pkgs/development/libraries/glibc/common.nix
@@ -124,7 +124,10 @@ stdenv.mkDerivation ({
 
   installFlags = [ "sysconfdir=$(out)/etc" ];
 
-  buildInputs = stdenv.lib.optionals (cross != null) [ gccCross ]
+  outputs = [ "dev" "out" "bin" "static" ];
+
+  buildInputs = [ ]
+    ++ stdenv.lib.optionals (cross != null) [ gccCross ]
     ++ stdenv.lib.optional (mig != null) mig
     ++ stdenv.lib.optionals withGd [ gd libpng ];
 
diff --git a/pkgs/development/libraries/glibc/default.nix b/pkgs/development/libraries/glibc/default.nix
index 08eaf555e02..26d2bda2aeb 100644
--- a/pkgs/development/libraries/glibc/default.nix
+++ b/pkgs/development/libraries/glibc/default.nix
@@ -97,7 +97,7 @@ in
 
       # To avoid a dependency on the build system 'bash'.
       preFixup = ''
-        rm $out/bin/{ldd,tzselect,catchsegv,xtrace}
+        rm $bin/bin/{ldd,tzselect,catchsegv,xtrace}
       '';
     }
    else {}))
diff --git a/pkgs/development/libraries/glibc/info.nix b/pkgs/development/libraries/glibc/info.nix
index e4cdb42dd68..f57e52f7b7a 100644
--- a/pkgs/development/libraries/glibc/info.nix
+++ b/pkgs/development/libraries/glibc/info.nix
@@ -8,6 +8,8 @@ build null {
 
   inherit fetchurl stdenv;
 
+  outputs = [ "out" ];
+
   configureFlags = [ "--enable-add-ons" ];
 
   buildInputs = [ texinfo perl ];
diff --git a/pkgs/development/libraries/glibc/locales.nix b/pkgs/development/libraries/glibc/locales.nix
index cbf7af22cac..0cf074323fb 100644
--- a/pkgs/development/libraries/glibc/locales.nix
+++ b/pkgs/development/libraries/glibc/locales.nix
@@ -18,6 +18,8 @@ build null {
 
   builder = ./locales-builder.sh;
 
+  outputs = [ "out" ];
+
   # Awful hack: `localedef' doesn't allow the path to `locale-archive'
   # to be overriden, but you *can* specify a prefix, i.e. it will use
   # <prefix>/<path-to-glibc>/lib/locale/locale-archive.  So we use
@@ -25,7 +27,7 @@ build null {
   # $TMPDIR/nix/store/...-glibc-.../lib/locale/locale-archive.
   buildPhase =
     ''
-      mkdir -p $TMPDIR/"$(dirname $(readlink -f $(type -p localedef)))/../lib/locale"
+      mkdir -p $TMPDIR/"${stdenv.cc.libc.out}/lib/locale"
 
       # Hack to allow building of the locales (needed since glibc-2.12)
       sed -i -e 's,^$(rtld-prefix) $(common-objpfx)locale/localedef,localedef --prefix='$TMPDIR',' ../glibc-2*/localedata/Makefile
diff --git a/pkgs/development/libraries/glibc/multi.nix b/pkgs/development/libraries/glibc/multi.nix
index b5b4eabe9c7..0d7bed99f22 100644
--- a/pkgs/development/libraries/glibc/multi.nix
+++ b/pkgs/development/libraries/glibc/multi.nix
@@ -3,32 +3,26 @@
 
 let
   nameVersion = builtins.parseDrvName glibc.name;
+  glibc64 = glibc;
 in
 runCommand "${nameVersion.name}-multi-${nameVersion.version}"
-  { inherit glibc32;
-   glibc64 = glibc;
-  }
+  { outputs = [ "dev" "out" "bin" ]; } # TODO: no static version here (yet)
   ''
-    mkdir -p $out
-    ln -s $glibc64/* $out/
-
-    rm $out/lib $out/lib64
-    mkdir -p $out/lib
-    ln -s $glibc64/lib/* $out/lib
-    ln -s $glibc32/lib $out/lib/32
-    ln -s lib $out/lib64
+    mkdir -p "$out/lib"
+    ln -s '${glibc64.out}'/lib/* "$out/lib"
+    ln -s '${glibc32.out}/lib' "$out/lib/32"
+    ln -s lib "$out/lib64"
 
     # fixing ldd RLTDLIST
-    rm $out/bin
-    cp -rs $glibc64/bin $out
-    chmod u+w $out/bin
-    rm $out/bin/ldd
+    mkdir -p "$bin/bin"
+    cp -s '${glibc64.bin}'/bin/* "$bin/bin/"
+    rm "$bin/bin/ldd"
     sed -e "s|^RTLDLIST=.*$|RTLDLIST=\"$out/lib/ld-linux-x86-64.so.2 $out/lib/32/ld-linux.so.2\"|g" \
-        $glibc64/bin/ldd > $out/bin/ldd
-    chmod 555 $out/bin/ldd
+        '${glibc64.bin}/bin/ldd' > "$bin/bin/ldd"
+    chmod +x "$bin/bin/ldd"
 
-    rm $out/include
-    cp -rs $glibc32/include $out
-    chmod -R u+w $out/include
-    cp -rsf $glibc64/include $out
+    mkdir "$dev"
+    cp -rs '${glibc32}'/include "$dev/"
+    chmod +w -R "$dev"
+    cp -rsf '${glibc64}'/include "$dev/"
   ''
diff --git a/pkgs/development/libraries/gmime/default.nix b/pkgs/development/libraries/gmime/default.nix
index 6564fc51186..ee81aec0797 100644
--- a/pkgs/development/libraries/gmime/default.nix
+++ b/pkgs/development/libraries/gmime/default.nix
@@ -8,9 +8,13 @@ stdenv.mkDerivation rec {
     sha256 = "0rfzbgsh8ira5p76kdghygl5i3fvmmx4wbw5rp7f8ajc4vxp18g0";
   };
 
+  outputs = [ "dev" "out" ];
+
   nativeBuildInputs = [ pkgconfig ];
   propagatedBuildInputs = [ glib zlib libgpgerror ];
 
+  enableParallelBuilding = true;
+
   meta = {
     homepage = http://spruce.sourceforge.net/gmime/;
     description = "A C/C++ library for manipulating MIME messages";
diff --git a/pkgs/development/libraries/gmp/5.1.x.nix b/pkgs/development/libraries/gmp/5.1.x.nix
index 7b393067ff5..0768df60a79 100644
--- a/pkgs/development/libraries/gmp/5.1.x.nix
+++ b/pkgs/development/libraries/gmp/5.1.x.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation rec {
     sha256 = "0q5i39pxrasgn9qdxzpfbwhh11ph80p57x6hf48m74261d97j83m";
   };
 
+  outputs = [ "out" "info" ];
+
   nativeBuildInputs = [ m4 ];
 
   patches = if stdenv.isDarwin then [ ./need-size-t.patch ] else null;
diff --git a/pkgs/development/libraries/gmp/6.x.nix b/pkgs/development/libraries/gmp/6.x.nix
index 5025557458c..a7443c02c5b 100644
--- a/pkgs/development/libraries/gmp/6.x.nix
+++ b/pkgs/development/libraries/gmp/6.x.nix
@@ -1,8 +1,8 @@
-{ stdenv, fetchurl, m4, cxx ? true, withStatic ? true }:
+{ stdenv, fetchurl, m4, cxx ? true, withStatic ? false }:
 
 with { inherit (stdenv.lib) optional optionalString; };
 
-stdenv.mkDerivation rec {
+let self = stdenv.mkDerivation rec {
   name = "gmp-6.1.0";
 
   src = fetchurl { # we need to use bz2, others aren't in bootstrapping stdenv
@@ -10,6 +10,12 @@ stdenv.mkDerivation rec {
     sha256 = "1s3kddydvngqrpc6i1vbz39raya2jdcl042wi0ksbszgjjllk129";
   };
 
+  #outputs TODO: split $cxx due to libstdc++ dependency; maybe port to gmp5;
+  # maybe let ghc use a version with *.so shared with rest of nixpkgs and *.a added
+  # - see #5855 for related discussion
+  outputs = [ "dev" "out" "info" ];
+  passthru.static = self.out;
+
   nativeBuildInputs = [ m4 ];
 
   configureFlags =
@@ -69,4 +75,5 @@ stdenv.mkDerivation rec {
     platforms = platforms.all;
     maintainers = [ maintainers.simons ];
   };
-}
+};
+  in self
diff --git a/pkgs/development/libraries/gnutls/generic.nix b/pkgs/development/libraries/gnutls/generic.nix
index f1eb62e0083..3bcc521504e 100644
--- a/pkgs/development/libraries/gnutls/generic.nix
+++ b/pkgs/development/libraries/gnutls/generic.nix
@@ -13,7 +13,8 @@ stdenv.mkDerivation {
 
   inherit src patches postPatch;
 
-  outputs = [ "out" "man" ];
+  outputs = [ "dev" "out" "bin" "man" "docdev" ];
+  outputInfo = "docdev";
 
   configureFlags =
     # FIXME: perhaps use $SSL_CERT_FILE instead
@@ -35,8 +36,6 @@ stdenv.mkDerivation {
     ++ [ unbound ]
     ++ lib.optional guileBindings guile;
 
-  # AutoreconfHook is temporary until the patch lands upstream to fix
-  # header file generation with parallel building
   nativeBuildInputs = [ perl pkgconfig ] ++ nativeBuildInputs;
 
   # XXX: Gnulib's `test-select' fails on FreeBSD:
@@ -46,9 +45,10 @@ stdenv.mkDerivation {
   # Fixup broken libtool and pkgconfig files
   preFixup = lib.optionalString (!stdenv.isDarwin) ''
     sed ${lib.optionalString tpmSupport "-e 's,-ltspi,-L${trousers}/lib -ltspi,'"} \
-        -e 's,-lz,-L${zlib}/lib -lz,' \
-        -e 's,-lgmp,-L${gmp}/lib -lgmp,' \
-        -i $out/lib/libgnutls.la $out/lib/pkgconfig/gnutls.pc
+        -e 's,-lz,-L${zlib.out}/lib -lz,' \
+        -e 's,-L${gmp.dev}/lib,-L${gmp.out}/lib,' \
+        -e 's,-lgmp,-L${gmp.out}/lib -lgmp,' \
+        -i $out/lib/*.la "$dev/lib/pkgconfig/gnutls.pc"
   '';
 
   meta = with lib; {
diff --git a/pkgs/development/libraries/gobject-introspection/default.nix b/pkgs/development/libraries/gobject-introspection/default.nix
index f429e1dc6c3..1a2ba3db29a 100644
--- a/pkgs/development/libraries/gobject-introspection/default.nix
+++ b/pkgs/development/libraries/gobject-introspection/default.nix
@@ -15,26 +15,31 @@ stdenv.mkDerivation rec {
     url = "mirror://gnome/sources/gobject-introspection/${ver_maj}/${name}.tar.xz";
     sha256 = "6658bd3c2b8813eb3e2511ee153238d09ace9d309e4574af27443d87423e4233";
   };
+  patches = [ ./absolute_shlib_path.patch ];
+
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
+  outputMan = "dev"; # tiny pages
 
-  buildInputs = [ flex bison pkgconfig python ]
+  buildInputs = [ flex bison pkgconfig python setupHook/*move .gir*/ ]
     ++ libintlOrEmpty
     ++ stdenv.lib.optional stdenv.isDarwin otool;
   propagatedBuildInputs = [ libffi glib ];
 
-  # Tests depend on cairo, which is undesirable (it pulls in lots of
-  # other dependencies).
-  configureFlags = [ "--disable-tests" ];
-
   preConfigure = ''
     sed 's|/usr/bin/env ||' -i tools/g-ir-tool-template.in
   '';
+  configureFlags = [
+    # Tests depend on cairo, which is undesirable (it pulls in lots of
+    # other dependencies).
+    "--disable-tests"
+  ];
 
-  postInstall = "rm -rf $out/share/gtk-doc";
+  # outputs TODO: share/gobject-introspection-1.0/tests is needed during build
+  # by pygobject3 (and maybe others), but it's only searched in $out
 
   setupHook = ./setup-hook.sh;
 
-  patches = [ ./absolute_shlib_path.patch ];
-
   meta = with stdenv.lib; {
     description = "A middleware layer between C libraries and language bindings";
     homepage    = http://live.gnome.org/GObjectIntrospection;
diff --git a/pkgs/development/libraries/gobject-introspection/setup-hook.sh b/pkgs/development/libraries/gobject-introspection/setup-hook.sh
index d411ad69dc4..583d8475ec3 100644
--- a/pkgs/development/libraries/gobject-introspection/setup-hook.sh
+++ b/pkgs/development/libraries/gobject-introspection/setup-hook.sh
@@ -12,3 +12,10 @@ make_gobject_introspection_find_gir_files() {
 }
 
 envHooks+=(make_gobject_introspection_find_gir_files)
+
+_multioutMoveGlibGir() {
+  moveToOutput share/gir-1.0 "${!outputDev}"
+}
+
+preFixupHooks+=(_multioutMoveGlibGir)
+
diff --git a/pkgs/development/libraries/gpgme/default.nix b/pkgs/development/libraries/gpgme/default.nix
index 1657ceaeece..8d8b9a91494 100644
--- a/pkgs/development/libraries/gpgme/default.nix
+++ b/pkgs/development/libraries/gpgme/default.nix
@@ -18,17 +18,20 @@ stdenv.mkDerivation rec {
     sha256 = "17892sclz3yg45wbyqqrzzpq3l0icbnfl28f101b3062g8cy97dh";
   };
 
+  outputs = [ "dev" "out" "info" ];
+  outputBin = "dev"; # gpgme-config; not so sure about gpgme-tool
+
   propagatedBuildInputs = [ libgpgerror glib libassuan pth ];
 
   nativeBuildInputs = [ pkgconfig gnupg ];
 
   configureFlags = "--with-gpg=${gpgPath}";
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "http://www.gnupg.org/related_software/gpgme";
     description = "Library for making GnuPG easier to use";
-    license = stdenv.lib.licenses.gpl2;
-    platforms = stdenv.lib.platforms.unix;
-    maintainers = with stdenv.lib.maintainers; [ fuuzetsu ];
+    license = licenses.gpl2;
+    platforms = platforms.unix;
+    maintainers = [ maintainers.fuuzetsu ];
   };
 }
diff --git a/pkgs/development/libraries/gstreamer/default.nix b/pkgs/development/libraries/gstreamer/default.nix
index efdaa37eba5..7d2b4caf2a5 100644
--- a/pkgs/development/libraries/gstreamer/default.nix
+++ b/pkgs/development/libraries/gstreamer/default.nix
@@ -1,4 +1,4 @@
-{ callPackage }:
+{ callPackage, libva-full }:
 
 rec {
   gstreamer = callPackage ./core { };
@@ -19,7 +19,10 @@ rec {
   # (Non Linear Engine).
   gst-editing-services = callPackage ./ges { inherit gnonlin; };
 
-  gst-vaapi = callPackage ./vaapi { inherit gst-plugins-base gstreamer gst-plugins-bad; };
+  gst-vaapi = callPackage ./vaapi {
+    inherit gst-plugins-base gstreamer gst-plugins-bad;
+    libva = libva-full; # looks also for libva-{x11,wayland}
+  };
 
   gst-validate = callPackage ./validate { inherit gst-plugins-base; };
 }
diff --git a/pkgs/development/libraries/gstreamer/legacy/gst-plugins-good/default.nix b/pkgs/development/libraries/gstreamer/legacy/gst-plugins-good/default.nix
index deca854008a..25f530ecfef 100644
--- a/pkgs/development/libraries/gstreamer/legacy/gst-plugins-good/default.nix
+++ b/pkgs/development/libraries/gstreamer/legacy/gst-plugins-good/default.nix
@@ -1,7 +1,7 @@
 { fetchurl, stdenv, pkgconfig, gst_plugins_base, aalib, cairo
 , flac, libjpeg, zlib, speex, libpng, libdv, libcaca, libvpx
 , libiec61883, libavc1394, taglib, libpulseaudio, gdk_pixbuf, orc
-, glib, gstreamer, bzip2, libsoup, libintlOrEmpty
+, glib, gstreamer, bzip2, libsoup, libintlOrEmpty, ncurses
 , # Whether to build no plugins that have external dependencies
   # (except the PulseAudio plugin).
   minimalDeps ? false
@@ -34,6 +34,11 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
+  postInstall = ''
+    substituteInPlace $out/lib/gstreamer-0.10/libgstaasink.la \
+      --replace "${ncurses.dev}/lib" "${ncurses.lib}/lib"
+  '';
+
   meta = {
     homepage = http://gstreamer.freedesktop.org;
 
diff --git a/pkgs/development/libraries/gstreamer/vaapi/default.nix b/pkgs/development/libraries/gstreamer/vaapi/default.nix
index 015aa4e07f5..bf061b4125b 100644
--- a/pkgs/development/libraries/gstreamer/vaapi/default.nix
+++ b/pkgs/development/libraries/gstreamer/vaapi/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, pkgconfig, gst-plugins-base, bzip2, libva
+{ stdenv, fetchurl, pkgconfig, gst-plugins-base, bzip2, libva, wayland
 , libdrm, udev, xorg, mesa, yasm, gstreamer, gst-plugins-bad, nasm
 , libvpx
 }:
@@ -14,8 +14,10 @@ stdenv.mkDerivation rec {
 
   nativeBuildInputs = with stdenv.lib; [ pkgconfig bzip2 ];
 
-  buildInputs = with stdenv.lib; [ gstreamer gst-plugins-base gst-plugins-bad libva libdrm udev
-    xorg.libX11 xorg.libXext xorg.libXv xorg.libXrandr xorg.libSM xorg.libICE mesa nasm libvpx ];
+  buildInputs = [
+    gstreamer gst-plugins-base gst-plugins-bad libva wayland libdrm udev
+    xorg.libX11 xorg.libXext xorg.libXv xorg.libXrandr xorg.libSM xorg.libICE mesa nasm libvpx
+  ];
 
   preConfigure = "
     export GST_PLUGIN_PATH_1_0=$out/lib/gstreamer-1.0
diff --git a/pkgs/development/libraries/gtk+/2.x.nix b/pkgs/development/libraries/gtk+/2.x.nix
index e821e693b0c..bc129d9f1fb 100644
--- a/pkgs/development/libraries/gtk+/2.x.nix
+++ b/pkgs/development/libraries/gtk+/2.x.nix
@@ -15,11 +15,16 @@ stdenv.mkDerivation rec {
     sha256 = "0mj6xn40py9r9lvzg633fal81xfwfm89d9mvz7jk4lmwk0g49imj";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputBin = "dev";
+
   enableParallelBuilding = true;
 
   NIX_CFLAGS_COMPILE = stdenv.lib.optionalString (libintlOrEmpty != []) "-lintl";
 
-  nativeBuildInputs = [ perl pkgconfig gettext ];
+  setupHook = ./setup-hook.sh;
+
+  nativeBuildInputs = [ setupHook perl pkgconfig gettext ];
 
   propagatedBuildInputs = with xorg; with stdenv.lib;
     [ glib cairo pango gdk_pixbuf atk ]
@@ -35,7 +40,9 @@ stdenv.mkDerivation rec {
     then "--disable-glibtest --disable-introspection --disable-visibility"
     else "--with-xinput=yes";
 
-  postInstall = "rm -rf $out/share/gtk-doc";
+  postInstall = ''
+    moveToOutput share/gtk-2.0/demo "$docdev"
+  '';
 
   passthru = {
     gtkExeEnvPostBuild = ''
diff --git a/pkgs/development/libraries/gtk+/3.x.nix b/pkgs/development/libraries/gtk+/3.x.nix
index 248c4fa385e..6c00a5df09f 100644
--- a/pkgs/development/libraries/gtk+/3.x.nix
+++ b/pkgs/development/libraries/gtk+/3.x.nix
@@ -1,11 +1,10 @@
 { stdenv, fetchurl, pkgconfig, gettext, perl
 , expat, glib, cairo, pango, gdk_pixbuf, atk, at_spi2_atk, gobjectIntrospection
-, xlibs, x11, wayland, libxkbcommon, epoxy
+, xorg, wayland, epoxy, json_glib, libxkbcommon, gmp
 , xineramaSupport ? stdenv.isLinux
 , cupsSupport ? stdenv.isLinux, cups ? null
 }:
 
-assert xineramaSupport -> xlibs.libXinerama != null;
 assert cupsSupport -> cups != null;
 
 let
@@ -21,23 +20,31 @@ stdenv.mkDerivation rec {
     sha256 = "107aeb9a4244ce3c044becdd6dffc32d83202595181597180d4c736302a71852";
   };
 
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
+
   nativeBuildInputs = [ pkgconfig gettext gobjectIntrospection perl ];
 
-  buildInputs = [ libxkbcommon epoxy ];
-  propagatedBuildInputs = with xlibs; with stdenv.lib;
-    [ expat glib cairo pango gdk_pixbuf atk at_spi2_atk libXrandr libXrender libXcomposite libXi libXcursor ]
+  buildInputs = [ libxkbcommon epoxy json_glib ];
+  propagatedBuildInputs = with xorg; with stdenv.lib;
+    [ expat glib cairo pango gdk_pixbuf atk at_spi2_atk
+      libXrandr libXrender libXcomposite libXi libXcursor libSM libICE ]
     ++ optionals stdenv.isLinux [ wayland ]
     ++ optional xineramaSupport libXinerama
     ++ optional cupsSupport cups;
+  #TODO: colord?
 
-  NIX_LDFLAGS = if stdenv.isDarwin then "-lintl" else null;
+  NIX_LDFLAGS = stdenv.lib.optionalString stdenv.isDarwin "-lintl";
 
   # demos fail to install, no idea where's the problem
   preConfigure = "sed '/^SRC_SUBDIRS /s/demos//' -i Makefile.in";
 
   enableParallelBuilding = true;
 
-  postInstall = "rm -rf $out/share/gtk-doc";
+  postInstall = ''
+    substituteInPlace "$out/lib/gtk-3.0/3.0.0/printbackends/libprintbackend-cups.la" \
+      --replace '-L${gmp.dev}/lib' '-L${gmp.out}/lib'
+  '';
 
   passthru = {
     gtkExeEnvPostBuild = ''
@@ -46,7 +53,7 @@ stdenv.mkDerivation rec {
     ''; # workaround for bug of nix-mode for Emacs */ '';
   };
 
-  meta = {
+  meta = with stdenv.lib; {
     description = "A multi-platform toolkit for creating graphical user interfaces";
 
     longDescription = ''
@@ -62,9 +69,9 @@ stdenv.mkDerivation rec {
 
     homepage = http://www.gtk.org/;
 
-    license = stdenv.lib.licenses.lgpl2Plus;
+    license = licenses.lgpl2Plus;
 
-    maintainers = with stdenv.lib.maintainers; [ urkud raskin vcunat lethalman ];
-    platforms = stdenv.lib.platforms.all;
+    maintainers = with maintainers; [ urkud raskin vcunat lethalman ];
+    platforms = platforms.all;
   };
 }
diff --git a/pkgs/development/libraries/gtk+/setup-hook.sh b/pkgs/development/libraries/gtk+/setup-hook.sh
new file mode 100644
index 00000000000..c2b0ab502db
--- /dev/null
+++ b/pkgs/development/libraries/gtk+/setup-hook.sh
@@ -0,0 +1,10 @@
+fixupOutputHooks+=(_gtk2CleanComments)
+
+# Clean comments that link to generator of the file
+_gtk2CleanComments() {
+    local f="$prefix/lib/gtk-2.0/2.10.0/immodules.cache"
+    if [ -f "$f" ]; then
+        sed 's|Created by .*bin/gtk-query-|Created by bin/gtk-query-|' -i "$f"
+    fi
+}
+
diff --git a/pkgs/development/libraries/gupnp/default.nix b/pkgs/development/libraries/gupnp/default.nix
index 6145c8c4947..45f5217d3c9 100644
--- a/pkgs/development/libraries/gupnp/default.nix
+++ b/pkgs/development/libraries/gupnp/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     ln -sv ${libsoup}/include/*/libsoup $out/include
-    ln -sv ${libxml2}/include/*/libxml $out/include
+    ln -sv ${libxml2.dev}/include/*/libxml $out/include
     ln -sv ${gssdp}/include/*/libgssdp $out/include
   '';
 
diff --git a/pkgs/development/libraries/gvfs/default.nix b/pkgs/development/libraries/gvfs/default.nix
index d2a958faed8..37403f50e2b 100644
--- a/pkgs/development/libraries/gvfs/default.nix
+++ b/pkgs/development/libraries/gvfs/default.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
   nativeBuildInputs = [ pkgconfig intltool libtool ];
 
   buildInputs =
-    [ makeWrapper glib dbus.libs udev libgudev udisks2 libgcrypt
+    [ makeWrapper glib dbus udev libgudev udisks2 libgcrypt
       libgphoto2 avahi libarchive fuse libcdio
       libxml2 libxslt docbook_xsl samba libmtp
       # ToDo: a ligther version of libsoup to have FTP/HTTP support?
diff --git a/pkgs/development/libraries/harfbuzz/default.nix b/pkgs/development/libraries/harfbuzz/default.nix
index 26c5d2fa825..865a4f1cfad 100644
--- a/pkgs/development/libraries/harfbuzz/default.nix
+++ b/pkgs/development/libraries/harfbuzz/default.nix
@@ -1,38 +1,49 @@
 { stdenv, fetchurl, pkgconfig, glib, freetype, cairo, libintlOrEmpty
-, icu, graphite2
+, icu, graphite2, harfbuzz # The icu variant uses and propagates the non-icu one.
 , withIcu ? false # recommended by upstream as default, but most don't needed and it's big
 , withGraphite2 ? true # it is small and major distros do include it
 }:
 
-# TODO: split non-icu and icu lib into different outputs?
-# (icu is a ~30 MB dependency, the rest is very small in comparison)
+let
+  version = "1.0.6";
+  inherit (stdenv.lib) optional optionals optionalString;
+in
 
-stdenv.mkDerivation rec {
-  name = "harfbuzz-1.0.6";
+stdenv.mkDerivation {
+  name = "harfbuzz${optionalString withIcu "-icu"}-${version}";
 
   src = fetchurl {
-    url = "http://www.freedesktop.org/software/harfbuzz/release/${name}.tar.bz2";
+    url = "http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-${version}.tar.bz2";
     sha256 = "09ivk5m4y09ar4zi9r6db7gp234cy05h0ach7w22g9kqvkxsf5pn";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
 
   configureFlags = [
     ( "--with-graphite2=" + (if withGraphite2 then "yes" else "no") ) # not auto-detected by default
     ( "--with-icu=" +       (if withIcu       then "yes" else "no") )
   ];
 
-  buildInputs = [ pkgconfig glib freetype cairo ] # recommended by upstream
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ glib freetype cairo ] # recommended by upstream
     ++ libintlOrEmpty;
   propagatedBuildInputs = []
-    ++ stdenv.lib.optional withGraphite2 graphite2
-    ++ stdenv.lib.optional withIcu icu
+    ++ optional withGraphite2 graphite2
+    ++ optionals withIcu [ icu harfbuzz ]
     ;
 
-  meta = {
+  # Slightly hacky; some pkgs expect them in a single directory.
+  postInstall = optionalString withIcu ''
+    rm "$out"/lib/libharfbuzz.* "$dev/lib/pkgconfig/harfbuzz.pc"
+    ln -s {'${harfbuzz.out}',"$out"}/lib/libharfbuzz.la
+    ln -s {'${harfbuzz.dev}',"$dev"}/lib/pkgconfig/harfbuzz.pc
+  '';
+
+  meta = with stdenv.lib; {
     description = "An OpenType text shaping engine";
     homepage = http://www.freedesktop.org/wiki/Software/HarfBuzz;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
-    platforms = stdenv.lib.platforms.linux ++ stdenv.lib.platforms.darwin;
+    maintainers = [ maintainers.eelco ];
+    platforms = with platforms; linux ++ darwin;
   };
 }
diff --git a/pkgs/development/libraries/hunspell/default.nix b/pkgs/development/libraries/hunspell/default.nix
index 98f6511f391..0d0ff38fb47 100644
--- a/pkgs/development/libraries/hunspell/default.nix
+++ b/pkgs/development/libraries/hunspell/default.nix
@@ -8,8 +8,10 @@ stdenv.mkDerivation rec {
     sha256 = "0v14ff9s37vkh45diaddndcrj0hmn67arh8xh8k79q9c1vgc1cm7";
   };
 
-  propagatedBuildInputs = [ ncurses readline ];
-  configureFlags = "--with-ui --with-readline";
+  outputs = [ "dev" "out" "bin" "man" ];
+
+  buildInputs = [ ncurses readline ];
+  configureFlags = [ "--with-ui" "--with-readline" ];
 
   meta = with stdenv.lib; {
     homepage = http://hunspell.sourceforge.net;
diff --git a/pkgs/development/libraries/icu/default.nix b/pkgs/development/libraries/icu/default.nix
index a2196d26524..58eb2e22781 100644
--- a/pkgs/development/libraries/icu/default.nix
+++ b/pkgs/development/libraries/icu/default.nix
@@ -13,6 +13,9 @@ stdenv.mkDerivation {
     sha256 = "05j86714qaj0lvhvyr2s1xncw6sk0h2dcghb3iiwykbkbh8fjr1s";
   };
 
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
+
   makeFlags = stdenv.lib.optionalString stdenv.isDarwin
     "CXXFLAGS=-headerpad_max_install_names";
 
@@ -37,6 +40,8 @@ stdenv.mkDerivation {
     sed -i 's/INSTALL_CMD=.*install/INSTALL_CMD=install/' $out/lib/icu/${version}/pkgdata.inc
   '';
 
+  postFixup = ''moveToOutput lib/icu "$dev" '';
+
   enableParallelBuilding = true;
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/libraries/jasper/default.nix b/pkgs/development/libraries/jasper/default.nix
index 2fa9cf7dbf9..17395561eda 100644
--- a/pkgs/development/libraries/jasper/default.nix
+++ b/pkgs/development/libraries/jasper/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, unzip, xorg, libjpeg }:
+{ stdenv, fetchurl, unzip, libjpeg, autoreconfHook }:
 
 stdenv.mkDerivation rec {
   name = "jasper-1.900.1";
@@ -17,11 +17,16 @@ stdenv.mkDerivation rec {
     ./jasper-CVE-2014-9029.diff
   ];
 
-  nativeBuildInputs = [unzip];
+  # newer reconf to recognize a multiout flag
+  nativeBuildInputs = [ unzip autoreconfHook ];
   propagatedBuildInputs = [ libjpeg ];
 
   configureFlags = "--enable-shared";
-  
+
+  outputs = [ "dev" "out" "man" "bin" ];
+
+  enableParallelBuilding = true;
+
   meta = {
     homepage = https://www.ece.uvic.ca/~frodo/jasper/;
     description = "JPEG2000 Library";
diff --git a/pkgs/development/libraries/json-c/default.nix b/pkgs/development/libraries/json-c/default.nix
index ad425f2a381..d5e0694e051 100644
--- a/pkgs/development/libraries/json-c/default.nix
+++ b/pkgs/development/libraries/json-c/default.nix
@@ -9,11 +9,13 @@ stdenv.mkDerivation rec {
 
   patches = [ ./unused-variable.patch ];
 
-  buildInputs = [ autoreconfHook ]; # won't configure without it, no idea why
+  outputs = [ "dev" "out" ];
+
+  nativeBuildInputs = [ autoreconfHook ]; # won't configure without it, no idea why
 
   # compatibility hack (for mypaint at least)
   postInstall = ''
-    ln -s json-c.pc "$out/lib/pkgconfig/json.pc"
+    ln -s json-c.pc "$dev/lib/pkgconfig/json.pc"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/libraries/lame/default.nix b/pkgs/development/libraries/lame/default.nix
index f4ea47e633f..b324494faff 100644
--- a/pkgs/development/libraries/lame/default.nix
+++ b/pkgs/development/libraries/lame/default.nix
@@ -32,6 +32,9 @@ stdenv.mkDerivation rec {
 
   patches = [ ./gcc-4.9.patch ];
 
+  outputs = [ "out" "lib" "doc" ]; # a small single header
+  outputMan = "out";
+
   nativeBuildInputs = [ ]
     ++ optional nasmSupport nasm;
 
diff --git a/pkgs/development/libraries/lcms/default.nix b/pkgs/development/libraries/lcms/default.nix
index c98a01f6f70..9365cf0b5f0 100644
--- a/pkgs/development/libraries/lcms/default.nix
+++ b/pkgs/development/libraries/lcms/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation {
     sha256 = "1abkf8iphwyfs3z305z3qczm3z1i9idc1lz4gvfg92jnkz5k5bl0";
   };
 
+  outputs = [ "dev" "out" "bin" "man" ];
+
   meta = {
     description = "Color management engine";
     homepage = http://www.littlecms.com/;
diff --git a/pkgs/development/libraries/lcms2/default.nix b/pkgs/development/libraries/lcms2/default.nix
index db82c943d7c..7dea029491a 100644
--- a/pkgs/development/libraries/lcms2/default.nix
+++ b/pkgs/development/libraries/lcms2/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl, libtiff, libjpeg, zlib}:
+{ stdenv, fetchurl, libtiff, libjpeg, zlib }:
 
 stdenv.mkDerivation rec {
   name = "lcms2-2.7";
@@ -8,13 +8,14 @@ stdenv.mkDerivation rec {
     sha256 = "0lvaglcjsvnyglgj3cb3pjc22nq8fml1vlx5dmmmw66ywx526925";
   };
 
+  outputs = [ "dev" "out" "bin" ];
+
   propagatedBuildInputs = [ libtiff libjpeg zlib ];
 
-  meta = {
+  meta = with stdenv.lib; {
     description = "Color management engine";
     homepage = http://www.littlecms.com/;
-    license = stdenv.lib.licenses.mit;
-    platforms = stdenv.lib.platforms.all;
-    maintainers = [ stdenv.lib.maintainers.urkud ];
+    license = licenses.mit;
+    platforms = platforms.all;
   };
 }
diff --git a/pkgs/development/libraries/libao/default.nix b/pkgs/development/libraries/libao/default.nix
index a8948e8ae8c..419ba8de9e4 100644
--- a/pkgs/development/libraries/libao/default.nix
+++ b/pkgs/development/libraries/libao/default.nix
@@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
     sha256 = "1bwwv1g9lchaq6qmhvj1pp3hnyqr64ydd4j38x94pmprs4d27b83";
   };
 
+  outputs = [ "dev" "out" "doc" ];
+
   buildInputs =
     [ pkgconfig ] ++
     lib.optional stdenv.isLinux (if usePulseAudio then libpulseaudio else alsaLib) ++
diff --git a/pkgs/development/libraries/libarchive/default.nix b/pkgs/development/libraries/libarchive/default.nix
index ff33043dbae..467dd87f43e 100644
--- a/pkgs/development/libraries/libarchive/default.nix
+++ b/pkgs/development/libraries/libarchive/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
 
   preFixup = ''
     sed -i $out/lib/libarchive.la \
-      -e 's|-lcrypto|-L${openssl}/lib -lcrypto|' \
+      -e 's|-lcrypto|-L${openssl.out}/lib -lcrypto|' \
       -e 's|-llzo2|-L${lzo}/lib -llzo2|'
   '';
 
diff --git a/pkgs/development/libraries/libassuan/default.nix b/pkgs/development/libraries/libassuan/default.nix
index a9c83594179..f2f31963d67 100644
--- a/pkgs/development/libraries/libassuan/default.nix
+++ b/pkgs/development/libraries/libassuan/default.nix
@@ -8,13 +8,16 @@ stdenv.mkDerivation rec {
     sha256 = "086bbcdnvs48qq5g4iac7dpk76j0q3jrp16mchdvyx0b720xq1mv";
   };
 
+  outputs = [ "dev" "out" "info" ];
+  outputBin = "dev"; # libassuan-config
+
   buildInputs = [ libgpgerror pth ];
 
   doCheck = true;
 
   # Make sure includes are fixed for callers who don't use libassuan-config
   postInstall = ''
-    sed -i 's,#include <gpg-error.h>,#include "${libgpgerror}/include/gpg-error.h",g' $out/include/assuan.h
+    sed -i 's,#include <gpg-error.h>,#include "${libgpgerror.dev}/include/gpg-error.h",g' $dev/include/assuan.h
   '';
 
   meta = {
diff --git a/pkgs/development/libraries/libav/default.nix b/pkgs/development/libraries/libav/default.nix
index 23b1402e3e7..78b1eef2ccf 100644
--- a/pkgs/development/libraries/libav/default.nix
+++ b/pkgs/development/libraries/libav/default.nix
@@ -7,10 +7,10 @@
 , x264Support   ? false,  x264      ? null
 , xvidSupport   ? true,   xvidcore  ? null
 , faacSupport   ? false,  faac      ? null
-, vaapiSupport  ? false,  libva     ? null # ToDo: it has huge closure
+, vaapiSupport  ? true,   libva     ? null
 , vdpauSupport  ? true,   libvdpau  ? null
 , freetypeSupport ? true, freetype  ? null # it's small and almost everywhere
-, SDL # only for avplay in $tools, adds nontrivial closure to it
+, SDL # only for avplay in $bin, adds nontrivial closure to it
 , enableGPL ? true # ToDo: some additional default stuff may need GPL
 , enableUnfree ? faacSupport
 }:
@@ -77,13 +77,11 @@ let
 
     enableParallelBuilding = true;
 
-    outputs = [ "out" "tools" ];
+    outputs = [ "dev" "out" "bin" ];
+    setOutputFlags = false;
 
-    # move avplay to get rid of the SDL dependency in the main output
-    postInstall = ''
-      mkdir -p "$tools/bin"
-      mv "$out/bin/avplay" "$tools/bin"
-    '';
+    # move tools away to lighten runtime deps and size
+    postInstall = ''moveToOutput bin "$bin" '';
 
     doInstallCheck = false; # fails randomly
     installCheckTarget = "check"; # tests need to be run *after* installation
diff --git a/pkgs/development/libraries/libcaca/default.nix b/pkgs/development/libraries/libcaca/default.nix
index c3059642382..7a905d9c82a 100644
--- a/pkgs/development/libraries/libcaca/default.nix
+++ b/pkgs/development/libraries/libcaca/default.nix
@@ -11,10 +11,17 @@ stdenv.mkDerivation rec {
     sha256 = "1x3j6yfyxl52adgnabycr0n38j9hx2j74la0hz0n8cnh9ry4d2qj";
   };
 
+  outputs = [ "dev" "bin" "out" "man" ];
+
   configureFlags = "--disable-x11 --disable-imlib2 --disable-doc";
 
   propagatedBuildInputs = [ ncurses zlib ];
 
+  postInstall = ''
+    mkdir -p $dev/bin
+    mv $bin/bin/caca-config $dev/bin/caca-config
+  '';
+
   meta = {
     homepage = http://libcaca.zoy.org/;
     description = "A graphics library that outputs text instead of pixels";
diff --git a/pkgs/development/libraries/libcanberra/default.nix b/pkgs/development/libraries/libcanberra/default.nix
index b441719d31c..8e3523a27e9 100644
--- a/pkgs/development/libraries/libcanberra/default.nix
+++ b/pkgs/development/libraries/libcanberra/default.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     for f in $out/lib/*.la; do
-      sed 's|-lltdl|-L${libtool}/lib -lltdl|' -i $f
+      sed 's|-lltdl|-L${libtool.lib}/lib -lltdl|' -i $f
     done
   '';
 
diff --git a/pkgs/development/libraries/libdbi-drivers/default.nix b/pkgs/development/libraries/libdbi-drivers/default.nix
index ccc0a199654..f64174778b2 100644
--- a/pkgs/development/libraries/libdbi-drivers/default.nix
+++ b/pkgs/development/libraries/libdbi-drivers/default.nix
@@ -31,11 +31,11 @@ stdenv.mkDerivation rec {
   ] ++ optionals (postgresql != null) [
     "--with-pgsql"
     "--with-pgsql_incdir=${postgresql}/include"
-    "--with-pgsql_libdir=${postgresql}/lib"
+    "--with-pgsql_libdir=${postgresql.lib}/lib"
   ] ++ optionals (sqlite != null) [
     "--with-sqlite3"
-    "--with-sqlite3-incdir=${sqlite}/include/sqlite"
-    "--with-sqlite3-libdir=${sqlite}/lib/sqlite"
+    "--with-sqlite3-incdir=${sqlite.dev}/include/sqlite"
+    "--with-sqlite3-libdir=${sqlite.out}/lib/sqlite"
   ];
 
   installFlags = [ "DESTDIR=\${out}" ];
diff --git a/pkgs/development/libraries/libdrm/default.nix b/pkgs/development/libraries/libdrm/default.nix
index 533512e9b68..4db67e73b8b 100644
--- a/pkgs/development/libraries/libdrm/default.nix
+++ b/pkgs/development/libraries/libdrm/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "71960ac8bde7d710992b1bc8879935e8300a870c36bd06f22412d0447e3d96c4";
   };
 
+  outputs = [ "dev" "out" ];
+
   nativeBuildInputs = [ pkgconfig ];
   buildInputs = [ libpthreadstubs libpciaccess ]
     ++ stdenv.lib.optional stdenv.isLinux udev;
diff --git a/pkgs/development/libraries/libedit/default.nix b/pkgs/development/libraries/libedit/default.nix
index dc8ecf7e95d..23b26e343db 100644
--- a/pkgs/development/libraries/libedit/default.nix
+++ b/pkgs/development/libraries/libedit/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     find $out/lib -type f | grep '\.\(la\|pc\)''$' | xargs sed -i \
-      -e 's,-lncurses[a-z]*,-L${ncurses}/lib -lncursesw,g'
+      -e 's,-lncurses[a-z]*,-L${ncurses.lib}/lib -lncursesw,g'
   '';
 
   configureFlags = [ "--enable-widec" ];
diff --git a/pkgs/development/libraries/libelf/default.nix b/pkgs/development/libraries/libelf/default.nix
index 048902f4fc4..623256bb6b7 100644
--- a/pkgs/development/libraries/libelf/default.nix
+++ b/pkgs/development/libraries/libelf/default.nix
@@ -1,6 +1,6 @@
 { fetchurl, stdenv, gettext, glibc }:
 
-stdenv.mkDerivation (rec {
+stdenv.mkDerivation rec {
   name = "libelf-0.8.13";
 
   src = fetchurl {
@@ -15,6 +15,11 @@ stdenv.mkDerivation (rec {
     nativeBuildInputs = [ glibc ];
   };
 
+  # Libelf's custom NLS macros fail to determine the catalog file extension on
+  # Darwin, so disable NLS for now.
+  # FIXME: Eventually make Gettext a build input on all platforms.
+  configureFlags = stdenv.lib.optional stdenv.isDarwin "--disable-nls";
+
   buildInputs = [ gettext ];
 
   meta = {
@@ -28,12 +33,3 @@ stdenv.mkDerivation (rec {
     maintainers = [ ];
   };
 }
-
-//
-
-# Libelf's custom NLS macros fail to determine the catalog file extension on
-# Darwin, so disable NLS for now.
-# FIXME: Eventually make Gettext a build input on all platforms.
-(if stdenv.isDarwin
- then { configureFlags = [ "--disable-nls" ]; }
- else { }))
diff --git a/pkgs/development/libraries/libevent/default.nix b/pkgs/development/libraries/libevent/default.nix
index bddda9f3ead..b0b537ddb17 100644
--- a/pkgs/development/libraries/libevent/default.nix
+++ b/pkgs/development/libraries/libevent/default.nix
@@ -8,14 +8,14 @@ stdenv.mkDerivation {
     url = "mirror://sourceforge/levent/libevent-${version}-stable.tar.gz";
     sha256 = "18qz9qfwrkakmazdlwxvjmw8p76g70n3faikwvdwznns1agw9hki";
   };
+  postPatch = "patchShebangs event_rpcgen.py";
+
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
 
   nativeBuildInputs = [ autoreconfHook ];
   buildInputs = [ openssl python ] ++ stdenv.lib.optional stdenv.isCygwin findutils;
 
-  patchPhase = ''
-    patchShebangs event_rpcgen.py
-  '';
-
   meta = with stdenv.lib; {
     description = "Event notification library";
 
diff --git a/pkgs/development/libraries/libextractor/default.nix b/pkgs/development/libraries/libextractor/default.nix
index 18387c904f8..2b6571290df 100644
--- a/pkgs/development/libraries/libextractor/default.nix
+++ b/pkgs/development/libraries/libextractor/default.nix
@@ -29,7 +29,7 @@ stdenv.mkDerivation rec {
 
   configureFlags = "--disable-ltdl-install "
     + "--with-ltdl-include=${libtool}/include "
-    + "--with-ltdl-lib=${libtool}/lib "
+    + "--with-ltdl-lib=${libtool.lib}/lib "
     + "--enable-xpdf";
 
   # Checks need to be run after "make install", otherwise plug-ins are not in
diff --git a/pkgs/development/libraries/libffi/default.nix b/pkgs/development/libraries/libffi/default.nix
index 824b909f1d9..816b9728cc9 100644
--- a/pkgs/development/libraries/libffi/default.nix
+++ b/pkgs/development/libraries/libffi/default.nix
@@ -8,7 +8,9 @@ stdenv.mkDerivation rec {
     sha256 = "0dya49bnhianl0r65m65xndz6ls2jn1xngyn72gd28ls3n7bnvnh";
   };
 
-  patches = if stdenv.isCygwin then [ ./3.2.1-cygwin.patch ] else null;
+  patches = stdenv.lib.optional stdenv.isCygwin ./3.2.1-cygwin.patch;
+
+  outputs = [ "dev" "out" "doc" ];
 
   configureFlags = [
     "--with-gcc-arch=generic" # no detection of -march= or -mtune=
@@ -17,12 +19,16 @@ stdenv.mkDerivation rec {
 
   dontStrip = stdenv ? cross; # Don't run the native `strip' when cross-compiling.
 
-  # Install headers in the right place.
-  postInstall = ''
-    ln -s${if (stdenv.isFreeBSD || stdenv.isOpenBSD || stdenv.isDarwin) then "" else "r"}v "$out/lib/"libffi*/include "$out/include"
+  # Install headers and libs in the right places.
+  postFixup = ''
+    mkdir -p "$dev/"
+    mv "$out/lib/${name}/include" "$dev/include"
+    rmdir "$out/lib/${name}"
+    substituteInPlace "$dev/lib/pkgconfig/libffi.pc" \
+      --replace 'includedir=''${libdir}/libffi-3.2.1' "includedir=$dev"
   '';
 
-  meta = {
+  meta = with stdenv.lib; {
     description = "A foreign function call interface library";
     longDescription = ''
       The libffi library provides a portable, high level programming
@@ -40,8 +46,8 @@ stdenv.mkDerivation rec {
     '';
     homepage = http://sourceware.org/libffi/;
     # See http://github.com/atgreen/libffi/blob/master/LICENSE .
-    license = stdenv.lib.licenses.free;
+    license = licenses.free;
     maintainers = [ ];
-    platforms = stdenv.lib.platforms.all;
+    platforms = platforms.all;
   };
 }
diff --git a/pkgs/development/libraries/libgcrypt/1.5.nix b/pkgs/development/libraries/libgcrypt/1.5.nix
index 990e73d0a63..d77946e5ec3 100644
--- a/pkgs/development/libraries/libgcrypt/1.5.nix
+++ b/pkgs/development/libraries/libgcrypt/1.5.nix
@@ -17,9 +17,9 @@ stdenv.mkDerivation rec {
   # Make sure libraries are correct for .pc and .la files
   # Also make sure includes are fixed for callers who don't use libgpgcrypt-config
   postInstall = ''
-    sed -i 's,#include <gpg-error.h>,#include "${libgpgerror}/include/gpg-error.h",g' $out/include/gcrypt.h
+    sed -i 's,#include <gpg-error.h>,#include "${libgpgerror.dev}/include/gpg-error.h",g' $out/include/gcrypt.h
   '' + stdenv.lib.optionalString enableCapabilities ''
-    sed -i 's,\(-lcap\),-L${libcap}/lib \1,' $out/lib/libgcrypt.la
+    sed -i 's,\(-lcap\),-L${libcap.out}/lib \1,' $out/lib/libgcrypt.la
   '';
 
   doCheck = true;
diff --git a/pkgs/development/libraries/libgcrypt/default.nix b/pkgs/development/libraries/libgcrypt/default.nix
index cc23d47e2bf..e03ed24e8fc 100644
--- a/pkgs/development/libraries/libgcrypt/default.nix
+++ b/pkgs/development/libraries/libgcrypt/default.nix
@@ -10,16 +10,19 @@ stdenv.mkDerivation rec {
     sha256 = "09k06gs27gxfha07sa9rpf4xh6mvphj9sky7n09ymx75w9zjrg69";
   };
 
+  outputs = [ "dev" "out" "info" ];
+  outputBin = "dev";
+
   buildInputs =
     [ libgpgerror ]
     ++ lib.optional enableCapabilities libcap;
 
   # Make sure libraries are correct for .pc and .la files
   # Also make sure includes are fixed for callers who don't use libgpgcrypt-config
-  postInstall = ''
-    sed -i 's,#include <gpg-error.h>,#include "${libgpgerror}/include/gpg-error.h",g' $out/include/gcrypt.h
+  postFixup = ''
+    sed -i 's,#include <gpg-error.h>,#include "${libgpgerror.dev}/include/gpg-error.h",g' "$dev/include/gcrypt.h"
   '' + stdenv.lib.optionalString enableCapabilities ''
-    sed -i 's,\(-lcap\),-L${libcap}/lib \1,' $out/lib/libgcrypt.la
+    sed -i 's,\(-lcap\),-L${libcap.out}/lib \1,' $out/lib/libgcrypt.la
   '';
 
   # TODO: figure out why this is even necessary and why the missing dylib only crashes
diff --git a/pkgs/development/libraries/libgpg-error/default.nix b/pkgs/development/libraries/libgpg-error/default.nix
index 19a6a8531be..3279bf3d9fb 100644
--- a/pkgs/development/libraries/libgpg-error/default.nix
+++ b/pkgs/development/libraries/libgpg-error/default.nix
@@ -10,6 +10,9 @@ stdenv.mkDerivation rec {
 
   postPatch = "sed '/BUILD_TIMESTAMP=/s/=.*/=1970-01-01T00:01+0000/' -i ./configure";
 
+  outputs = [ "dev" "out" "info" ];
+  outputBin = "dev"; # deps want just the lib, most likely
+
   # If architecture-dependent MO files aren't available, they're generated
   # during build, so we need gettext for cross-builds.
   crossAttrs.buildInputs = [ gettext ];
@@ -25,7 +28,7 @@ stdenv.mkDerivation rec {
 
   doCheck = true;
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = "https://www.gnupg.org/related_software/libgpg-error/index.html";
     description = "A small library that defines common error values for all GnuPG components";
 
@@ -36,9 +39,9 @@ stdenv.mkDerivation rec {
       Daemon and possibly more in the future.
     '';
 
-    license = stdenv.lib.licenses.lgpl2Plus;
-    platforms = stdenv.lib.platforms.all;
-    maintainers = with stdenv.lib.maintainers; [ fuuzetsu ];
+    license = licenses.lgpl2Plus;
+    platforms = platforms.all;
+    maintainers = [ maintainers.fuuzetsu ];
   };
 }
 
diff --git a/pkgs/development/libraries/libguestfs/default.nix b/pkgs/development/libraries/libguestfs/default.nix
index fb988db65d1..661a5c8b8ca 100644
--- a/pkgs/development/libraries/libguestfs/default.nix
+++ b/pkgs/development/libraries/libguestfs/default.nix
@@ -26,7 +26,7 @@ stdenv.mkDerivation rec {
 
   configureFlags = "--disable-appliance --disable-daemon";
   patches = [ ./libguestfs-syms.patch ];
-  NIX_CFLAGS_COMPILE="-I${libxml2}/include/libxml2/";
+  NIX_CFLAGS_COMPILE="-I${libxml2.dev}/include/libxml2/";
 
   preConfigure = ''
     AUTOPOINT=true LIBTOOLIZE=true autoreconf --verbose --install
diff --git a/pkgs/development/libraries/libidn/default.nix b/pkgs/development/libraries/libidn/default.nix
index c3c6c13c98f..b16dc835741 100644
--- a/pkgs/development/libraries/libidn/default.nix
+++ b/pkgs/development/libraries/libidn/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "1xf4hphhahcjm2xwx147lfpsavjwv9l4c2gf6hx71zxywbz5lpds";
   };
 
+  outputs = [ "dev" "out" "bin" "info" "docdev" ];
+
   doCheck = ! stdenv.isDarwin;
 
   buildInputs = stdenv.lib.optional stdenv.isDarwin libiconv;
diff --git a/pkgs/development/libraries/libjpeg-turbo/default.nix b/pkgs/development/libraries/libjpeg-turbo/default.nix
index 3660a652e79..79cf45a8005 100644
--- a/pkgs/development/libraries/libjpeg-turbo/default.nix
+++ b/pkgs/development/libraries/libjpeg-turbo/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, nasm }:
+{ stdenv, fetchurl, nasm, autoreconfHook }:
 
 stdenv.mkDerivation rec {
   name = "libjpeg-turbo-1.4.2";
@@ -8,7 +8,11 @@ stdenv.mkDerivation rec {
     sha256 = "0gi349hp1x7mb98s4mf66sb2xay2kjjxj9ihrriw0yiy0k9va6sj";
   };
 
-  buildInputs = [ nasm ];
+  outputs = [ "dev" "out" "doc" "bin" ];
+
+  buildInputs = [ autoreconfHook nasm ];
+
+  enableParallelBuilding = true;
 
   doCheck = true;
   checkTarget = "test";
diff --git a/pkgs/development/libraries/libjpeg/default.nix b/pkgs/development/libraries/libjpeg/default.nix
index bf2ebb27f37..025be200959 100644
--- a/pkgs/development/libraries/libjpeg/default.nix
+++ b/pkgs/development/libraries/libjpeg/default.nix
@@ -12,6 +12,8 @@ stdenv.mkDerivation {
 
   configureFlags = optional static "--enable-static --disable-shared";
 
+  outputs = [ "dev" "out" "man" "bin" ];
+
   meta = {
     homepage = http://www.ijg.org/;
     description = "A library that implements the JPEG image file format";
diff --git a/pkgs/development/libraries/libmbim/default.nix b/pkgs/development/libraries/libmbim/default.nix
index f910741c446..8baf4a77c36 100644
--- a/pkgs/development/libraries/libmbim/default.nix
+++ b/pkgs/development/libraries/libmbim/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "0abv0h9c3kbw4bq1b9270sg189jcjj3x3wa91bj836ynwg9m34wl";
   };
 
+  outputs = [ "dev" "out" "doc" ];
+
   preConfigure = ''
     patchShebangs .
   '';
diff --git a/pkgs/development/libraries/libmicrohttpd/default.nix b/pkgs/development/libraries/libmicrohttpd/default.nix
index 3ef4ba77c31..c6818794533 100644
--- a/pkgs/development/libraries/libmicrohttpd/default.nix
+++ b/pkgs/development/libraries/libmicrohttpd/default.nix
@@ -8,7 +8,7 @@ stdenv.mkDerivation rec {
     sha256 = "07j1p21rvbrrfpxngk8xswzkmjkh94bp1971xfjh1p0ja709qwzj";
   };
 
-  outputs = [ "out" "info" ];
+  outputs = [ "dev" "out" "docdev" ];
 
   buildInputs = [ libgcrypt ];
 
diff --git a/pkgs/development/libraries/libmng/default.nix b/pkgs/development/libraries/libmng/default.nix
index 234f56863c0..b97ee6a4ced 100644
--- a/pkgs/development/libraries/libmng/default.nix
+++ b/pkgs/development/libraries/libmng/default.nix
@@ -8,13 +8,16 @@ stdenv.mkDerivation rec {
     sha256 = "0l5wa3b9rr4zl49zbbjpapqyccqjwzkzw1ph3p4pk9p5h73h9317";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputMan= "docdev";
+
   propagatedBuildInputs = [ zlib libpng libjpeg lcms2 ];
 
-  meta = {
+  meta = with stdenv.lib; {
     description = "Reference library for reading, displaying, writing and examining Multiple-Image Network Graphics";
     homepage = http://www.libmng.com;
-    license = stdenv.lib.licenses.zlib;
-    maintainers = with stdenv.lib.maintainers; [ marcweber urkud ];
-    hydraPlatforms = stdenv.lib.platforms.linux;
+    license = licenses.zlib;
+    maintainers = with maintainers; [ marcweber urkud ];
+    hydraPlatforms = platforms.linux;
   };
 }
diff --git a/pkgs/development/libraries/libmpc/default.nix b/pkgs/development/libraries/libmpc/default.nix
index 1e8ea0ffa13..2a4600f5204 100644
--- a/pkgs/development/libraries/libmpc/default.nix
+++ b/pkgs/development/libraries/libmpc/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ gmp mpfr ];
 
-  CFLAGS = "-I${gmp}/include";
+  CFLAGS = "-I${gmp.dev}/include";
 
   doCheck = true;
 
diff --git a/pkgs/development/libraries/libmtp/default.nix b/pkgs/development/libraries/libmtp/default.nix
index 13b40501933..671169b9ab3 100644
--- a/pkgs/development/libraries/libmtp/default.nix
+++ b/pkgs/development/libraries/libmtp/default.nix
@@ -3,17 +3,19 @@
 stdenv.mkDerivation rec {
   name = "libmtp-1.1.9";
 
-  propagatedBuildInputs = [ libusb1 ];
-  buildInputs = [ pkgconfig ];
-
-  # tried to install files to /lib/udev, hopefully OK
-  configureFlags = [ "--with-udev=$$out/lib/udev" ];
-
   src = fetchurl {
     url = "mirror://sourceforge/libmtp/${name}.tar.gz";
     sha256 = "12dinqic0ljnhrwx3rc61jc7q24ybr0mckc2ya5kh1s1np0d7w93";
   };
 
+  outputs = [ "dev" "bin" "out" ];
+
+  propagatedBuildInputs = [ libusb1 ];
+  buildInputs = [ pkgconfig ];
+
+  # tried to install files to /lib/udev, hopefully OK
+  configureFlags = [ "--with-udev=$$bin/lib/udev" ];
+
   meta = {
     homepage = http://libmtp.sourceforge.net;
     description = "An implementation of Microsoft's Media Transfer Protocol";
diff --git a/pkgs/development/libraries/libogg/default.nix b/pkgs/development/libraries/libogg/default.nix
index 407e218065b..1aa4b8ad045 100644
--- a/pkgs/development/libraries/libogg/default.nix
+++ b/pkgs/development/libraries/libogg/default.nix
@@ -8,7 +8,7 @@ stdenv.mkDerivation rec {
     sha256 = "16z74q422jmprhyvy7c9x909li8cqzmvzyr8cgbm52xcsp6pqs1z";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "dev" "out" "doc" ];
 
   meta = with stdenv.lib; {
     homepage = http://xiph.org/ogg/;
diff --git a/pkgs/development/libraries/liboil/default.nix b/pkgs/development/libraries/liboil/default.nix
index 43b1f347093..754e308ac15 100644
--- a/pkgs/development/libraries/liboil/default.nix
+++ b/pkgs/development/libraries/liboil/default.nix
@@ -8,10 +8,13 @@ stdenv.mkDerivation rec {
     sha256 = "0sgwic99hxlb1av8cm0albzh8myb7r3lpcwxfm606l0bkc3h4pqh";
   };
 
-  buildInputs = [ pkgconfig ];
-
   patches = [ ./x86_64-cpuid.patch ];
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputBin = "dev"; # oil-bugreport
+
+  nativeBuildInputs = [ pkgconfig ];
+
   # fix "argb_paint_i386.c:53:Incorrect register `%rax' used with `l' suffix"
   # errors
   configureFlags = stdenv.lib.optional stdenv.isDarwin "--build=x86_64";
diff --git a/pkgs/development/libraries/libopensc-dnie/default.nix b/pkgs/development/libraries/libopensc-dnie/default.nix
index f2855dd2a92..b610fe23ede 100644
--- a/pkgs/development/libraries/libopensc-dnie/default.nix
+++ b/pkgs/development/libraries/libopensc-dnie/default.nix
@@ -22,7 +22,7 @@ stdenv.mkDerivation rec {
     ar x opensc-dnie*
     tar xf data.tar.gz
 
-    RPATH=${glib}/lib:${opensc}/lib:${openssl}/lib:${openct}/lib:${libtool}/lib:${pcsclite}/lib:${stdenv.cc.libc}/lib:${zlib}/lib
+    RPATH=${stdenv.lib.makeLibraryPath [ glib opensc openssl openct libtool pcsclite stdenv.cc.libc zlib ]}
 
     for a in "usr/lib/"*.so*; do
         if ! test -L $a; then
diff --git a/pkgs/development/libraries/libopus/default.nix b/pkgs/development/libraries/libopus/default.nix
index 460aaa2b0ec..b8951e66c8b 100644
--- a/pkgs/development/libraries/libopus/default.nix
+++ b/pkgs/development/libraries/libopus/default.nix
@@ -11,6 +11,8 @@ stdenv.mkDerivation rec {
     sha256 = "158xprn2086arvdib3vbbygz7z6jqkw2nci7nlywzzwallap0wmr";
   };
 
+  outputs = [ "dev" "out" ];
+
   configureFlags = stdenv.lib.optional fixedPoint "--enable-fixed-point"
                 ++ stdenv.lib.optional withCustomModes "--enable-custom-modes";
 
diff --git a/pkgs/development/libraries/libpng/12.nix b/pkgs/development/libraries/libpng/12.nix
index d2fa6b184d6..6e7481805e7 100644
--- a/pkgs/development/libraries/libpng/12.nix
+++ b/pkgs/development/libraries/libpng/12.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation rec {
     sha256 = "0wnjy7gqn0f24qrlggs7kl0ij59by413j1xmqp12n3vqh9j531fg";
   };
 
+  outputs = [ "dev" "out" "man" ];
+
   propagatedBuildInputs = [ zlib ];
 
   passthru = { inherit zlib; };
@@ -21,6 +23,8 @@ stdenv.mkDerivation rec {
 
   configureFlags = "--enable-static";
 
+  postInstall = ''mv "$out/bin" "$dev/bin"'';
+
   meta = with stdenv.lib; {
     description = "The official reference implementation for the PNG file format";
     homepage = http://www.libpng.org/pub/png/libpng.html;
diff --git a/pkgs/development/libraries/libpng/default.nix b/pkgs/development/libraries/libpng/default.nix
index a2454aa02f0..00abbbbdca4 100644
--- a/pkgs/development/libraries/libpng/default.nix
+++ b/pkgs/development/libraries/libpng/default.nix
@@ -18,13 +18,18 @@ in stdenv.mkDerivation rec {
     url = "mirror://sourceforge/libpng/libpng-${version}.tar.xz";
     inherit sha256;
   };
-
   postPatch = whenPatched "gunzip < ${patch_src} | patch -Np1";
 
+  outputs = [ "dev" "out" "man" ];
+
   propagatedBuildInputs = [ zlib ];
 
+  preConfigure = "export bin=$dev";
+
   doCheck = true;
 
+  postInstall = ''mv "$out/bin" "$dev/bin"'';
+
   passthru = { inherit zlib; };
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/libraries/libproxy/default.nix b/pkgs/development/libraries/libproxy/default.nix
index 7085236feb5..0f080850639 100644
--- a/pkgs/development/libraries/libproxy/default.nix
+++ b/pkgs/development/libraries/libproxy/default.nix
@@ -7,6 +7,8 @@ stdenv.mkDerivation rec {
     sha256 = "0jw6454gxjykmbnbh544axi8hzz9gmm4jz1y5gw1hdqnakg36gyw";
   };
 
+  outputs = [ "dev" "out" ]; # to deal with propagatedBuildInputs
+
   nativeBuildInputs = [ pkgconfig cmake ];
   propagatedBuildInputs = [ zlib ]
     # now some optional deps, but many more are possible
diff --git a/pkgs/development/libraries/libqmi/default.nix b/pkgs/development/libraries/libqmi/default.nix
index 9699d67d7b8..82768cd350d 100644
--- a/pkgs/development/libraries/libqmi/default.nix
+++ b/pkgs/development/libraries/libqmi/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "101ppan2q1h4pyp2zbn9b8sdwy2c7fk9rp91yykxz3afrvzbymq8";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+
   preBuild = ''
     patchShebangs .
   '';
diff --git a/pkgs/development/libraries/libraw/default.nix b/pkgs/development/libraries/libraw/default.nix
index 3d564fc00f8..031886d3451 100644
--- a/pkgs/development/libraries/libraw/default.nix
+++ b/pkgs/development/libraries/libraw/default.nix
@@ -9,7 +9,7 @@ stdenv.mkDerivation rec {
     sha256 = "043kckxjqanw8dl3m9f6kvsf0l20ywxmgxd1xb0slj6m8l4w4hz6";
   };
 
-  buildInputs = [ lcms2 jasper ] ;
+  buildInputs = [ lcms2 jasper ];
 
   nativeBuildInputs = [ pkgconfig ];
 
diff --git a/pkgs/development/libraries/librsvg/default.nix b/pkgs/development/libraries/librsvg/default.nix
index ea1910733e7..0768a21bf54 100644
--- a/pkgs/development/libraries/librsvg/default.nix
+++ b/pkgs/development/libraries/librsvg/default.nix
@@ -26,7 +26,7 @@ stdenv.mkDerivation rec {
     ++ stdenv.lib.optional stdenv.isDarwin "--disable-Bsymbolic";
 
   NIX_CFLAGS_COMPILE
-    = stdenv.lib.optionalString stdenv.isDarwin "-I${cairo}/include/cairo";
+    = stdenv.lib.optionalString stdenv.isDarwin "-I${cairo.dev}/include/cairo";
 
   # It wants to add loaders and update the loaders.cache in gdk-pixbuf
   # Patching the Makefiles to it creates rsvg specific loaders and the
@@ -47,7 +47,7 @@ stdenv.mkDerivation rec {
   # Merge gdkpixbuf and librsvg loaders
   postInstall = ''
     mv $GDK_PIXBUF/loaders.cache $GDK_PIXBUF/loaders.cache.tmp
-    cat ${gdk_pixbuf}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache $GDK_PIXBUF/loaders.cache.tmp > $GDK_PIXBUF/loaders.cache
+    cat ${gdk_pixbuf.out}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache $GDK_PIXBUF/loaders.cache.tmp > $GDK_PIXBUF/loaders.cache
     rm $GDK_PIXBUF/loaders.cache.tmp
   '';
 }
diff --git a/pkgs/development/libraries/libsamplerate/default.nix b/pkgs/development/libraries/libsamplerate/default.nix
index 481d82c0c9a..f0ff549c716 100644
--- a/pkgs/development/libraries/libsamplerate/default.nix
+++ b/pkgs/development/libraries/libsamplerate/default.nix
@@ -1,6 +1,4 @@
-{ stdenv, fetchurl, pkgconfig
-, fftw, libsndfile
-}:
+{ stdenv, fetchurl, pkgconfig, libsndfile }:
 
 stdenv.mkDerivation rec {
   name = "libsamplerate-0.1.8";
@@ -11,12 +9,14 @@ stdenv.mkDerivation rec {
   };
 
   nativeBuildInputs = [ pkgconfig ];
-  buildInputs = [ fftw libsndfile ];
+  buildInputs = [ libsndfile ];
 
   # maybe interesting configure flags:
   #--disable-fftw          disable usage of FFTW
   #--disable-cpu-clip      disable tricky cpu specific clipper
 
+  outputs = [ "dev" "bin" "out" ];
+
   postConfigure = stdenv.lib.optionalString stdenv.isDarwin
     ''
       # need headers from the Carbon.framework in /System/Library/Frameworks to
diff --git a/pkgs/development/libraries/libsndfile/default.nix b/pkgs/development/libraries/libsndfile/default.nix
index 48a2999e7af..5be8730ba01 100644
--- a/pkgs/development/libraries/libsndfile/default.nix
+++ b/pkgs/development/libraries/libsndfile/default.nix
@@ -13,6 +13,10 @@ stdenv.mkDerivation rec {
   buildInputs = [ pkgconfig flac libogg libvorbis ]
     ++ stdenv.lib.optional stdenv.isDarwin Carbon;
 
+  enableParallelBuilding = true;
+
+  outputs = [ "dev" "out" "bin" "doc" ];
+
   # need headers from the Carbon.framework in /System/Library/Frameworks to
   # compile this on darwin -- not sure how to handle
   preConfigure = stdenv.lib.optionalString stdenv.isDarwin
diff --git a/pkgs/development/libraries/libsodium/default.nix b/pkgs/development/libraries/libsodium/default.nix
index c6f10a5531c..42450275ad5 100644
--- a/pkgs/development/libraries/libsodium/default.nix
+++ b/pkgs/development/libraries/libsodium/default.nix
@@ -8,7 +8,9 @@ stdenv.mkDerivation rec {
     sha256 = "0ngvcjwg6m9nivzi208yvz8yvmk6kxnvyr25w907kaicgpm063cl";
   };
 
-  NIX_LDFLAGS = stdenv.lib.optionalString stdenv.cc.isGNU "-lssp";
+  outputs = [ "dev" "out" ];
+
+  enableParallelBuilding = true;
 
   doCheck = true;
 
diff --git a/pkgs/development/libraries/libsoup/default.nix b/pkgs/development/libraries/libsoup/default.nix
index f71cc77321a..b9a6c8341ef 100644
--- a/pkgs/development/libraries/libsoup/default.nix
+++ b/pkgs/development/libraries/libsoup/default.nix
@@ -18,11 +18,13 @@ stdenv.mkDerivation {
     patchShebangs libsoup/
   '';
 
+  outputs = [ "dev" "out" ];
+
   buildInputs = libintlOrEmpty ++ [ intltool python sqlite ];
   nativeBuildInputs = [ pkgconfig ];
   propagatedBuildInputs = [ glib libxml2 gobjectIntrospection ]
     ++ stdenv.lib.optionals gnomeSupport [ libgnome_keyring ];
-  passthru.propagatedUserEnvPackages = [ glib_networking ];
+  passthru.propagatedUserEnvPackages = [ glib_networking.out ];
 
   # glib_networking is a runtime dependency, not a compile-time dependency
   configureFlags = "--disable-tls-check" + stdenv.lib.optionalString (!gnomeSupport) " --without-gnome";
diff --git a/pkgs/development/libraries/libssh/default.nix b/pkgs/development/libraries/libssh/default.nix
index 3f6eeac892b..e33d0c89b7d 100644
--- a/pkgs/development/libraries/libssh/default.nix
+++ b/pkgs/development/libraries/libssh/default.nix
@@ -13,6 +13,8 @@ stdenv.mkDerivation rec {
     sed -i 's,nacl/,sodium/,g' ./include/libssh/curve25519.h src/curve25519.c
   '';
 
+  outputs = [ "dev" "out" ];
+
   buildInputs = [ zlib openssl libsodium ];
 
   nativeBuildInputs = [ cmake pkgconfig ];
diff --git a/pkgs/development/libraries/libssh2/default.nix b/pkgs/development/libraries/libssh2/default.nix
index 5e12ea734c1..26a4e1d504a 100644
--- a/pkgs/development/libraries/libssh2/default.nix
+++ b/pkgs/development/libraries/libssh2/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "05c2is69c50lyikkh29nk6zhghjk4i7hjx0zqfhq47aald1jj82s";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+
   buildInputs = [ openssl zlib ];
 
   crossAttrs = {
diff --git a/pkgs/development/libraries/libtasn1/default.nix b/pkgs/development/libraries/libtasn1/default.nix
index 1ae26c48fc2..5ac8cc94d04 100644
--- a/pkgs/development/libraries/libtasn1/default.nix
+++ b/pkgs/development/libraries/libtasn1/default.nix
@@ -8,6 +8,9 @@ stdenv.mkDerivation rec {
     sha256 = "1j8iixynchziw1y39lnibyl5h81m4p78w3i4f28q2vgwjgf801x4";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputBin = "dev";
+
   buildInputs = [ perl texinfo ];
 
   doCheck = true;
diff --git a/pkgs/development/libraries/libtheora/default.nix b/pkgs/development/libraries/libtheora/default.nix
index da590adae06..129dface2d9 100644
--- a/pkgs/development/libraries/libtheora/default.nix
+++ b/pkgs/development/libraries/libtheora/default.nix
@@ -8,6 +8,9 @@ stdenv.mkDerivation rec {
     sha256 = "0swiaj8987n995rc7hw0asvpwhhzpjiws8kr3s6r44bqqib2k5a0";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputDoc = "docdev";
+
   nativeBuildInputs = [ pkgconfig ];
   propagatedBuildInputs = [ libogg libvorbis ];
 
diff --git a/pkgs/development/libraries/libtiff/default.nix b/pkgs/development/libraries/libtiff/default.nix
index 2c559d221ab..a506279c2a4 100644
--- a/pkgs/development/libraries/libtiff/default.nix
+++ b/pkgs/development/libraries/libtiff/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
     sha256 = "136nf1rj9dp5jgv1p7z4dk0xy3wki1w0vfjbk82f645m0w4samsd";
   };
 
-  outputs = [ "out" "doc" "man" ];
+  outputs = [ "dev" "out" "bin" "doc" ];
 
   nativeBuildInputs = [ pkgconfig ];
 
diff --git a/pkgs/development/libraries/libtoxcore/new-api/default.nix b/pkgs/development/libraries/libtoxcore/new-api/default.nix
index 42f81cf6a9d..0433d146680 100644
--- a/pkgs/development/libraries/libtoxcore/new-api/default.nix
+++ b/pkgs/development/libraries/libtoxcore/new-api/default.nix
@@ -27,8 +27,8 @@ stdenv.mkDerivation rec {
   '';
 
   configureFlags = [
-    "--with-libsodium-headers=${libsodium}/include"
-    "--with-libsodium-libs=${libsodium}/lib"
+    "--with-libsodium-headers=${libsodium.dev}/include"
+    "--with-libsodium-libs=${libsodium.out}/lib"
     "--enable-ntox"
     "--enable-daemon"
   ];
diff --git a/pkgs/development/libraries/libtoxcore/old-api/default.nix b/pkgs/development/libraries/libtoxcore/old-api/default.nix
index 3ff2e1ad285..6bc69792b53 100644
--- a/pkgs/development/libraries/libtoxcore/old-api/default.nix
+++ b/pkgs/development/libraries/libtoxcore/old-api/default.nix
@@ -31,8 +31,8 @@ stdenv.mkDerivation rec {
   '';
 
   configureFlags = [
-    "--with-libsodium-headers=${libsodium}/include"
-    "--with-libsodium-libs=${libsodium}/lib"
+    "--with-libsodium-headers=${libsodium.dev}/include"
+    "--with-libsodium-libs=${libsodium.out}/lib"
     "--enable-ntox"
     "--enable-daemon"
   ];
diff --git a/pkgs/development/libraries/libunwind/default.nix b/pkgs/development/libraries/libunwind/default.nix
index 3fc8b508559..da09e2fcbe2 100644
--- a/pkgs/development/libraries/libunwind/default.nix
+++ b/pkgs/development/libraries/libunwind/default.nix
@@ -20,6 +20,8 @@ stdenv.mkDerivation rec {
     sed -i -e '/LIBLZMA/s:-lzma:-llzma:' configure
   '';
 
+  outputs = [ "dev" "out" ];
+
   propagatedBuildInputs = [ xz ];
 
   NIX_CFLAGS_COMPILE = if stdenv.system == "x86_64-linux" then "-fPIC" else "";
@@ -30,7 +32,7 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     find $out -name \*.la | while read file; do
-      sed -i 's,-llzma,${xz}/lib/liblzma.la,' $file
+      sed -i 's,-llzma,${xz.out}/lib/liblzma.la,' $file
     done
   '';
 
diff --git a/pkgs/development/libraries/libusb/default.nix b/pkgs/development/libraries/libusb/default.nix
index 7aec64d596f..b1872779b70 100644
--- a/pkgs/development/libraries/libusb/default.nix
+++ b/pkgs/development/libraries/libusb/default.nix
@@ -3,6 +3,9 @@
 stdenv.mkDerivation {
   name = "libusb-compat-0.1.5";
 
+  outputs = [ "dev" "out" ]; # get rid of propagating systemd closure
+  outputBin = "dev";
+
   nativeBuildInputs = [ pkgconfig ];
   propagatedBuildInputs = [ libusb1 ];
 
diff --git a/pkgs/development/libraries/libusb1/default.nix b/pkgs/development/libraries/libusb1/default.nix
index 75d6bdb4cc6..fe920bba411 100644
--- a/pkgs/development/libraries/libusb1/default.nix
+++ b/pkgs/development/libraries/libusb1/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, pkgconfig, udev ? null, libobjc, IOKit }:
+{ stdenv, fetchurl, pkgconfig, libudev ? null, libobjc, IOKit }:
 
 stdenv.mkDerivation rec {
   name = "libusb-1.0.19";
@@ -8,15 +8,17 @@ stdenv.mkDerivation rec {
     sha256 = "0h38p9rxfpg9vkrbyb120i1diq57qcln82h5fr7hvy82c20jql3c";
   };
 
+  outputs = [ "dev" "out" ]; # get rid of propagating systemd closure
+
   buildInputs = [ pkgconfig ];
   propagatedBuildInputs =
-    stdenv.lib.optional stdenv.isLinux udev ++
+    stdenv.lib.optional stdenv.isLinux libudev ++
     stdenv.lib.optionals stdenv.isDarwin [ libobjc IOKit ];
 
   NIX_LDFLAGS = stdenv.lib.optionalString stdenv.isLinux "-lgcc_s";
 
   preFixup = stdenv.lib.optionalString stdenv.isLinux ''
-    sed 's,-ludev,-L${udev}/lib -ludev,' -i $out/lib/libusb-1.0.la
+    sed 's,-ludev,-L${libudev.out}/lib -ludev,' -i $out/lib/libusb-1.0.la
   '';
 
   meta = {
diff --git a/pkgs/development/libraries/libva/default.nix b/pkgs/development/libraries/libva/default.nix
index 12de07ced32..ff44b157eaf 100644
--- a/pkgs/development/libraries/libva/default.nix
+++ b/pkgs/development/libraries/libva/default.nix
@@ -1,5 +1,6 @@
 { stdenv, fetchurl, libX11, pkgconfig, libXext, libdrm, libXfixes, wayland, libffi
-, mesa ? null
+, mesa_noglu
+, minimal ? true, libva
 }:
 
 stdenv.mkDerivation rec {
@@ -10,9 +11,15 @@ stdenv.mkDerivation rec {
     sha256 = "0bjfb5s8dk3lql843l91ffxzlq47isqks5sj19cxh7j3nhzw58kz";
   };
 
-  buildInputs = [ libX11 libXext pkgconfig libdrm libXfixes wayland libffi mesa ];
+  outputs = [ "dev" "out" "bin" ];
 
-  configureFlags = stdenv.lib.optional (mesa != null) "--enable-glx";
+  nativeBuildInputs = [ pkgconfig ];
+
+  buildInputs = [ libdrm ]
+    ++ stdenv.lib.optionals (!minimal) [ libva libX11 libXext libXfixes wayland libffi mesa_noglu ];
+  # TODO: share libs between minimal and !minimal - perhaps just symlink them
+
+  #configureFlags = stdenv.lib.optional (mesa != null) "--enable-glx";
 
   meta = with stdenv.lib; {
     homepage = http://www.freedesktop.org/wiki/Software/vaapi;
diff --git a/pkgs/development/libraries/libvdpau/default.nix b/pkgs/development/libraries/libvdpau/default.nix
index 6c5d5a91ad8..04d06a149fc 100644
--- a/pkgs/development/libraries/libvdpau/default.nix
+++ b/pkgs/development/libraries/libvdpau/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "857a01932609225b9a3a5bf222b85e39b55c08787d0ad427dbd9ec033d58d736";
   };
 
+  outputs = [ "dev" "out" ];
+
   buildInputs = with xorg; [ pkgconfig dri2proto libXext ];
 
   propagatedBuildInputs = [ xorg.libX11 ];
diff --git a/pkgs/development/libraries/libvirt/default.nix b/pkgs/development/libraries/libvirt/default.nix
index e946f27791b..a8295380829 100644
--- a/pkgs/development/libraries/libvirt/default.nix
+++ b/pkgs/development/libraries/libvirt/default.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchurl, pkgconfig, libxml2, gnutls, devicemapper, perl, python
-, iproute, iptables, readline, lvm2, utillinux, udev, libpciaccess, gettext
+, iproute, iptables, readline, lvm2, utillinux, systemd, libpciaccess, gettext
 , libtasn1, ebtables, libgcrypt, yajl, makeWrapper, pmutils, libcap_ng
 , dnsmasq, libnl, libpcap, libxslt, xhtml1
 , pythonPackages, perlPackages
@@ -19,12 +19,12 @@ stdenv.mkDerivation rec {
 
   buildInputs = [
     pkgconfig libxml2 gnutls devicemapper perl python readline lvm2
-    utillinux udev libpciaccess gettext libtasn1 libgcrypt yajl makeWrapper
+    utillinux systemd.udev.lib libpciaccess gettext libtasn1 libgcrypt yajl makeWrapper
     libcap_ng libnl libxslt xhtml1 perlPackages.XMLXPath
   ];
 
   preConfigure = ''
-    PATH=${iproute}/sbin:${iptables}/sbin:${ebtables}/sbin:${lvm2}/sbin:${udev}/sbin:${dnsmasq}/bin:$PATH
+    PATH=${iproute}/sbin:${iptables}/sbin:${ebtables}/sbin:${lvm2}/sbin:${systemd.udev.bin}/sbin:${dnsmasq}/bin:$PATH
     patchShebangs . # fixes /usr/bin/python references
   '';
 
diff --git a/pkgs/development/libraries/libvorbis/default.nix b/pkgs/development/libraries/libvorbis/default.nix
index 68f1fe72085..0022799c88f 100644
--- a/pkgs/development/libraries/libvorbis/default.nix
+++ b/pkgs/development/libraries/libvorbis/default.nix
@@ -8,7 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "1lg1n3a6r41492r7in0fpvzc7909mc5ir9z0gd3qh2pz4yalmyal";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "dev" "out" "doc" ];
+
 
   nativeBuildInputs = [ pkgconfig ];
   propagatedBuildInputs = [ libogg ];
diff --git a/pkgs/development/libraries/libvpx/default.nix b/pkgs/development/libraries/libvpx/default.nix
index 6a475667078..5c593dd1f75 100644
--- a/pkgs/development/libraries/libvpx/default.nix
+++ b/pkgs/development/libraries/libvpx/default.nix
@@ -72,6 +72,9 @@ stdenv.mkDerivation rec {
 
   patchPhase = ''patchShebangs .'';
 
+  outputs = [ "dev" "out" "bin" ];
+  setOutputFlags = false;
+
   configureFlags = [
     (enableFeature (vp8EncoderSupport || vp8DecoderSupport) "vp8")
     (enableFeature vp8EncoderSupport "vp8-encoder")
@@ -146,6 +149,8 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
+  postInstall = ''moveToOutput bin "$bin" '';
+
   crossAttrs = let
     isCygwin = stdenv.cross.libc == "msvcrt";
     isDarwin = stdenv.cross.libc == "libSystem";
diff --git a/pkgs/development/libraries/libvpx/git.nix b/pkgs/development/libraries/libvpx/git.nix
index 31b1c197e9f..064fb807a21 100644
--- a/pkgs/development/libraries/libvpx/git.nix
+++ b/pkgs/development/libraries/libvpx/git.nix
@@ -73,6 +73,9 @@ stdenv.mkDerivation rec {
 
   patchPhase = ''patchShebangs .'';
 
+  outputs = [ "dev" "out" "bin" ];
+  setOutputFlags = false;
+
   configureFlags = [
     (enableFeature (vp8EncoderSupport || vp8DecoderSupport) "vp8")
     (enableFeature vp8EncoderSupport "vp8-encoder")
@@ -147,6 +150,8 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
+  postInstall = ''moveToOutput bin "$bin" '';
+
   crossAttrs = let
     isCygwin = stdenv.cross.libc == "msvcrt";
     isDarwin = stdenv.cross.libc == "libSystem";
diff --git a/pkgs/development/libraries/libwnck/3.x.nix b/pkgs/development/libraries/libwnck/3.x.nix
index 6c6c0812c43..a763af96667 100644
--- a/pkgs/development/libraries/libwnck/3.x.nix
+++ b/pkgs/development/libraries/libwnck/3.x.nix
@@ -8,6 +8,9 @@ stdenv.mkDerivation {
     sha256 = "d48ac9c7f50c0d563097f63d07bcc83744c7d92a1b4ef65e5faeab32b5ccb723";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputBin = "dev";
+
   patches = [ ./install_introspection_to_prefix.patch ];
 
   buildInputs = [ pkgconfig intltool ];
diff --git a/pkgs/development/libraries/libwnck/default.nix b/pkgs/development/libraries/libwnck/default.nix
index 6a4479bdda3..bb525812049 100644
--- a/pkgs/development/libraries/libwnck/default.nix
+++ b/pkgs/development/libraries/libwnck/default.nix
@@ -12,6 +12,9 @@ stdenv.mkDerivation rec {
     sha256 = "17isfjvrzgj5znld2a7zsk9vd39q9wnsysnw5jr8iz410z935xw3";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputBin = "dev";
+
   buildInputs = [ pkgconfig gtk intltool xorg.libX11 xorg.libXres ];
   # ?another optional: startup-notification
 
diff --git a/pkgs/development/libraries/libxkbcommon/default.nix b/pkgs/development/libraries/libxkbcommon/default.nix
index 5543b05ce9d..d11e2ed9439 100644
--- a/pkgs/development/libraries/libxkbcommon/default.nix
+++ b/pkgs/development/libraries/libxkbcommon/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha1 = "z9dvxrkcyb4b7f2zybgkrqb9zcxrj9vi";
   };
 
+  outputs = [ "dev" "out" ];
+
   buildInputs = [ pkgconfig yacc flex xkeyboard_config libxcb ];
 
   configureFlags = ''
diff --git a/pkgs/development/libraries/libxklavier/default.nix b/pkgs/development/libraries/libxklavier/default.nix
index d69276a070b..f074b31bb68 100644
--- a/pkgs/development/libraries/libxklavier/default.nix
+++ b/pkgs/development/libraries/libxklavier/default.nix
@@ -12,6 +12,8 @@ stdenv.mkDerivation rec {
     sha256 = "016lpdv35z0qsw1cprdc2k5qzkdi5waj6qmr0a2q6ljn9g2kpv7b";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+
   # TODO: enable xmodmap support, needs xmodmap DB
   propagatedBuildInputs = with xorg; [ libX11 libXi xkeyboard_config libxml2 libICE glib libxkbfile isocodes ];
 
diff --git a/pkgs/development/libraries/libxml2/default.nix b/pkgs/development/libraries/libxml2/default.nix
index 2fdc198aa11..2b2b1d81a16 100644
--- a/pkgs/development/libraries/libxml2/default.nix
+++ b/pkgs/development/libraries/libxml2/default.nix
@@ -1,14 +1,11 @@
-{ stdenv, fetchurl, zlib, xz, python ? null, pythonSupport ? true, findXMLCatalogs }:
-
-assert pythonSupport -> python != null;
-
-#TODO: share most stuff between python and non-python builds, perhaps via multiple-output
+{ stdenv, fetchurl, zlib, xz, python, findXMLCatalogs }:
 
 let
   version = "2.9.2";
+  inherit (stdenv.lib) optional;
 in
 
-stdenv.mkDerivation (rec {
+stdenv.mkDerivation rec {
   name = "libxml2-${version}";
 
   src = fetchurl {
@@ -16,20 +13,32 @@ stdenv.mkDerivation (rec {
     sha256 = "1g6mf03xcabmk5ing1lwqmasr803616gb2xhn7pll10x2l5w6y2i";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "dev" "out" "bin" "doc" "py" ];
+  propagatedBuildOutputs = "out bin py";
 
-  buildInputs = stdenv.lib.optional pythonSupport python
+  buildInputs = [ python ]
     # Libxml2 has an optional dependency on liblzma.  However, on impure
     # platforms, it may end up using that from /usr/lib, and thus lack a
     # RUNPATH for that, leading to undefined references for its users.
-    ++ stdenv.lib.optional stdenv.isFreeBSD xz;
+    ++ optional stdenv.isFreeBSD xz;
 
   propagatedBuildInputs = [ zlib findXMLCatalogs ];
 
-  passthru = { inherit pythonSupport version; };
+  configureFlags = "--with-python=${python}";
 
   enableParallelBuilding = true;
 
+  preInstall = ''substituteInPlace python/libxml2mod.la --replace "${python}" "$py"'';
+  installFlags = ''pythondir="$(py)/lib/${python.libPrefix}/site-packages"'';
+
+  postFixup = ''
+    moveToOutput bin/xml2-config "$dev"
+    moveToOutput lib/xml2Conf.sh "$dev"
+    moveToOutput share/man/man1 "$bin"
+  '';
+
+  passthru = { inherit version; pythonSupport = true; };
+
   meta = {
     homepage = http://xmlsoft.org/;
     description = "An XML parsing library for C";
@@ -37,15 +46,5 @@ stdenv.mkDerivation (rec {
     platforms = stdenv.lib.platforms.unix;
     maintainers = [ stdenv.lib.maintainers.eelco ];
   };
-
-} // stdenv.lib.optionalAttrs pythonSupport {
-  configureFlags = "--with-python=${python}";
-
-  # this is a pair of ugly hacks to make python stuff install into the right place
-  preInstall = ''substituteInPlace python/libxml2mod.la --replace "${python}" "$out"'';
-  installFlags = ''pythondir="$(out)/lib/${python.libPrefix}/site-packages"'';
-
-} // stdenv.lib.optionalAttrs (!pythonSupport) {
-  configureFlags = "--with-python=no"; # otherwise build impurity bites us
-})
+}
 
diff --git a/pkgs/development/libraries/libxslt/default.nix b/pkgs/development/libraries/libxslt/default.nix
index 3579e99ec7a..2784093d50a 100644
--- a/pkgs/development/libraries/libxslt/default.nix
+++ b/pkgs/development/libraries/libxslt/default.nix
@@ -8,7 +8,7 @@ stdenv.mkDerivation rec {
     sha256 = "13029baw9kkyjgr7q3jccw2mz38amq7mmpr5p3bh775qawd1bisz";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "dev" "out" "bin" "doc" ];
 
   buildInputs = [ libxml2 ];
 
@@ -17,7 +17,6 @@ stdenv.mkDerivation rec {
   patches = stdenv.lib.optionals stdenv.isSunOS [ ./patch-ah.patch ];
 
   configureFlags = [
-    "--with-libxml-prefix=${libxml2}"
     "--without-python"
     "--without-crypto"
     "--without-debug"
@@ -25,11 +24,17 @@ stdenv.mkDerivation rec {
     "--without-debugger"
   ];
 
-  meta = {
+  postFixup = ''
+    moveToOutput bin/xslt-config "$dev"
+    moveToOutput lib/xsltConf.sh "$dev"
+    moveToOutput share/man/man1 "$bin"
+  '';
+
+  meta = with stdenv.lib; {
     homepage = http://xmlsoft.org/XSLT/;
     description = "A C library and tools to do XSL transformations";
     license = "bsd";
-    platforms = stdenv.lib.platforms.unix;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
+    platforms = platforms.unix;
+    maintainers = [ maintainers.eelco ];
   };
 }
diff --git a/pkgs/development/libraries/mailcore2/default.nix b/pkgs/development/libraries/mailcore2/default.nix
index de82bd0243e..f535b19bd0e 100644
--- a/pkgs/development/libraries/mailcore2/default.nix
+++ b/pkgs/development/libraries/mailcore2/default.nix
@@ -23,9 +23,10 @@ stdenv.mkDerivation rec {
     substituteInPlace CMakeLists.txt \
        --replace "tidy/tidy.h" "tidy.h" \
        --replace "/usr/include/tidy" "${libtidy}/include" \
-       --replace "/usr/include/libxml2" "${libxml2}/include/libxml2"
+       --replace "/usr/include/libxml2" "${libxml2.dev}/include/libxml2"
     substituteInPlace src/core/basetypes/MCHTMLCleaner.cpp \
       --replace buffio.h tidybuffio.h
+>>>>>>> master
   '';
 
   cmakeFlags = [
diff --git a/pkgs/development/libraries/mesa/default.nix b/pkgs/development/libraries/mesa/default.nix
index 11fafc8f038..3386de316b9 100644
--- a/pkgs/development/libraries/mesa/default.nix
+++ b/pkgs/development/libraries/mesa/default.nix
@@ -1,6 +1,5 @@
-{ stdenv, fetchurl, fetchpatch, pkgconfig, intltool, flex, bison, autoreconfHook, substituteAll
-, python, libxml2Python, file, expat, makedepend, pythonPackages
-, libdrm, xorg, wayland, udev, llvmPackages, libffi, libomxil-bellagio
+{ stdenv, fetchurl, fetchpatch, pkgconfig, intltool, autoreconfHook, substituteAll
+, file, expat, libdrm, xorg, wayland, libudev, llvmPackages, libffi, libomxil-bellagio
 , libvdpau, libelf, libva
 , grsecEnabled
 , enableTextureFloats ? false # Texture floats are patented, see docs/patents.txt
@@ -21,12 +20,13 @@ else
   - libOSMesa is in $osmesa (~4 MB)
 */
 
+with { inherit (stdenv.lib) optional optionalString; };
+
 let
   version = "11.0.5";
   # this is the default search path for DRI drivers
-  driverLink = "/run/opengl-driver" + stdenv.lib.optionalString stdenv.isi686 "-32";
+  driverLink = "/run/opengl-driver" + optionalString stdenv.isi686 "-32";
 in
-with { inherit (stdenv.lib) optional optionals optionalString; };
 
 stdenv.mkDerivation {
   name = "mesa-noglu-${version}";
@@ -48,7 +48,7 @@ stdenv.mkDerivation {
   ] ++ optional stdenv.isLinux
       (substituteAll {
         src = ./dlopen-absolute-paths.diff;
-        inherit udev;
+        libudev = libudev.out;
       });
 
   postPatch = ''
@@ -56,7 +56,7 @@ stdenv.mkDerivation {
       --replace _EGL_DRIVER_SEARCH_DIR '"${driverLink}"'
   '';
 
-  outputs = ["out" "drivers" "osmesa"];
+  outputs = [ "dev" "out" "drivers" "osmesa" ];
 
   configureFlags = [
     "--sysconfdir=/etc"
@@ -97,17 +97,17 @@ stdenv.mkDerivation {
   ] ++ optional enableTextureFloats "--enable-texture-float"
     ++ optional grsecEnabled "--enable-glx-rts"; # slight performance degradation, enable only for grsec
 
-  nativeBuildInputs = [ pkgconfig python makedepend file flex bison pythonPackages.Mako ];
+  nativeBuildInputs = [ pkgconfig file ];
 
   propagatedBuildInputs = with xorg; [ libXdamage libXxf86vm ]
-    ++ optionals stdenv.isLinux [ libdrm ];
+    ++ optional stdenv.isLinux libdrm;
 
   buildInputs = with xorg; [
-    autoreconfHook intltool expat libxml2Python llvmPackages.llvm
+    autoreconfHook intltool expat llvmPackages.llvm
     glproto dri2proto dri3proto presentproto
     libX11 libXext libxcb libXt libXfixes libxshmfence
     libffi wayland libvdpau libelf libXvMC /* libomxil-bellagio libva */
-  ] ++ optional stdenv.isLinux udev;
+  ] ++ optional stdenv.isLinux libudev;
 
   enableParallelBuilding = true;
   doCheck = false;
@@ -127,43 +127,42 @@ stdenv.mkDerivation {
       $out/lib/vdpau \
       $out/lib/libxatracker*
 
-    mkdir -p {$osmesa,$drivers}/lib/pkgconfig
+    mkdir -p {$osmesa,$drivers}/lib/
     mv -t $osmesa/lib/ \
       $out/lib/libOSMesa*
 
-    mv -t $drivers/lib/pkgconfig/ \
-      $out/lib/pkgconfig/xatracker.pc
-
-    mv -t $osmesa/lib/pkgconfig/ \
-      $out/lib/pkgconfig/osmesa.pc
-
   '' + /* now fix references in .la files */ ''
     sed "/^libdir=/s,$out,$osmesa," -i \
       $osmesa/lib/libOSMesa*.la
 
-  '' + /* work around bug #529, but maybe $drivers should also be patchelf-ed */ ''
-    find $drivers/ $osmesa/ -type f -executable -print0 | xargs -0 strip -S || true
+  '' + /* set the default search path for DRI drivers; used e.g. by X server */ ''
+    substituteInPlace "$dev/lib/pkgconfig/dri.pc" --replace '$(drivers)' "${driverLink}"
+  '' + /* move vdpau drivers to $drivers/lib, so they are found */ ''
+    mv "$drivers"/lib/vdpau/* "$drivers"/lib/ && rmdir "$drivers"/lib/vdpau
+  '';
+  #ToDo: @vcunat isn't sure if drirc will be found when in $out/etc/, but it doesn't seem important ATM */
 
-  '' + /* add RPATH so the drivers can find the moved libgallium and libdricore9 */ ''
+  postFixup =
+    # add RPATH so the drivers can find the moved libgallium and libdricore9
+    # moved here to avoid problems with stripping patchelfed files
+  ''
     for lib in $drivers/lib/*.so* $drivers/lib/*/*.so*; do
       if [[ ! -L "$lib" ]]; then
         patchelf --set-rpath "$(patchelf --print-rpath $lib):$drivers/lib" "$lib"
       fi
     done
-  '' + /* set the default search path for DRI drivers; used e.g. by X server */ ''
-    substituteInPlace "$out/lib/pkgconfig/dri.pc" --replace '$(drivers)' "${driverLink}"
-  '' + /* move vdpau drivers to $drivers/lib, so they are found */ ''
-    mv "$drivers"/lib/vdpau/* "$drivers"/lib/ && rmdir "$drivers"/lib/vdpau
   '';
-  #ToDo: @vcunat isn't sure if drirc will be found when in $out/etc/, but it doesn't seem important ATM
+  # ToDo + /* check $out doesn't depend on llvm */ ''
+  # builder failures are ignored for some reason
+  #   grep -qv '${llvmPackages.llvm}' -R "$out"
 
   passthru = { inherit libdrm version driverLink; };
 
-  meta = {
+  meta = with stdenv.lib; {
     description = "An open source implementation of OpenGL";
     homepage = http://www.mesa3d.org/;
-    license = "bsd";
-    platforms = stdenv.lib.platforms.mesaPlatforms;
-    maintainers = with stdenv.lib.maintainers; [ eduarrrd simons vcunat ];
+    license = licenses.mit; # X11 variant, in most files
+    platforms = platforms.mesaPlatforms;
+    maintainers = with maintainers; [ eduarrrd simons vcunat ];
   };
 }
diff --git a/pkgs/development/libraries/mesa/dlopen-absolute-paths.diff b/pkgs/development/libraries/mesa/dlopen-absolute-paths.diff
index a4bb6a72b13..9a522657223 100644
--- a/pkgs/development/libraries/mesa/dlopen-absolute-paths.diff
+++ b/pkgs/development/libraries/mesa/dlopen-absolute-paths.diff
@@ -16,7 +16,7 @@ index 4fdf3c2..69ea22d 100644
     do {
        for (version = 1; version >= 0; version--) {
 -         snprintf(name, sizeof(name), "libudev.so.%d", version);
-+         snprintf(name, sizeof(name), "@udev@/lib/libudev.so.%d", version);
++         snprintf(name, sizeof(name), "@libudev@/lib/libudev.so.%d", version);
           udev_handle = dlopen(name, flags);
           if (udev_handle)
              return udev_handle;
diff --git a/pkgs/development/libraries/mpfr/default.nix b/pkgs/development/libraries/mpfr/default.nix
index 581f956b0af..8a964af01c8 100644
--- a/pkgs/development/libraries/mpfr/default.nix
+++ b/pkgs/development/libraries/mpfr/default.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation rec {
 
   patches = [ ./upstream.patch ];
 
+  outputs = [ "dev" "out" "doc" ];
+
   # mpfr.h requires gmp.h
   propagatedBuildInputs = [ gmp ];
 
diff --git a/pkgs/development/libraries/ncurses/default.nix b/pkgs/development/libraries/ncurses/default.nix
index 8817e2c5523..41d609db478 100644
--- a/pkgs/development/libraries/ncurses/default.nix
+++ b/pkgs/development/libraries/ncurses/default.nix
@@ -20,6 +20,9 @@ stdenv.mkDerivation rec {
   # gcc-5.patch should be removed after 5.9
   patches = [ ./clang.patch ./gcc-5.patch ];
 
+  outputs = [ "dev" "lib" "out" "man" ];
+  setOutputFlags = false; # some aren't supported
+
   configureFlags = [
     "--with-shared"
     "--without-debug"
@@ -33,9 +36,15 @@ stdenv.mkDerivation rec {
   buildInputs = lib.optional (mouseSupport && stdenv.isLinux) gpm;
 
   preConfigure = ''
-    configureFlagsArray+=("--includedir=$out/include")
-    export PKG_CONFIG_LIBDIR="$out/lib/pkgconfig"
+    export PKG_CONFIG_LIBDIR="$dev/lib/pkgconfig"
     mkdir -p "$PKG_CONFIG_LIBDIR"
+    configureFlagsArray+=(
+      "--libdir=$lib/lib"
+      "--includedir=$dev/include"
+      "--bindir=$dev/bin"
+      "--mandir=$man/share/man"
+      "--with-pkg-config-libdir=$PKG_CONFIG_LIBDIR"
+    )
   ''
   + lib.optionalString stdenv.isSunOS ''
     sed -i -e '/-D__EXTENSIONS__/ s/-D_XOPEN_SOURCE=\$cf_XOPEN_SOURCE//' \
@@ -55,44 +64,44 @@ stdenv.mkDerivation rec {
   # When building a wide-character (Unicode) build, create backward
   # compatibility links from the the "normal" libraries to the
   # wide-character libraries (e.g. libncurses.so to libncursesw.so).
-  postInstall = ''
+  postFixup = ''
     # Determine what suffixes our libraries have
     suffix="$(awk -F': ' 'f{print $3; f=0} /default library suffix/{f=1}' config.log)"
-    libs="$(ls $out/lib/pkgconfig | tr ' ' '\n' | sed "s,\(.*\)$suffix\.pc,\1,g")"
+    libs="$(ls $dev/lib/pkgconfig | tr ' ' '\n' | sed "s,\(.*\)$suffix\.pc,\1,g")"
     suffixes="$(echo "$suffix" | awk '{for (i=1; i < length($0); i++) {x=substr($0, i+1, length($0)-i); print x}}')"
 
     # Get the path to the config util
-    cfg=$(basename $out/bin/ncurses*-config)
+    cfg=$(basename $dev/bin/ncurses*-config)
 
     # symlink the full suffixed include directory
-    ln -svf . $out/include/ncurses$suffix
+    ln -svf . $dev/include/ncurses$suffix
 
     for newsuffix in $suffixes ""; do
       # Create a non-abi versioned config util links
-      ln -svf $cfg $out/bin/ncurses$newsuffix-config
+      ln -svf $cfg $dev/bin/ncurses$newsuffix-config
 
       # Allow for end users who #include <ncurses?w/*.h>
-      ln -svf . $out/include/ncurses$newsuffix
+      ln -svf . $dev/include/ncurses$newsuffix
 
-      for lib in $libs; do
+      for library in $libs; do
         for dylibtype in so dll dylib; do
-          if [ -e "$out/lib/lib''${lib}$suffix.$dylibtype" ]; then
-            ln -svf lib''${lib}$suffix.$dylibtype $out/lib/lib$lib$newsuffix.$dylibtype
-            ln -svf lib''${lib}$suffix.$dylibtype.${abiVersion} $out/lib/lib$lib$newsuffix.$dylibtype.${abiVersion}
+          if [ -e "$lib/lib/lib''${library}$suffix.$dylibtype" ]; then
+            ln -svf lib''${library}$suffix.$dylibtype $lib/lib/lib$library$newsuffix.$dylibtype
+            ln -svf lib''${library}$suffix.$dylibtype.${abiVersion} $lib/lib/lib$library$newsuffix.$dylibtype.${abiVersion}
           fi
         done
         for statictype in a dll.a la; do
-          if [ -e "$out/lib/lib''${lib}$suffix.$statictype" ]; then
-            ln -svf lib''${lib}$suffix.$statictype $out/lib/lib$lib$newsuffix.$statictype
+          if [ -e "$lib/lib/lib''${library}$suffix.$statictype" ]; then
+            ln -svf lib''${library}$suffix.$statictype $lib/lib/lib$library$newsuffix.$statictype
           fi
         done
-        ln -svf ''${lib}$suffix.pc $out/lib/pkgconfig/$lib$newsuffix.pc
+        ln -svf ''${library}$suffix.pc $dev/lib/pkgconfig/$library$newsuffix.pc
       done
     done
   '';
 
   preFixup = ''
-    rm $out/lib/*.a
+    rm "$lib"/lib/*.a
   '';
 
   meta = {
diff --git a/pkgs/development/libraries/nettle/generic.nix b/pkgs/development/libraries/nettle/generic.nix
index 3c439eb404c..1bfb739712f 100644
--- a/pkgs/development/libraries/nettle/generic.nix
+++ b/pkgs/development/libraries/nettle/generic.nix
@@ -9,6 +9,9 @@ stdenv.mkDerivation (rec {
 
   inherit src;
 
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
+
   buildInputs = [ gnum4 ];
   propagatedBuildInputs = [ gmp ];
 
@@ -61,5 +64,5 @@ stdenv.lib.optionalAttrs stdenv.isSunOS {
   # /usr/include/mp.h from OpenSolaris.  See
   # <https://lists.gnu.org/archive/html/hydra-users/2012-08/msg00000.html>
   # for details.
-  configureFlags = [ "--with-include-path=${gmp}/include" ];
+  configureFlags = [ "--with-include-path=${gmp.dev}/include" ];
 })
diff --git a/pkgs/development/libraries/newt/default.nix b/pkgs/development/libraries/newt/default.nix
index f5f72c006c7..8a4b793cad7 100644
--- a/pkgs/development/libraries/newt/default.nix
+++ b/pkgs/development/libraries/newt/default.nix
@@ -14,16 +14,18 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ slang popt ];
 
+  NIX_LDFLAGS = "-lncurses";
+
   crossAttrs = {
     makeFlags = "CROSS_COMPILE=${stdenv.cross.config}-";
   };
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = https://fedorahosted.org/newt/;
     description = "Library for color text mode, widget based user interfaces";
 
-    license = stdenv.lib.licenses.lgpl2;
-    platforms = stdenv.lib.platforms.linux;
-    maintainers = [ stdenv.lib.maintainers.viric ];
+    license = licenses.lgpl2;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.viric ];
   };
 }
diff --git a/pkgs/development/libraries/nspr/default.nix b/pkgs/development/libraries/nspr/default.nix
index e1b7a01c4cd..b0261194414 100644
--- a/pkgs/development/libraries/nspr/default.nix
+++ b/pkgs/development/libraries/nspr/default.nix
@@ -10,6 +10,9 @@ stdenv.mkDerivation {
     sha256 = "343614971c30520d0fa55f4af0a72578e2d8674bb71caf7187490c3379523107";
   };
 
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
+
   preConfigure = ''
     cd nspr
   '';
@@ -21,6 +24,7 @@ stdenv.mkDerivation {
 
   postInstall = ''
     find $out -name "*.a" -delete
+    moveToOutput share "$dev" # just aclocal
   '';
 
   enableParallelBuilding = true;
diff --git a/pkgs/development/libraries/nss/default.nix b/pkgs/development/libraries/nss/default.nix
index 47bb5cde228..12c44c4cae0 100644
--- a/pkgs/development/libraries/nss/default.nix
+++ b/pkgs/development/libraries/nss/default.nix
@@ -1,6 +1,4 @@
-{ stdenv, fetchurl, nspr, perl, zlib, sqlite
-, includeTools ? false
-}:
+{ stdenv, fetchurl, nspr, perl, zlib, sqlite }:
 
 let
 
@@ -46,15 +44,18 @@ in stdenv.mkDerivation rec {
     INSTALL_TARGET
   '';
 
+  outputs = [ "dev" "out" "tools" ];
+
   preConfigure = "cd nss";
 
   makeFlags = [
-    "NSPR_INCLUDE_DIR=${nspr}/include/nspr"
-    "NSPR_LIB_DIR=${nspr}/lib"
+    "NSPR_INCLUDE_DIR=${nspr.dev}/include/nspr"
+    "NSPR_LIB_DIR=${nspr.out}/lib"
     "NSDISTMODE=copy"
     "BUILD_OPT=1"
     "SOURCE_PREFIX=\$(out)"
     "NSS_ENABLE_ECC=1"
+    "USE_SYSTEM_ZLIB=1"
     "NSS_USE_SYSTEM_SQLITE=1"
   ] ++ stdenv.lib.optional stdenv.is64bit "USE_64=1";
 
@@ -75,8 +76,11 @@ in stdenv.mkDerivation rec {
       libfile="$out/lib/lib$libname.so"
       LD_LIBRARY_PATH=$out/lib $out/bin/shlibsign -v -i "$libfile"
     done
-  '' + stdenv.lib.optionalString (!includeTools) ''
-    find $out/bin -type f \( -name nss-config -o -delete \)
+
+    moveToOutput bin "$tools"
+    moveToOutput bin/nss-config "$dev"
+    moveToOutput lib/libcrmf.a "$dev" # needed by firefox, for example
+    rm "$out"/lib/*.a
   '';
 
   meta = {
diff --git a/pkgs/development/libraries/nss_wrapper/default.nix b/pkgs/development/libraries/nss_wrapper/default.nix
index 278834190bb..a81d95e6b98 100644
--- a/pkgs/development/libraries/nss_wrapper/default.nix
+++ b/pkgs/development/libraries/nss_wrapper/default.nix
@@ -8,7 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "0bysdijvi9n0jk74iklbfhbp0kvv81a727lcfd5q03q2hkzjfm18";
   };
 
-  buildInputs = [ cmake pkgconfig ];
+  buildInputs = [ cmake pkgconfig (stdenv.cc.libc.out or null) ];
+  # outputs TODO: missing glibc.out might become a general problem
 
   meta = with stdenv.lib; {
     description = "A wrapper for the user, group and hosts NSS API";
diff --git a/pkgs/development/libraries/openldap/default.nix b/pkgs/development/libraries/openldap/default.nix
index 253f74ecc6a..e9895ff56a0 100644
--- a/pkgs/development/libraries/openldap/default.nix
+++ b/pkgs/development/libraries/openldap/default.nix
@@ -11,7 +11,8 @@ stdenv.mkDerivation rec {
   # Should be removed with >=2.4.43
   patches = [ ./CVE-2015-6908.patch ];
 
-  outputs = [ "out" "man" ];
+  # TODO: separate "out" and "bin"
+  outputs = [ "dev" "out" "man" "docdev" ];
 
   buildInputs = [ openssl cyrus_sasl db groff ];
 
@@ -21,12 +22,10 @@ stdenv.mkDerivation rec {
     ] ++ stdenv.lib.optional (openssl == null) "--without-tls"
       ++ stdenv.lib.optional (cyrus_sasl == null) "--without-cyrus-sasl";
 
-  dontPatchELF = 1; # !!!
-
   # Fixup broken libtool
   preFixup = ''
-    sed -e 's,-lsasl2,-L${cyrus_sasl}/lib -lsasl2,' \
-        -e 's,-lssl,-L${openssl}/lib -lssl,' \
+    sed -e 's,-lsasl2,-L${cyrus_sasl.out}/lib -lsasl2,' \
+        -e 's,-lssl,-L${openssl.out}/lib -lssl,' \
         -i $out/lib/libldap.la -i $out/lib/libldap_r.la
   '';
 
diff --git a/pkgs/development/libraries/openssl/default.nix b/pkgs/development/libraries/openssl/default.nix
index 21e7706be8c..1d898df6e02 100644
--- a/pkgs/development/libraries/openssl/default.nix
+++ b/pkgs/development/libraries/openssl/default.nix
@@ -18,11 +18,12 @@ stdenv.mkDerivation rec {
     sha256 = "1dvz0hx7fjxag06b51pawy154y6d2xajm5rwxmfnlq7ax628nrdk";
   };
 
-  outputs = [ "out" "man" ];
-
   patches = optional stdenv.isCygwin ./1.0.1-cygwin64.patch
     ++ optional (stdenv.isDarwin || (stdenv ? cross && stdenv.cross.libc == "libSystem")) ./darwin-arch.patch;
 
+  outputs = [ "dev" "out" "man" "bin" ];
+  setOutputFlags = false;
+
   nativeBuildInputs = [ perl ];
   buildInputs = stdenv.lib.optional withCryptodev cryptodevHeaders;
 
@@ -42,9 +43,7 @@ stdenv.mkDerivation rec {
     "-DUSE_CRYPTODEV_DIGESTS"
   ];
 
-  makeFlags = [
-    "MANDIR=$(out)/share/man"
-  ];
+  makeFlags = [ "MANDIR=$(man)/share/man" ];
 
   # Parallel building is broken in OpenSSL.
   enableParallelBuilding = false;
@@ -56,12 +55,18 @@ stdenv.mkDerivation rec {
         rm "$out/lib/"*.a
     fi
 
+    mkdir -p $bin
+    mv $out/bin $bin/
+
+    mkdir $dev
+    mv $out/include $dev/
+
     # remove dependency on Perl at runtime
-    rm -r $out/etc/ssl/misc $out/bin/c_rehash
+    rm -r $out/etc/ssl/misc
   '';
 
   postFixup = ''
-    # Check to make sure we don't depend on perl
+    # Check to make sure the main output doesn't depend on perl
     if grep -r '${perl}' $out; then
       echo "Found an erroneous dependency on perl ^^^" >&2
       exit 1
diff --git a/pkgs/development/libraries/p11-kit/default.nix b/pkgs/development/libraries/p11-kit/default.nix
index eefed304134..f2a9bdc1230 100644
--- a/pkgs/development/libraries/p11-kit/default.nix
+++ b/pkgs/development/libraries/p11-kit/default.nix
@@ -8,6 +8,9 @@ stdenv.mkDerivation rec {
     sha256 = "1i3a1wdpagm0p3y1bwaz5x5rjhcpqbcrnhkcp10p259vkxk72wz5";
   };
 
+  outputs = [ "dev" "out" "docdev" ];
+  outputBin = "dev";
+
   buildInputs = [ pkgconfig libffi libtasn1 libiconv ];
 
   configureFlags = [
diff --git a/pkgs/development/libraries/pango/default.nix b/pkgs/development/libraries/pango/default.nix
index e7106b9877e..e213fa56a7c 100644
--- a/pkgs/development/libraries/pango/default.nix
+++ b/pkgs/development/libraries/pango/default.nix
@@ -1,5 +1,5 @@
-{ stdenv, fetchurl, pkgconfig, xlibsWrapper, glib, cairo, libpng, harfbuzz
-, fontconfig, freetype, libintlOrEmpty, gobjectIntrospection
+{ stdenv, fetchurl, pkgconfig, libXft, cairo, harfbuzz
+, libintlOrEmpty, gobjectIntrospection
 }:
 
 let
@@ -14,11 +14,11 @@ stdenv.mkDerivation rec {
     sha256 = "0v12gi7f01iq3z852pclpnmkbcksbvpcmiazmklkx1dd9fbpakhx";
   };
 
-  buildInputs = with stdenv.lib; [ gobjectIntrospection ]
-    ++ optional stdenv.isDarwin fontconfig;
-  nativeBuildInputs = [ pkgconfig ];
+  outputs = [ "dev" "out" "bin" "docdev" ];
 
-  propagatedBuildInputs = [ xlibsWrapper glib cairo libpng fontconfig freetype harfbuzz ] ++ libintlOrEmpty;
+  buildInputs = [ gobjectIntrospection ];
+  nativeBuildInputs = [ pkgconfig ];
+  propagatedBuildInputs = [ cairo harfbuzz libXft ] ++ libintlOrEmpty;
 
   enableParallelBuilding = true;
 
@@ -29,8 +29,6 @@ stdenv.mkDerivation rec {
   # .../bin/sh: line 5: 14823 Abort trap: 6 srcdir=. PANGO_RC_FILE=./pangorc ${dir}$tst
   # FAIL: testiter
 
-  postInstall = "rm -rf $out/share/gtk-doc";
-
   meta = with stdenv.lib; {
     description = "A library for laying out and rendering of text, with an emphasis on internationalization";
 
diff --git a/pkgs/development/libraries/pcre/default.nix b/pkgs/development/libraries/pcre/default.nix
index 3370e910565..0056ac3ffac 100644
--- a/pkgs/development/libraries/pcre/default.nix
+++ b/pkgs/development/libraries/pcre/default.nix
@@ -1,9 +1,11 @@
-{ stdenv, fetchurl, unicodeSupport ? true, cplusplusSupport ? true
-, windows ? null
+{ stdenv, fetchurl
+, windows ? null, variant ? null, pcre
 }:
 
 with stdenv.lib;
 
+assert elem variant [ null "cpp" "pcre16" "pcre32" ];
+
 stdenv.mkDerivation rec {
   name = "pcre-8.37";
 
@@ -17,18 +19,26 @@ stdenv.mkDerivation rec {
       ./cve-2015-5073.patch
     ];
 
-  outputs = [ "out" "doc" "man" ];
+  outputs = [ "dev" "out" "bin" "doc" "man" ];
 
-  configureFlags = ''
-    --enable-jit
-    ${if unicodeSupport then "--enable-unicode-properties" else ""}
-    ${if !cplusplusSupport then "--disable-cpp" else ""}
-  '';
+  configureFlags = [
+    "--enable-jit"
+    "--enable-unicode-properties"
+    "--disable-cpp"
+  ]
+    ++ optional (variant != null) "--enable-${variant}";
 
   doCheck = with stdenv; !(isCygwin || isFreeBSD);
     # XXX: test failure on Cygwin
     # we are running out of stack on both freeBSDs on Hydra
 
+  postFixup = ''
+    moveToOutput bin/pcre-config "$dev"
+  ''
+    + optionalString (variant != null) ''
+    ln -sf -t "$out/lib/" '${pcre.out}'/lib/libpcre{,posix}.so.*.*.*
+  '';
+
   crossAttrs = optionalAttrs (stdenv.cross.libc == "msvcrt") {
     buildInputs = [ windows.mingw_w64_pthreads.crossDrv ];
   };
diff --git a/pkgs/development/libraries/pdf2xml/default.nix b/pkgs/development/libraries/pdf2xml/default.nix
index c7c5aff2455..4ebb0cbcc26 100644
--- a/pkgs/development/libraries/pdf2xml/default.nix
+++ b/pkgs/development/libraries/pdf2xml/default.nix
@@ -16,8 +16,8 @@ stdenv.mkDerivation {
   preBuild = ''
     cp Makefile.linux Makefile
   
-    sed -i 's|/usr/include/libxml2|${libxml2}/include/libxml2|' Makefile
-    sed -i 's|-lxml2|-lxml2 -L${libxml2}/lib|' Makefile
+    sed -i 's|/usr/include/libxml2|${libxml2.dev}/include/libxml2|' Makefile
+    sed -i 's|-lxml2|-lxml2 -L${libxml2.out}/lib|' Makefile
     sed -i 's|XPDF = xpdf_3.01|XPDF = ${libxpdf}/lib|' Makefile
 
     mkdir exe
diff --git a/pkgs/development/libraries/phonon-backend-gstreamer/qt5/old.nix b/pkgs/development/libraries/phonon-backend-gstreamer/qt5/old.nix
index d91808ec880..08bce2b68eb 100644
--- a/pkgs/development/libraries/phonon-backend-gstreamer/qt5/old.nix
+++ b/pkgs/development/libraries/phonon-backend-gstreamer/qt5/old.nix
@@ -32,6 +32,8 @@ stdenv.mkDerivation rec {
   ]
   ++ optional debug "-DCMAKE_BUILD_TYPE=Debug";
 
+  NIX_CFLAGS_COMPILE = "-fPIC";
+
   meta = with stdenv.lib; {
     homepage = http://phonon.kde.org/;
     description = "GStreamer backend for Phonon";
diff --git a/pkgs/development/libraries/policykit/default.nix b/pkgs/development/libraries/policykit/default.nix
index f494710be63..9f8b702f897 100644
--- a/pkgs/development/libraries/policykit/default.nix
+++ b/pkgs/development/libraries/policykit/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
   buildInputs =
     [ pkgconfig glib dbus_glib pam intltool gettext libxslt ];
 
-  propagatedBuildInputs = [ expat dbus.libs ];
+  propagatedBuildInputs = [ expat dbus ];
 
   configureFlags = "--localstatedir=/var --sysconfdir=/etc";
 
diff --git a/pkgs/development/libraries/polkit/default.nix b/pkgs/development/libraries/polkit/default.nix
index cdeaa0cb1d9..5744460008f 100644
--- a/pkgs/development/libraries/polkit/default.nix
+++ b/pkgs/development/libraries/polkit/default.nix
@@ -22,6 +22,8 @@ stdenv.mkDerivation rec {
     sha256 = "109w86kfqrgz83g9ivggplmgc77rz8kx8646izvm2jb57h4rbh71";
   };
 
+  outputs = [ "dev" "out" "bin" ]; # small man pages in $bin
+
   buildInputs =
     [ pkgconfig glib expat pam intltool spidermonkey gobjectIntrospection ]
     ++ [ libxslt docbook_xsl docbook_xml_dtd_412 ] # man pages
diff --git a/pkgs/development/libraries/poppler/default.nix b/pkgs/development/libraries/poppler/default.nix
index 92777f00169..ebcdcc2b3ef 100644
--- a/pkgs/development/libraries/poppler/default.nix
+++ b/pkgs/development/libraries/poppler/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
     inherit sha256;
   };
 
-  outputs = [ "out" ] ++ lib.optional (!minimal) "doc";
+  outputs = [ "dev" "out" ];
 
   patches = [ ./datadir_env.patch ];
 
diff --git a/pkgs/development/libraries/portaudio/default.nix b/pkgs/development/libraries/portaudio/default.nix
index 46d51281401..5d8c2430ab9 100644
--- a/pkgs/development/libraries/portaudio/default.nix
+++ b/pkgs/development/libraries/portaudio/default.nix
@@ -35,7 +35,7 @@ stdenv.mkDerivation rec {
     make install
 
     # fixup .pc file to find alsa library
-    sed -i "s|-lasound|-L${alsaLib}/lib -lasound|" "$out/lib/pkgconfig/"*.pc
+    sed -i "s|-lasound|-L${alsaLib.out}/lib -lasound|" "$out/lib/pkgconfig/"*.pc
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/libraries/qt-3/default.nix b/pkgs/development/libraries/qt-3/default.nix
index 08d8f141deb..40fa63d75ca 100644
--- a/pkgs/development/libraries/qt-3/default.nix
+++ b/pkgs/development/libraries/qt-3/default.nix
@@ -49,9 +49,9 @@ stdenv.mkDerivation {
     ${if cursorSupport then "-L${libXcursor}/lib -I${libXcursor}/include" else ""}
     ${if mysqlSupport then "-qt-sql-mysql -L${mysql.lib}/lib/mysql -I${mysql.lib}/include/mysql" else ""}
     ${if xftSupport then "-xft
-      -L${libXft}/lib -I${libXft}/include
-      -L${libXft.freetype}/lib -I${libXft.freetype}/include
-      -L${libXft.fontconfig}/lib -I${libXft.fontconfig}/include" else "-no-xft"}
+      -L${libXft.out}/lib -I${libXft.dev}/include
+      -L${libXft.freetype.out}/lib -I${libXft.freetype.dev}/include
+      -L${libXft.fontconfig.lib}/lib -I${libXft.fontconfig.dev}/include" else "-no-xft"}
   ";
 
   patches = [
diff --git a/pkgs/development/libraries/qt-4.x/4.8/default.nix b/pkgs/development/libraries/qt-4.x/4.8/default.nix
index e4d1bae636c..ccc486692e2 100644
--- a/pkgs/development/libraries/qt-4.x/4.8/default.nix
+++ b/pkgs/development/libraries/qt-4.x/4.8/default.nix
@@ -52,19 +52,24 @@ stdenv.mkDerivation rec {
     [ ./glib-2.32.patch
       (substituteAll {
         src = ./dlopen-absolute-paths.diff;
-        inherit cups icu libXfixes;
-        glibc = stdenv.cc.libc;
+        cups = cups.out;
+        icu = icu.out;
+        libXfixes = libXfixes.out;
+        glibc = stdenv.cc.libc.out;
         openglDriver = if mesaSupported then mesa.driverLink else "/no-such-path";
       })
     ] ++ stdenv.lib.optional gtkStyle (substituteAll {
         src = ./dlopen-gtkstyle.diff;
         # substituteAll ignores env vars starting with capital letter
-        gconf = GConf;
-        inherit gnome_vfs libgnomeui gtk;
+        gconf = GConf.out;
+        gtk = gtk.out;
+        libgnomeui = libgnomeui.out;
+        gnome_vfs = gnome_vfs.out;
       })
     ++ stdenv.lib.optional flashplayerFix (substituteAll {
         src = ./dlopen-webkit-nsplugin.diff;
-        inherit gtk gdk_pixbuf;
+        gtk = gtk.out;
+        gdk_pixbuf = gdk_pixbuf.out;
       })
     ++ [(fetchpatch {
         name = "fix-medium-font.patch";
@@ -112,7 +117,7 @@ stdenv.mkDerivation rec {
 
   propagatedBuildInputs =
     [ libXrender libXrandr libXinerama libXcursor libXext libXfixes libXv libXi
-      libSM zlib libpng openssl dbus.libs freetype fontconfig glib ]
+      libSM zlib libpng openssl dbus freetype fontconfig glib ]
         # Qt doesn't directly need GLU (just GL), but many apps use, it's small and doesn't remain a runtime-dep if not used
     ++ optional mesaSupported mesa_glu
     ++ optional ((buildWebkit || buildMultimedia) && stdenv.isLinux ) alsaLib
@@ -129,7 +134,7 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = false;
 
   NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin
-    "-I${glib}/include/glib-2.0 -I${glib}/lib/glib-2.0/include";
+    "-I${glib.dev}/include/glib-2.0 -I${glib.out}/lib/glib-2.0/include";
 
   NIX_LDFLAGS = optionalString stdenv.isDarwin
     "-lglib-2.0";
diff --git a/pkgs/development/libraries/qt-5/5.4/0008-dlopen-webkit-udev.patch b/pkgs/development/libraries/qt-5/5.4/0008-dlopen-webkit-udev.patch
index e8a4ba6a215..fd226708a91 100644
--- a/pkgs/development/libraries/qt-5/5.4/0008-dlopen-webkit-udev.patch
+++ b/pkgs/development/libraries/qt-5/5.4/0008-dlopen-webkit-udev.patch
@@ -16,13 +16,13 @@ index 60ff317..da8ac69 100644
      {
          m_libUdev.setLoadHints(QLibrary::ResolveAllSymbolsHint);
 -        m_libUdev.setFileNameAndVersion(QStringLiteral("udev"), 1);
-+        m_libUdev.setFileNameAndVersion(QStringLiteral("@udev@/lib/libudev"), 1);
++        m_libUdev.setFileNameAndVersion(QStringLiteral("@libudev@/lib/libudev"), 1);
          m_loaded = m_libUdev.load();
          if (resolveMethods())
              return true;
  
 -        m_libUdev.setFileNameAndVersion(QStringLiteral("udev"), 0);
-+        m_libUdev.setFileNameAndVersion(QStringLiteral("@udev@/lib/libudev"), 0);
++        m_libUdev.setFileNameAndVersion(QStringLiteral("@libudev@/lib/libudev"), 0);
          m_loaded = m_libUdev.load();
          return resolveMethods();
      }
diff --git a/pkgs/development/libraries/qt-5/5.4/0009-dlopen-serialport-udev.patch b/pkgs/development/libraries/qt-5/5.4/0009-dlopen-serialport-udev.patch
index e1e66a3ce95..bb304392af4 100644
--- a/pkgs/development/libraries/qt-5/5.4/0009-dlopen-serialport-udev.patch
+++ b/pkgs/development/libraries/qt-5/5.4/0009-dlopen-serialport-udev.patch
@@ -16,10 +16,10 @@ index 09940ab..45460f9 100644
  {
      if (!udevLibrary->isLoaded()) {
 -        udevLibrary->setFileNameAndVersion(QStringLiteral("udev"), 1);
-+        udevLibrary->setFileNameAndVersion(QStringLiteral("@udev@/lib/libudev"), 1);
++        udevLibrary->setFileNameAndVersion(QStringLiteral("@libudev@/lib/libudev"), 1);
          if (!udevLibrary->load()) {
 -            udevLibrary->setFileNameAndVersion(QStringLiteral("udev"), 0);
-+            udevLibrary->setFileNameAndVersion(QStringLiteral("@udev@/lib/libudev"), 0);
++            udevLibrary->setFileNameAndVersion(QStringLiteral("@libudev@/lib/libudev"), 0);
              if (!udevLibrary->load()) {
                  qWarning("Failed to load the library: %s, supported version(s): %i and %i", qPrintable(udevLibrary->fileName()), 1, 0);
                  return false;
diff --git a/pkgs/development/libraries/qt-5/5.4/0014-mkspecs-libgl.patch b/pkgs/development/libraries/qt-5/5.4/0014-mkspecs-libgl.patch
index 1fc4bbd6076..4ec1947f6f9 100644
--- a/pkgs/development/libraries/qt-5/5.4/0014-mkspecs-libgl.patch
+++ b/pkgs/development/libraries/qt-5/5.4/0014-mkspecs-libgl.patch
@@ -10,8 +10,8 @@ diff -uNr qt-everywhere-opensource-src-5.3.2.orig/qtbase/mkspecs/common/linux.co
  QMAKE_LIBDIR_X11        =
 -QMAKE_INCDIR_OPENGL     =
 -QMAKE_LIBDIR_OPENGL     =
-+QMAKE_INCDIR_OPENGL     = @mesa@/include
-+QMAKE_LIBDIR_OPENGL     = @mesa@/lib
++QMAKE_INCDIR_OPENGL     = @mesa_inc@/include
++QMAKE_LIBDIR_OPENGL     = @mesa_lib@/lib
  QMAKE_INCDIR_OPENGL_ES2 = $$QMAKE_INCDIR_OPENGL
  QMAKE_LIBDIR_OPENGL_ES2 = $$QMAKE_LIBDIR_OPENGL
  QMAKE_INCDIR_EGL        =
diff --git a/pkgs/development/libraries/qt-5/5.4/default.nix b/pkgs/development/libraries/qt-5/5.4/default.nix
index 136c352d1aa..5807e685872 100644
--- a/pkgs/development/libraries/qt-5/5.4/default.nix
+++ b/pkgs/development/libraries/qt-5/5.4/default.nix
@@ -15,6 +15,7 @@
 
 , bison2
 , mesa_noglu
+, libudev
 , cups
 , gnome
 
@@ -214,13 +215,18 @@ let
 
       serialport = callPackage
         (
-          { qtSubmodule, base }:
+          { qtSubmodule, base, substituteAll }:
 
           qtSubmodule {
             name = "qtserialport";
             qtInputs = [ base ];
             patchFlags = "-p2"; # patches originally for monolithic build
-            patches = [ ./0009-dlopen-serialport-udev.patch ];
+            patches = [
+              (substituteAll {
+                src = ./0009-dlopen-serialport-udev.patch;
+                libudev = libudev.out;
+              })
+            ];
           }
         )
         {};
@@ -268,7 +274,7 @@ let
         (
           { qtSubmodule, declarative, location, multimedia, sensors
           , fontconfig, gdk_pixbuf, gtk, libwebp, libxml2, libxslt
-          , sqlite, udev
+          , sqlite, libudev
           , bison2, flex, gdb, gperf, perl, pkgconfig, python, ruby
           , substituteAll
           , flashplayerFix ? false
@@ -287,21 +293,22 @@ let
                 (substituteAll
                   {
                     src = ./0002-dlopen-webkit-nsplugin.patch;
-                    inherit gtk gdk_pixbuf;
+                    gtk = gtk.out;
+                    gdk_pixbuf = gdk_pixbuf.out;
                   }
                 )
               ++ optional flashplayerFix
                 (substituteAll
                   {
                     src = ./0007-dlopen-webkit-gtk.patch;
-                    inherit gtk;
+                    gtk = gtk.out;
                   }
                 )
               ++ [
                 (substituteAll
                   {
                     src = ./0008-dlopen-webkit-udev.patch;
-                    inherit udev;
+                    libudev = libudev.out;
                   }
                 )
               ];
diff --git a/pkgs/development/libraries/qt-5/5.4/qtbase.nix b/pkgs/development/libraries/qt-5/5.4/qtbase.nix
index 30d53eb874b..2b7052e1ca6 100644
--- a/pkgs/development/libraries/qt-5/5.4/qtbase.nix
+++ b/pkgs/development/libraries/qt-5/5.4/qtbase.nix
@@ -44,8 +44,8 @@ stdenv.mkDerivation {
     substituteInPlace qtbase/configure --replace /bin/pwd pwd
     substituteInPlace qtbase/src/corelib/global/global.pri --replace /bin/ls ${coreutils}/bin/ls
     substituteInPlace qtbase/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp \
-        --replace /usr/share/X11/locale ${libX11}/share/X11/locale \
-        --replace /usr/lib/X11/locale ${libX11}/share/X11/locale
+        --replace /usr/share/X11/locale ${libX11.out}/share/X11/locale \
+        --replace /usr/lib/X11/locale ${libX11.out}/share/X11/locale
     sed -e 's@/\(usr\|opt\)/@/var/empty/@g' -i config.tests/*/*.test -i qtbase/mkspecs/*/*.conf
   '';
 
@@ -54,25 +54,27 @@ stdenv.mkDerivation {
       (substituteAll {
         src = ./0001-dlopen-gtkstyle.patch;
         # substituteAll ignores env vars starting with capital letter
-        gconf = GConf;
-        inherit gnome_vfs libgnomeui gtk;
+        gconf = GConf.out;
+        gtk = gtk.out;
+        libgnomeui = libgnomeui.out;
+        gnome_vfs = gnome_vfs.out;
       })
     ++ [
       (substituteAll {
         src = ./0004-dlopen-resolv.patch;
-        glibc = stdenv.cc.libc;
+        glibc = stdenv.cc.libc.out;
       })
       (substituteAll {
         src = ./0005-dlopen-gl.patch;
         openglDriver = if mesaSupported then mesa.driverLink else "/no-such-path";
       })
       ./0006-tzdir.patch
-      (substituteAll { src = ./0010-dlopen-libXcursor.patch; inherit libXcursor; })
-      (substituteAll { src = ./0011-dlopen-openssl.patch; inherit openssl; })
-      (substituteAll { src = ./0012-dlopen-dbus.patch; dbus_libs = dbus; })
+      (substituteAll { src = ./0010-dlopen-libXcursor.patch; libXcursor = libXcursor.out; })
+      (substituteAll { src = ./0011-dlopen-openssl.patch; openssl = openssl.out; })
+      (substituteAll { src = ./0012-dlopen-dbus.patch; dbus_libs = dbus.lib; })
       ./0013-xdg_config_dirs.patch
     ] ++ optional mesaSupported
-      (substituteAll { src = ./0014-mkspecs-libgl.patch; inherit mesa; })
+      (substituteAll { src = ./0014-mkspecs-libgl.patch; mesa_inc = mesa.dev; mesa_lib = mesa.out; })
     ++ (optional decryptSslTraffic ./0100-ssl.patch);
 
   preConfigure = ''
@@ -160,11 +162,11 @@ stdenv.mkDerivation {
   # PostgreSQL autodetection fails sporadically because Qt omits the "-lpq" flag
   # if dependency paths contain the string "pq", which can occur in the hash.
   # To prevent these failures, we need to override PostgreSQL detection.
-  PSQL_LIBS = optionalString (postgresql != null) "-L${postgresql}/lib -lpq";
+  PSQL_LIBS = optionalString (postgresql != null) "-L${postgresql.lib}/lib -lpq";
 
   propagatedBuildInputs = [
     xorg.libXcomposite libX11 libxcb libXext libXrender libXi
-    fontconfig freetype openssl dbus.libs glib udev libxml2 libxslt pcre
+    fontconfig freetype openssl dbus glib udev libxml2 libxslt pcre
     zlib libjpeg libpng libtiff sqlite icu
     xcbutil xcbutilimage xcbutilkeysyms xcbutilwm libxkbcommon
   ]
diff --git a/pkgs/development/libraries/qt-5/5.5/qtbase/0010-mkspecs-libgl.patch b/pkgs/development/libraries/qt-5/5.5/qtbase/0010-mkspecs-libgl.patch
index 0f418e600f1..3a60abb5f4a 100644
--- a/pkgs/development/libraries/qt-5/5.5/qtbase/0010-mkspecs-libgl.patch
+++ b/pkgs/development/libraries/qt-5/5.5/qtbase/0010-mkspecs-libgl.patch
@@ -17,8 +17,8 @@ index 8d6fb6f..0ff9181 100644
  QMAKE_LIBDIR_X11        =
 -QMAKE_INCDIR_OPENGL     =
 -QMAKE_LIBDIR_OPENGL     =
-+QMAKE_INCDIR_OPENGL     = @mesa@/include
-+QMAKE_LIBDIR_OPENGL     = @mesa@/lib
++QMAKE_INCDIR_OPENGL     = @mesa_inc@/include
++QMAKE_LIBDIR_OPENGL     = @mesa_lib@/lib
  QMAKE_INCDIR_OPENGL_ES2 = $$QMAKE_INCDIR_OPENGL
  QMAKE_LIBDIR_OPENGL_ES2 = $$QMAKE_LIBDIR_OPENGL
  QMAKE_INCDIR_EGL        =
diff --git a/pkgs/development/libraries/qt-5/5.5/qtbase/default.nix b/pkgs/development/libraries/qt-5/5.5/qtbase/default.nix
index 7c48c4571d9..1ec89acfcd2 100644
--- a/pkgs/development/libraries/qt-5/5.5/qtbase/default.nix
+++ b/pkgs/development/libraries/qt-5/5.5/qtbase/default.nix
@@ -48,8 +48,8 @@ stdenv.mkDerivation {
     substituteInPlace qtbase/configure --replace /bin/pwd pwd
     substituteInPlace qtbase/src/corelib/global/global.pri --replace /bin/ls ${coreutils}/bin/ls
     substituteInPlace qtbase/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp \
-        --replace /usr/share/X11/locale ${libX11}/share/X11/locale \
-        --replace /usr/lib/X11/locale ${libX11}/share/X11/locale
+        --replace /usr/share/X11/locale ${libX11.out}/share/X11/locale \
+        --replace /usr/lib/X11/locale ${libX11.out}/share/X11/locale
     sed -e 's@/\(usr\|opt\)/@/var/empty/@g' -i config.tests/*/*.test -i qtbase/mkspecs/*/*.conf
   '';
 
@@ -57,12 +57,14 @@ stdenv.mkDerivation {
     let dlopen-gtkstyle = substituteAll {
           src = ./0001-dlopen-gtkstyle.patch;
           # substituteAll ignores env vars starting with capital letter
-          gconf = GConf;
-          inherit gnome_vfs libgnomeui gtk;
+          gconf = GConf.out;
+          gtk = gtk.out;
+          libgnomeui = libgnomeui.out;
+          gnome_vfs = gnome_vfs.out;
         };
         dlopen-resolv = substituteAll {
           src = ./0002-dlopen-resolv.patch;
-          glibc = stdenv.cc.libc;
+          glibc = stdenv.cc.libc.out;
         };
         dlopen-gl = substituteAll {
           src = ./0003-dlopen-gl.patch;
@@ -71,21 +73,22 @@ stdenv.mkDerivation {
         tzdir = ./0004-tzdir.patch;
         dlopen-libXcursor = substituteAll {
           src = ./0005-dlopen-libXcursor.patch;
-          inherit libXcursor;
+          libXcursor = libXcursor.out;
         };
         dlopen-openssl = substituteAll {
           src = ./0006-dlopen-openssl.patch;
-          inherit openssl;
+          openssl = openssl.out;
         };
         dlopen-dbus = substituteAll {
           src = ./0007-dlopen-dbus.patch;
-          dbus_libs = dbus;
+          dbus_libs = dbus.lib;
         };
         xdg-config-dirs = ./0008-xdg-config-dirs.patch;
         decrypt-ssl-traffic = ./0009-decrypt-ssl-traffic.patch;
         mkspecs-libgl = substituteAll {
           src = ./0010-mkspecs-libgl.patch;
-          inherit mesa;
+          mesa_inc = mesa.dev;
+          mesa_lib = mesa.out;
         };
         nix-profiles-library-paths = ./0011-nix-profiles-library-paths.patch;
     in [
@@ -181,11 +184,11 @@ stdenv.mkDerivation {
   # PostgreSQL autodetection fails sporadically because Qt omits the "-lpq" flag
   # if dependency paths contain the string "pq", which can occur in the hash.
   # To prevent these failures, we need to override PostgreSQL detection.
-  PSQL_LIBS = optionalString (postgresql != null) "-L${postgresql}/lib -lpq";
+  PSQL_LIBS = optionalString (postgresql != null) "-L${postgresql.lib}/lib -lpq";
 
   propagatedBuildInputs = [
     xlibs.libXcomposite libX11 libxcb libXext libXrender libXi
-    fontconfig freetype openssl dbus.libs glib udev libxml2 libxslt pcre
+    fontconfig freetype openssl dbus glib udev libxml2 libxslt pcre
     zlib libjpeg libpng libtiff sqlite icu
     xcbutil xcbutilimage xcbutilkeysyms xcbutilwm libxkbcommon
   ]
diff --git a/pkgs/development/libraries/qt-5/5.5/qtserialport/0001-dlopen-serialport-udev.patch b/pkgs/development/libraries/qt-5/5.5/qtserialport/0001-dlopen-serialport-udev.patch
index 6636cc9265a..3a813dc8007 100644
--- a/pkgs/development/libraries/qt-5/5.5/qtserialport/0001-dlopen-serialport-udev.patch
+++ b/pkgs/development/libraries/qt-5/5.5/qtserialport/0001-dlopen-serialport-udev.patch
@@ -16,10 +16,10 @@ index 6f2cabd..81b9849 100644
  {
      if (!udevLibrary->isLoaded()) {
 -        udevLibrary->setFileNameAndVersion(QStringLiteral("udev"), 1);
-+        udevLibrary->setFileNameAndVersion(QStringLiteral("@udev@/lib/libudev"), 1);
++        udevLibrary->setFileNameAndVersion(QStringLiteral("@libudev@/lib/libudev"), 1);
          if (!udevLibrary->load()) {
 -            udevLibrary->setFileNameAndVersion(QStringLiteral("udev"), 0);
-+            udevLibrary->setFileNameAndVersion(QStringLiteral("@udev@/lib/libudev"), 0);
++            udevLibrary->setFileNameAndVersion(QStringLiteral("@libudev@/lib/libudev"), 0);
              if (!udevLibrary->load()) {
                  qWarning("Failed to load the library: %s, supported version(s): %i and %i", qPrintable(udevLibrary->fileName()), 1, 0);
                  return false;
diff --git a/pkgs/development/libraries/qt-5/5.5/qtserialport/default.nix b/pkgs/development/libraries/qt-5/5.5/qtserialport/default.nix
index fa7383fc1e7..32549c95344 100644
--- a/pkgs/development/libraries/qt-5/5.5/qtserialport/default.nix
+++ b/pkgs/development/libraries/qt-5/5.5/qtserialport/default.nix
@@ -1,7 +1,12 @@
-{ qtSubmodule, qtbase }:
+{ qtSubmodule, qtbase, substituteAll, libudev }:
 
 qtSubmodule {
   name = "qtserialport";
   qtInputs = [ qtbase ];
-  patches = [ ./0001-dlopen-serialport-udev.patch ];
+  patches = [
+    (substituteAll {
+      src = ./0001-dlopen-serialport-udev.patch;
+      libudev = libudev.out;
+    })
+  ];
 }
diff --git a/pkgs/development/libraries/qt-5/5.5/qtwebkit/0003-dlopen-webkit-udev.patch b/pkgs/development/libraries/qt-5/5.5/qtwebkit/0003-dlopen-webkit-udev.patch
index f3b9d407bd7..1c360cd81aa 100644
--- a/pkgs/development/libraries/qt-5/5.5/qtwebkit/0003-dlopen-webkit-udev.patch
+++ b/pkgs/development/libraries/qt-5/5.5/qtwebkit/0003-dlopen-webkit-udev.patch
@@ -16,13 +16,13 @@ index 60ff317..da8ac69 100644
      {
          m_libUdev.setLoadHints(QLibrary::ResolveAllSymbolsHint);
 -        m_libUdev.setFileNameAndVersion(QStringLiteral("udev"), 1);
-+        m_libUdev.setFileNameAndVersion(QStringLiteral("@udev@/lib/libudev"), 1);
++        m_libUdev.setFileNameAndVersion(QStringLiteral("@libudev@/lib/libudev"), 1);
          m_loaded = m_libUdev.load();
          if (resolveMethods())
              return true;
  
 -        m_libUdev.setFileNameAndVersion(QStringLiteral("udev"), 0);
-+        m_libUdev.setFileNameAndVersion(QStringLiteral("@udev@/lib/libudev"), 0);
++        m_libUdev.setFileNameAndVersion(QStringLiteral("@libudev@/lib/libudev"), 0);
          m_loaded = m_libUdev.load();
          return resolveMethods();
      }
diff --git a/pkgs/development/libraries/qt-5/5.5/qtwebkit/default.nix b/pkgs/development/libraries/qt-5/5.5/qtwebkit/default.nix
index 596c02d39af..2e92391f4c0 100644
--- a/pkgs/development/libraries/qt-5/5.5/qtwebkit/default.nix
+++ b/pkgs/development/libraries/qt-5/5.5/qtwebkit/default.nix
@@ -1,6 +1,6 @@
 { qtSubmodule, stdenv, qtdeclarative, qtlocation, qtmultimedia, qtsensors
 , fontconfig, gdk_pixbuf, gtk, libwebp, libxml2, libxslt
-, sqlite, udev
+, sqlite, libudev
 , bison2, flex, gdb, gperf, perl, pkgconfig, python, ruby
 , substituteAll
 , flashplayerFix ? false
@@ -18,15 +18,16 @@ qtSubmodule {
   patches =
     let dlopen-webkit-nsplugin = substituteAll {
           src = ./0001-dlopen-webkit-nsplugin.patch;
-          inherit gtk gdk_pixbuf;
+          gtk = gtk.out;
+          gdk_pixbuf = gdk_pixbuf.out;
         };
         dlopen-webkit-gtk = substituteAll {
           src = ./0002-dlopen-webkit-gtk.patch;
-          inherit gtk;
+          gtk = gtk.out;
         };
         dlopen-webkit-udev = substituteAll {
           src = ./0003-dlopen-webkit-udev.patch;
-          inherit udev;
+          libudev = libudev.out;
         };
     in optionals flashplayerFix [ dlopen-webkit-nsplugin dlopen-webkit-gtk ]
     ++ [ dlopen-webkit-udev ];
diff --git a/pkgs/development/libraries/rdkafka/default.nix b/pkgs/development/libraries/rdkafka/default.nix
index 947b06021cd..32fff70ebfb 100644
--- a/pkgs/development/libraries/rdkafka/default.nix
+++ b/pkgs/development/libraries/rdkafka/default.nix
@@ -12,6 +12,8 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ zlib perl ];
 
+  NIX_CFLAGS_COMPILE = "-Wno-error=strict-overflow";
+
   postPatch = ''
     patchShebangs .
   '';
diff --git a/pkgs/development/libraries/readline/6.3.nix b/pkgs/development/libraries/readline/6.3.nix
index f770fabb35d..11d4271b168 100644
--- a/pkgs/development/libraries/readline/6.3.nix
+++ b/pkgs/development/libraries/readline/6.3.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "0hzxr9jxqqx5sxsv9vmlxdnvlr9vi4ih1avjb869hbs6p5qn1fjn";
   };
 
+  outputs = [ "dev" "out" "doc" ];
+
   propagatedBuildInputs = [ncurses];
 
   patchFlags = "-p0";
diff --git a/pkgs/development/libraries/schroedinger/default.nix b/pkgs/development/libraries/schroedinger/default.nix
index 33f5ba867d6..2df7d051894 100644
--- a/pkgs/development/libraries/schroedinger/default.nix
+++ b/pkgs/development/libraries/schroedinger/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl, orc, pkgconfig}:
+{ stdenv, fetchurl, orc, pkgconfig }:
 
 stdenv.mkDerivation {
   name = "schroedinger-1.0.11";
@@ -11,16 +11,12 @@ stdenv.mkDerivation {
     sha256 = "04prr667l4sn4zx256v1z36a0nnkxfdqyln48rbwlamr6l3jlmqy";
   };
 
-  buildInputs = [orc pkgconfig];
+  outputs = [ "dev" "out" "docdev" ];
 
-  # The test suite is known not to build against Orc >0.4.16 in Schroedinger 1.0.11.
-  # A fix is in upstream, so test when pulling 1.0.12 if this is still needed. See:
-  # http://www.mail-archive.com/schrodinger-devel@lists.sourceforge.net/msg00415.html
-  preBuild = ''
-    substituteInPlace Makefile \
-      --replace "SUBDIRS = schroedinger doc tools testsuite" "SUBDIRS = schroedinger doc tools" \
-      --replace "DIST_SUBDIRS = schroedinger doc tools testsuite" "DIST_SUBDIRS = schroedinger doc tools"
-  '';
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ orc ];
+
+  doCheck = true;
 
   meta = with stdenv.lib; {
     homepage = "http://diracvideo.org/";
diff --git a/pkgs/development/libraries/scmccid/default.nix b/pkgs/development/libraries/scmccid/default.nix
index 7dcde2a09a8..f9845d60b49 100644
--- a/pkgs/development/libraries/scmccid/default.nix
+++ b/pkgs/development/libraries/scmccid/default.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ patchelf ];
 
   installPhase = ''
-    RPATH=${libusb}/lib:${stdenv.cc.libc}/lib
+    RPATH=${libusb}/lib:${stdenv.cc.libc.out}/lib
 
     for a in proprietary/*/Contents/Linux/*.so*; do
         if ! test -L $a; then
diff --git a/pkgs/development/libraries/slang/default.nix b/pkgs/development/libraries/slang/default.nix
index bf1f38fbb83..e83718673aa 100644
--- a/pkgs/development/libraries/slang/default.nix
+++ b/pkgs/development/libraries/slang/default.nix
@@ -7,20 +7,29 @@ stdenv.mkDerivation rec {
     sha256 = "0aqd2cjabj6nhd4r3dc4vhqif2bf3dmqnrn2gj0xm4gqyfd177jy";
   };
 
+  outputs = [ "dev" "out" "doc" ];
+
   # Fix some wrong hardcoded paths
   preConfigure = ''
-    sed -i -e "s|/usr/lib/terminfo|${ncurses}/lib/terminfo|" configure
-    sed -i -e "s|/usr/lib/terminfo|${ncurses}/lib/terminfo|" src/sltermin.c
+    sed -i -e "s|/usr/lib/terminfo|${ncurses.out}/lib/terminfo|" configure
+    sed -i -e "s|/usr/lib/terminfo|${ncurses.out}/lib/terminfo|" src/sltermin.c
     sed -i -e "s|/bin/ln|ln|" src/Makefile.in
+    sed -i -e "s|-ltermcap|-lncurses|" ./configure
   '';
   configureFlags = "--with-png=${libpng} --with-z=${zlib} --with-pcre=${pcre} --with-readline=${readline}";
-  buildInputs = [ncurses pcre libpng zlib readline];
+  buildInputs = [ pcre libpng zlib readline ];
+  propagatedBuildInputs = [ ncurses ];
+
+  postInstall = ''
+    find "$out"/lib/ -name '*.so' -exec chmod +x "{}" \;
+    sed '/^Libs:/s/$/ -lncurses/' -i "$dev"/lib/pkgconfig/slang.pc
+  '';
 
-  meta = {
+  meta = with stdenv.lib; {
     description = "A multi-platform programmer's library designed to allow a developer to create robust software";
     homepage = http://www.jedsoft.org/slang/;
-    license = stdenv.lib.licenses.gpl2Plus;
-    platforms = stdenv.lib.platforms.unix;
-    maintainers = with stdenv.lib.maintainers; [ fuuzetsu ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.unix;
+    maintainers = [ maintainers.fuuzetsu ];
   };
 }
diff --git a/pkgs/development/libraries/smpeg/default.nix b/pkgs/development/libraries/smpeg/default.nix
index c2473ae2c5d..2f300abebbf 100644
--- a/pkgs/development/libraries/smpeg/default.nix
+++ b/pkgs/development/libraries/smpeg/default.nix
@@ -31,7 +31,7 @@ stdenv.mkDerivation rec {
 
     wrapProgram $out/bin/smpeg-config \
       --prefix PATH ":" "${pkgconfig}/bin" \
-      --prefix PKG_CONFIG_PATH ":" "${SDL}/lib/pkgconfig"
+      --prefix PKG_CONFIG_PATH ":" "${SDL.dev}/lib/pkgconfig"
   '';
 
   meta = {
diff --git a/pkgs/development/libraries/socket_wrapper/default.nix b/pkgs/development/libraries/socket_wrapper/default.nix
index 0c6f40c8b14..bff4f393d1d 100644
--- a/pkgs/development/libraries/socket_wrapper/default.nix
+++ b/pkgs/development/libraries/socket_wrapper/default.nix
@@ -9,6 +9,7 @@ stdenv.mkDerivation rec {
   };
 
   nativeBuildInputs = [ cmake pkgconfig ];
+  buildInputs = [ (stdenv.cc.libc.out or null) ];
 
   meta = with stdenv.lib; {
     description = "a library passing all socket communications through unix sockets";
diff --git a/pkgs/development/libraries/speex/default.nix b/pkgs/development/libraries/speex/default.nix
index 9a1c00e63b9..8e3cf899e40 100644
--- a/pkgs/development/libraries/speex/default.nix
+++ b/pkgs/development/libraries/speex/default.nix
@@ -2,7 +2,7 @@
 
 stdenv.mkDerivation rec {
   name = "speex-1.2rc2";
-  
+
   src = fetchurl {
     url = "http://downloads.us.xiph.org/releases/speex/${name}.tar.gz";
     sha256 = "14g8ph39inkrif749lzjm089g7kwk0hymq1a3i9ch5gz8xr7r8na";
@@ -11,7 +11,9 @@ stdenv.mkDerivation rec {
   postPatch = ''
     sed -i '/AC_CONFIG_MACRO_DIR/i PKG_PROG_PKG_CONFIG' configure.ac
   '';
-  
+
+  outputs = [ "dev" "out" "doc" ];
+
   nativeBuildInputs = [ autoreconfHook pkgconfig ];
   buildInputs = [ fftw speexdsp ];
 
diff --git a/pkgs/development/libraries/speexdsp/default.nix b/pkgs/development/libraries/speexdsp/default.nix
index 7112afbea8a..56b1900837a 100644
--- a/pkgs/development/libraries/speexdsp/default.nix
+++ b/pkgs/development/libraries/speexdsp/default.nix
@@ -11,6 +11,8 @@ stdenv.mkDerivation rec {
   patches = [ ./build-fix.patch ];
   postPatch = "sed '3i#include <stdint.h>' -i ./include/speex/speexdsp_config_types.h.in";
 
+  outputs = [ "dev" "out" "doc" ];
+
   nativeBuildInputs = [ autoreconfHook pkgconfig ];
   buildInputs = [ fftw ];
 
diff --git a/pkgs/development/libraries/sqlite/default.nix b/pkgs/development/libraries/sqlite/default.nix
index d9fbde9aa09..1a623819273 100644
--- a/pkgs/development/libraries/sqlite/default.nix
+++ b/pkgs/development/libraries/sqlite/default.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation {
     sha1 = "dae1ae5297fece9671ae0c434a7ecd0cda09c76a";
   };
 
+  outputs = [ "dev" "out" "bin" ];
+
   buildInputs = lib.optionals interactive [ readline ncurses ];
 
   configureFlags = [ "--enable-threadsafe" ];
diff --git a/pkgs/development/libraries/uid_wrapper/default.nix b/pkgs/development/libraries/uid_wrapper/default.nix
index 35d7f53173f..0675ec68b4e 100644
--- a/pkgs/development/libraries/uid_wrapper/default.nix
+++ b/pkgs/development/libraries/uid_wrapper/default.nix
@@ -9,6 +9,7 @@ stdenv.mkDerivation rec {
   };
 
   nativeBuildInputs = [ cmake pkgconfig ];
+  buildInputs = [ (stdenv.cc.libc.out or null) ];
 
   meta = with stdenv.lib; {
     description = "a wrapper for the user, group and hosts NSS API";
diff --git a/pkgs/development/libraries/webkitgtk/2.4.nix b/pkgs/development/libraries/webkitgtk/2.4.nix
index 8ad3fcd0428..607c706fdb5 100644
--- a/pkgs/development/libraries/webkitgtk/2.4.nix
+++ b/pkgs/development/libraries/webkitgtk/2.4.nix
@@ -1,7 +1,7 @@
 { stdenv, fetchurl, perl, python, ruby, bison, gperf, flex
 , pkgconfig, which, gettext, gobjectIntrospection
 , gtk2, gtk3, wayland, libwebp, enchant, sqlite
-, libxml2, libsoup, libsecret, libxslt, harfbuzz
+, libxml2, libsoup, libsecret, libxslt, harfbuzz, xorg
 , gst-plugins-base
 , withGtk2 ? false
 , enableIntrospection ? true
@@ -49,7 +49,7 @@ stdenv.mkDerivation rec {
   buildInputs = [
     gtk2 wayland libwebp enchant
     libxml2 libsecret libxslt
-    gst-plugins-base sqlite
+    gst-plugins-base sqlite xorg.libXt
   ];
 
   propagatedBuildInputs = [
diff --git a/pkgs/development/libraries/webkitgtk/default.nix b/pkgs/development/libraries/webkitgtk/default.nix
index 4df1ba71c11..3637bec63ce 100644
--- a/pkgs/development/libraries/webkitgtk/default.nix
+++ b/pkgs/development/libraries/webkitgtk/default.nix
@@ -2,7 +2,7 @@
 , pkgconfig, gettext, gobjectIntrospection, libnotify
 , gtk2, gtk3, wayland, libwebp, enchant
 , libxml2, libsoup, libsecret, libxslt, harfbuzz, libpthreadstubs
-, enableGeoLocation ? true, geoclue2, sqlite
+, enableGeoLocation ? true, geoclue2, sqlite, xorg
 , gst-plugins-base
 }:
 
@@ -44,7 +44,7 @@ stdenv.mkDerivation rec {
   buildInputs = [
     gtk2 wayland libwebp enchant libnotify
     libxml2 libsecret libxslt harfbuzz libpthreadstubs
-    gst-plugins-base
+    gst-plugins-base xorg.libXt
   ] ++ optional enableGeoLocation geoclue2;
 
   propagatedBuildInputs = [
diff --git a/pkgs/development/libraries/wildmidi/default.nix b/pkgs/development/libraries/wildmidi/default.nix
index 8660d15e06a..4dec0555ae9 100644
--- a/pkgs/development/libraries/wildmidi/default.nix
+++ b/pkgs/development/libraries/wildmidi/default.nix
@@ -10,7 +10,7 @@ stdenv.mkDerivation rec {
 
   nativeBuildInputs = [ cmake ];
 
-  buildInputs = [ alsaLib ];
+  buildInputs = [ alsaLib stdenv.cc.libc/*couldn't find libm*/ ];
 
   preConfigure = ''
     substituteInPlace CMakeLists.txt \
diff --git a/pkgs/development/libraries/wxGTK-2.8/default.nix b/pkgs/development/libraries/wxGTK-2.8/default.nix
index d7ca92f70d9..90cc1d995a5 100644
--- a/pkgs/development/libraries/wxGTK-2.8/default.nix
+++ b/pkgs/development/libraries/wxGTK-2.8/default.nix
@@ -33,10 +33,10 @@ stdenv.mkDerivation rec {
 
   # These variables are used by configure to find some dependencies.
   SEARCH_INCLUDE =
-    "${libXinerama}/include ${libSM}/include ${libXxf86vm}/include";
+    "${libXinerama.dev}/include ${libSM.dev}/include ${libXxf86vm.dev}/include";
   SEARCH_LIB =
-    "${libXinerama}/lib ${libSM}/lib ${libXxf86vm}/lib "
-    + optionalString withMesa "${mesa}/lib ";
+    "${libXinerama.out}/lib ${libSM.out}/lib ${libXxf86vm.out}/lib "
+    + optionalString withMesa "${mesa.out}/lib ";
 
   # Work around a bug in configure.
   NIX_CFLAGS_COMPILE = "-DHAVE_X11_XLIB_H=1";
diff --git a/pkgs/development/libraries/x264/default.nix b/pkgs/development/libraries/x264/default.nix
index 6c541f1aa68..26e32314503 100644
--- a/pkgs/development/libraries/x264/default.nix
+++ b/pkgs/development/libraries/x264/default.nix
@@ -13,6 +13,8 @@ stdenv.mkDerivation rec {
     sed -i s,/bin/bash,${stdenv.shell}, configure version.sh
   '';
 
+  outputs = [ "out" "lib" ]; # leaving 52 kB of headers
+
   configureFlags = [ "--enable-shared" ]
     ++ stdenv.lib.optional (!stdenv.isi686) "--enable-pic"
     ++ stdenv.lib.optional (enable10bit) "--bit-depth=10";
diff --git a/pkgs/development/libraries/x265/default.nix b/pkgs/development/libraries/x265/default.nix
index 1598fec6194..1feba886764 100644
--- a/pkgs/development/libraries/x265/default.nix
+++ b/pkgs/development/libraries/x265/default.nix
@@ -46,6 +46,8 @@ stdenv.mkDerivation rec {
 
   nativeBuildInputs = [ cmake yasm ];
 
+  NIX_LDFLAGS = "-L${stdenv.cc.libc.out}/lib"; #outputs TODO: this is strange
+
   meta = with stdenv.lib; {
     description = "Library for encoding h.265/HEVC video streams";
     homepage    = http://x265.org;
diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix
index 93474d14344..9fe45996b10 100644
--- a/pkgs/development/libraries/zlib/default.nix
+++ b/pkgs/development/libraries/zlib/default.nix
@@ -2,7 +2,7 @@
 
 let version = "1.2.8"; in
 
-stdenv.mkDerivation (rec {
+stdenv.mkDerivation rec {
   name = "zlib-${version}";
 
   src = fetchurl {
@@ -20,15 +20,31 @@ stdenv.mkDerivation (rec {
       --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"'
   '';
 
-  configureFlags = if static then "" else "--shared";
+  outputs = [ "dev" "out" "static" ];
+  setOutputFlags = false;
+  outputDoc = "dev"; # single tiny man3 page
+
 
   preConfigure = ''
     if test -n "$crossConfig"; then
       export CC=$crossConfig-gcc
-      configureFlags=${if static then "" else "--shared"}
     fi
   '';
 
+  configureFlags = stdenv.lib.optional (!static) "--shared";
+
+  postInstall = ''
+    moveToOutput lib/libz.a "$static"
+  ''
+    # jww (2015-01-06): Sometimes this library install as a .so, even on
+    # Darwin; others time it installs as a .dylib.  I haven't yet figured out
+    # what causes this difference.
+  + stdenv.lib.optionalString stdenv.isDarwin ''
+    for file in $out/lib/*.so* $out/lib/*.dylib* ; do
+      install_name_tool -id "$file" $file
+    done
+  '';
+
   # As zlib takes part in the stdenv building, we don't want references
   # to the bootstrap-tools libgcc (as uses to happen on arm/mips)
   NIX_CFLAGS_COMPILE = stdenv.lib.optionalString (!stdenv.isDarwin) "-static-libgcc";
@@ -57,13 +73,5 @@ stdenv.mkDerivation (rec {
     license = licenses.zlib;
     platforms = platforms.all;
   };
-} // (if stdenv.isDarwin then {
-  postInstall = ''
-    # jww (2015-01-06): Sometimes this library install as a .so, even on
-    # Darwin; others time it installs as a .dylib.  I haven't yet figured out
-    # what causes this difference.
-    for file in $out/lib/*.so* $out/lib/*.dylib* ; do
-      install_name_tool -id "$file" $file
-    done
-  '';
-} else {}))
+}
+
diff --git a/pkgs/development/mobile/androidenv/androidndk.nix b/pkgs/development/mobile/androidenv/androidndk.nix
index 595c98f76aa..0ae5fc3b540 100644
--- a/pkgs/development/mobile/androidenv/androidndk.nix
+++ b/pkgs/development/mobile/androidenv/androidndk.nix
@@ -54,8 +54,8 @@ stdenv.mkDerivation rec {
     find $out \( \
         \( -type f -a -name "*.so*" \) -o \
         \( -type f -a -perm -0100 \) \
-        \) -exec patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-*so.? \
-                          --set-rpath ${zlib}/lib:${ncurses}/lib {} \;
+        \) -exec patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-*so.? \
+                          --set-rpath ${stdenv.lib.makeLibraryPath [ zlib ncurses ]} {} \;
     # fix ineffective PROGDIR / MYNDKDIR determination
     for i in ndk-build ndk-gdb ndk-gdb-py
     do
diff --git a/pkgs/development/mobile/androidenv/androidndk_r8e.nix b/pkgs/development/mobile/androidenv/androidndk_r8e.nix
index 90994ae708e..d3f66c918ec 100644
--- a/pkgs/development/mobile/androidenv/androidndk_r8e.nix
+++ b/pkgs/development/mobile/androidenv/androidndk_r8e.nix
@@ -54,7 +54,7 @@ stdenv.mkDerivation rec {
     find $out \( \
         \( -type f -a -name "*.so*" \) -o \
         \( -type f -a -perm -0100 \) \
-        \) -exec patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-*so.? \
+        \) -exec patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-*so.? \
                           --set-rpath ${zlib}/lib:${ncurses}/lib {} \;
     # fix ineffective PROGDIR / MYNDKDIR determination
     for i in ndk-build ndk-gdb ndk-gdb-py
diff --git a/pkgs/development/mobile/androidenv/androidsdk.nix b/pkgs/development/mobile/androidenv/androidsdk.nix
index 02c1546ace7..eb0c4295bcd 100644
--- a/pkgs/development/mobile/androidenv/androidsdk.nix
+++ b/pkgs/development/mobile/androidenv/androidsdk.nix
@@ -7,6 +7,8 @@
 }:
 { platformVersions, abiVersions, useGoogleAPIs, useExtraSupportLibs ? false, useGooglePlayServices ? false }:
 
+with { inherit (stdenv.lib) makeLibraryPath; };
+
 stdenv.mkDerivation rec {
   name = "android-sdk-${version}";
   version = "24.4";
@@ -39,7 +41,7 @@ stdenv.mkDerivation rec {
       
       for i in emulator emulator-arm emulator-mips emulator-x86 mksdcard
       do
-          patchelf --set-interpreter ${stdenv_32bit.cc.libc}/lib/ld-linux.so.2 $i
+          patchelf --set-interpreter ${stdenv_32bit.cc.libc.out}/lib/ld-linux.so.2 $i
           patchelf --set-rpath ${stdenv_32bit.cc.cc}/lib $i
       done
       
@@ -48,7 +50,7 @@ stdenv.mkDerivation rec {
         
         for i in emulator64-arm emulator64-mips emulator64-x86
         do
-            patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 $i
+            patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 $i
             patchelf --set-rpath ${stdenv.cc.cc}/lib64 $i
         done
       ''}
@@ -58,7 +60,7 @@ stdenv.mkDerivation rec {
       
       wrapProgram `pwd`/android \
         --prefix PATH : ${jdk}/bin \
-        --prefix LD_LIBRARY_PATH : ${glib}/lib:${gtk}/lib:${libXtst}/lib
+        --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ glib gtk libXtst ]}
     
       wrapProgram `pwd`/uiautomatorviewer \
         --prefix PATH : ${jdk}/bin \
@@ -74,7 +76,7 @@ stdenv.mkDerivation rec {
       do
           wrapProgram `pwd`/$i \
             --prefix PATH : ${file}/bin \
-            --suffix LD_LIBRARY_PATH : `pwd`/lib:${libX11_32bit}/lib:${libxcb_32bit}/lib:${libXau_32bit}/lib:${libXdmcp_32bit}/lib:${libXext_32bit}/lib:${mesa_32bit}/lib
+            --suffix LD_LIBRARY_PATH : `pwd`/lib:${makeLibraryPath [ libX11_32bit libxcb_32bit libXau_32bit libXdmcp_32bit libXext_32bit mesa_32bit ]}
       done
       
       ${stdenv.lib.optionalString (stdenv.system == "x86_64-linux") ''
@@ -82,7 +84,7 @@ stdenv.mkDerivation rec {
         do
             wrapProgram `pwd`/$i \
               --prefix PATH : ${file}/bin \
-              --suffix LD_LIBRARY_PATH : `pwd`/lib:${libX11}/lib:${libxcb}/lib:${libXau}/lib:${libXdmcp}/lib:${libXext}/lib:${mesa}/lib:${alsaLib}/lib
+              --suffix LD_LIBRARY_PATH : `pwd`/lib:${makeLibraryPath [ libX11 libxcb libXau libXdmcp libXext mesa alsaLib ]}
         done
       ''}
     ''}
@@ -94,11 +96,11 @@ stdenv.mkDerivation rec {
         # The monitor requires some more patching
         
         cd lib/monitor-x86
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 monitor
-        patchelf --set-rpath ${libX11}/lib:${libXext}/lib:${libXrender}/lib:${freetype}/lib:${fontconfig}/lib libcairo-swt.so
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux.so.2 monitor
+        patchelf --set-rpath ${makeLibraryPath [ libX11 libXext libXrender freetype fontconfig ]} libcairo-swt.so
         
         wrapProgram `pwd`/monitor \
-          --prefix LD_LIBRARY_PATH : ${gtk}/lib:${atk}/lib:${stdenv.cc.cc}/lib:${libXtst}/lib
+          --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ gtk atk stdenv.cc.cc libXtst ]}
 
         cd ../..
       ''
@@ -107,11 +109,11 @@ stdenv.mkDerivation rec {
         # The monitor requires some more patching
         
         cd lib/monitor-x86_64
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 monitor
-        patchelf --set-rpath ${libX11}/lib:${libXext}/lib:${libXrender}/lib:${freetype}/lib:${fontconfig}/lib libcairo-swt.so
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 monitor
+        patchelf --set-rpath ${makeLibraryPath [ libX11 libXext libXrender freetype fontconfig ]} libcairo-swt.so
         
         wrapProgram `pwd`/monitor \
-          --prefix LD_LIBRARY_PATH : ${gtk}/lib:${atk}/lib:${stdenv.cc.cc}/lib::${libXtst}/lib
+          --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ gtk atk stdenv.cc.cc libXtst ]}
 
         cd ../..
       ''
diff --git a/pkgs/development/mobile/androidenv/build-tools.nix b/pkgs/development/mobile/androidenv/build-tools.nix
index 1b49c8f6fc4..f429a629f31 100644
--- a/pkgs/development/mobile/androidenv/build-tools.nix
+++ b/pkgs/development/mobile/androidenv/build-tools.nix
@@ -26,7 +26,7 @@ stdenv.mkDerivation rec {
         # Patch the interpreter
         for i in aapt aidl bcc_compat dexdump llvm-rs-cc
         do
-            patchelf --set-interpreter ${stdenv_32bit.cc.libc}/lib/ld-linux.so.2 $i
+            patchelf --set-interpreter ${stdenv_32bit.cc.libc.out}/lib/ld-linux.so.2 $i
         done
         
         # These binaries need to find libstdc++ and libgcc_s
@@ -53,7 +53,7 @@ stdenv.mkDerivation rec {
         # These binaries also need zlib in addition to libstdc++
         for i in arm-linux-androideabi-ld i686-linux-android-ld mipsel-linux-android-ld split-select zipalign
         do
-            patchelf --set-interpreter ${stdenv_32bit.cc.libc}/lib/ld-linux.so.2 $i
+            patchelf --set-interpreter ${stdenv_32bit.cc.libc.out}/lib/ld-linux.so.2 $i
             patchelf --set-rpath ${stdenv_32bit.cc.cc}/lib:${zlib_32bit}/lib:`pwd`/lib $i
         done
         
diff --git a/pkgs/development/mobile/androidenv/platform-tools.nix b/pkgs/development/mobile/androidenv/platform-tools.nix
index 1243ba429a3..1654b13d13b 100644
--- a/pkgs/development/mobile/androidenv/platform-tools.nix
+++ b/pkgs/development/mobile/androidenv/platform-tools.nix
@@ -24,7 +24,7 @@ stdenv.mkDerivation rec {
       ''
         for i in adb dmtracedump fastboot hprof-conv sqlite3
         do
-            patchelf --set-interpreter ${stdenv_32bit.cc.libc}/lib/ld-linux.so.2 $i
+            patchelf --set-interpreter ${stdenv_32bit.cc.libc.out}/lib/ld-linux.so.2 $i
             patchelf --set-rpath ${stdenv_32bit.cc.cc}/lib:`pwd`/lib $i
         done
         
diff --git a/pkgs/development/mobile/titaniumenv/titaniumsdk-3.1.nix b/pkgs/development/mobile/titaniumenv/titaniumsdk-3.1.nix
index 60cab19ecbd..0437edad63f 100644
--- a/pkgs/development/mobile/titaniumenv/titaniumsdk-3.1.nix
+++ b/pkgs/development/mobile/titaniumenv/titaniumsdk-3.1.nix
@@ -45,11 +45,11 @@ stdenv.mkDerivation {
     
     ${if stdenv.system == "i686-linux" then
       ''
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 titanium_prep.linux32
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux.so.2 titanium_prep.linux32
       ''
       else if stdenv.system == "x86_64-linux" then
       ''
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 titanium_prep.linux64
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 titanium_prep.linux64
       ''
       else ""}
     
diff --git a/pkgs/development/mobile/titaniumenv/titaniumsdk-3.2.nix b/pkgs/development/mobile/titaniumenv/titaniumsdk-3.2.nix
index 47414e205a0..37ecf62706d 100644
--- a/pkgs/development/mobile/titaniumenv/titaniumsdk-3.2.nix
+++ b/pkgs/development/mobile/titaniumenv/titaniumsdk-3.2.nix
@@ -44,11 +44,11 @@ stdenv.mkDerivation {
     
     ${if stdenv.system == "i686-linux" then
       ''
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 titanium_prep.linux32
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux.so.2 titanium_prep.linux32
       ''
       else if stdenv.system == "x86_64-linux" then
       ''
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 titanium_prep.linux64
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 titanium_prep.linux64
       ''
       else ""}
     
diff --git a/pkgs/development/mobile/titaniumenv/titaniumsdk-3.3.nix b/pkgs/development/mobile/titaniumenv/titaniumsdk-3.3.nix
index 59a405f61fa..b5f1c6c5312 100644
--- a/pkgs/development/mobile/titaniumenv/titaniumsdk-3.3.nix
+++ b/pkgs/development/mobile/titaniumenv/titaniumsdk-3.3.nix
@@ -44,11 +44,11 @@ stdenv.mkDerivation {
     
     ${if stdenv.system == "i686-linux" then
       ''
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 titanium_prep.linux32
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux.so.2 titanium_prep.linux32
       ''
       else if stdenv.system == "x86_64-linux" then
       ''
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 titanium_prep.linux64
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 titanium_prep.linux64
       ''
       else ""}
     
diff --git a/pkgs/development/mobile/titaniumenv/titaniumsdk-3.4.nix b/pkgs/development/mobile/titaniumenv/titaniumsdk-3.4.nix
index 041ba0d4a6c..a927a74729a 100644
--- a/pkgs/development/mobile/titaniumenv/titaniumsdk-3.4.nix
+++ b/pkgs/development/mobile/titaniumenv/titaniumsdk-3.4.nix
@@ -44,11 +44,11 @@ stdenv.mkDerivation {
     
     ${if stdenv.system == "i686-linux" then
       ''
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 titanium_prep.linux32
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux.so.2 titanium_prep.linux32
       ''
       else if stdenv.system == "x86_64-linux" then
       ''
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 titanium_prep.linux64
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 titanium_prep.linux64
       ''
       else ""}
     
diff --git a/pkgs/development/mobile/titaniumenv/titaniumsdk-3.5.nix b/pkgs/development/mobile/titaniumenv/titaniumsdk-3.5.nix
index f9c5ce8812f..3fa119dda65 100644
--- a/pkgs/development/mobile/titaniumenv/titaniumsdk-3.5.nix
+++ b/pkgs/development/mobile/titaniumenv/titaniumsdk-3.5.nix
@@ -44,11 +44,11 @@ stdenv.mkDerivation {
     
     ${if stdenv.system == "i686-linux" then
       ''
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 titanium_prep.linux32
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux.so.2 titanium_prep.linux32
       ''
       else if stdenv.system == "x86_64-linux" then
       ''
-        patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 titanium_prep.linux64
+        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 titanium_prep.linux64
       ''
       else ""}
     
diff --git a/pkgs/development/ocaml-modules/expat/default.nix b/pkgs/development/ocaml-modules/expat/default.nix
index f4837bd047f..b6ee0d192e3 100644
--- a/pkgs/development/ocaml-modules/expat/default.nix
+++ b/pkgs/development/ocaml-modules/expat/default.nix
@@ -28,8 +28,8 @@ stdenv.mkDerivation {
   postPatch = ''
     substituteInPlace "unittest.ml" \
       --replace "/home/maas/xml-samples/REC-xml-19980210.xml.txt" "${testcase}"
-    substituteInPlace Makefile --replace "EXPAT_LIBDIR=/usr/local/lib" "EXPAT_LIBDIR=${expat}/lib" \
-    substituteInPlace Makefile --replace "EXPAT_INCDIR=/usr/local/include" "EXPAT_INCDIR=${expat}/include" \
+    substituteInPlace Makefile --replace "EXPAT_LIBDIR=/usr/local/lib" "EXPAT_LIBDIR=${expat.out}/lib" \
+    substituteInPlace Makefile --replace "EXPAT_INCDIR=/usr/local/include" "EXPAT_INCDIR=${expat.dev}/include" \
   '';
 
   configurePhase = "true";  	# Skip configure
diff --git a/pkgs/development/perl-modules/DBD-SQLite/default.nix b/pkgs/development/perl-modules/DBD-SQLite/default.nix
index 985e7946b6b..13b633f4704 100644
--- a/pkgs/development/perl-modules/DBD-SQLite/default.nix
+++ b/pkgs/development/perl-modules/DBD-SQLite/default.nix
@@ -17,6 +17,10 @@ buildPerlPackage rec {
     ./external-sqlite.patch
   ];
 
+  sqlite_dev = sqlite.dev;
+  sqlite_out = sqlite.out;
+  postPatch = "substituteAllInPlace Makefile.PL; cat Makefile.PL";
+
   preBuild =
     ''
       substituteInPlace Makefile --replace -L/usr/lib ""
diff --git a/pkgs/development/perl-modules/DBD-SQLite/external-sqlite.patch b/pkgs/development/perl-modules/DBD-SQLite/external-sqlite.patch
index 9a20fa25039..1f90546b252 100644
--- a/pkgs/development/perl-modules/DBD-SQLite/external-sqlite.patch
+++ b/pkgs/development/perl-modules/DBD-SQLite/external-sqlite.patch
@@ -1,39 +1,33 @@
-diff -rc DBD-SQLite-1.29/Makefile.PL DBD-SQLite-1.29-new/Makefile.PL
-*** DBD-SQLite-1.29/Makefile.PL	2010-01-08 10:08:29.000000000 +0100
---- DBD-SQLite-1.29-new/Makefile.PL	2010-08-05 11:42:53.000000000 +0200
-***************
-*** 123,129 ****
-  # a system sqlite is also sophisticated enough to have a patching system
-  # that can change the if ( 0 ) to if ( 1 )
-  my ($sqlite_local, $sqlite_base, $sqlite_lib, $sqlite_inc);
-! if ( 0 ) {
-  	require File::Spec;
-  	if ( $sqlite_base = (grep(/SQLITE_LOCATION=.*/, @ARGV))[0] ) {
-  		$sqlite_base =~ /=(.*)/;
---- 123,129 ----
-  # a system sqlite is also sophisticated enough to have a patching system
-  # that can change the if ( 0 ) to if ( 1 )
-  my ($sqlite_local, $sqlite_base, $sqlite_lib, $sqlite_inc);
-! if ( 1 ) {
-  	require File::Spec;
-  	if ( $sqlite_base = (grep(/SQLITE_LOCATION=.*/, @ARGV))[0] ) {
-  		$sqlite_base =~ /=(.*)/;
-***************
-*** 184,191 ****
-  } else {
-  	# Always the bundled one.
-  	# XXX: ... and this message should be more informative.
-! 	$sqlite_local = 1;
-! 	print "We're using the bundled sqlite library.\n" if $ENV{AUTOMATED_TESTING};
-  }
-  
-  @ARGV = grep( ! /SQLITE_LOCATION|USE_LOCAL_SQLITE/, @ARGV );
---- 184,191 ----
-  } else {
-  	# Always the bundled one.
-  	# XXX: ... and this message should be more informative.
-! #	$sqlite_local = 1;
-! #	print "We're using the bundled sqlite library.\n" if $ENV{AUTOMATED_TESTING};
-  }
-  
-  @ARGV = grep( ! /SQLITE_LOCATION|USE_LOCAL_SQLITE/, @ARGV );
+diff --git a/Makefile.PL b/Makefile.PL
+index 606b28d..0cea060 100644
+--- a/Makefile.PL
++++ b/Makefile.PL
+@@ -128,24 +128,10 @@ SCOPE: {
+ # the system SQLite. We expect that anyone sophisticated enough to use
+ # a system sqlite is also sophisticated enough to have a patching system
+ # that can change the if ( 0 ) to if ( 1 )
+-my ($sqlite_local, $sqlite_base, $sqlite_lib, $sqlite_inc);
+-if ( 0 ) {
+-	require File::Spec;
+-	if ( $sqlite_base = (grep(/SQLITE_LOCATION=.*/, @ARGV))[0] ) {
+-		$sqlite_base =~ /=(.*)/;
+-		$sqlite_base = $1;
+-		$sqlite_lib = File::Spec->catdir( $sqlite_base, 'lib'     );
+-		$sqlite_inc = File::Spec->catdir( $sqlite_base, 'include' );
+-	}
+-	if ( $sqlite_local = (grep(/USE_LOCAL_SQLITE=.*/, @ARGV))[0] ) {
+-		$sqlite_local =~ /=(.*)/;
+-		$sqlite_local = "$1" ? 1 : 0;
+-		if ( $sqlite_local ) {
+-			# Keep these from making into CFLAGS/LDFLAGS
+-			undef $sqlite_lib;
+-			undef $sqlite_inc;
+-		}
+-	}
++my ($sqlite_local, $sqlite_lib, $sqlite_inc);
++if ( 1 ) {
++		$sqlite_lib = '@sqlite_out@/lib';
++		$sqlite_inc = '@sqlite_dev@/include';
+ 
+ 	# Now check for a compatible sqlite3
+ 	unless ( $sqlite_local ) {
diff --git a/pkgs/development/perl-modules/generic/builder.sh b/pkgs/development/perl-modules/generic/builder.sh
index 7c51bf1b591..9ee8be87c02 100644
--- a/pkgs/development/perl-modules/generic/builder.sh
+++ b/pkgs/development/perl-modules/generic/builder.sh
@@ -28,6 +28,7 @@ preConfigure() {
     perl Makefile.PL PREFIX=$out INSTALLDIRS=site $makeMakerFlags
 }
 
+
 postFixup() {
     # If a user installs a Perl package, she probably also wants its
     # dependencies in the user environment (since Perl modules don't
diff --git a/pkgs/development/perl-modules/generic/default.nix b/pkgs/development/perl-modules/generic/default.nix
index 6cd4134cc9c..91a004a7f68 100644
--- a/pkgs/development/perl-modules/generic/default.nix
+++ b/pkgs/development/perl-modules/generic/default.nix
@@ -1,13 +1,15 @@
 perl:
 
-{ buildInputs ? [], ... } @ attrs:
+{ buildInputs ? [], name, ... } @ attrs:
 
 perl.stdenv.mkDerivation (
   {
+    outputs = [ "out" "docdev" ];
+
     doCheck = true;
-    
+
     checkTarget = "test";
-    
+
     # Prevent CPAN downloads.
     PERL_AUTOINSTALL = "--skipdeps";
 
@@ -23,7 +25,7 @@ perl.stdenv.mkDerivation (
   attrs
   //
   {
-    name = "perl-" + attrs.name;
+    name = "perl-" + name;
     builder = ./builder.sh;
     buildInputs = buildInputs ++ [ perl ];
   }
diff --git a/pkgs/development/python-modules/pygobject/default.nix b/pkgs/development/python-modules/pygobject/default.nix
index 6f713933040..897210a4046 100644
--- a/pkgs/development/python-modules/pygobject/default.nix
+++ b/pkgs/development/python-modules/pygobject/default.nix
@@ -8,7 +8,7 @@ stdenv.mkDerivation rec {
     sha256 = "1f5dfxjnil2glfwxnqr14d2cjfbkghsbsn8n04js2c2icr7iv2pv";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "out" "docdev" ];
 
   configureFlags = "--disable-introspection";
 
diff --git a/pkgs/development/r-modules/default.nix b/pkgs/development/r-modules/default.nix
index 14be68988f8..e393d92b02f 100644
--- a/pkgs/development/r-modules/default.nix
+++ b/pkgs/development/r-modules/default.nix
@@ -2260,7 +2260,7 @@ let
 
     xml2 = old.xml2.overrideDerivation (attrs: {
       preConfigure = ''
-        export LIBXML_INCDIR=${pkgs.libxml2}/include/libxml2
+        export LIBXML_INCDIR=${pkgs.libxml2.dev}/include/libxml2
         patchShebangs configure
         '';
     });
diff --git a/pkgs/development/tools/build-managers/cargo/snapshot.nix b/pkgs/development/tools/build-managers/cargo/snapshot.nix
index ad07148815b..8f5467f6311 100644
--- a/pkgs/development/tools/build-managers/cargo/snapshot.nix
+++ b/pkgs/development/tools/build-managers/cargo/snapshot.nix
@@ -38,7 +38,7 @@ stdenv.mkDerivation {
     mkdir -p "$out"
     ./install.sh "--prefix=$out"
   '' + (if stdenv.isLinux then ''
-    patchelf --interpreter "${stdenv.glibc}/lib/${stdenv.cc.dynamicLinker}" \
+    patchelf --interpreter "${stdenv.glibc.out}/lib/${stdenv.cc.dynamicLinker}" \
              --set-rpath "${stdenv.cc.cc}/lib/:${stdenv.cc.cc}/lib64/:${zlib}/lib" \
              "$out/bin/cargo"
   '' else "") + postInstall;
diff --git a/pkgs/development/tools/build-managers/cmake/2.8.nix b/pkgs/development/tools/build-managers/cmake/2.8.nix
index 60a941a6637..80fdce59607 100644
--- a/pkgs/development/tools/build-managers/cmake/2.8.nix
+++ b/pkgs/development/tools/build-managers/cmake/2.8.nix
@@ -47,8 +47,9 @@ stdenv.mkDerivation rec {
 
   propagatedBuildInputs = optional wantPS ps;
 
-  CMAKE_PREFIX_PATH = stdenv.lib.concatStringsSep ":" buildInputs;
-  
+  CMAKE_PREFIX_PATH = stdenv.lib.concatStringsSep ":"
+    (concatMap (p: [ p p.out ]) buildInputs);
+
   configureFlags =
     "--docdir=/share/doc/${name} --mandir=/share/man --system-libs"
     + stdenv.lib.optionalString useQt4 " --qt-gui";
diff --git a/pkgs/development/tools/build-managers/cmake/default.nix b/pkgs/development/tools/build-managers/cmake/default.nix
index 09e54d3dfa6..f97b7b432ea 100644
--- a/pkgs/development/tools/build-managers/cmake/default.nix
+++ b/pkgs/development/tools/build-managers/cmake/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl
+{ stdenv, fetchurl, pkgconfig
 , bzip2, curl, expat, libarchive, xz, zlib
 , useNcurses ? false, ncurses, useQt4 ? false, qt4
 , wantPS ? false, ps ? null
@@ -25,26 +25,34 @@ stdenv.mkDerivation rec {
     sha256 = "1shwim3gfdybjx9f11ykxz5l09rh58vmvz8ip76q3i76mkv2pf55";
   };
 
-  enableParallelBuilding = true;
-
   patches =
     # Don't search in non-Nix locations such as /usr, but do search in
     # Nixpkgs' Glibc.
     optional (stdenv ? glibc) ./search-path-3.2.patch
     ++ optional stdenv.isCygwin ./3.2.2-cygwin.patch;
 
+  outputs = [ "out" "doc" ];
+  setOutputFlags = false;
+
+  setupHook = ./setup-hook.sh;
+
   buildInputs =
-    [ bzip2 curl expat libarchive xz zlib ]
+    [ setupHook pkgconfig bzip2 curl expat libarchive xz zlib ]
     ++ optional useNcurses ncurses
     ++ optional useQt4 qt4;
 
   propagatedBuildInputs = optional wantPS ps;
 
-  CMAKE_PREFIX_PATH = stdenv.lib.concatStringsSep ":" buildInputs;
-
+  preConfigure = with stdenv; optionalString (stdenv ? glibc)
+    ''
+      fixCmakeFiles .
+      substituteInPlace Modules/Platform/UnixPaths.cmake \
+        --subst-var-by glibc_bin ${glibc.bin or glibc} \
+        --subst-var-by glibc_dev ${glibc.dev or glibc} \
+        --subst-var-by glibc_lib ${glibc.out or glibc}
+    '';
   configureFlags =
     [ "--docdir=/share/doc/${name}"
-      "--mandir=/share/man"
       "--no-system-jsoncpp"
     ]
     ++ optional (!stdenv.isCygwin) "--system-libs"
@@ -52,22 +60,18 @@ stdenv.mkDerivation rec {
     ++ ["--"]
     ++ optional (!useNcurses) "-DBUILD_CursesDialog=OFF";
 
-  setupHook = ./setup-hook.sh;
-
   dontUseCmakeConfigure = true;
 
-  preConfigure = optionalString (stdenv ? glibc)
-    ''
-      source $setupHook
-      fixCmakeFiles .
-      substituteInPlace Modules/Platform/UnixPaths.cmake \
-        --subst-var-by glibc ${stdenv.glibc}
-    '';
+  enableParallelBuilding = true;
+
+  preInstall = ''mkdir "$doc" '';
+
+  postInstall = ''moveToOutput "share/cmake-*/Help" "$doc" '';
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.cmake.org/;
     description = "Cross-Platform Makefile Generator";
-    platforms = if useQt4 then qt4.meta.platforms else stdenv.lib.platforms.all;
-    maintainers = with stdenv.lib.maintainers; [ urkud mornfall ttuegel ];
+    platforms = if useQt4 then qt4.meta.platforms else platforms.all;
+    maintainers = with maintainers; [ urkud mornfall ttuegel ];
   };
 }
diff --git a/pkgs/development/tools/build-managers/cmake/search-path-3.2.patch b/pkgs/development/tools/build-managers/cmake/search-path-3.2.patch
index b0447e70607..0a2d4ad43ab 100644
--- a/pkgs/development/tools/build-managers/cmake/search-path-3.2.patch
+++ b/pkgs/development/tools/build-managers/cmake/search-path-3.2.patch
@@ -53,21 +53,21 @@ index 20ee1d1..39834e6 100644
 -
 -list(APPEND CMAKE_SYSTEM_PROGRAM_PATH
 -  /usr/pkg/bin
-+  "@glibc@"
++  "@glibc_bin@"
    )
  
  list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
 -  /lib /lib32 /lib64 /usr/lib /usr/lib32 /usr/lib64
-+  "@glibc@/lib"
++  "@glibc_lib@/lib"
    )
  
  list(APPEND CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES
 -  /usr/include
-+  "@glibc@/include"
++  "@glibc_dev@/include"
    )
  list(APPEND CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
 -  /usr/include
-+  "@glibc@/include"
++  "@glibc_dev@/include"
    )
  
  # Enable use of lib64 search path variants by default.
diff --git a/pkgs/development/tools/build-managers/gnumake/4.1/default.nix b/pkgs/development/tools/build-managers/gnumake/4.1/default.nix
index 9ac20107018..de6f96ce99f 100644
--- a/pkgs/development/tools/build-managers/gnumake/4.1/default.nix
+++ b/pkgs/development/tools/build-managers/gnumake/4.1/default.nix
@@ -22,6 +22,8 @@ stdenv.mkDerivation {
     ./no-tty-name.patch
   ];
 
+  outputs = [ "out" "doc" ];
+
   meta = {
     homepage = http://www.gnu.org/software/make/;
     description = "A tool to control the generation of non-source files from sources";
diff --git a/pkgs/development/tools/misc/autogen/default.nix b/pkgs/development/tools/misc/autogen/default.nix
index bba50b32089..d2ddcabc0b1 100644
--- a/pkgs/development/tools/misc/autogen/default.nix
+++ b/pkgs/development/tools/misc/autogen/default.nix
@@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
     sha256 = "0sfmmy19k9z0j3f738fyk6ljf6b66410cvd5zzyplxi2683j10qs";
   };
 
+  outputs = [ "dev" "bin" "lib" "out" "man" "info" ];
+
   nativeBuildInputs = [ which pkgconfig perl ];
   buildInputs = [ guile libxml2 ];
 
@@ -20,6 +22,17 @@ stdenv.mkDerivation rec {
     substituteInPlace pkg/libopts/mklibsrc.sh --replace /tmp $TMPDIR
   '';
 
+  postInstall = ''
+    mkdir -p $dev/bin
+    mv $bin/bin/autoopts-config $dev/bin
+
+    for f in $lib/lib/autogen/tpl-config.tlib $out/share/autogen/tpl-config.tlib; do
+      sed -e "s|$dev/include|/no-such-autogen-include-path|" -i $f
+      sed -e "s|$bin/bin|/no-such-autogen-bin-path|" -i $f
+      sed -e "s|$lib/lib|/no-such-autogen-lib-path|" -i $f
+    done
+  '';
+
   #doCheck = true; # 2 tests fail because of missing /dev/tty
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix
index 61824eb607b..ceec956004f 100644
--- a/pkgs/development/tools/misc/binutils/default.nix
+++ b/pkgs/development/tools/misc/binutils/default.nix
@@ -34,6 +34,8 @@ stdenv.mkDerivation rec {
     ./pt-pax-flags-20121023.patch
   ];
 
+  outputs = (optional (cross == null) "dev") ++ [ "out" "info" ];
+
   nativeBuildInputs = optional gold bison;
   buildInputs = [ zlib ];
 
@@ -67,6 +69,8 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
+  postFixup = optionalString (cross == null) "ln -s $out/bin $dev/bin"; # tools needed for development
+
   meta = {
     description = "Tools for manipulating binaries (linker, assembler, etc.)";
 
diff --git a/pkgs/development/tools/misc/drush/default.nix b/pkgs/development/tools/misc/drush/default.nix
index cb534d511ea..0751f51281d 100644
--- a/pkgs/development/tools/misc/drush/default.nix
+++ b/pkgs/development/tools/misc/drush/default.nix
@@ -32,7 +32,7 @@ stdenv.mkDerivation rec {
     mkdir -p "$out"
     cp -r . "$out/src"
     mkdir "$out/bin"
-    wrapProgram "$out/src/drush" --prefix PATH : "${which}/bin:${php}/bin:${bash}/bin:${coreutils}/bin:${ncurses}/bin"
+    wrapProgram "$out/src/drush" --prefix PATH : "${which}/bin:${php}/bin:${bash}/bin:${coreutils}/bin:${ncurses.dev}/bin"
     ln -s "$out/src/drush" "$out/bin/drush"
   '';
 }
diff --git a/pkgs/development/tools/misc/eggdbus/default.nix b/pkgs/development/tools/misc/eggdbus/default.nix
index 97031a533fa..9f04e283722 100644
--- a/pkgs/development/tools/misc/eggdbus/default.nix
+++ b/pkgs/development/tools/misc/eggdbus/default.nix
@@ -8,7 +8,7 @@ stdenv.mkDerivation rec {
     sha256 = "118hj63ac65zlg71kydv4607qcg1qpdlql4kvhnwnnhar421jnq4";
   };
   
-  buildInputs = [ pkgconfig glib dbus.libs dbus_glib ];
+  buildInputs = [ pkgconfig glib dbus dbus_glib ];
 
   meta = {
     homepage = http://hal.freedesktop.org/releases/;
diff --git a/pkgs/development/tools/misc/global/default.nix b/pkgs/development/tools/misc/global/default.nix
index 63b29fccd52..741b494ec39 100644
--- a/pkgs/development/tools/misc/global/default.nix
+++ b/pkgs/development/tools/misc/global/default.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation rec {
 
   configureFlags = [
     "--with-ltdl-include=${libtool}/include"
-    "--with-ltdl-lib=${libtool}/lib"
+    "--with-ltdl-lib=${libtool.lib}/lib"
     "--with-ncurses=${ncurses}"
     "--with-sqlite3=${sqlite}"
     "--with-exuberant-ctags=${ctags}/bin/ctags"
diff --git a/pkgs/development/tools/misc/libtool/libtool2.nix b/pkgs/development/tools/misc/libtool/libtool2.nix
index 5d27b469680..27ec2772e09 100644
--- a/pkgs/development/tools/misc/libtool/libtool2.nix
+++ b/pkgs/development/tools/misc/libtool/libtool2.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "1qq61k6lp1fp75xs398yzi6wvbx232l7xbyn3p13cnh27mflvgg3";
   };
 
+  outputs = [ "out" "lib" ];
+
   propagatedNativeBuildInputs = [ m4 ];
   nativeBuildInputs = [ perl help2man ];
 
@@ -43,4 +45,3 @@ stdenv.mkDerivation rec {
     maintainers = [ ];
   };
 }
-
diff --git a/pkgs/development/tools/misc/patchelf/default.nix b/pkgs/development/tools/misc/patchelf/default.nix
index 5aa81e46bed..b3121ac7944 100644
--- a/pkgs/development/tools/misc/patchelf/default.nix
+++ b/pkgs/development/tools/misc/patchelf/default.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation rec {
 
   setupHook = [ ./setup-hook.sh ];
 
+  #doCheck = true; # problems when loading libc.so.6
+
   meta = {
     homepage = http://nixos.org/patchelf.html;
     license = "GPL";
diff --git a/pkgs/development/tools/misc/pkgconfig/default.nix b/pkgs/development/tools/misc/pkgconfig/default.nix
index c82a626336f..c98bddf53c0 100644
--- a/pkgs/development/tools/misc/pkgconfig/default.nix
+++ b/pkgs/development/tools/misc/pkgconfig/default.nix
@@ -1,25 +1,30 @@
-{stdenv, fetchurl, automake, libiconv, vanilla ? false}:
+{stdenv, fetchurl, automake, libiconv, vanilla ? false }:
 
-stdenv.mkDerivation (rec {
+let
+  inherit (stdenv.lib) optional;
+in
+stdenv.mkDerivation rec {
   name = "pkg-config-0.29";
-  
+
   setupHook = ./setup-hook.sh;
-  
+
   src = fetchurl {
     url = "http://pkgconfig.freedesktop.org/releases/${name}.tar.gz";
     sha256 = "0sq09a39wj4cxf8l2jvkq067g08ywfma4v6nhprnf351s82pfl68";
   };
+    # Process Requires.private properly, see
+    # http://bugs.freedesktop.org/show_bug.cgi?id=4738.
+  patches = optional (!vanilla) ./requires-private.patch
+    ++ optional stdenv.isCygwin ./2.36.3-not-win32.patch;
 
+  preConfigure = stdenv.lib.optionalString (stdenv.system == "mips64el-linux")
+    ''cp -v ${automake}/share/automake*/config.{sub,guess} .'';
   buildInputs = stdenv.lib.optional (stdenv.isCygwin || stdenv.isDarwin || stdenv.isSunOS) libiconv;
 
   configureFlags = [ "--with-internal-glib" ]
     ++ stdenv.lib.optional (stdenv.isSunOS) [ "--with-libiconv=gnu" "--with-system-library-path" "--with-system-include-path" "CFLAGS=-DENABLE_NLS" ];
 
-  patches = (if vanilla then [] else [
-    # Process Requires.private properly, see
-    # http://bugs.freedesktop.org/show_bug.cgi?id=4738.
-    ./requires-private.patch
-  ]) ++ stdenv.lib.optional stdenv.isCygwin ./2.36.3-not-win32.patch;
+  postInstall = ''rm "$out"/bin/*-pkg-config''; # clean the duplicate file
 
   meta = {
     description = "A tool that allows packages to find out information about other packages";
@@ -27,9 +32,5 @@ stdenv.mkDerivation (rec {
     platforms = stdenv.lib.platforms.all;
   };
 
-} // (if stdenv.system == "mips64el-linux" then
-  {
-    preConfigure = ''
-      cp -v ${automake}/share/automake*/config.{sub,guess} .
-    '';
-  } else {}))
+}
+
diff --git a/pkgs/development/tools/misc/texinfo/5.2.nix b/pkgs/development/tools/misc/texinfo/5.2.nix
index c43ebcd2de2..a9edccbd200 100644
--- a/pkgs/development/tools/misc/texinfo/5.2.nix
+++ b/pkgs/development/tools/misc/texinfo/5.2.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, ncurses, perl, xz, interactive ? false }:
+{ stdenv, fetchurl, xz, ncurses, perl, interactive ? false }:
 
 stdenv.mkDerivation rec {
   name = "texinfo-5.2";
@@ -8,7 +8,7 @@ stdenv.mkDerivation rec {
     sha256 = "1njfwh2z34r2c4r0iqa7v24wmjzvsfyz4vplzry8ln3479lfywal";
   };
 
-  buildInputs = [ perl xz ]
+  buildInputs = [ perl xz.bin ]
     ++ stdenv.lib.optional interactive ncurses;
 
   preInstall = ''
diff --git a/pkgs/development/tools/node-webkit/nw11.nix b/pkgs/development/tools/node-webkit/nw11.nix
index ed3b99aad00..2fe1ddf42d4 100644
--- a/pkgs/development/tools/node-webkit/nw11.nix
+++ b/pkgs/development/tools/node-webkit/nw11.nix
@@ -1,6 +1,6 @@
 { stdenv, fetchurl, buildEnv, makeWrapper
 , xorg, alsaLib, dbus, glib, gtk, atk, pango, freetype, fontconfig
-, gdk_pixbuf, cairo, zlib, nss, nssTools, nspr, gconf, expat, udev, libcap
+, gdk_pixbuf, cairo, zlib, nss, nssTools, nspr, gconf, expat, libudev, libcap
 , libnotify}:
 let
   bits = if stdenv.system == "x86_64-linux" then "x64"
@@ -35,7 +35,7 @@ in stdenv.mkDerivation rec {
     patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/share/node-webkit/nw
     patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/share/node-webkit/nwsnapshot
 
-    ln -s ${udev}/lib/libudev.so $out/share/node-webkit/libudev.so.0
+    ln -s ${libudev.out}/lib/libudev.so $out/share/node-webkit/libudev.so.0
 
     patchelf --set-rpath "${nwEnv}/lib:${nwEnv}/lib64:$out/share/node-webkit" $out/share/node-webkit/nw
     patchelf --set-rpath "${nwEnv}/lib:${nwEnv}/lib64:$out/share/node-webkit" $out/share/node-webkit/nwsnapshot
diff --git a/pkgs/development/tools/node-webkit/nw12.nix b/pkgs/development/tools/node-webkit/nw12.nix
index 7492acb1367..4cacc75d777 100644
--- a/pkgs/development/tools/node-webkit/nw12.nix
+++ b/pkgs/development/tools/node-webkit/nw12.nix
@@ -1,6 +1,6 @@
 { stdenv, fetchurl, buildEnv, makeWrapper
 , xorg, alsaLib, dbus, glib, gtk, atk, pango, freetype, fontconfig
-, gdk_pixbuf, cairo, zlib, nss, nssTools, nspr, gconf, expat, udev, libcap
+, gdk_pixbuf, cairo, zlib, nss, nssTools, nspr, gconf, expat, libudev, libcap
 , libnotify}:
 let
   bits = if stdenv.system == "x86_64-linux" then "x64"
@@ -37,7 +37,7 @@ in stdenv.mkDerivation rec {
     patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/share/nwjs/nw
     patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/share/nwjs/nwjc
 
-    ln -s ${udev}/lib/libudev.so $out/share/nwjs/libudev.so.0
+    ln -s ${libudev.out}/lib/libudev.so $out/share/nwjs/libudev.so.0
 
     patchelf --set-rpath "${nwEnv}/lib:${nwEnv}/lib64:$out/share/nwjs" $out/share/nwjs/nw
     patchelf --set-rpath "${nwEnv}/lib:${nwEnv}/lib64:$out/share/nwjs" $out/share/nwjs/nwjc
diff --git a/pkgs/development/tools/node-webkit/nw9.nix b/pkgs/development/tools/node-webkit/nw9.nix
index 213b94102b0..d8601865c6d 100644
--- a/pkgs/development/tools/node-webkit/nw9.nix
+++ b/pkgs/development/tools/node-webkit/nw9.nix
@@ -1,6 +1,6 @@
 { stdenv, fetchurl, buildEnv, makeWrapper
 , xorg, alsaLib, dbus, glib, gtk, atk, pango, freetype, fontconfig
-, gdk_pixbuf, cairo, zlib, nss, nssTools, nspr, gconf, expat, udev}:
+, gdk_pixbuf, cairo, zlib, nss, nssTools, nspr, gconf, expat, libudev }:
 let
   bits = if stdenv.system == "x86_64-linux" then "x64"
          else "ia32";
@@ -33,7 +33,7 @@ in stdenv.mkDerivation rec {
     patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/share/node-webkit/nw
     patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/share/node-webkit/nwsnapshot
 
-    ln -s ${udev}/lib/libudev.so $out/share/node-webkit/libudev.so.0
+    ln -s ${libudev.out}/lib/libudev.so $out/share/node-webkit/libudev.so.0
 
     patchelf --set-rpath "${nwEnv}/lib:${nwEnv}/lib64:$out/share/node-webkit" $out/share/node-webkit/nw
     patchelf --set-rpath "${nwEnv}/lib:${nwEnv}/lib64:$out/share/node-webkit" $out/share/node-webkit/nwsnapshot
diff --git a/pkgs/development/tools/phantomjs/default.nix b/pkgs/development/tools/phantomjs/default.nix
index 77bc1e5a885..8b6b655b6a5 100644
--- a/pkgs/development/tools/phantomjs/default.nix
+++ b/pkgs/development/tools/phantomjs/default.nix
@@ -1,6 +1,9 @@
-{ stdenv, fetchurl, freetype, fontconfig, openssl, unzip }:
+{ stdenv, lib, fetchurl, freetype, fontconfig, openssl, unzip }:
 
-assert stdenv.lib.elem stdenv.system [ "i686-linux" "x86_64-linux" "x86_64-darwin" ];
+let
+  platforms = [ "i686-linux" "x86_64-linux" "x86_64-darwin" ];
+in
+assert lib.elem stdenv.system platforms;
 
 stdenv.mkDerivation rec {
   name = "phantomjs-1.9.8";
@@ -27,12 +30,12 @@ stdenv.mkDerivation rec {
               sha256 = "0j0aq8dgzmb210xdrh0v3d4nblskl3zsckl8bzf1a603wcx085cg";
             };
 
-  buildInputs = if stdenv.isDarwin then [ unzip ] else [];
+  buildInputs = lib.optional stdenv.isDarwin unzip;
 
-  buildPhase = if stdenv.isDarwin then "" else ''
+  buildPhase = lib.optionalString (!stdenv.isDarwin) ''
     patchelf \
       --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-      --set-rpath "${freetype}/lib:${fontconfig}/lib:${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib:${openssl}/lib" \
+      --set-rpath "${stdenv.lib.makeLibraryPath [ freetype fontconfig stdenv.cc.cc stdenv.cc.cc openssl ]}" \
       bin/phantomjs
   '';
 
@@ -60,9 +63,9 @@ stdenv.mkDerivation rec {
     '';
 
     homepage = http://phantomjs.org/;
-    license = stdenv.lib.licenses.bsd3;
+    license = lib.licenses.bsd3;
 
-    maintainers = [ stdenv.lib.maintainers.bluescreen303 ];
-    platforms = ["i686-linux" "x86_64-linux" "x86_64-darwin" ];
+    maintainers = [ lib.maintainers.bluescreen303 ];
+    inherit platforms;
   };
 }
diff --git a/pkgs/development/tools/selenium/chromedriver/default.nix b/pkgs/development/tools/selenium/chromedriver/default.nix
index 8d9db34446d..b2f566ece8d 100644
--- a/pkgs/development/tools/selenium/chromedriver/default.nix
+++ b/pkgs/development/tools/selenium/chromedriver/default.nix
@@ -23,9 +23,9 @@ stdenv.mkDerivation rec {
   installPhase = ''
     mkdir -p $out/bin
     mv chromedriver $out/bin
-    patchelf --set-interpreter ${glibc}/lib/ld-linux-x86-64.so.2 $out/bin/chromedriver
+    patchelf --set-interpreter ${glibc.out}/lib/ld-linux-x86-64.so.2 $out/bin/chromedriver
     wrapProgram "$out/bin/chromedriver" \
-      --prefix LD_LIBRARY_PATH : "$(cat ${stdenv.cc}/nix-support/orig-cc)/lib64:${cairo}/lib:${fontconfig}/lib:${freetype}/lib:${gdk_pixbuf}/lib:${glib}/lib:${gtk}/lib:${libX11}/lib:${nspr}/lib:${nss}/lib:${pango}/lib:${libXrender}/lib:${gconf}/lib:${libXext}/lib:${libXi}/lib:\$LD_LIBRARY_PATH"
+      --prefix LD_LIBRARY_PATH : "$(cat ${stdenv.cc}/nix-support/orig-cc)/lib64:${stdenv.lib.makeLibraryPath [ cairo fontconfig freetype gdk_pixbuf glib gtk libX11 nspr nss pango libXrender gconf libXext libXi ]}:\$LD_LIBRARY_PATH"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/tools/vagrant/default.nix b/pkgs/development/tools/vagrant/default.nix
index 085807e1bfa..7d980287629 100644
--- a/pkgs/development/tools/vagrant/default.nix
+++ b/pkgs/development/tools/vagrant/default.nix
@@ -48,7 +48,7 @@ stdenv.mkDerivation rec {
 
     # curl: curl
     rm opt/vagrant/embedded/bin/curl
-    ln -s ${curl}/bin/curl opt/vagrant/embedded/bin
+    ln -s ${curl.bin}/bin/curl opt/vagrant/embedded/bin
 
     # libarchive: bsdtar, bsdcpio
     rm opt/vagrant/embedded/bin/{bsdtar,bsdcpio}
@@ -57,8 +57,8 @@ stdenv.mkDerivation rec {
 
     # openssl: c_rehash, openssl
     rm opt/vagrant/embedded/bin/{c_rehash,openssl}
-    ln -s ${openssl}/bin/c_rehash opt/vagrant/embedded/bin
-    ln -s ${openssl}/bin/openssl opt/vagrant/embedded/bin
+    ln -s ${openssl.bin}/bin/c_rehash opt/vagrant/embedded/bin
+    ln -s ${openssl.bin}/bin/openssl opt/vagrant/embedded/bin
 
     # ruby: erb, gem, irb, rake, rdoc, ri, ruby, testrb
     rm opt/vagrant/embedded/bin/{erb,gem,irb,rake,rdoc,ri,ruby,testrb}
@@ -77,14 +77,14 @@ stdenv.mkDerivation rec {
 
     # libxml: xml2-config, xmlcatalog, xmllint
     rm opt/vagrant/embedded/bin/{xml2-config,xmlcatalog,xmllint}
-    ln -s ${libxml2}/bin/xml2-config opt/vagrant/embedded/bin
-    ln -s ${libxml2}/bin/xmlcatalog opt/vagrant/embedded/bin
-    ln -s ${libxml2}/bin/xmllint opt/vagrant/embedded/bin
+    ln -s ${libxml2.dev}/bin/xml2-config opt/vagrant/embedded/bin
+    ln -s ${libxml2.bin}/bin/xmlcatalog opt/vagrant/embedded/bin
+    ln -s ${libxml2.bin}/bin/xmllint opt/vagrant/embedded/bin
 
     # libxslt: xslt-config, xsltproc
     rm opt/vagrant/embedded/bin/{xslt-config,xsltproc}
-    ln -s ${libxslt}/bin/xslt-config opt/vagrant/embedded/bin
-    ln -s ${libxslt}/bin/xsltproc opt/vagrant/embedded/bin
+    ln -s ${libxslt.dev}/bin/xslt-config opt/vagrant/embedded/bin
+    ln -s ${libxslt.bin}/bin/xsltproc opt/vagrant/embedded/bin
 
     mkdir -p "$out"
     cp -r opt "$out"
diff --git a/pkgs/development/web/nodejs/v4.nix b/pkgs/development/web/nodejs/v4.nix
index b3958fc8529..8ccf8976a94 100644
--- a/pkgs/development/web/nodejs/v4.nix
+++ b/pkgs/development/web/nodejs/v4.nix
@@ -43,9 +43,11 @@ in stdenv.mkDerivation {
 
   patches = stdenv.lib.optionals stdenv.isDarwin [ ./no-xcode.patch ./pkg-libpath.patch ];
 
-  buildInputs = [ python which zlib libuv openssl python ]
-    ++ optionals stdenv.isLinux [ utillinux http-parser ]
-    ++ optionals stdenv.isDarwin [ pkgconfig openssl libtool ];
+  buildInputs = [ python zlib libuv openssl python ]
+    ++ optionals stdenv.isLinux [ utillinux http-parser ];
+  nativeBuildInputs = [ pkgconfig ]
+    ++ optional stdenv.isDarwin libtool;
+
   setupHook = ./setup-hook.sh;
 
   enableParallelBuilding = true;