about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/applications/altcoins/bitcoin-xt.nix2
-rw-r--r--pkgs/applications/audio/ardour/default.nix2
-rw-r--r--pkgs/applications/audio/audacity/default.nix6
-rw-r--r--pkgs/applications/audio/baudline/default.nix2
-rw-r--r--pkgs/applications/audio/flac/default.nix4
-rw-r--r--pkgs/applications/audio/google-musicmanager/default.nix2
-rw-r--r--pkgs/applications/audio/milkytracker/default.nix2
-rw-r--r--pkgs/applications/audio/spotify/default.nix8
-rw-r--r--pkgs/applications/audio/swh-lv2/default.nix2
-rw-r--r--pkgs/applications/audio/yoshimi/default.nix2
-rw-r--r--pkgs/applications/display-managers/slim/default.nix4
-rw-r--r--pkgs/applications/editors/brackets/default.nix6
-rw-r--r--pkgs/applications/editors/codeblocks/default.nix2
-rw-r--r--pkgs/applications/editors/eclipse/default.nix2
-rw-r--r--pkgs/applications/editors/edbrowse/default.nix2
-rw-r--r--pkgs/applications/editors/emacs-24/default.nix2
-rw-r--r--pkgs/applications/editors/emacs-24/macport-24.5.nix4
-rw-r--r--pkgs/applications/editors/heme/default.nix5
-rw-r--r--pkgs/applications/editors/idea/common.nix2
-rw-r--r--pkgs/applications/editors/lighttable/default.nix4
-rw-r--r--pkgs/applications/editors/music/tuxguitar/default.nix2
-rw-r--r--pkgs/applications/editors/sublime3/default.nix2
-rw-r--r--pkgs/applications/editors/texmacs/default.nix2
-rw-r--r--pkgs/applications/graphics/darktable/default.nix16
-rw-r--r--pkgs/applications/graphics/digikam/default.nix2
-rw-r--r--pkgs/applications/graphics/feh/default.nix4
-rw-r--r--pkgs/applications/graphics/gimp/2.8.nix2
-rw-r--r--pkgs/applications/graphics/seg3d/default.nix4
-rw-r--r--pkgs/applications/graphics/shotwell/default.nix2
-rw-r--r--pkgs/applications/graphics/xfig/default.nix2
-rw-r--r--pkgs/applications/kde-apps-15.12/kdelibs/default.nix4
-rw-r--r--pkgs/applications/misc/audio/soxr/default.nix2
-rw-r--r--pkgs/applications/misc/calibre/default.nix6
-rw-r--r--pkgs/applications/misc/djvulibre/default.nix2
-rw-r--r--pkgs/applications/misc/get_iplayer/default.nix2
-rw-r--r--pkgs/applications/misc/girara/default.nix2
-rw-r--r--pkgs/applications/misc/ikiwiki/default.nix2
-rw-r--r--pkgs/applications/misc/kiwix/default.nix2
-rw-r--r--pkgs/applications/misc/monero/default.nix2
-rw-r--r--pkgs/applications/misc/mysql-workbench/default.nix2
-rw-r--r--pkgs/applications/misc/nut/default.nix2
-rw-r--r--pkgs/applications/misc/pdfmod/default.nix2
-rw-r--r--pkgs/applications/misc/pinfo/default.nix2
-rw-r--r--pkgs/applications/misc/roxterm/default.nix8
-rw-r--r--pkgs/applications/misc/sweethome3d/default.nix2
-rw-r--r--pkgs/applications/misc/sweethome3d/editors.nix2
-rw-r--r--pkgs/applications/misc/tilda/default.nix2
-rw-r--r--pkgs/applications/misc/xca/default.nix3
-rw-r--r--pkgs/applications/misc/xneur/default.nix14
-rw-r--r--pkgs/applications/misc/zathura/core/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/chromium/common.nix6
-rw-r--r--pkgs/applications/networking/browsers/dwb/default.nix4
-rw-r--r--pkgs/applications/networking/browsers/jumanji/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/luakit/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/midori/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/mozilla-plugins/gecko-mediaplayer/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/opera/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/surf/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/uzbl/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/vimb/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/vimprobable2/default.nix2
-rw-r--r--pkgs/applications/networking/copy-com/default.nix2
-rw-r--r--pkgs/applications/networking/feedreaders/newsbeuter/dev.nix2
-rw-r--r--pkgs/applications/networking/ike/default.nix2
-rw-r--r--pkgs/applications/networking/instant-messengers/blink/default.nix2
-rw-r--r--pkgs/applications/networking/instant-messengers/carrier/2.5.0.nix10
-rw-r--r--pkgs/applications/networking/instant-messengers/oneteam/default.nix2
-rw-r--r--pkgs/applications/networking/instant-messengers/pidgin/default.nix10
-rw-r--r--pkgs/applications/networking/instant-messengers/pybitmessage/default.nix2
-rw-r--r--pkgs/applications/networking/instant-messengers/sflphone/default.nix2
-rw-r--r--pkgs/applications/networking/instant-messengers/telepathy/kde/default.nix6
-rw-r--r--pkgs/applications/networking/instant-messengers/telepathy/logger/default.nix2
-rw-r--r--pkgs/applications/networking/newsreaders/liferea/default.nix2
-rw-r--r--pkgs/applications/networking/p2p/retroshare/0.6.nix2
-rw-r--r--pkgs/applications/networking/p2p/retroshare/default.nix2
-rw-r--r--pkgs/applications/networking/spideroak/default.nix2
-rw-r--r--pkgs/applications/science/astronomy/celestia/default.nix2
-rw-r--r--pkgs/applications/science/electronics/tkgate/1.x.nix4
-rw-r--r--pkgs/applications/science/logic/hol/default.nix2
-rw-r--r--pkgs/applications/science/logic/saw-tools/default.nix2
-rw-r--r--pkgs/applications/science/logic/tptp/default.nix2
-rw-r--r--pkgs/applications/science/logic/yices/default.nix8
-rw-r--r--pkgs/applications/science/math/R/default.nix1
-rw-r--r--pkgs/applications/search/recoll/default.nix8
-rw-r--r--pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix2
-rw-r--r--pkgs/applications/version-management/rabbitvcs/default.nix2
-rw-r--r--pkgs/applications/version-management/rapidsvn/default.nix4
-rw-r--r--pkgs/applications/version-management/redmine/bootstrap.nix4
-rw-r--r--pkgs/applications/version-management/subversion/default.nix9
-rw-r--r--pkgs/applications/video/avidemux/default.nix4
-rw-r--r--pkgs/applications/video/avxsynth/default.nix2
-rw-r--r--pkgs/applications/video/clipgrab/default.nix4
-rw-r--r--pkgs/applications/video/dvd-slideshow/default.nix2
-rw-r--r--pkgs/applications/video/gnash/default.nix4
-rw-r--r--pkgs/applications/video/kazam/default.nix4
-rw-r--r--pkgs/applications/video/kodi/default.nix10
-rw-r--r--pkgs/applications/video/miro/default.nix4
-rw-r--r--pkgs/applications/video/vlc/default.nix2
-rw-r--r--pkgs/applications/virtualization/bochs/default.nix4
-rw-r--r--pkgs/applications/virtualization/docker/default.nix2
-rw-r--r--pkgs/applications/virtualization/virtualbox/default.nix10
-rw-r--r--pkgs/applications/virtualization/virtualbox/guest-additions/default.nix8
-rw-r--r--pkgs/applications/virtualization/xen/generic.nix2
-rw-r--r--pkgs/applications/window-managers/awesome/default.nix8
-rw-r--r--pkgs/applications/window-managers/fvwm/default.nix4
-rw-r--r--pkgs/applications/window-managers/qtile/default.nix8
-rw-r--r--pkgs/applications/window-managers/weston/default.nix2
-rw-r--r--pkgs/build-support/buildenv/default.nix8
-rw-r--r--pkgs/build-support/cc-wrapper/add-flags4
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix60
-rw-r--r--pkgs/build-support/cc-wrapper/setup-hook.sh12
-rw-r--r--pkgs/build-support/gcc-wrapper-old/builder.sh9
-rw-r--r--pkgs/build-support/gcc-wrapper-old/default.nix3
-rw-r--r--pkgs/build-support/gcc-wrapper-old/setup-hook.sh2
-rw-r--r--pkgs/build-support/grsecurity/default.nix6
-rw-r--r--pkgs/build-support/setup-hooks/compress-man-pages.sh1
-rw-r--r--pkgs/build-support/setup-hooks/move-docs.sh30
-rw-r--r--pkgs/build-support/setup-hooks/multiple-outputs.sh177
-rw-r--r--pkgs/build-support/vm/default.nix8
-rw-r--r--pkgs/data/documentation/man-pages/default.nix3
-rw-r--r--pkgs/data/documentation/std-man-pages/default.nix4
-rw-r--r--pkgs/data/documentation/stdman/default.nix4
-rw-r--r--pkgs/data/misc/media-player-info/default.nix4
-rw-r--r--pkgs/data/misc/tzdata/default.nix15
-rw-r--r--pkgs/desktops/e19/efl.nix6
-rw-r--r--pkgs/desktops/gnome-2/desktop/gnome-keyring/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/apps/evolution/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/empathy/default.nix6
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/epiphany/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/evince/default.nix4
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/folks/default.nix4
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/gdm/3.16-wip/default.nix4
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/gdm/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/gjs/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/gnome-dictionary/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/gnome-online-accounts/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/gnome-screenshot/default.nix4
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/gnome-system-log/default.nix4
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/gnome-user-share/default.nix4
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/libcroco/default.nix3
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/vte/2.90.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/core/vte/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/misc/gitg/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/misc/gnome-tweak-tool/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.16/misc/gpaste/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/apps/evolution/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/empathy/default.nix6
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/epiphany/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/evince/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/folks/default.nix4
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/gdm/3.16-wip/default.nix4
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/gdm/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/gjs/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/gnome-dictionary/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/gnome-online-accounts/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/gnome-screenshot/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/gnome-system-log/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/gnome-user-share/default.nix4
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/libcroco/default.nix3
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/vte/2.90.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/core/vte/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/misc/gitg/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/misc/gnome-tweak-tool/default.nix2
-rw-r--r--pkgs/desktops/gnome-3/3.18/misc/gpaste/default.nix2
-rw-r--r--pkgs/desktops/kde-4.14/kde-runtime.nix2
-rw-r--r--pkgs/desktops/kde-4.14/kdenetwork/kopete.nix1
-rw-r--r--pkgs/desktops/xfce/core/exo.nix9
-rw-r--r--pkgs/desktops/xfce/core/garcon.nix16
-rw-r--r--pkgs/desktops/xfce/core/libxfce4ui.nix30
-rw-r--r--pkgs/desktops/xfce/core/libxfce4util.nix10
-rw-r--r--pkgs/desktops/xfce/core/libxfcegui4.nix21
-rw-r--r--pkgs/desktops/xfce/core/tumbler.nix28
-rw-r--r--pkgs/desktops/xfce/core/xfce4-appfinder.nix16
-rw-r--r--pkgs/desktops/xfce/core/xfce4-dev-tools.nix8
-rw-r--r--pkgs/desktops/xfce/core/xfce4-panel.nix29
-rw-r--r--pkgs/desktops/xfce/core/xfce4-power-manager.nix22
-rw-r--r--pkgs/desktops/xfce/core/xfce4-session.nix26
-rw-r--r--pkgs/desktops/xfce/core/xfce4-settings.nix22
-rw-r--r--pkgs/desktops/xfce/core/xfconf.nix16
-rw-r--r--pkgs/desktops/xfce/core/xfdesktop.nix22
-rw-r--r--pkgs/desktops/xfce/core/xfwm4.nix16
-rw-r--r--pkgs/development/compilers/gcc-arm-embedded/default.nix4
-rw-r--r--pkgs/development/compilers/gcc/4.3/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.10.3.nix4
-rw-r--r--pkgs/development/compilers/ghc/7.2.2.nix8
-rw-r--r--pkgs/development/compilers/ghc/7.4.2-binary.nix8
-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/8.0.1.nix4
-rw-r--r--pkgs/development/compilers/ghc/head.nix4
-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/opendylan/bin.nix4
-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/ponyc/default.nix6
-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.nix58
-rw-r--r--pkgs/development/interpreters/perl/5.22/default.nix39
-rw-r--r--pkgs/development/interpreters/php/default.nix12
-rw-r--r--pkgs/development/interpreters/pypy/default.nix16
-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/gemconfig/default.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.nix8
-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.nix128
-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.nix5
-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.nix4
-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.nix32
-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.nix14
-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/liboauth/default.nix2
-rw-r--r--pkgs/development/libraries/libogg/default.nix2
-rw-r--r--pkgs/development/libraries/liboil/default.nix7
-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.nix25
-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.nix38
-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.nix57
-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/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/qtbase/default.nix26
-rw-r--r--pkgs/development/libraries/qt-5/5.4/qtbase/dlopen-gl.patch2
-rw-r--r--pkgs/development/libraries/qt-5/5.4/qtbase/mkspecs-libgl.patch4
-rw-r--r--pkgs/development/libraries/qt-5/5.4/qtserialport/0001-dlopen-serialport-udev.patch4
-rw-r--r--pkgs/development/libraries/qt-5/5.4/qtserialport/default.nix10
-rw-r--r--pkgs/development/libraries/qt-5/5.4/qtwebkit/0003-dlopen-webkit-udev.patch4
-rw-r--r--pkgs/development/libraries/qt-5/5.4/qtwebkit/default.nix9
-rw-r--r--pkgs/development/libraries/qt-5/5.5/qtbase/default.nix32
-rw-r--r--pkgs/development/libraries/qt-5/5.5/qtbase/dlopen-gl.patch2
-rw-r--r--pkgs/development/libraries/qt-5/5.5/qtbase/mkspecs-libgl.patch4
-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/tokyo-cabinet/default.nix4
-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.nix4
-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/flashtool/default.nix2
-rw-r--r--pkgs/development/ocaml-modules/camlzip/default.nix2
-rw-r--r--pkgs/development/ocaml-modules/expat/default.nix4
-rw-r--r--pkgs/development/perl-modules/Compress-Raw-Zlib/default.nix2
-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.nix4
-rw-r--r--pkgs/development/tools/build-managers/cargo/snapshot.nix4
-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/documentation/gtk-doc/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.nix2
-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/selenium/server/default.nix2
-rw-r--r--pkgs/development/tools/vagrant/default.nix16
-rw-r--r--pkgs/development/web/nodejs/v4.nix9
-rw-r--r--pkgs/games/beret/default.nix2
-rw-r--r--pkgs/games/bitsnbots/default.nix2
-rw-r--r--pkgs/games/extremetuxracer/default.nix2
-rw-r--r--pkgs/games/gemrb/default.nix2
-rw-r--r--pkgs/games/hedgewars/default.nix6
-rw-r--r--pkgs/games/jamp/default.nix2
-rw-r--r--pkgs/games/liquidwar/default.nix2
-rw-r--r--pkgs/games/micropolis/default.nix2
-rw-r--r--pkgs/games/minetest/default.nix2
-rw-r--r--pkgs/games/nexuiz/default.nix16
-rw-r--r--pkgs/games/oilrush/default.nix14
-rw-r--r--pkgs/games/openarena/default.nix5
-rw-r--r--pkgs/games/openlierox/default.nix2
-rw-r--r--pkgs/games/openttd/default.nix2
-rw-r--r--pkgs/games/planetaryannihilation/default.nix6
-rw-r--r--pkgs/games/quantumminigolf/default.nix2
-rw-r--r--pkgs/games/rili/default.nix2
-rw-r--r--pkgs/games/sdlmame/default.nix2
-rw-r--r--pkgs/games/tibia/default.nix4
-rw-r--r--pkgs/games/trackballs/default.nix2
-rw-r--r--pkgs/games/ue4demos/default.nix2
-rw-r--r--pkgs/games/ultrastardx/default.nix2
-rw-r--r--pkgs/games/warsow/default.nix2
-rw-r--r--pkgs/games/xonotic/default.nix6
-rw-r--r--pkgs/games/xsokoban/default.nix2
-rw-r--r--pkgs/games/zdoom/default.nix4
-rw-r--r--pkgs/misc/cups/default.nix8
-rw-r--r--pkgs/misc/cups/drivers/canon/default.nix4
-rw-r--r--pkgs/misc/cups/drivers/mfcj470dw/default.nix4
-rw-r--r--pkgs/misc/drivers/foo2zjs/default.nix4
-rw-r--r--pkgs/misc/emulators/retroarch/cores.nix2
-rw-r--r--pkgs/os-specific/darwin/binutils/default.nix2
-rw-r--r--pkgs/os-specific/linux/alsa-lib/default.nix2
-rw-r--r--pkgs/os-specific/linux/apparmor/2.9/default.nix183
-rw-r--r--pkgs/os-specific/linux/apparmor/default.nix8
-rw-r--r--pkgs/os-specific/linux/ati-drivers/default.nix18
-rw-r--r--pkgs/os-specific/linux/bluez/bluez5.nix2
-rw-r--r--pkgs/os-specific/linux/bluez/bluez5_28.nix2
-rw-r--r--pkgs/os-specific/linux/bluez/default.nix2
-rw-r--r--pkgs/os-specific/linux/checksec/default.nix2
-rw-r--r--pkgs/os-specific/linux/drbd/default.nix4
-rw-r--r--pkgs/os-specific/linux/fusionio/util.nix2
-rw-r--r--pkgs/os-specific/linux/kbd/default.nix2
-rw-r--r--pkgs/os-specific/linux/kernel/manual-config.nix2
-rw-r--r--pkgs/os-specific/linux/klibc/shrunk.nix6
-rw-r--r--pkgs/os-specific/linux/libcap/default.nix19
-rw-r--r--pkgs/os-specific/linux/libcap/man.nix2
-rw-r--r--pkgs/os-specific/linux/libcap/pam.nix2
-rw-r--r--pkgs/os-specific/linux/libcap/progs.nix5
-rw-r--r--pkgs/os-specific/linux/libnl/default.nix2
-rw-r--r--pkgs/os-specific/linux/lvm2/default.nix6
-rw-r--r--pkgs/os-specific/linux/mdadm/default.nix2
-rw-r--r--pkgs/os-specific/linux/module-init-tools/default.nix2
-rw-r--r--pkgs/os-specific/linux/nfs-utils/default.nix2
-rw-r--r--pkgs/os-specific/linux/pam/default.nix13
-rw-r--r--pkgs/os-specific/linux/shadow/default.nix2
-rw-r--r--pkgs/os-specific/linux/systemd/default.nix74
-rw-r--r--pkgs/os-specific/linux/systemd/hwdb-location.diff19
-rw-r--r--pkgs/os-specific/linux/systemd/libudev.nix19
-rw-r--r--pkgs/os-specific/linux/udev/145.nix53
-rw-r--r--pkgs/os-specific/linux/util-linux/default.nix19
-rw-r--r--pkgs/servers/dns/nsd/default.nix2
-rw-r--r--pkgs/servers/http/apache-httpd/2.2.nix30
-rw-r--r--pkgs/servers/http/apache-httpd/2.4.nix27
-rw-r--r--pkgs/servers/http/apache-modules/mod_fastcgi/default.nix2
-rw-r--r--pkgs/servers/http/nginx/default.nix2
-rw-r--r--pkgs/servers/http/nginx/unstable.nix2
-rw-r--r--pkgs/servers/http/openresty/default.nix4
-rw-r--r--pkgs/servers/mail/opensmtpd/default.nix2
-rw-r--r--pkgs/servers/meteor/default.nix4
-rw-r--r--pkgs/servers/monitoring/net-snmp/default.nix6
-rw-r--r--pkgs/servers/nosql/arangodb/default.nix2
-rw-r--r--pkgs/servers/nosql/eventstore/default.nix4
-rw-r--r--pkgs/servers/openafs-client/default.nix2
-rw-r--r--pkgs/servers/plex/default.nix4
-rw-r--r--pkgs/servers/pulseaudio/default.nix9
-rw-r--r--pkgs/servers/shellinabox/default.nix2
-rw-r--r--pkgs/servers/shishi/default.nix13
-rw-r--r--pkgs/servers/sql/mariadb/default.nix8
-rw-r--r--pkgs/servers/sql/postgresql/default.nix16
-rw-r--r--pkgs/servers/x11/xorg/builder.sh6
-rw-r--r--pkgs/servers/x11/xorg/default.nix15
-rw-r--r--pkgs/servers/x11/xorg/imake-cc-wrapper-uberhack.patch13
-rw-r--r--pkgs/servers/x11/xorg/overrides.nix130
-rw-r--r--pkgs/servers/x11/xquartz/default.nix2
-rw-r--r--pkgs/shells/bash/default.nix33
-rw-r--r--pkgs/stdenv/common-path.nix4
-rw-r--r--pkgs/stdenv/darwin/make-bootstrap-tools.nix32
-rw-r--r--pkgs/stdenv/generic/default.nix1
-rw-r--r--pkgs/stdenv/generic/setup.sh59
-rw-r--r--pkgs/stdenv/linux/default.nix11
-rw-r--r--pkgs/stdenv/linux/make-bootstrap-tools-cross.nix32
-rw-r--r--pkgs/stdenv/linux/make-bootstrap-tools.nix36
-rw-r--r--pkgs/test/openftd/default.nix2
-rw-r--r--pkgs/tools/X11/xlaunch/default.nix2
-rw-r--r--pkgs/tools/X11/xpra/default.nix4
-rw-r--r--pkgs/tools/X11/xpra/gtk3.nix4
-rw-r--r--pkgs/tools/admin/gtk-vnc/default.nix2
-rw-r--r--pkgs/tools/archivers/gnutar/default.nix7
-rw-r--r--pkgs/tools/archivers/unrar/default.nix2
-rw-r--r--pkgs/tools/audio/qastools/default.nix2
-rw-r--r--pkgs/tools/bluetooth/blueman/default.nix2
-rw-r--r--pkgs/tools/bluetooth/obex-data-server/default.nix2
-rw-r--r--pkgs/tools/bluetooth/obexd/default.nix2
-rw-r--r--pkgs/tools/compression/bzip2/default.nix13
-rw-r--r--pkgs/tools/compression/gzip/default.nix6
-rw-r--r--pkgs/tools/compression/kzipmix/default.nix4
-rw-r--r--pkgs/tools/compression/xz/default.nix2
-rw-r--r--pkgs/tools/filesystems/e2fsprogs/default.nix23
-rw-r--r--pkgs/tools/filesystems/nixpart/0.4/blivet.nix12
-rw-r--r--pkgs/tools/filesystems/nixpart/0.4/default.nix6
-rw-r--r--pkgs/tools/filesystems/nixpart/0.4/lvm2.nix8
-rw-r--r--pkgs/tools/filesystems/nixpart/0.4/multipath-tools.nix6
-rw-r--r--pkgs/tools/filesystems/svnfs/default.nix4
-rw-r--r--pkgs/tools/filesystems/xfsprogs/default.nix4
-rw-r--r--pkgs/tools/filesystems/xtreemfs/default.nix2
-rw-r--r--pkgs/tools/filesystems/yandex-disk/default.nix2
-rw-r--r--pkgs/tools/graphics/cuneiform/default.nix2
-rw-r--r--pkgs/tools/graphics/gnuplot/default.nix2
-rw-r--r--pkgs/tools/graphics/graphviz/2.0.nix6
-rw-r--r--pkgs/tools/graphics/graphviz/2.32.nix8
-rw-r--r--pkgs/tools/graphics/graphviz/default.nix17
-rw-r--r--pkgs/tools/graphics/netpbm/default.nix2
-rw-r--r--pkgs/tools/graphics/pdfread/default.nix2
-rw-r--r--pkgs/tools/graphics/pngcheck/default.nix2
-rw-r--r--pkgs/tools/graphics/pngout/default.nix4
-rw-r--r--pkgs/tools/graphics/quirc/default.nix2
-rw-r--r--pkgs/tools/inputmethods/ibus/default.nix2
-rw-r--r--pkgs/tools/misc/coreutils/default.nix6
-rw-r--r--pkgs/tools/misc/debian-devscripts/default.nix2
-rw-r--r--pkgs/tools/misc/entr/default.nix2
-rw-r--r--pkgs/tools/misc/findutils/default.nix4
-rw-r--r--pkgs/tools/misc/grub/2.0x.nix3
-rw-r--r--pkgs/tools/misc/kde-gtk-config/default.nix4
-rw-r--r--pkgs/tools/misc/pipelight/default.nix2
-rw-r--r--pkgs/tools/misc/plowshare/default.nix2
-rw-r--r--pkgs/tools/misc/profile-cleaner/default.nix2
-rw-r--r--pkgs/tools/misc/trash-cli/default.nix2
-rw-r--r--pkgs/tools/misc/xdummy/default.nix4
-rw-r--r--pkgs/tools/misc/xvfb-run/default.nix2
-rw-r--r--pkgs/tools/misc/youtube-dl/default.nix2
-rw-r--r--pkgs/tools/networking/cjdns/default.nix4
-rw-r--r--pkgs/tools/networking/curl/default.nix10
-rw-r--r--pkgs/tools/networking/gupnp-tools/default.nix2
-rw-r--r--pkgs/tools/networking/inetutils/default.nix2
-rw-r--r--pkgs/tools/networking/megatools/default.nix2
-rw-r--r--pkgs/tools/networking/netsniff-ng/default.nix2
-rw-r--r--pkgs/tools/networking/network-manager-applet/default.nix2
-rw-r--r--pkgs/tools/networking/network-manager/default.nix4
-rw-r--r--pkgs/tools/networking/nylon/default.nix12
-rw-r--r--pkgs/tools/networking/openconnect.nix4
-rw-r--r--pkgs/tools/networking/p2p/gtk-gnutella/default.nix2
-rw-r--r--pkgs/tools/networking/p2p/seeks/default.nix6
-rw-r--r--pkgs/tools/networking/plasma-nm/default.nix2
-rw-r--r--pkgs/tools/networking/ppp/default.nix2
-rw-r--r--pkgs/tools/networking/unbound/default.nix16
-rw-r--r--pkgs/tools/networking/uwimap/default.nix5
-rw-r--r--pkgs/tools/networking/wget/default.nix2
-rw-r--r--pkgs/tools/networking/wget/remove-runtime-dep-on-openssl-headers.patch17
-rw-r--r--pkgs/tools/networking/zerotierone/default.nix2
-rw-r--r--pkgs/tools/package-management/checkinstall/default.nix2
-rw-r--r--pkgs/tools/package-management/nix-prefetch-scripts/default.nix4
-rw-r--r--pkgs/tools/package-management/nix/default.nix4
-rw-r--r--pkgs/tools/package-management/nix/unstable.nix76
-rw-r--r--pkgs/tools/package-management/rpm/default.nix2
-rw-r--r--pkgs/tools/security/chntpw/default.nix3
-rw-r--r--pkgs/tools/security/modsecurity/default.nix3
-rw-r--r--pkgs/tools/security/mpw/default.nix2
-rw-r--r--pkgs/tools/security/prey/default.nix2
-rw-r--r--pkgs/tools/security/thc-hydra/default.nix7
-rw-r--r--pkgs/tools/security/tor/tor-arm.nix2
-rw-r--r--pkgs/tools/security/trousers/default.nix2
-rw-r--r--pkgs/tools/system/gptfdisk/default.nix2
-rw-r--r--pkgs/tools/system/monit/default.nix2
-rw-r--r--pkgs/tools/system/plan9port/builder.sh4
-rw-r--r--pkgs/tools/system/plan9port/default.nix4
-rw-r--r--pkgs/tools/system/storebrowse/default.nix6
-rw-r--r--pkgs/tools/system/syslog-ng/default.nix4
-rw-r--r--pkgs/tools/system/thermald/default.nix2
-rw-r--r--pkgs/tools/text/diffutils/default.nix6
-rw-r--r--pkgs/tools/text/gawk/default.nix24
-rw-r--r--pkgs/tools/text/gnugrep/default.nix10
-rw-r--r--pkgs/tools/text/gnused/default.nix4
-rw-r--r--pkgs/tools/text/groff/default.nix4
-rw-r--r--pkgs/tools/text/multitran/data/default.nix2
-rw-r--r--pkgs/tools/text/xidel/default.nix2
-rw-r--r--pkgs/tools/typesetting/asciidoc/default.nix4
-rw-r--r--pkgs/tools/typesetting/tex/dblatex/default.nix8
-rw-r--r--pkgs/tools/typesetting/tex/texlive-new/bin.nix3
-rw-r--r--pkgs/tools/typesetting/tex/texlive/aggregate.nix2
-rw-r--r--pkgs/tools/typesetting/tex/texlive/default.nix8
-rw-r--r--pkgs/tools/typesetting/xmlto/default.nix2
-rw-r--r--pkgs/tools/virtualization/aws/default.nix2
-rw-r--r--pkgs/top-level/all-packages.nix75
-rw-r--r--pkgs/top-level/lua-packages.nix2
-rw-r--r--pkgs/top-level/perl-packages.nix41
-rw-r--r--pkgs/top-level/python-packages.nix58
662 files changed, 3786 insertions, 1987 deletions
diff --git a/pkgs/applications/altcoins/bitcoin-xt.nix b/pkgs/applications/altcoins/bitcoin-xt.nix
index e6c95729c6ec..c14113076685 100644
--- a/pkgs/applications/altcoins/bitcoin-xt.nix
+++ b/pkgs/applications/altcoins/bitcoin-xt.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec{
 
   configureFlags = [
     "--with-boost-libdir=${boost.lib}/lib"
-    "--with-libcurl-headers=${curl}/include"
+    "--with-libcurl-headers=${curl.dev}/include"
   ] ++ optionals withGui [ "--with-gui=qt4" ];
 
   meta = {
diff --git a/pkgs/applications/audio/ardour/default.nix b/pkgs/applications/audio/ardour/default.nix
index f44f1a2b78a0..c10a0d8a4ce4 100644
--- a/pkgs/applications/audio/ardour/default.nix
+++ b/pkgs/applications/audio/ardour/default.nix
@@ -42,7 +42,7 @@ stdenv.mkDerivation rec {
   # have to do that ourself.
   patchPhase = ''
     printf '#include "libs/ardour/ardour/revision.h"\nnamespace ARDOUR { const char* revision = \"${tag}-${builtins.substring 0 8 src.rev}\"; }\n' > libs/ardour/revision.cc
-    sed 's|/usr/include/libintl.h|${glibc}/include/libintl.h|' -i wscript
+    sed 's|/usr/include/libintl.h|${glibc.dev}/include/libintl.h|' -i wscript
     patchShebangs ./tools/
   '';
 
diff --git a/pkgs/applications/audio/audacity/default.nix b/pkgs/applications/audio/audacity/default.nix
index 627d68525b9b..afa8a94d200d 100644
--- a/pkgs/applications/audio/audacity/default.nix
+++ b/pkgs/applications/audio/audacity/default.nix
@@ -18,6 +18,12 @@ stdenv.mkDerivation rec {
     sha256 = "19fr674mw844zmkp1476yigkcnmb6zyn78av64ccdwi3p68i00rf";
   })];
 
+  # fix with gcc-5 from http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2012-December/245884.html
+  postPatch = ''
+    substituteInPlace lib-src/libnyquist/nyquist/ffts/src/fftlib.c \
+      --replace 'inline void' 'static inline void'
+  '';
+
   preConfigure = /* we prefer system-wide libs */ ''
     mv lib-src lib-src-rm
     mkdir lib-src
diff --git a/pkgs/applications/audio/baudline/default.nix b/pkgs/applications/audio/baudline/default.nix
index 543329ef679b..2d6b0434d6a1 100644
--- a/pkgs/applications/audio/baudline/default.nix
+++ b/pkgs/applications/audio/baudline/default.nix
@@ -36,7 +36,7 @@ stdenv.mkDerivation rec {
 
     cp -r . "$out/libexec/baudline/"
 
-    interpreter="$(echo ${stdenv.glibc}/lib/ld-linux*)"
+    interpreter="$(echo ${stdenv.glibc.out}/lib/ld-linux*)"
     for prog in "$out"/libexec/baudline/baudline*; do
         patchelf --interpreter "$interpreter" "$prog"
         ln -sr "$prog" "$out/bin/"
diff --git a/pkgs/applications/audio/flac/default.nix b/pkgs/applications/audio/flac/default.nix
index 18fb48a17ba1..80e4e49fb183 100644
--- a/pkgs/applications/audio/flac/default.nix
+++ b/pkgs/applications/audio/flac/default.nix
@@ -8,12 +8,12 @@ stdenv.mkDerivation rec {
     sha256 = "4773c0099dba767d963fd92143263be338c48702172e8754b9bc5103efe1c56c";
   };
 
-  outputs = [ "out" "doc" ];
-
   buildInputs = [ libogg ];
 
   #doCheck = true; # takes lots of time
 
+  outputs = [ "dev" "out" "bin" "doc" ];
+
   meta = with stdenv.lib; {
     homepage = http://xiph.org/flac/;
     description = "Library and tools for encoding and decoding the FLAC lossless audio file format";
diff --git a/pkgs/applications/audio/google-musicmanager/default.nix b/pkgs/applications/audio/google-musicmanager/default.nix
index f86513659b64..72bec52b2663 100644
--- a/pkgs/applications/audio/google-musicmanager/default.nix
+++ b/pkgs/applications/audio/google-musicmanager/default.nix
@@ -36,7 +36,7 @@ stdenv.mkDerivation rec {
   buildPhase = ''
     patchelf \
       --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-      --set-rpath "$out/opt/google/musicmanager:${readline}/lib:${ncurses}/lib:${stdenv.cc.libc}/lib:${qt48}/lib:${stdenv.cc.cc}/lib:${libidn}/lib:${expat}/lib:${flac}/lib:${libvorbis}/lib" opt/google/musicmanager/MusicManager
+      --set-rpath "$out/opt/google/musicmanager:${stdenv.lib.makeLibraryPath [ readline ncurses stdenv.cc.libc.out qt48 stdenv.cc.cc libidn expat flac libvorbis ]}" opt/google/musicmanager/MusicManager
   '';
 
   dontPatchELF = true;
diff --git a/pkgs/applications/audio/milkytracker/default.nix b/pkgs/applications/audio/milkytracker/default.nix
index 8bc0aebba5a8..f22ccd08a8e8 100644
--- a/pkgs/applications/audio/milkytracker/default.nix
+++ b/pkgs/applications/audio/milkytracker/default.nix
@@ -29,7 +29,7 @@ stdenv.mkDerivation rec {
   '';
 
   preBuild=''
-    export CPATH=${zlib}/lib
+    export CPATH=${zlib.out}/lib
   '';
 
   buildInputs = [ SDL alsaLib autoconf automake libjack2 perl zlib zziplib ];
diff --git a/pkgs/applications/audio/spotify/default.nix b/pkgs/applications/audio/spotify/default.nix
index cdfbf2f2b4c7..6e4bf1b73111 100644
--- a/pkgs/applications/audio/spotify/default.nix
+++ b/pkgs/applications/audio/spotify/default.nix
@@ -68,10 +68,10 @@ stdenv.mkDerivation {
       # Work around Spotify referring to a specific minor version of
       # OpenSSL.
 
-      ln -s ${openssl_1_0_1}/lib/libssl.so $libdir/libssl.so.1.0.0
-      ln -s ${openssl_1_0_1}/lib/libcrypto.so $libdir/libcrypto.so.1.0.0
-      ln -s ${nspr}/lib/libnspr4.so $libdir/libnspr4.so
-      ln -s ${nspr}/lib/libplc4.so $libdir/libplc4.so
+      ln -s ${openssl_1_0_1.out}/lib/libssl.so $libdir/libssl.so.1.0.0
+      ln -s ${openssl_1_0_1.out}/lib/libcrypto.so $libdir/libcrypto.so.1.0.0
+      ln -s ${nspr.out}/lib/libnspr4.so $libdir/libnspr4.so
+      ln -s ${nspr.out}/lib/libplc4.so $libdir/libplc4.so
 
       rpath="$out/share/spotify:$libdir"
 
diff --git a/pkgs/applications/audio/swh-lv2/default.nix b/pkgs/applications/audio/swh-lv2/default.nix
index 2955a9371ff6..4bc7801637c6 100644
--- a/pkgs/applications/audio/swh-lv2/default.nix
+++ b/pkgs/applications/audio/swh-lv2/default.nix
@@ -10,7 +10,7 @@ stdenv.mkDerivation rec {
   };
 
   patchPhase = ''
-    sed -e "s#xsltproc#${libxslt}/bin/xsltproc#" -i Makefile
+    sed -e "s#xsltproc#${libxslt.bin}/bin/xsltproc#" -i Makefile
     sed -e "s#PREFIX = /usr/local#PREFIX = $out#" -i Makefile
   '';
 
diff --git a/pkgs/applications/audio/yoshimi/default.nix b/pkgs/applications/audio/yoshimi/default.nix
index 5d60824c3b0d..e9a42b3bbea4 100644
--- a/pkgs/applications/audio/yoshimi/default.nix
+++ b/pkgs/applications/audio/yoshimi/default.nix
@@ -22,7 +22,7 @@ stdenv.mkDerivation  rec {
 
   preConfigure = "cd src";
 
-  cmakeFlags = [ "-DFLTK_MATH_LIBRARY=${stdenv.glibc}/lib/libm.so -DCMAKE_INSTALL_DATAROOTDIR=$out" ];
+  cmakeFlags = [ "-DFLTK_MATH_LIBRARY=${stdenv.glibc.out}/lib/libm.so -DCMAKE_INSTALL_DATAROOTDIR=$out" ];
 
   meta = with stdenv.lib; {
     description = "high quality software synthesizer based on ZynAddSubFX";
diff --git a/pkgs/applications/display-managers/slim/default.nix b/pkgs/applications/display-managers/slim/default.nix
index 42d2c777aea2..f3147ca5187c 100644
--- a/pkgs/applications/display-managers/slim/default.nix
+++ b/pkgs/applications/display-managers/slim/default.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchurl, cmake, pkgconfig, xorg, libjpeg, libpng
-, fontconfig, freetype, pam, dbus_libs, makeWrapper, pkgs }:
+, fontconfig, freetype, pam, dbus_libs, makeWrapper }:
 
 stdenv.mkDerivation rec {
   name = "slim-1.3.6";
@@ -30,7 +30,7 @@ stdenv.mkDerivation rec {
 
   buildInputs =
     [ cmake pkgconfig libjpeg libpng fontconfig freetype
-      pam dbus_libs
+      pam dbus_libs (stdenv.cc.libc.out or null)
       xorg.libX11 xorg.libXext xorg.libXrandr xorg.libXrender xorg.libXmu xorg.libXft makeWrapper
     ];
 
diff --git a/pkgs/applications/editors/brackets/default.nix b/pkgs/applications/editors/brackets/default.nix
index 131675486bad..127ed981a6c8 100644
--- a/pkgs/applications/editors/brackets/default.nix
+++ b/pkgs/applications/editors/brackets/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchurl, buildEnv, gtk, glib, gdk_pixbuf, alsaLib, nss, nspr, gconf
-, cups, libgcrypt_1_5, makeWrapper, dbus, udev }:
+, cups, libgcrypt_1_5, libudev, makeWrapper, dbus }:
 let
   bracketsEnv = buildEnv {
     name = "env-brackets";
     paths = [
       gtk glib gdk_pixbuf stdenv.cc.cc alsaLib nss nspr gconf cups libgcrypt_1_5
-      dbus udev
+      dbus libudev.out
     ];
   };
 in
@@ -31,7 +31,7 @@ stdenv.mkDerivation rec {
     rmdir $out/usr
     ln -sf $out/opt/brackets/brackets $out/bin/brackets
 
-    ln -s ${udev}/lib/libudev.so.1 $out/opt/brackets/lib/libudev.so.0
+    ln -s ${libudev.out}/lib/libudev.so.1 $out/opt/brackets/lib/libudev.so.0
 
     patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
       --set-rpath "${bracketsEnv}/lib:${bracketsEnv}/lib64" \
diff --git a/pkgs/applications/editors/codeblocks/default.nix b/pkgs/applications/editors/codeblocks/default.nix
index 53b7b5750a04..76df6d4d2b99 100644
--- a/pkgs/applications/editors/codeblocks/default.nix
+++ b/pkgs/applications/editors/codeblocks/default.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = true;
   patches = [ ./writable-projects.patch ];
   preConfigure = "substituteInPlace ./configure --replace /usr/bin/file ${file}/bin/file";
-  postConfigure = optionalString stdenv.isLinux "substituteInPlace libtool --replace ldconfig ${stdenv.cc.libc}/sbin/ldconfig";
+  postConfigure = optionalString stdenv.isLinux "substituteInPlace libtool --replace ldconfig ${stdenv.cc.libc.bin}/bin/ldconfig";
   configureFlags = [ "--enable-pch=no" ]
     ++ optional contribPlugins "--with-contrib-plugins";
 
diff --git a/pkgs/applications/editors/eclipse/default.nix b/pkgs/applications/editors/eclipse/default.nix
index 75736356fb27..f692d40fb121 100644
--- a/pkgs/applications/editors/eclipse/default.nix
+++ b/pkgs/applications/editors/eclipse/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, makeDesktopItem, makeWrapper
+{ stdenv, lib, fetchurl, makeDesktopItem, makeWrapper
 , freetype, fontconfig, libX11, libXext, libXrender, zlib
 , glib, gtk, libXtst, jre
 , webkitgtk2 ? null  # for internal web browser
diff --git a/pkgs/applications/editors/edbrowse/default.nix b/pkgs/applications/editors/edbrowse/default.nix
index d969552ecde4..712ede2e316f 100644
--- a/pkgs/applications/editors/edbrowse/default.nix
+++ b/pkgs/applications/editors/edbrowse/default.nix
@@ -10,7 +10,7 @@ stdenv.mkDerivation rec {
     substituteInPlace src/ebjs.c --replace \"edbrowse-js\" \"$out/bin/edbrowse-js\"
   '';
 
-  NIX_CFLAGS_COMPILE = "-I${spidermonkey_24}/include/mozjs-24";
+  NIX_CFLAGS_COMPILE = "-I${spidermonkey_24.dev}/include/mozjs-24";
   makeFlags = "-C src prefix=$(out)";
 
   src = fetchurl {
diff --git a/pkgs/applications/editors/emacs-24/default.nix b/pkgs/applications/editors/emacs-24/default.nix
index 1db56577278c..05b64eaf7ab6 100644
--- a/pkgs/applications/editors/emacs-24/default.nix
+++ b/pkgs/applications/editors/emacs-24/default.nix
@@ -60,7 +60,7 @@ stdenv.mkDerivation rec {
              "--with-gif=no" "--with-tiff=no" ];
 
   NIX_CFLAGS_COMPILE = stdenv.lib.optionalString (stdenv.isDarwin && withX)
-    "-I${cairo}/include/cairo";
+    "-I${cairo.dev}/include/cairo";
 
   postInstall = ''
     mkdir -p $out/share/emacs/site-lisp/
diff --git a/pkgs/applications/editors/emacs-24/macport-24.5.nix b/pkgs/applications/editors/emacs-24/macport-24.5.nix
index c778c42de857..ae0a66b30fee 100644
--- a/pkgs/applications/editors/emacs-24/macport-24.5.nix
+++ b/pkgs/applications/editors/emacs-24/macport-24.5.nix
@@ -40,7 +40,7 @@ stdenv.mkDerivation rec {
   '';
 
   configureFlags = [
-    "LDFLAGS=-L${ncurses}/lib"
+    "LDFLAGS=-L${ncurses.lib}/lib"
     "--with-xml2=yes"
     "--with-gnutls=yes"
     "--with-mac"
@@ -48,7 +48,7 @@ stdenv.mkDerivation rec {
   ];
 
   CFLAGS = "-O3";
-  LDFLAGS = "-O3 -L${ncurses}/lib";
+  LDFLAGS = "-O3 -L${ncurses.lib}/lib";
 
   postInstall = ''
     mkdir -p $out/share/emacs/site-lisp/
diff --git a/pkgs/applications/editors/heme/default.nix b/pkgs/applications/editors/heme/default.nix
index d377e5cb36f6..19c4183ea672 100644
--- a/pkgs/applications/editors/heme/default.nix
+++ b/pkgs/applications/editors/heme/default.nix
@@ -10,10 +10,11 @@ stdenv.mkDerivation rec {
   postPatch = ''
     substituteInPlace Makefile \
       --replace "/usr/local" "$out" \
-      --replace "CFLAGS = " "CFLAGS = -I${ncurses}/include " \
-      --replace "LDFLAGS = " "LDFLAGS = -L${ncurses}/lib " \
+      --replace "CFLAGS = " "CFLAGS = -I${ncurses.dev}/include " \
+      --replace "LDFLAGS = " "LDFLAGS = -L${ncurses.lib}/lib " \
       --replace "-lcurses" "-lncurses"
   '';
+  buildInputs = [ ncurses ];
   preBuild = ''
     mkdir -p $out/bin
     mkdir -p $out/man/man1
diff --git a/pkgs/applications/editors/idea/common.nix b/pkgs/applications/editors/idea/common.nix
index 36f600c14860..fbe6210a39ba 100644
--- a/pkgs/applications/editors/idea/common.nix
+++ b/pkgs/applications/editors/idea/common.nix
@@ -37,7 +37,7 @@ with stdenv; lib.makeOverridable mkDerivation rec {
         truncate --size=$size $fname
       }
 
-      interpreter=$(echo ${stdenv.glibc}/lib/ld-linux*.so.2)
+      interpreter=$(echo ${stdenv.glibc.out}/lib/ld-linux*.so.2)
       if [ "${stdenv.system}" == "x86_64-linux" ]; then
         target_size=$(get_file_size bin/fsnotifier64)
         patchelf --set-interpreter "$interpreter" bin/fsnotifier64
diff --git a/pkgs/applications/editors/lighttable/default.nix b/pkgs/applications/editors/lighttable/default.nix
index 6dbeff55063c..72ecbbc59839 100644
--- a/pkgs/applications/editors/lighttable/default.nix
+++ b/pkgs/applications/editors/lighttable/default.nix
@@ -1,6 +1,6 @@
 { stdenv, fetchurl, buildEnv, makeDesktopItem, makeWrapper, zlib, glib, alsaLib
 , dbus, gtk, atk, pango, freetype, fontconfig, libgnome_keyring3, gdk_pixbuf
-, cairo, cups, expat, libgpgerror, nspr, gnome3, nss, xorg, udev
+, cairo, cups, expat, libgpgerror, nspr, gnome3, nss, xorg, libudev
 }:
 
 let
@@ -44,7 +44,7 @@ stdenv.mkDerivation rec {
       --set-rpath ${libPath}:${stdenv.cc.cc}/lib${stdenv.lib.optionalString stdenv.is64bit "64"} \
       $out/LightTable/ltbin
 
-    ln -sf ${udev}/lib/libudev.so.1 $out/LightTable/libudev.so.0
+    ln -sf ${libudev.out}/lib/libudev.so.1 $out/LightTable/libudev.so.0
 
     makeWrapper $out/LightTable/ltbin $out/bin/lighttable \
       --prefix "LD_LIBRARY_PATH" : $out/LightTable
diff --git a/pkgs/applications/editors/music/tuxguitar/default.nix b/pkgs/applications/editors/music/tuxguitar/default.nix
index 768842a3875d..65ea62b33686 100644
--- a/pkgs/applications/editors/music/tuxguitar/default.nix
+++ b/pkgs/applications/editors/music/tuxguitar/default.nix
@@ -26,7 +26,7 @@ in stdenv.mkDerivation rec {
 
     wrapProgram $out/bin/tuxguitar \
       --set JAVA "${jdk}/bin/java" \
-      --prefix LD_LIBRARY_PATH : "$out/lib/:${swt}/lib:${alsaLib}/lib" \
+      --prefix LD_LIBRARY_PATH : "$out/lib/:${swt}/lib:${alsaLib.out}/lib" \
       --prefix CLASSPATH : "${swt}/jars/swt.jar:$out/lib/tuxguitar.jar:$out/lib/itext.jar"
   '';
 
diff --git a/pkgs/applications/editors/sublime3/default.nix b/pkgs/applications/editors/sublime3/default.nix
index 49c30a1f6d60..5a1d10a1468c 100644
--- a/pkgs/applications/editors/sublime3/default.nix
+++ b/pkgs/applications/editors/sublime3/default.nix
@@ -57,7 +57,7 @@ in let
         --set NIX_REDIRECTS ${builtins.concatStringsSep ":" redirects}
 
       # Without this, plugin_host crashes, even though it has the rpath
-      wrapProgram $out/plugin_host --prefix LD_PRELOAD : ${stdenv.cc.cc}/lib${stdenv.lib.optionalString stdenv.is64bit "64"}/libgcc_s.so.1:${openssl}/lib/libssl.so:${bzip2}/lib/libbz2.so
+      wrapProgram $out/plugin_host --prefix LD_PRELOAD : ${stdenv.cc.cc}/lib${stdenv.lib.optionalString stdenv.is64bit "64"}/libgcc_s.so.1:${openssl.out}/lib/libssl.so:${bzip2.out}/lib/libbz2.so
     '';
   };
 in stdenv.mkDerivation {
diff --git a/pkgs/applications/editors/texmacs/default.nix b/pkgs/applications/editors/texmacs/default.nix
index e415239d76fb..e51813459c6f 100644
--- a/pkgs/applications/editors/texmacs/default.nix
+++ b/pkgs/applications/editors/texmacs/default.nix
@@ -69,7 +69,7 @@ stdenv.mkDerivation rec {
   postFixup = ''
     bin="$out/libexec/TeXmacs/bin/texmacs.bin"
     rpath=$(patchelf --print-rpath "$bin")
-    patchelf --set-rpath "$rpath:${zlib}/lib" "$bin"
+    patchelf --set-rpath "$rpath:${zlib.out}/lib" "$bin"
   '';
 
   meta = {
diff --git a/pkgs/applications/graphics/darktable/default.nix b/pkgs/applications/graphics/darktable/default.nix
index 77bddc89e2fc..1715e3785dac 100644
--- a/pkgs/applications/graphics/darktable/default.nix
+++ b/pkgs/applications/graphics/darktable/default.nix
@@ -26,21 +26,21 @@ stdenv.mkDerivation rec {
     ];
 
   preConfigure = ''
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gtk}/include/gtk-2.0"
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gtk}/lib/gtk-2.0/include"
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${cairo}/include/cairo"
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${atk}/include/atk-1.0"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gtk.dev}/include/gtk-2.0"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gtk.out}/lib/gtk-2.0/include"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${cairo.dev}/include/cairo"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${atk.dev}/include/atk-1.0"
     export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${ilmbase}/include/OpenEXR"
     export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${openexr}/include/OpenEXR"
   '';
 
   cmakeFlags = [
-    "-DPTHREAD_INCLUDE_DIR=${stdenv.glibc}/include"
-    "-DPTHREAD_LIBRARY=${stdenv.glibc}/lib/libpthread.so"
+    "-DPTHREAD_INCLUDE_DIR=${stdenv.glibc.dev}/include"
+    "-DPTHREAD_LIBRARY=${stdenv.glibc.out}/lib/libpthread.so"
     "-DCMAKE_BUILD_TYPE=Release"
     "-DBINARY_PACKAGE_BUILD=1"
-    "-DGTK2_GLIBCONFIG_INCLUDE_DIR=${glib}/lib/glib-2.0/include"
-    "-DGTK2_GDKCONFIG_INCLUDE_DIR=${gtk}/lib/gtk-2.0/include"
+    "-DGTK2_GLIBCONFIG_INCLUDE_DIR=${glib.out}/lib/glib-2.0/include"
+    "-DGTK2_GDKCONFIG_INCLUDE_DIR=${gtk.out}/lib/gtk-2.0/include"
     "-DBUILD_USERMANUAL=False"
   ];
 
diff --git a/pkgs/applications/graphics/digikam/default.nix b/pkgs/applications/graphics/digikam/default.nix
index bdf8077624db..bc3678811a5b 100644
--- a/pkgs/applications/graphics/digikam/default.nix
+++ b/pkgs/applications/graphics/digikam/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
 
   # Help digiKam find libusb, otherwise gphoto2 support is disabled
   cmakeFlags = [
-    "-DLIBUSB_LIBRARIES=${libusb1}/lib"
+    "-DLIBUSB_LIBRARIES=${libusb1.out}/lib"
     "-DLIBUSB_INCLUDE_DIR=${libusb1}/include/libusb-1.0"
     "-DDIGIKAMSC_COMPILE_LIBKFACE=ON"
   ];
diff --git a/pkgs/applications/graphics/feh/default.nix b/pkgs/applications/graphics/feh/default.nix
index 8602a9a04f85..39132bb9b6f8 100644
--- a/pkgs/applications/graphics/feh/default.nix
+++ b/pkgs/applications/graphics/feh/default.nix
@@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
     sha256 = "0j5wxpqccnd0hl74z2vwv25n7qnik1n2mcm2jn0c0z7cjn4wsa9q";
   };
 
+  outputs = [ "out" "doc" ];
+
   nativeBuildInputs = [ makeWrapper ];
   buildInputs = [ xlibsWrapper imlib2 libjpeg libpng libXinerama curl libexif ];
 
@@ -17,7 +19,7 @@ stdenv.mkDerivation rec {
   '';
 
   postInstall = ''
-    wrapProgram "$out/bin/feh" --prefix PATH : "${libjpeg}/bin" \
+    wrapProgram "$out/bin/feh" --prefix PATH : "${libjpeg.bin}/bin" \
                                --add-flags '--theme=feh'
   '';
 
diff --git a/pkgs/applications/graphics/gimp/2.8.nix b/pkgs/applications/graphics/gimp/2.8.nix
index 96d6dbd52857..1184a498c668 100644
--- a/pkgs/applications/graphics/gimp/2.8.nix
+++ b/pkgs/applications/graphics/gimp/2.8.nix
@@ -30,7 +30,7 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = true;
 
   # "screenshot" needs this.
-  NIX_LDFLAGS = "-rpath ${xorg.libX11}/lib"
+  NIX_LDFLAGS = "-rpath ${xorg.libX11.out}/lib"
     + stdenv.lib.optionalString stdenv.isDarwin " -lintl";
 
   meta = {
diff --git a/pkgs/applications/graphics/seg3d/default.nix b/pkgs/applications/graphics/seg3d/default.nix
index 23a2d23b1ae1..d645a15b02ea 100644
--- a/pkgs/applications/graphics/seg3d/default.nix
+++ b/pkgs/applications/graphics/seg3d/default.nix
@@ -13,8 +13,8 @@ stdenv.mkDerivation {
   patches = [ ./cstdio.patch ];
 
   cmakeFlags = [
-    "-DM_LIBRARY=${stdenv.glibc}/lib/libm.so"
-    "-DDL_LIBRARY=${stdenv.glibc}/lib/libdl.so"
+    "-DM_LIBRARY=${stdenv.glibc.out}/lib/libm.so"
+    "-DDL_LIBRARY=${stdenv.glibc.out}/lib/libdl.so"
     "-DBUILD_UTILS=1"
     "-DBUILD_SEG3D=1"
     "-DBUILD_DATAFLOW=0"
diff --git a/pkgs/applications/graphics/shotwell/default.nix b/pkgs/applications/graphics/shotwell/default.nix
index da8bbad33cad..3238a3ba974d 100644
--- a/pkgs/applications/graphics/shotwell/default.nix
+++ b/pkgs/applications/graphics/shotwell/default.nix
@@ -30,7 +30,7 @@ stdenv.mkDerivation rec {
   preFixup = ''
     wrapProgram "$out/bin/shotwell" \
      --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-     --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3}/share:$out/share:$GSETTINGS_SCHEMAS_PATH" \
+     --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3.out}/share:$out/share:$GSETTINGS_SCHEMAS_PATH" \
      --prefix GIO_EXTRA_MODULES : "${gnome3.dconf}/lib/gio/modules"
   '';
 
diff --git a/pkgs/applications/graphics/xfig/default.nix b/pkgs/applications/graphics/xfig/default.nix
index 9e53fe3efe2c..ca1d5345fb6a 100644
--- a/pkgs/applications/graphics/xfig/default.nix
+++ b/pkgs/applications/graphics/xfig/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation {
 
   nativeBuildInputs = [ imake makeWrapper ];
 
-  NIX_CFLAGS_COMPILE = "-I${libXpm}/include/X11";
+  NIX_CFLAGS_COMPILE = "-I${libXpm.dev}/include/X11";
 
   patches =
     let
diff --git a/pkgs/applications/kde-apps-15.12/kdelibs/default.nix b/pkgs/applications/kde-apps-15.12/kdelibs/default.nix
index a30b19774f2a..91c1f3af448a 100644
--- a/pkgs/applications/kde-apps-15.12/kdelibs/default.nix
+++ b/pkgs/applications/kde-apps-15.12/kdelibs/default.nix
@@ -2,7 +2,7 @@
 , docbook_xml_dtd_42, docbook_xsl, flex, giflib, ilmbase
 , libdbusmenu_qt, libjpeg, libxml2, libxslt, perl, phonon, pkgconfig
 , polkit_qt4, qca2, qt4, shared_desktop_ontologies, shared_mime_info
-, soprano, strigi, udev, xz
+, soprano, strigi, udev, xz, pcre
 , lib
 }:
 
@@ -11,7 +11,7 @@ kdeApp {
 
   buildInputs = [
     attica attr avahi giflib libdbusmenu_qt libjpeg libxml2
-    polkit_qt4 qca2 shared_desktop_ontologies udev xz
+    polkit_qt4 qca2 shared_desktop_ontologies udev xz pcre
   ];
   propagatedBuildInputs = [ qt4 soprano phonon strigi ];
   nativeBuildInputs = [
diff --git a/pkgs/applications/misc/audio/soxr/default.nix b/pkgs/applications/misc/audio/soxr/default.nix
index 135ae47aa846..941e1a393b15 100644
--- a/pkgs/applications/misc/audio/soxr/default.nix
+++ b/pkgs/applications/misc/audio/soxr/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "0xf2w3piwz9gfr1xqyrj4k685q5dy53kq3igv663i4f4y4sg9rjl";
   };
 
+  outputs = [ "out" "doc" ]; # headers are just two and very small
+
   preConfigure = if stdenv.isDarwin then ''
     export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:"`pwd`/build/src
   '' else ''
diff --git a/pkgs/applications/misc/calibre/default.nix b/pkgs/applications/misc/calibre/default.nix
index 28e97a930674..f464c3ccd027 100644
--- a/pkgs/applications/misc/calibre/default.nix
+++ b/pkgs/applications/misc/calibre/default.nix
@@ -40,11 +40,11 @@ stdenv.mkDerivation rec {
   installPhase = ''
     export HOME=$TMPDIR/fakehome
     export POPPLER_INC_DIR=${poppler_utils}/include/poppler
-    export POPPLER_LIB_DIR=${poppler_utils}/lib
+    export POPPLER_LIB_DIR=${poppler_utils.out}/lib
     export MAGICK_INC=${imagemagick}/include/ImageMagick
     export MAGICK_LIB=${imagemagick}/lib
-    export FC_INC_DIR=${fontconfig}/include/fontconfig
-    export FC_LIB_DIR=${fontconfig}/lib
+    export FC_INC_DIR=${fontconfig.dev}/include/fontconfig
+    export FC_LIB_DIR=${fontconfig.lib}/lib
     export PODOFO_INC_DIR=${podofo}/include/podofo
     export PODOFO_LIB_DIR=${podofo}/lib
     export SIP_BIN=${sip_4_16}/bin/sip
diff --git a/pkgs/applications/misc/djvulibre/default.nix b/pkgs/applications/misc/djvulibre/default.nix
index b0f89cc5ea03..910b24358b48 100644
--- a/pkgs/applications/misc/djvulibre/default.nix
+++ b/pkgs/applications/misc/djvulibre/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "0psh3zl9dj4n4r3lx25390nx34xz0bg0ql48zdskhq354ljni5p6";
   };
 
+  outputs = [ "dev" "out" "bin" ];
+
   buildInputs = [ libjpeg libtiff librsvg ] ++ libintlOrEmpty;
 
   NIX_LDFLAGS = stdenv.lib.optionalString stdenv.isDarwin "-lintl";
diff --git a/pkgs/applications/misc/get_iplayer/default.nix b/pkgs/applications/misc/get_iplayer/default.nix
index 488a9a3732e2..e6ca8d207e89 100644
--- a/pkgs/applications/misc/get_iplayer/default.nix
+++ b/pkgs/applications/misc/get_iplayer/default.nix
@@ -17,7 +17,7 @@ buildPerlPackage {
   installPhase = '' 
     mkdir -p $out/bin
     cp get_iplayer $out/bin
-    wrapProgram $out/bin/get_iplayer --suffix PATH : ${ffmpeg}/bin:${flvstreamer}/bin:${vlc}/bin:${rtmpdump}/bin --prefix PERL5LIB : $PERL5LIB
+    wrapProgram $out/bin/get_iplayer --suffix PATH : ${ffmpeg.bin}/bin:${flvstreamer}/bin:${vlc}/bin:${rtmpdump}/bin --prefix PERL5LIB : $PERL5LIB
   '';  
   
   src = fetchurl {
diff --git a/pkgs/applications/misc/girara/default.nix b/pkgs/applications/misc/girara/default.nix
index e91e94695f5a..7bb5fb7ddcc0 100644
--- a/pkgs/applications/misc/girara/default.nix
+++ b/pkgs/applications/misc/girara/default.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ pkgconfig gtk gettext ];
 
   makeFlags = [ "PREFIX=$(out)" ]
-    ++ optional withBuildColors "TPUT=${ncurses}/bin/tput"
+    ++ optional withBuildColors "TPUT=${ncurses.dev}/bin/tput"
     ++ optional (!withBuildColors) "TPUT_AVAILABLE=0"
     ;
 
diff --git a/pkgs/applications/misc/ikiwiki/default.nix b/pkgs/applications/misc/ikiwiki/default.nix
index 1f78355ca3a1..3e35b7bde4b8 100644
--- a/pkgs/applications/misc/ikiwiki/default.nix
+++ b/pkgs/applications/misc/ikiwiki/default.nix
@@ -66,7 +66,7 @@ stdenv.mkDerivation {
       ${lib.optionalString bazaarSupport ''--prefix PATH : ${bazaar}/bin \''}
       ${lib.optionalString cvsSupport ''--prefix PATH : ${cvs}/bin \''}
       ${lib.optionalString cvsSupport ''--prefix PATH : ${cvsps}/bin \''}
-      ${lib.optionalString subversionSupport ''--prefix PATH : ${subversion}/bin \''}
+      ${lib.optionalString subversionSupport ''--prefix PATH : ${subversion.out}/bin \''}
       ${lib.optionalString mercurialSupport ''--prefix PATH : ${mercurial}/bin \''}
       ${lib.concatMapStrings (x: "--prefix PATH : ${x}/bin ") extraUtils}
     done
diff --git a/pkgs/applications/misc/kiwix/default.nix b/pkgs/applications/misc/kiwix/default.nix
index 30db6a45ea1b..d29e4fca3b29 100644
--- a/pkgs/applications/misc/kiwix/default.nix
+++ b/pkgs/applications/misc/kiwix/default.nix
@@ -93,7 +93,7 @@ stdenv.mkDerivation rec {
     make install
     cp -r src/dependencies/xulrunner $out/lib/kiwix
 
-    patchelf --set-interpreter ${glibc}/lib/ld-linux${optionalString (stdenv.system == "x86_64-linux") "-x86-64"}.so.2 $out/lib/kiwix/xulrunner/xulrunner
+    patchelf --set-interpreter ${glibc.out}/lib/ld-linux${optionalString (stdenv.system == "x86_64-linux") "-x86-64"}.so.2 $out/lib/kiwix/xulrunner/xulrunner
 
     rm $out/bin/kiwix
     makeWrapper $out/lib/kiwix/kiwix-launcher $out/bin/kiwix \
diff --git a/pkgs/applications/misc/monero/default.nix b/pkgs/applications/misc/monero/default.nix
index e7829be03647..1fa5d1a28d57 100644
--- a/pkgs/applications/misc/monero/default.nix
+++ b/pkgs/applications/misc/monero/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation {
   checkTarget = "test-release"; # this would be the target
 
   installPhase = ''
-    installBin \
+    install -Dt "$out/bin/" \
         src/bitmonerod \
         src/connectivity_tool \
         src/simpleminer \
diff --git a/pkgs/applications/misc/mysql-workbench/default.nix b/pkgs/applications/misc/mysql-workbench/default.nix
index 16a20015c629..056edd801c07 100644
--- a/pkgs/applications/misc/mysql-workbench/default.nix
+++ b/pkgs/applications/misc/mysql-workbench/default.nix
@@ -21,7 +21,7 @@ stdenv.mkDerivation rec {
     mysql.lib paramiko pcre pexpect pkgconfig pycrypto python sqlite ];
 
   preConfigure = ''
-    substituteInPlace $(pwd)/frontend/linux/workbench/mysql-workbench.in --replace "catchsegv" "${glibc}/bin/catchsegv"
+    substituteInPlace $(pwd)/frontend/linux/workbench/mysql-workbench.in --replace "catchsegv" "${glibc.bin}/bin/catchsegv"
   '';
 
   postInstall = ''
diff --git a/pkgs/applications/misc/nut/default.nix b/pkgs/applications/misc/nut/default.nix
index 3e972f672cc2..25c904880923 100644
--- a/pkgs/applications/misc/nut/default.nix
+++ b/pkgs/applications/misc/nut/default.nix
@@ -29,7 +29,7 @@ stdenv.mkDerivation rec {
   
   postInstall = ''
     wrapProgram $out/bin/nut-scanner --prefix LD_LIBRARY_PATH : \
-      "$out/lib:${neon}/lib:${libusb}/lib:${avahi}/lib:${freeipmi}/lib"
+      "$out/lib:${neon}/lib:${libusb.out}/lib:${avahi}/lib:${freeipmi}/lib"
   '';
 
   meta = {
diff --git a/pkgs/applications/misc/pdfmod/default.nix b/pkgs/applications/misc/pdfmod/default.nix
index f23238b2dc61..12e3e696777d 100644
--- a/pkgs/applications/misc/pdfmod/default.nix
+++ b/pkgs/applications/misc/pdfmod/default.nix
@@ -39,7 +39,7 @@ stdenv.mkDerivation rec {
       --prefix LD_LIBRARY_PATH : ${gnome-sharp}/lib \
       --prefix LD_LIBRARY_PATH : ${gtk-sharp.gtk}/lib \
       --prefix LD_LIBRARY_PATH : ${gnome3.gconf}/lib \
-      --prefix LD_LIBRARY_PATH : ${poppler}/lib
+      --prefix LD_LIBRARY_PATH : ${poppler.out}/lib
   '';
 
   dontStrip = true;
diff --git a/pkgs/applications/misc/pinfo/default.nix b/pkgs/applications/misc/pinfo/default.nix
index 658ff410d379..222dddc0e897 100644
--- a/pkgs/applications/misc/pinfo/default.nix
+++ b/pkgs/applications/misc/pinfo/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation {
 
   buildInputs = [ autoreconfHook gettext texinfo ncurses readline ];
 
-  configureFlags = [ "--with-curses=${ncurses}" "--with-readline=${readline}" ];
+  configureFlags = [ "--with-curses=${ncurses.dev}" "--with-readline=${readline}" ];
 
   meta = with stdenv.lib; {
     description = "A viewer for info files";
diff --git a/pkgs/applications/misc/roxterm/default.nix b/pkgs/applications/misc/roxterm/default.nix
index 60322c2b911e..096ee9381c73 100644
--- a/pkgs/applications/misc/roxterm/default.nix
+++ b/pkgs/applications/misc/roxterm/default.nix
@@ -24,9 +24,9 @@ in stdenv.mkDerivation rec {
   propagatedBuildInputs =
     [ dbus_libs dbus_glib gdk_pixbuf gettext gsettings_desktop_schemas gtk2 gtk3 hicolor_icon_theme vte ];
 
-  NIX_CFLAGS_COMPILE = [ "-I${dbus_glib}/include/dbus-1.0"
-                         "-I${dbus_libs}/include/dbus-1.0"
-                         "-I${dbus_libs}/lib/dbus-1.0/include" ];
+  NIX_CFLAGS_COMPILE = [ "-I${dbus_glib.dev}/include/dbus-1.0"
+                         "-I${dbus_libs.dev}/include/dbus-1.0"
+                         "-I${dbus_libs.lib}/lib/dbus-1.0/include" ];
 
   # Fix up python path so the lockfile library is on it.
   PYTHONPATH = stdenv.lib.makeSearchPath "lib/${pythonFull.libPrefix}/site-packages" [
@@ -35,7 +35,7 @@ in stdenv.mkDerivation rec {
 
   buildPhase = ''
     # Fix up the LD_LIBRARY_PATH so that expat is on it
-    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${expat}/lib"
+    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${expat.out}/lib"
 
     python mscript.py configure --prefix="$out"
     python mscript.py build
diff --git a/pkgs/applications/misc/sweethome3d/default.nix b/pkgs/applications/misc/sweethome3d/default.nix
index 0c9b6e8c08a0..f55d8ed34eeb 100644
--- a/pkgs/applications/misc/sweethome3d/default.nix
+++ b/pkgs/applications/misc/sweethome3d/default.nix
@@ -31,7 +31,7 @@ let
       cp install/${module}-${version}.jar $out/share/java/.
       cp "${sweethome3dItem}/share/applications/"* $out/share/applications
       makeWrapper ${jre}/bin/java $out/bin/$exec \
-        --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3}/share:${gsettings_desktop_schemas}/share:$out/share:$GSETTINGS_SCHEMAS_PATH" \
+        --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3.out}/share:${gsettings_desktop_schemas}/share:$out/share:$GSETTINGS_SCHEMAS_PATH" \
         --add-flags "-jar $out/share/java/${module}-${version}.jar -cp $out/share/java/Furniture.jar:$out/share/java/Textures.jar:$out/share/java/Help.jar ${if stdenv.system == "x86_64-linux" then "-d64" else "-d32"}"
     '';
 
diff --git a/pkgs/applications/misc/sweethome3d/editors.nix b/pkgs/applications/misc/sweethome3d/editors.nix
index 87da1c6643b2..204e5eeae595 100644
--- a/pkgs/applications/misc/sweethome3d/editors.nix
+++ b/pkgs/applications/misc/sweethome3d/editors.nix
@@ -40,7 +40,7 @@ let
       cp ${module}-${version}.jar $out/share/java/.
       cp "${editorItem}/share/applications/"* $out/share/applications
       makeWrapper ${jre}/bin/java $out/bin/$exec \
-        --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3}/share:${gsettings_desktop_schemas}/share:$out/share:$GSETTINGS_SCHEMAS_PATH" \
+        --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3.out}/share:${gsettings_desktop_schemas}/share:$out/share:$GSETTINGS_SCHEMAS_PATH" \
         --add-flags "-jar $out/share/java/${module}-${version}.jar ${if stdenv.system == "x86_64-linux" then "-d64" else "-d32"}"
     '';
 
diff --git a/pkgs/applications/misc/tilda/default.nix b/pkgs/applications/misc/tilda/default.nix
index bf99f0f5f651..43b7312cda64 100644
--- a/pkgs/applications/misc/tilda/default.nix
+++ b/pkgs/applications/misc/tilda/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ pkgconfig autoreconfHook gettext confuse vte gtk makeWrapper ];
 
-  LD_LIBRARY_PATH = "${expat}/lib"; # ugly hack for xgettext to work during build
+  LD_LIBRARY_PATH = "${expat.out}/lib"; # ugly hack for xgettext to work during build
 
   # The config locking scheme relies on the binary being called "tilda",
   # (`pgrep -C tilda`), so a simple `wrapProgram` won't suffice:
diff --git a/pkgs/applications/misc/xca/default.nix b/pkgs/applications/misc/xca/default.nix
index ffba09e69f95..e861973b13cc 100644
--- a/pkgs/applications/misc/xca/default.nix
+++ b/pkgs/applications/misc/xca/default.nix
@@ -11,7 +11,8 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     wrapProgram "$out/bin/xca" \
-      --prefix LD_LIBRARY_PATH : "${qt4}/lib:${gcc.cc}/lib:${gcc.cc}/lib64:${openssl}/lib:${libtool}/lib"
+      --prefix LD_LIBRARY_PATH : \
+        "${gcc.cc.lib}/lib64:${stdenv.lib.makeLibraryPath [ qt4 gcc.cc openssl libtool ]}"
   '';
 
   buildInputs = [ openssl qt4 libtool gcc makeWrapper ];
diff --git a/pkgs/applications/misc/xneur/default.nix b/pkgs/applications/misc/xneur/default.nix
index cc08436fa033..8e3165b75d26 100644
--- a/pkgs/applications/misc/xneur/default.nix
+++ b/pkgs/applications/misc/xneur/default.nix
@@ -23,13 +23,13 @@ stdenv.mkDerivation rec {
     sed -e 's@for imlib2_dir in@for imlib2_dir in ${imlib2} @' -i configure
     sed -e 's@for xosd_dir in@for xosd_dir in ${xosd} @' -i configure
 
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gtk}/include/gtk-2.0"
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gtk}/lib/gtk-2.0/include"
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${cairo}/include/cairo"
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${pango}/include/pango-1.0"
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${atk}/include/atk-1.0"
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gdk_pixbuf}/include/gdk-pixbuf-2.0"
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gdk_pixbuf}/lib/gdk-pixbuf-2.0/include"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gtk.dev}/include/gtk-2.0"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gtk.out}/lib/gtk-2.0/include"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${cairo.dev}/include/cairo"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${pango.dev}/include/pango-1.0"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${atk.dev}/include/atk-1.0"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gdk_pixbuf.dev}/include/gdk-pixbuf-2.0"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gdk_pixbuf.out}/lib/gdk-pixbuf-2.0/include"
 
     export NIX_LDFLAGS="$NIX_LDFLAGS -lnotify"
   '';
diff --git a/pkgs/applications/misc/zathura/core/default.nix b/pkgs/applications/misc/zathura/core/default.nix
index cab6423b77e5..92892b54845c 100644
--- a/pkgs/applications/misc/zathura/core/default.nix
+++ b/pkgs/applications/misc/zathura/core/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
     "PREFIX=$(out)"
     "RSTTOMAN=${docutils}/bin/rst2man.py"
     "VERBOSE=1"
-    "TPUT=${ncurses}/bin/tput"
+    "TPUT=${ncurses.dev}/bin/tput"
   ];
 
   postInstall = ''
diff --git a/pkgs/applications/networking/browsers/chromium/common.nix b/pkgs/applications/networking/browsers/chromium/common.nix
index 237dfd17ac71..e5727e63a100 100644
--- a/pkgs/applications/networking/browsers/chromium/common.nix
+++ b/pkgs/applications/networking/browsers/chromium/common.nix
@@ -8,7 +8,7 @@
 , libusb1, libexif, pciutils, nss
 
 , python, pythonPackages, perl, pkgconfig
-, nspr, udev, kerberos
+, nspr, libudev, kerberos
 , utillinux, alsaLib
 , bison, gperf
 , glib, gtk, dbus_glib
@@ -105,7 +105,7 @@ let
     buildInputs = defaultDependencies ++ [
       which
       python perl pkgconfig
-      nspr nss udev
+      nspr nss libudev
       utillinux alsaLib
       bison gperf kerberos
       glib gtk dbus_glib
@@ -132,7 +132,7 @@ let
         s|= [^;]*|= base::FilePath().AppendASCII("${libexif}/lib/libexif.so")|
       }' chrome/utility/media_galleries/image_metadata_extractor.cc
 
-      sed -i -e '/lib_loader.*Load/s!"\(libudev\.so\)!"${udev}/lib/\1!' \
+      sed -i -e '/lib_loader.*Load/s!"\(libudev\.so\)!"${libudev.out}/lib/\1!' \
         device/udev_linux/udev?_loader.cc
 
       sed -i -e '/libpci_loader.*Load/s!"\(libpci\.so\)!"${pciutils}/lib/\1!' \
diff --git a/pkgs/applications/networking/browsers/dwb/default.nix b/pkgs/applications/networking/browsers/dwb/default.nix
index d79a5215ce21..8a8478d3867a 100644
--- a/pkgs/applications/networking/browsers/dwb/default.nix
+++ b/pkgs/applications/networking/browsers/dwb/default.nix
@@ -18,10 +18,10 @@ stdenv.mkDerivation {
 
   preFixup=''
     wrapProgram "$out/bin/dwb" \
-     --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules:${dconf}/lib/gio/modules" \
+     --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules:${dconf}/lib/gio/modules" \
      --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share"
     wrapProgram "$out/bin/dwbem" \
-     --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules"
+     --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/applications/networking/browsers/jumanji/default.nix b/pkgs/applications/networking/browsers/jumanji/default.nix
index 0e962f5fc1f6..ce9b94409072 100644
--- a/pkgs/applications/networking/browsers/jumanji/default.nix
+++ b/pkgs/applications/networking/browsers/jumanji/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
 
   preFixup=''
     wrapProgram "$out/bin/jumanji" \
-     --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules" \
+     --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules" \
      --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH"
   '';
 
diff --git a/pkgs/applications/networking/browsers/luakit/default.nix b/pkgs/applications/networking/browsers/luakit/default.nix
index a3edaad37d40..2777cb15fca9 100644
--- a/pkgs/applications/networking/browsers/luakit/default.nix
+++ b/pkgs/applications/networking/browsers/luakit/default.nix
@@ -45,7 +45,7 @@ stdenv.mkDerivation {
   in ''
     make DEVELOPMENT_PATHS=0 INSTALLDIR=$out DESTDIR=$out PREFIX=$out USE_GTK3=1 install
     wrapProgram $out/bin/luakit                                         \
-      --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules" \
+      --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules" \
       --prefix XDG_DATA_DIRS : "${gsettings_desktop_schemas}/share:$out/usr/share/:$out/share/:$GSETTINGS_SCHEMAS_PATH"     \
       --prefix XDG_CONFIG_DIRS : "$out/etc/xdg"                         \
       --set LUA_PATH '"${luaKitPath};${luaPath};"'                      \
diff --git a/pkgs/applications/networking/browsers/midori/default.nix b/pkgs/applications/networking/browsers/midori/default.nix
index 336d6ae609d5..353c133ee5d0 100644
--- a/pkgs/applications/networking/browsers/midori/default.nix
+++ b/pkgs/applications/networking/browsers/midori/default.nix
@@ -41,7 +41,7 @@ stdenv.mkDerivation rec {
 
   preFixup = ''
     wrapProgram $out/bin/midori \
-      --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules" \
+      --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules" \
       --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH"
   '';
 }
diff --git a/pkgs/applications/networking/browsers/mozilla-plugins/gecko-mediaplayer/default.nix b/pkgs/applications/networking/browsers/mozilla-plugins/gecko-mediaplayer/default.nix
index ba40925e1d1e..f59de7db9f5c 100644
--- a/pkgs/applications/networking/browsers/mozilla-plugins/gecko-mediaplayer/default.nix
+++ b/pkgs/applications/networking/browsers/mozilla-plugins/gecko-mediaplayer/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   # !!! fix this
   preBuild =
     ''
-      export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I$(echo ${browser}/include/xulrunner-*) -I${browser.nspr}/include/nspr"
+      export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I$(echo ${browser}/include/xulrunner-*) -I${browser.nspr.dev}/include/nspr"
       echo $NIX_CFLAGS_COMPILE
     '';
 
diff --git a/pkgs/applications/networking/browsers/opera/default.nix b/pkgs/applications/networking/browsers/opera/default.nix
index ab199ff97cdf..de7240d3a83b 100644
--- a/pkgs/applications/networking/browsers/opera/default.nix
+++ b/pkgs/applications/networking/browsers/opera/default.nix
@@ -73,7 +73,7 @@ stdenv.mkDerivation rec {
 
   postFixup = ''
     oldRPATH=`patchelf --print-rpath $out/lib/opera/opera`
-    patchelf --set-rpath $oldRPATH:${cups}/lib $out/lib/opera/opera
+    patchelf --set-rpath $oldRPATH:${cups.out}/lib $out/lib/opera/opera
 
     # This file should normally require a gtk-update-icon-cache -q /usr/share/icons/hicolor command
     # It have no reasons to exist in a redistribuable package
diff --git a/pkgs/applications/networking/browsers/surf/default.nix b/pkgs/applications/networking/browsers/surf/default.nix
index 7bbe84847f25..fcaaec63b9e6 100644
--- a/pkgs/applications/networking/browsers/surf/default.nix
+++ b/pkgs/applications/networking/browsers/surf/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
 
   preFixup = ''
     wrapProgram "$out/bin/surf" \
-      --prefix GIO_EXTRA_MODULES : ${glib_networking}/lib/gio/modules \
+      --prefix GIO_EXTRA_MODULES : ${glib_networking.out}/lib/gio/modules \
       --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH"
   '';
 
diff --git a/pkgs/applications/networking/browsers/uzbl/default.nix b/pkgs/applications/networking/browsers/uzbl/default.nix
index 318b95763920..1a46b1adce8a 100644
--- a/pkgs/applications/networking/browsers/uzbl/default.nix
+++ b/pkgs/applications/networking/browsers/uzbl/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
   preFixup = ''
     for f in $out/bin/*; do
       wrapProgram $f \
-        --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules" \
+        --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules" \
         --prefix PYTHONPATH : "$PYTHONPATH" \
         --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share"
     done
diff --git a/pkgs/applications/networking/browsers/vimb/default.nix b/pkgs/applications/networking/browsers/vimb/default.nix
index cfbaa908902d..ddaaa68f60d4 100644
--- a/pkgs/applications/networking/browsers/vimb/default.nix
+++ b/pkgs/applications/networking/browsers/vimb/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
 
   preFixup = ''
     wrapProgram "$out/bin/vimb" \
-      --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules" \
+      --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules" \
       --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH"
   '';
 
diff --git a/pkgs/applications/networking/browsers/vimprobable2/default.nix b/pkgs/applications/networking/browsers/vimprobable2/default.nix
index 6f8eede9b3f8..45aa2a9c2d12 100644
--- a/pkgs/applications/networking/browsers/vimprobable2/default.nix
+++ b/pkgs/applications/networking/browsers/vimprobable2/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
 
   preFixup = ''
     wrapProgram "$out/bin/vimprobable2" \
-      --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules" \
+      --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules" \
       --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH"
   '';
 
diff --git a/pkgs/applications/networking/copy-com/default.nix b/pkgs/applications/networking/copy-com/default.nix
index 0ec2f5ac87a0..21dc23739775 100644
--- a/pkgs/applications/networking/copy-com/default.nix
+++ b/pkgs/applications/networking/copy-com/default.nix
@@ -41,7 +41,7 @@ in stdenv.mkDerivation {
     for binary in Copy{Agent,Console,Cmd}; do
       binary="$out/${appdir}/$binary"
       ln -sv "$binary" "$out/bin"
-      patchelf --set-interpreter ${stdenv.glibc}/lib/${interpreter} "$binary"
+      patchelf --set-interpreter ${stdenv.glibc.out}/lib/${interpreter} "$binary"
     done
 
     RPATH=${libPaths}:$out/${appdir}
diff --git a/pkgs/applications/networking/feedreaders/newsbeuter/dev.nix b/pkgs/applications/networking/feedreaders/newsbeuter/dev.nix
index a254535dd703..99196cdf796b 100644
--- a/pkgs/applications/networking/feedreaders/newsbeuter/dev.nix
+++ b/pkgs/applications/networking/feedreaders/newsbeuter/dev.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
   '';
 
   NIX_CFLAGS_COMPILE =
-    "-I${libxml2}/include/libxml2 -I${json-c-0-11}/include/json-c";
+    "-I${libxml2.dev}/include/libxml2 -I${json-c-0-11}/include/json-c";
 
   NIX_LDFLAGS = "-lsqlite3 -lcurl -lxml2 -lstfl -ljson";
 
diff --git a/pkgs/applications/networking/ike/default.nix b/pkgs/applications/networking/ike/default.nix
index 56341b64d6ce..5ea0975e15f3 100644
--- a/pkgs/applications/networking/ike/default.nix
+++ b/pkgs/applications/networking/ike/default.nix
@@ -33,7 +33,7 @@ stdenv.mkDerivation rec {
   installPhase = ''
     make install
     for file in "$out"/bin/* "$out"/sbin/*; do
-        wrapProgram $file --prefix LD_LIBRARY_PATH ":" "$out/lib:${openssl}/lib:${gcc.cc}/lib:${stdenv.glibc}/lib::${gcc.cc}/lib64:${stdenv.glibc}/lib64:${libedit}/lib:${qt4}/lib"
+        wrapProgram $file --prefix LD_LIBRARY_PATH ":" "$out/lib:${openssl.out}/lib:${gcc.cc}/lib:${stdenv.glibc.out}/lib::${gcc.cc}/lib64:${stdenv.glibc.out}/lib64:${libedit}/lib:${qt4}/lib"
     done
   '';
 
diff --git a/pkgs/applications/networking/instant-messengers/blink/default.nix b/pkgs/applications/networking/instant-messengers/blink/default.nix
index 9c75af2c77f5..ebb63967b008 100644
--- a/pkgs/applications/networking/instant-messengers/blink/default.nix
+++ b/pkgs/applications/networking/instant-messengers/blink/default.nix
@@ -22,7 +22,7 @@ pythonPackages.buildPythonPackage rec {
 
   postInstall = ''
     wrapProgram $out/bin/blink \
-      --prefix LD_LIBRARY_PATH ":" ${gnutls}/lib
+      --prefix LD_LIBRARY_PATH ":" ${gnutls.out}/lib
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/applications/networking/instant-messengers/carrier/2.5.0.nix b/pkgs/applications/networking/instant-messengers/carrier/2.5.0.nix
index 7368a8842147..d29ec7ab8d3b 100644
--- a/pkgs/applications/networking/instant-messengers/carrier/2.5.0.nix
+++ b/pkgs/applications/networking/instant-messengers/carrier/2.5.0.nix
@@ -1,4 +1,4 @@
-args @ { fetchurl, stdenv, pkgconfig, perl, perlXMLParser, libxml2, openssl, nss
+args @ { fetchurl, stdenv, pkgconfig, perl, perlXMLParser, libxml2, openssl, nss, nspr
 , gtkspell, aspell, gettext, ncurses, avahi, dbus, dbus_glib, python
 , libtool, automake, autoconf, gstreamer
 , gtk, glib
@@ -19,7 +19,7 @@ rec {
 
   buildInputs = [gtkspell aspell
     gstreamer startupnotification
-    libxml2 openssl nss
+    libxml2 openssl nss nspr
     libXScrnSaver ncurses scrnsaverproto
     libX11 xproto kbproto GConf avahi
     dbus dbus_glib glib python
@@ -29,9 +29,9 @@ rec {
     pkgconfig gtk perl perlXMLParser gettext
   ];
 
-  configureFlags="--with-nspr-includes=${nss}/include/nspr"
-    + " --with-nspr-libs=${nss}/lib --with-nss-includes=${nss}/include/nss"
-    + " --with-nss-libs=${nss}/lib --with-ncurses-headers=${ncurses}/include"
+  configureFlags="--with-nspr-includes=${nspr.dev}/include/nspr"
+    + " --with-nspr-libs=${nspr.out}/lib --with-nss-includes=${nss.dev}/include/nss"
+    + " --with-nss-libs=${nss.out}/lib --with-ncurses-headers=${ncurses.dev}/include"
     + " --enable-screensaver --disable-meanwhile --disable-nm --disable-tcl";
 
   preBuild = fullDepEntry (''
diff --git a/pkgs/applications/networking/instant-messengers/oneteam/default.nix b/pkgs/applications/networking/instant-messengers/oneteam/default.nix
index 2ab0930842bc..bec367818e2f 100644
--- a/pkgs/applications/networking/instant-messengers/oneteam/default.nix
+++ b/pkgs/applications/networking/instant-messengers/oneteam/default.nix
@@ -43,7 +43,7 @@ rec {
   '' ["minInit" "doUnpack"];
 
   setVars=a.noDepEntry ''
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${nspr}/include/nspr"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${nspr.dev}/include/nspr"
   '';
 
   cmakeBuildDir="cmake-build";
diff --git a/pkgs/applications/networking/instant-messengers/pidgin/default.nix b/pkgs/applications/networking/instant-messengers/pidgin/default.nix
index 5e8f266930ff..ebb82a782625 100644
--- a/pkgs/applications/networking/instant-messengers/pidgin/default.nix
+++ b/pkgs/applications/networking/instant-messengers/pidgin/default.nix
@@ -41,11 +41,11 @@ stdenv.mkDerivation rec {
   patches = [./pidgin-makefile.patch ./add-search-path.patch ];
 
   configureFlags = [
-    "--with-nspr-includes=${nspr}/include/nspr"
-    "--with-nspr-libs=${nspr}/lib"
-    "--with-nss-includes=${nss}/include/nss"
-    "--with-nss-libs=${nss}/lib"
-    "--with-ncurses-headers=${ncurses}/include"
+    "--with-nspr-includes=${nspr.dev}/include/nspr"
+    "--with-nspr-libs=${nspr.out}/lib"
+    "--with-nss-includes=${nss.dev}/include/nss"
+    "--with-nss-libs=${nss.out}/lib"
+    "--with-ncurses-headers=${ncurses.dev}/include"
     "--disable-meanwhile"
     "--disable-nm"
     "--disable-tcl"
diff --git a/pkgs/applications/networking/instant-messengers/pybitmessage/default.nix b/pkgs/applications/networking/instant-messengers/pybitmessage/default.nix
index c19b5ff31f9d..17462cb75ad5 100644
--- a/pkgs/applications/networking/instant-messengers/pybitmessage/default.nix
+++ b/pkgs/applications/networking/instant-messengers/pybitmessage/default.nix
@@ -25,7 +25,7 @@ stdenv.mkDerivation rec {
   postInstall = ''
     substituteInPlace $out/bin/pybitmessage \
       --replace "exec python2" "exec ${python}/bin/python" \
-      --replace "/opt/openssl-compat-bitcoin/lib/" "${openssl}/lib/"
+      --replace "/opt/openssl-compat-bitcoin/lib/" "${openssl.out}/lib/"
     wrapProgram $out/bin/pybitmessage \
       --prefix PYTHONPATH : "$(toPythonPath $out):$PYTHONPATH"
   '';
diff --git a/pkgs/applications/networking/instant-messengers/sflphone/default.nix b/pkgs/applications/networking/instant-messengers/sflphone/default.nix
index 8b259c90fe50..7322ff2bb345 100644
--- a/pkgs/applications/networking/instant-messengers/sflphone/default.nix
+++ b/pkgs/applications/networking/instant-messengers/sflphone/default.nix
@@ -40,7 +40,7 @@ rec {
       cd ..
     '';
 
-    configureFlags = "--with-expat --with-expat-inc=${expat}/include " +
+    configureFlags = "--with-expat --with-expat-inc=${expat.dev}/include " +
       "--with-expat-lib=-lexpat --with-opus ";
 
     buildInputs = [ libyaml alsaLib openssl libuuid pkgconfig libpulseaudio libsamplerate
diff --git a/pkgs/applications/networking/instant-messengers/telepathy/kde/default.nix b/pkgs/applications/networking/instant-messengers/telepathy/kde/default.nix
index 532d68ad6605..84ced8f62c6e 100644
--- a/pkgs/applications/networking/instant-messengers/telepathy/kde/default.nix
+++ b/pkgs/applications/networking/instant-messengers/telepathy/kde/default.nix
@@ -11,11 +11,11 @@ let
     call_ui = x : x // {
       NIX_CFLAGS_COMPILE =
         "-I${telepathy_glib}/include/telepathy-1.0"
-        + " -I${dbus_glib}/include/dbus-1.0"
-        + " -I${dbus_libs}/include/dbus-1.0";
+        + " -I${dbus_glib.dev}/include/dbus-1.0"
+        + " -I${dbus_libs.dev}/include/dbus-1.0";
     };
     telepathy_logger_qt = x : x // {
-      NIX_CFLAGS_COMPILE = "-I${dbus_libs}/include/dbus-1.0";
+      NIX_CFLAGS_COMPILE = "-I${dbus_libs.dev}/include/dbus-1.0";
     };
   };
 
diff --git a/pkgs/applications/networking/instant-messengers/telepathy/logger/default.nix b/pkgs/applications/networking/instant-messengers/telepathy/logger/default.nix
index 173dfe9c929f..aaff39ccb44d 100644
--- a/pkgs/applications/networking/instant-messengers/telepathy/logger/default.nix
+++ b/pkgs/applications/networking/instant-messengers/telepathy/logger/default.nix
@@ -10,7 +10,7 @@ stdenv.mkDerivation rec {
     sha256 = "18i00l8lnp5dghqmgmpxnn0is2a20pkisxy0sb78hnd2dz0z6xnl";
   };
 
-  NIX_CFLAGS_COMPILE = "-I${dbus_glib}/include/dbus-1.0 -I${dbus_libs}/include/dbus-1.0";
+  NIX_CFLAGS_COMPILE = "-I${dbus_glib.dev}/include/dbus-1.0 -I${dbus_libs.dev}/include/dbus-1.0";
 
   buildInputs = [ dbus_glib libxml2 sqlite telepathy_glib pkgconfig intltool
                   gobjectIntrospection dbus_libs ];
diff --git a/pkgs/applications/networking/newsreaders/liferea/default.nix b/pkgs/applications/networking/newsreaders/liferea/default.nix
index 952c763c5f4a..8948ca22ee93 100644
--- a/pkgs/applications/networking/newsreaders/liferea/default.nix
+++ b/pkgs/applications/networking/newsreaders/liferea/default.nix
@@ -32,7 +32,7 @@ stdenv.mkDerivation rec {
       wrapProgram "$f" \
         --prefix PYTHONPATH : "$(toPythonPath $out):$(toPythonPath ${pygobject3})" \
         --prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH" \
-        --prefix GIO_EXTRA_MODULES : "${gnome3.dconf}/lib/gio/modules:${glib_networking}/lib/gio/modules" \
+        --prefix GIO_EXTRA_MODULES : "${gnome3.dconf}/lib/gio/modules:${glib_networking.out}/lib/gio/modules" \
         --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gnome3.gtk}/share:$out/share:$GSETTINGS_SCHEMAS_PATH"
     done
   '';
diff --git a/pkgs/applications/networking/p2p/retroshare/0.6.nix b/pkgs/applications/networking/p2p/retroshare/0.6.nix
index 855ebdd05936..020d00170531 100644
--- a/pkgs/applications/networking/p2p/retroshare/0.6.nix
+++ b/pkgs/applications/networking/p2p/retroshare/0.6.nix
@@ -11,7 +11,7 @@ stdenv.mkDerivation {
     sha256 = "189qndkfq9kgv3qi3wx8ivla4j8fxr4iv7c8y9rjrjaz8jwdkn5x";
   };
 
-  NIX_CFLAGS_COMPILE = "-I${glib}/include/glib-2.0 -I${glib}/lib/glib-2.0/include -I${libxml2}/include/libxml2 -I${sqlcipher}/include/sqlcipher";
+  NIX_CFLAGS_COMPILE = "-I${glib.dev}/include/glib-2.0 -I${glib.dev}/lib/glib-2.0/include -I${libxml2.dev}/include/libxml2 -I${sqlcipher}/include/sqlcipher";
 
   patchPhase = ''
     # Fix build error
diff --git a/pkgs/applications/networking/p2p/retroshare/default.nix b/pkgs/applications/networking/p2p/retroshare/default.nix
index a139531b19a6..e7fe79d66a56 100644
--- a/pkgs/applications/networking/p2p/retroshare/default.nix
+++ b/pkgs/applications/networking/p2p/retroshare/default.nix
@@ -9,7 +9,7 @@ stdenv.mkDerivation {
     sha256 = "0l2n4pr1hq66q6qa073hrdx3s3d7iw54z8ay1zy82zhk2rwhsavp";
   };
 
-  NIX_CFLAGS_COMPILE = "-I${glib}/include/glib-2.0 -I${glib}/lib/glib-2.0/include -I${libxml2}/include/libxml2";
+  NIX_CFLAGS_COMPILE = "-I${glib.dev}/include/glib-2.0 -I${glib.dev}/lib/glib-2.0/include -I${libxml2.dev}/include/libxml2";
 
   patchPhase = ''
     sed -i 's/UpnpString_get_String(es_event->PublisherUrl)/es_event->PublisherUrl/' \
diff --git a/pkgs/applications/networking/spideroak/default.nix b/pkgs/applications/networking/spideroak/default.nix
index 525e15470232..fd060ad08801 100644
--- a/pkgs/applications/networking/spideroak/default.nix
+++ b/pkgs/applications/networking/spideroak/default.nix
@@ -41,7 +41,7 @@ in stdenv.mkDerivation {
     mkdir "$out/bin"
     rm "$out/usr/bin/SpiderOakONE"
 
-    patchelf --set-interpreter ${stdenv.glibc}/lib/${interpreter} \
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/${interpreter} \
       "$out/opt/SpiderOakONE/lib/SpiderOakONE"
 
     RPATH=$out/opt/SpiderOakONE/lib:${ldpath}
diff --git a/pkgs/applications/science/astronomy/celestia/default.nix b/pkgs/applications/science/astronomy/celestia/default.nix
index 86b0ffbcf24c..f2407e1a8333 100644
--- a/pkgs/applications/science/astronomy/celestia/default.nix
+++ b/pkgs/applications/science/astronomy/celestia/default.nix
@@ -59,7 +59,7 @@ stdenv.mkDerivation {
   CPPFLAGS = "-DNDEBUG";
   CFLAGS = "-O2 -fsigned-char";
   CXXFLAGS = "-O2 -fsigned-char";
-  GTK_CFLAGS = "-I${gtk2}/include/gtk-2.0 -I${gtk2}/lib/gtk-2.0/include -I${glib}/include/glib-2.0 -I${glib}/lib/glib-2.0/include -I${cairo}/include/cairo -I${pango}/include/pango-1.0 -I${gdk_pixbuf}/include/gdk-pixbuf-2.0 -I${atk}/include/atk-1.0 -I${gtkglext}/include/gtkglext-1.0 -I${gtkglext}/lib/gtkglext-1.0/include";
+  GTK_CFLAGS = "-I${gtk2.dev}/include/gtk-2.0 -I${gtk2.out}/lib/gtk-2.0/include -I${glib.dev}/include/glib-2.0 -I${glib.out}/lib/glib-2.0/include -I${cairo.dev}/include/cairo -I${pango.dev}/include/pango-1.0 -I${gdk_pixbuf.dev}/include/gdk-pixbuf-2.0 -I${atk}/include/atk-1.0 -I${gtkglext}/include/gtkglext-1.0 -I${gtkglext}/lib/gtkglext-1.0/include";
   GTK_LIBS = "-lgtk-x11-2.0 -lgtkglext-x11-1.0 -lcairo -lgdk_pixbuf-2.0 -lpango-1.0 -lgobject-2.0";
 
   installPhase = ''make MKDIR_P="mkdir -p" install'';
diff --git a/pkgs/applications/science/electronics/tkgate/1.x.nix b/pkgs/applications/science/electronics/tkgate/1.x.nix
index e9849d0460c8..c62ecdcd1e2a 100644
--- a/pkgs/applications/science/electronics/tkgate/1.x.nix
+++ b/pkgs/applications/science/electronics/tkgate/1.x.nix
@@ -1,8 +1,8 @@
 { stdenv, fetchurl, tcl, tk, libX11, glibc, which, yacc, flex, imake, xproto, gccmakedep }:
 
 let
-  libiconvInc = stdenv.lib.optionalString stdenv.isLinux "${glibc}/include";
-  libiconvLib = stdenv.lib.optionalString stdenv.isLinux "${glibc}/lib";
+  libiconvInc = stdenv.lib.optionalString stdenv.isLinux "${glibc.dev}/include";
+  libiconvLib = stdenv.lib.optionalString stdenv.isLinux "${glibc.out}/lib";
 in
 stdenv.mkDerivation rec {
   name = "tkgate-1.8.7";
diff --git a/pkgs/applications/science/logic/hol/default.nix b/pkgs/applications/science/logic/hol/default.nix
index f8a57aebb6dc..c7fb4ffbb978 100644
--- a/pkgs/applications/science/logic/hol/default.nix
+++ b/pkgs/applications/science/logic/hol/default.nix
@@ -32,7 +32,7 @@ stdenv.mkDerivation {
   buildCommand = ''
 
     mkdir chroot-fontconfig
-    cat ${fontconfig}/etc/fonts/fonts.conf > chroot-fontconfig/fonts.conf
+    cat ${fontconfig.out}/etc/fonts/fonts.conf > chroot-fontconfig/fonts.conf
     sed -e 's@</fontconfig>@@' -i chroot-fontconfig/fonts.conf
     echo "<dir>${liberation_ttf}</dir>" >> chroot-fontconfig/fonts.conf
     echo "</fontconfig>" >> chroot-fontconfig/fonts.conf
diff --git a/pkgs/applications/science/logic/saw-tools/default.nix b/pkgs/applications/science/logic/saw-tools/default.nix
index eebe6ff0a06c..97a06bf093d3 100644
--- a/pkgs/applications/science/logic/saw-tools/default.nix
+++ b/pkgs/applications/science/logic/saw-tools/default.nix
@@ -35,7 +35,7 @@ stdenv.mkDerivation rec {
     mv doc $out/share
 
     # Hack around lack of libtinfo in NixOS
-    ln -s ${ncurses}/lib/libncursesw.so.5       $out/lib/libtinfo.so.5
+    ln -s ${ncurses.lib}/lib/libncursesw.so.5       $out/lib/libtinfo.so.5
     ln -s ${stdenv.cc.libc}/lib/libpthread.so.0 $out/lib/libpthread.so.0
 
     # Add a clang symlink for easy building with a suitable compiler.
diff --git a/pkgs/applications/science/logic/tptp/default.nix b/pkgs/applications/science/logic/tptp/default.nix
index d4c628587535..f3c0a7917cf3 100644
--- a/pkgs/applications/science/logic/tptp/default.nix
+++ b/pkgs/applications/science/logic/tptp/default.nix
@@ -65,7 +65,7 @@ rec {
   '' ["defEnsureDir" "minInit"];
 
   patchBinaries = a.fullDepEntry ''
-    patchelf --set-interpreter "${pkgsi686Linux.glibc}"/lib/ld-linux.so.* \
+    patchelf --set-interpreter "${pkgsi686Linux.glibc.out}"/lib/ld-linux.so.* \
       "Scripts/tptp4X"
   '' ["addInputs"];
       
diff --git a/pkgs/applications/science/logic/yices/default.nix b/pkgs/applications/science/logic/yices/default.nix
index 5daaa444c127..f495ee257ff0 100644
--- a/pkgs/applications/science/logic/yices/default.nix
+++ b/pkgs/applications/science/logic/yices/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, gmp, gperf, autoreconfHook }:
+{ stdenv, fetchurl, gmp-static, gperf, autoreconfHook }:
 
 stdenv.mkDerivation rec {
   name    = "yices-${version}";
@@ -10,10 +10,10 @@ stdenv.mkDerivation rec {
     sha256 = "1da70n0cah0dh3pk7fcrvjkszx9qmhc0csgl15jqa7bdh707k2zs";
   };
 
-  configureFlags = [ "--with-static-gmp=${gmp}/lib/libgmp.a"
-                     "--with-static-gmp-include-dir=${gmp}/include"
+  configureFlags = [ "--with-static-gmp=${gmp-static.out}/lib/libgmp.a"
+                     "--with-static-gmp-include-dir=${gmp-static.dev}/include"
                    ];
-  buildInputs = [ gmp gperf autoreconfHook ];
+  buildInputs = [ gmp-static gperf autoreconfHook ];
 
   meta = {
     description = "A high-performance theorem prover and SMT solver";
diff --git a/pkgs/applications/science/math/R/default.nix b/pkgs/applications/science/math/R/default.nix
index e7a195659491..2ca2cab3afd8 100644
--- a/pkgs/applications/science/math/R/default.nix
+++ b/pkgs/applications/science/math/R/default.nix
@@ -48,7 +48,6 @@ stdenv.mkDerivation rec {
       CXX=$(type -p g++)
       FC="${gfortran}/bin/gfortran" F77="${gfortran}/bin/gfortran"
       JAVA_HOME="${jdk}"
-      LDFLAGS="-L${gfortran.cc}/lib"
       RANLIB=$(type -p ranlib)
       R_SHELL="${stdenv.shell}"
   '' + stdenv.lib.optionalString stdenv.isDarwin ''
diff --git a/pkgs/applications/search/recoll/default.nix b/pkgs/applications/search/recoll/default.nix
index 555da3de6d53..631555234cee 100644
--- a/pkgs/applications/search/recoll/default.nix
+++ b/pkgs/applications/search/recoll/default.nix
@@ -27,12 +27,12 @@ stdenv.mkDerivation rec {
       substituteInPlace  $f --replace antiword      ${antiword}/bin/antiword
       substituteInPlace  $f --replace awk           ${gawk}/bin/awk
       substituteInPlace  $f --replace catppt        ${catdoc}/bin/catppt
-      substituteInPlace  $f --replace djvused       ${djvulibre}/bin/djvused
-      substituteInPlace  $f --replace djvutxt       ${djvulibre}/bin/djvutxt
+      substituteInPlace  $f --replace djvused       ${djvulibre.bin}/bin/djvused
+      substituteInPlace  $f --replace djvutxt       ${djvulibre.bin}/bin/djvutxt
       substituteInPlace  $f --replace grep          ${gnugrep}/bin/grep
       substituteInPlace  $f --replace groff         ${groff}/bin/groff
       substituteInPlace  $f --replace gunzip        ${gzip}/bin/gunzip
-      substituteInPlace  $f --replace iconv         ${libiconv}/bin/iconv
+      substituteInPlace  $f --replace iconv         ${libiconv.bin}/bin/iconv
       substituteInPlace  $f --replace lyx           ${lyx}/bin/lyx
       substituteInPlace  $f --replace pdftotext     ${poppler_utils}/bin/pdftotext
       substituteInPlace  $f --replace pstotext      ${ghostscript}/bin/ps2ascii 
@@ -40,7 +40,7 @@ stdenv.mkDerivation rec {
       substituteInPlace  $f --replace tar           ${gnutar}/bin/tar
       substituteInPlace  $f --replace unzip         ${unzip}/bin/unzip
       substituteInPlace  $f --replace xls2csv       ${catdoc}/bin/xls2csv
-      substituteInPlace  $f --replace xsltproc      ${libxslt}/bin/xsltproc
+      substituteInPlace  $f --replace xsltproc      ${libxslt.bin}/bin/xsltproc
       substituteInPlace  $f --replace unrtf         ${unrtf}/bin/unrtf
       substituteInPlace  $f --replace untex         ${untex}/bin/untex
       substituteInPlace  $f --replace wpd2html      ${libwpd}/bin/wpd2html
diff --git a/pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix b/pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix
index 91fe1662efec..f282fa6635b8 100644
--- a/pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix
+++ b/pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
   buildPhase = ''
     sed -i 's|/bin/cat|cat|' ./src/repository.cpp
     qmake
-    make CXXFLAGS='-I${apr}/include/apr-1 -I${subversion}/include/subversion-1 -DVER="\"${src.rev}\""'
+    make CXXFLAGS='-I${apr}/include/apr-1 -I${subversion.dev}/include/subversion-1 -DVER="\"${src.rev}\""'
   '';
 
   installPhase = ''
diff --git a/pkgs/applications/version-management/rabbitvcs/default.nix b/pkgs/applications/version-management/rabbitvcs/default.nix
index 100e854f29b8..9f817a397f0e 100644
--- a/pkgs/applications/version-management/rabbitvcs/default.nix
+++ b/pkgs/applications/version-management/rabbitvcs/default.nix
@@ -17,7 +17,7 @@ python2Packages.buildPythonPackage rec {
       sed -ie 's|if sys\.argv\[1\] == "install":|if False:|' ./setup.py
       sed -ie "s|PREFIX = sys.prefix|PREFIX = \"$out\"|" ./setup.py
       sed -ie 's|/usr/bin/meld|${meld}/bin/meld|' ./rabbitvcs/util/configspec/configspec.ini
-      sed -ie 's|/usr/bin/svnadmin|${subversion}/bin/svnadmin|' ./rabbitvcs/ui/create.py
+      sed -ie 's|/usr/bin/svnadmin|${subversion.out}/bin/svnadmin|' ./rabbitvcs/ui/create.py
       sed -ie "s|/usr/share/doc|$out/share/doc|" ./rabbitvcs/ui/about.py
       sed -ie "s|gnome-open|xdg-open|" ./rabbitvcs/util/helper.py
     '';
diff --git a/pkgs/applications/version-management/rapidsvn/default.nix b/pkgs/applications/version-management/rapidsvn/default.nix
index 843fe9ad3230..9397aa8a1e19 100644
--- a/pkgs/applications/version-management/rapidsvn/default.nix
+++ b/pkgs/applications/version-management/rapidsvn/default.nix
@@ -10,8 +10,8 @@ stdenv.mkDerivation {
 
   buildInputs = [ wxGTK subversion apr aprutil python ];
 
-  configureFlags = [ "--with-svn-include=${subversion}/include" 
-    "--with-svn-lib=${subversion}/lib" ];
+  configureFlags = [ "--with-svn-include=${subversion.dev}/include"
+    "--with-svn-lib=${subversion.out}/lib" ];
 
   meta = {
     description = "Multi-platform GUI front-end for the Subversion revision system";
diff --git a/pkgs/applications/version-management/redmine/bootstrap.nix b/pkgs/applications/version-management/redmine/bootstrap.nix
index 5971f2e9cddc..82643f18a554 100644
--- a/pkgs/applications/version-management/redmine/bootstrap.nix
+++ b/pkgs/applications/version-management/redmine/bootstrap.nix
@@ -32,8 +32,8 @@ in stdenv.mkDerivation rec {
 
     bundle config --local build.nokogiri --use-system-libraries \
       --with-iconv-dir=${libiconv} \
-      --with-xslt-dir=${libxslt} \
-      --with-xml2-dir=${libxml2} \
+      --with-xslt-dir=${libxslt.out} \
+      --with-xml2-dir=${libxml2.out} \
       --with-pkg-config \
       --with-pg-config=${postgresql}/bin/pg_config
 
diff --git a/pkgs/applications/version-management/subversion/default.nix b/pkgs/applications/version-management/subversion/default.nix
index 219dd0babb7d..f18184162fe7 100644
--- a/pkgs/applications/version-management/subversion/default.nix
+++ b/pkgs/applications/version-management/subversion/default.nix
@@ -26,6 +26,9 @@ let
       inherit sha1;
     };
 
+  # Can't do separate $lib and $bin, as libs reference bins
+  outputs = [ "dev" "out" "man" ];
+
     buildInputs = [ zlib apr aprutil sqlite ]
       ++ stdenv.lib.optional httpSupport serf
       ++ stdenv.lib.optional pythonBindings python
@@ -65,6 +68,12 @@ let
 
       mkdir -p $out/share/bash-completion/completions
       cp tools/client-side/bash_completion $out/share/bash-completion/completions/subversion
+
+    for f in $out/lib/*.la; do
+      substituteInPlace $f --replace "${expat.dev}/lib" "${expat.out}/lib"
+      substituteInPlace $f --replace "${zlib.dev}/lib" "${zlib.out}/lib"
+      substituteInPlace $f --replace "${sqlite.dev}/lib" "${sqlite.out}/lib"
+    done
     '';
 
     inherit perlBindings pythonBindings;
diff --git a/pkgs/applications/video/avidemux/default.nix b/pkgs/applications/video/avidemux/default.nix
index 485d8c54eb36..3b48a447f6ff 100644
--- a/pkgs/applications/video/avidemux/default.nix
+++ b/pkgs/applications/video/avidemux/default.nix
@@ -19,9 +19,9 @@ stdenv.mkDerivation {
     lame faad2 libvorbis yasm libvpx xvidcore libva
   ] ++ stdenv.lib.optional faacSupport faac;
 
-  cmakeFlags = "-DPTHREAD_INCLUDE_DIR=${stdenv.glibc}/include" +
+  cmakeFlags = "-DPTHREAD_INCLUDE_DIR=${stdenv.glibc.dev}/include" +
     " -DGETTEXT_INCLUDE_DIR=${gettext}/include" +
-    " -DSDL_INCLUDE_DIR=${SDL}/include/SDL";
+    " -DSDL_INCLUDE_DIR=${SDL.dev}/include/SDL";
 
   NIX_LDFLAGS="-lpthread";
 
diff --git a/pkgs/applications/video/avxsynth/default.nix b/pkgs/applications/video/avxsynth/default.nix
index d8ec715a38cb..06dcaf31b443 100644
--- a/pkgs/applications/video/avxsynth/default.nix
+++ b/pkgs/applications/video/avxsynth/default.nix
@@ -24,7 +24,7 @@ stdenv.mkDerivation rec {
     "--enable-subtitle"
     "--enable-ffms2"
     (enableFeature avxeditSupport "avxedit")
-    "--with-jpeg=${libjpeg}/lib"
+    "--with-jpeg=${libjpeg.out}/lib"
   ];
 
   nativeBuildInputs = [ autoreconfHook pkgconfig ];
diff --git a/pkgs/applications/video/clipgrab/default.nix b/pkgs/applications/video/clipgrab/default.nix
index 961471cd9b36..e634a0caa3f4 100644
--- a/pkgs/applications/video/clipgrab/default.nix
+++ b/pkgs/applications/video/clipgrab/default.nix
@@ -14,8 +14,8 @@ stdenv.mkDerivation rec {
 
   postPatch = stdenv.lib.optionalString (ffmpeg != null) ''
   substituteInPlace converter_ffmpeg.cpp \
-    --replace '"ffmpeg"' '"${ffmpeg}/bin/ffmpeg"' \
-    --replace '"ffmpeg ' '"${ffmpeg}/bin/ffmpeg '
+    --replace '"ffmpeg"' '"${ffmpeg.bin}/bin/ffmpeg"' \
+    --replace '"ffmpeg ' '"${ffmpeg.bin}/bin/ffmpeg '
   '';
 
   configurePhase = ''
diff --git a/pkgs/applications/video/dvd-slideshow/default.nix b/pkgs/applications/video/dvd-slideshow/default.nix
index fe95c2c6d7d8..040a7a2e7a69 100644
--- a/pkgs/applications/video/dvd-slideshow/default.nix
+++ b/pkgs/applications/video/dvd-slideshow/default.nix
@@ -4,7 +4,7 @@ let
   wrapper = writeScript "dvd-slideshow.sh" ''
       #!/bin/bash
       # wrapper script for dvd-slideshow programs
-      export PATH=${cdrtools}/bin:${dvdauthor}/bin:${ffmpeg}/bin:${imagemagick}/bin:${lame}/bin:${mjpegtools}/bin:${sox}/bin:${transcode}/bin:${vorbis-tools}/bin:$PATH
+      export PATH=${cdrtools}/bin:${dvdauthor}/bin:${ffmpeg.bin}/bin:${imagemagick}/bin:${lame}/bin:${mjpegtools}/bin:${sox}/bin:${transcode}/bin:${vorbis-tools}/bin:$PATH
 
       dir=`dirname "$0"`
       exe=`basename "$0"`
diff --git a/pkgs/applications/video/gnash/default.nix b/pkgs/applications/video/gnash/default.nix
index f53ce93328bf..0200b0c70f4e 100644
--- a/pkgs/applications/video/gnash/default.nix
+++ b/pkgs/applications/video/gnash/default.nix
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
     for lib in $libs; do
       echo -n "$lib " >> macros/libslist
     done
-    echo -n "${stdenv.glibc}/lib" >> macros/libslist
+    echo -n "${stdenv.glibc.out}/lib" >> macros/libslist
 
     # Make sure to honor $TMPDIR, for chroot builds.
     for file in configure gui/Makefile.in Makefile.in
@@ -65,7 +65,7 @@ stdenv.mkDerivation rec {
 
   preConfigure =
     '' configureFlags="                                         \
-         --with-sdl-incl=${SDL}/include/SDL                     \
+         --with-sdl-incl=${SDL.dev}/include/SDL                     \
          --with-npapi-plugindir=$out/plugins                    \
          --enable-media=gst                                     \
          --without-gconf
diff --git a/pkgs/applications/video/kazam/default.nix b/pkgs/applications/video/kazam/default.nix
index 17bf282a459a..1e3f5d57a064 100644
--- a/pkgs/applications/video/kazam/default.nix
+++ b/pkgs/applications/video/kazam/default.nix
@@ -34,9 +34,9 @@ python3Packages.buildPythonPackage rec {
   preFixup = ''
     wrapProgram $out/bin/kazam \
       --prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH" \
-      --prefix LD_LIBRARY_PATH ":" "${gtk3}/lib:${gst_all_1.gstreamer}/lib:${keybinder}/lib" \
+      --prefix LD_LIBRARY_PATH ":" "${gtk3.out}/lib:${gst_all_1.gstreamer}/lib:${keybinder}/lib" \
       --prefix GST_PLUGIN_SYSTEM_PATH : "$GST_PLUGIN_SYSTEM_PATH" \
-      --prefix XDG_DATA_DIRS : "${gtk3}/share" \
+      --prefix XDG_DATA_DIRS : "${gtk3.out}/share" \
       --set GST_REGISTRY "/tmp/kazam.gstreamer.registry";
   '';
 
diff --git a/pkgs/applications/video/kodi/default.nix b/pkgs/applications/video/kodi/default.nix
index e1dc182ba0b9..792cb67f8124 100644
--- a/pkgs/applications/video/kodi/default.nix
+++ b/pkgs/applications/video/kodi/default.nix
@@ -104,14 +104,10 @@ in stdenv.mkDerivation rec {
           --prefix PATH ":" "${pythonFull}/bin" \
           --prefix PATH ":" "${glxinfo}/bin" \
           --prefix PATH ":" "${xdpyinfo}/bin" \
-          --prefix LD_LIBRARY_PATH ":" "${curl}/lib" \
-          --prefix LD_LIBRARY_PATH ":" "${systemd}/lib" \
-          --prefix LD_LIBRARY_PATH ":" "${libmad}/lib" \
-          --prefix LD_LIBRARY_PATH ":" "${libvdpau}/lib" \
-          --prefix LD_LIBRARY_PATH ":" "${libcec}/lib" \
-          --prefix LD_LIBRARY_PATH ":" "${libcec_platform}/lib" \
+          --prefix LD_LIBRARY_PATH ":" "${lib.makeLibraryPath
+              [ curl systemd libmad libvdpau libcec libcec_platform rtmpdump ]
+            }"
           --prefix LD_LIBRARY_PATH ":" "${libass}/lib" \
-          --prefix LD_LIBRARY_PATH ":" "${rtmpdump}/lib"
       done
     '';
 
diff --git a/pkgs/applications/video/miro/default.nix b/pkgs/applications/video/miro/default.nix
index 6585306b2898..5209cce36a11 100644
--- a/pkgs/applications/video/miro/default.nix
+++ b/pkgs/applications/video/miro/default.nix
@@ -33,7 +33,7 @@ buildPythonPackage rec {
     sed -i -e 's|/usr/bin/||' -e 's|/usr||' \
            -e 's/BUILD_TIME[^,]*/BUILD_TIME=0/' setup.py
 
-    sed -i -e 's|default="/usr/bin/ffmpeg"|default="${ffmpeg}/bin/ffmpeg"|' \
+    sed -i -e 's|default="/usr/bin/ffmpeg"|default="${ffmpeg.bin}/bin/ffmpeg"|' \
       plat/options.py
 
     sed -i -e 's|/usr/share/miro/themes|'"$out/share/miro/themes"'|' \
@@ -64,7 +64,7 @@ buildPythonPackage rec {
     mv "$out/bin/miro.real" "$out/bin/miro"
     wrapProgram "$out/bin/miro" \
       --prefix GST_PLUGIN_SYSTEM_PATH : "$GST_PLUGIN_SYSTEM_PATH" \
-      --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules" \
+      --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules" \
       --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share"
   '';
 
diff --git a/pkgs/applications/video/vlc/default.nix b/pkgs/applications/video/vlc/default.nix
index 12df7e41dd88..5566d1aafe5a 100644
--- a/pkgs/applications/video/vlc/default.nix
+++ b/pkgs/applications/video/vlc/default.nix
@@ -27,6 +27,8 @@ stdenv.mkDerivation rec {
     sha256 = "1jqzrzrpw6932lbkf863xk8cfmn4z2ngbxz7w8ggmh4f6xz9sgal";
   };
 
+  # outputs TODO: some modules are "corrupt", even without splitting vlc
+
   buildInputs =
     [ xz bzip2 perl zlib a52dec libmad faad2 ffmpeg alsaLib libdvdnav libdvdnav.libdvdread
       libbluray dbus fribidi libvorbis libtheora speex lua5 libgcrypt
diff --git a/pkgs/applications/virtualization/bochs/default.nix b/pkgs/applications/virtualization/bochs/default.nix
index b876403d6327..d1150d7024b2 100644
--- a/pkgs/applications/virtualization/bochs/default.nix
+++ b/pkgs/applications/virtualization/bochs/default.nix
@@ -143,8 +143,8 @@ stdenv.mkDerivation rec {
     ++ stdenv.lib.optional busMouse "--enable-busmouse"
     ;
 
-  NIX_CFLAGS_COMPILE="-I${gtk}/include/gtk-2.0/ -I${libtool}/include/";
-  NIX_LDFLAGS="-L${libtool}/lib";
+  NIX_CFLAGS_COMPILE="-I${gtk.dev}/include/gtk-2.0/ -I${libtool}/include/";
+  NIX_LDFLAGS="-L${libtool.lib}/lib";
 	
   meta = with stdenv.lib; {
     description = "An open-source IA-32 (x86) PC emulator";
diff --git a/pkgs/applications/virtualization/docker/default.nix b/pkgs/applications/virtualization/docker/default.nix
index 31daedd6d1eb..2af39cd33deb 100644
--- a/pkgs/applications/virtualization/docker/default.nix
+++ b/pkgs/applications/virtualization/docker/default.nix
@@ -22,7 +22,7 @@ stdenv.mkDerivation rec {
 
   buildInputs = [
     makeWrapper go sqlite iproute bridge-utils devicemapper btrfs-progs
-    iptables e2fsprogs systemd pkgconfig
+    iptables e2fsprogs systemd pkgconfig stdenv.glibc stdenv.glibc.static
   ];
 
   dontStrip = true;
diff --git a/pkgs/applications/virtualization/virtualbox/default.nix b/pkgs/applications/virtualization/virtualbox/default.nix
index 855694e04120..6f7609e85e28 100644
--- a/pkgs/applications/virtualization/virtualbox/default.nix
+++ b/pkgs/applications/virtualization/virtualbox/default.nix
@@ -81,14 +81,14 @@ in stdenv.mkDerivation {
         -e 's@MKISOFS --version@MKISOFS -version@' \
         -e 's@PYTHONDIR=.*@PYTHONDIR=${if pythonBindings then python else ""}@' \
         -i configure
-    ls kBuild/bin/linux.x86/k* tools/linux.x86/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux.so.2
-    ls kBuild/bin/linux.amd64/k* tools/linux.amd64/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux-x86-64.so.2
+    ls kBuild/bin/linux.x86/k* tools/linux.x86/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2
+    ls kBuild/bin/linux.amd64/k* tools/linux.amd64/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux-x86-64.so.2
     find . -type f -iname '*makefile*' -exec sed -i -e 's/depmod -a/:/g' {} +
     sed -i -e '
-      s@"libdbus-1\.so\.3"@"${dbus}/lib/libdbus-1.so.3"@g
-      s@"libasound\.so\.2"@"${alsaLib}/lib/libasound.so.2"@g
+      s@"libdbus-1\.so\.3"@"${dbus.lib}/lib/libdbus-1.so.3"@g
+      s@"libasound\.so\.2"@"${alsaLib.out}/lib/libasound.so.2"@g
       ${optionalString pulseSupport ''
-      s@"libpulse\.so\.0"@"${libpulseaudio}/lib/libpulse.so.0"@g
+      s@"libpulse\.so\.0"@"${libpulseaudio.out}/lib/libpulse.so.0"@g
       ''}
     ' src/VBox/Main/xml/Settings.cpp \
       src/VBox/Devices/Audio/{alsa,pulse}_stubs.c \
diff --git a/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix b/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix
index 43f591cf6aad..15366fb1380f 100644
--- a/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix
+++ b/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix
@@ -63,19 +63,19 @@ stdenv.mkDerivation {
     for i in sbin/VBoxService bin/{VBoxClient,VBoxControl} lib/VBoxGuestAdditions/mount.vboxsf
     do
         ${if stdenv.system == "i686-linux" then ''
-          patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux.so.2 $i
+          patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $i
         ''
         else if stdenv.system == "x86_64-linux" then ''
-          patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux-x86-64.so.2 $i
+          patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux-x86-64.so.2 $i
         ''
         else throw ("Architecture: "+stdenv.system+" not supported for VirtualBox guest additions")
         }
-        patchelf --set-rpath ${stdenv.cc.cc}/lib:${dbus}/lib:${libX11}/lib:${libXt}/lib:${libXext}/lib:${libXmu}/lib:${libXfixes}/lib:${libXrandr}/lib:${libXcursor}/lib $i
+        patchelf --set-rpath ${lib.makeLibraryPath [ stdenv.cc.cc dbus libX11 libXt libXext libXmu libXfixes libXrandr libXcursor ]} $i
     done
 
     for i in lib/VBoxOGL*.so
     do
-        patchelf --set-rpath $out/lib:${dbus}/lib:${libXcomposite}/lib:${libXdamage}/lib:${libXext}/lib:${libXfixes}/lib $i
+        patchelf --set-rpath $out/lib:${dbus.lib}/lib:${libXcomposite.out}/lib:${libXdamage.out}/lib:${libXext.out}/lib:${libXfixes.out}/lib $i
     done
 
     # FIXME: Virtualbox 4.3.22 moved VBoxClient-all (required by Guest Additions
diff --git a/pkgs/applications/virtualization/xen/generic.nix b/pkgs/applications/virtualization/xen/generic.nix
index 6774675266c4..fcd7aab808b3 100644
--- a/pkgs/applications/virtualization/xen/generic.nix
+++ b/pkgs/applications/virtualization/xen/generic.nix
@@ -130,7 +130,7 @@ stdenv.mkDerivation {
         --replace /usr/bin/pkill ${procps}/bin/pkill
 
       substituteInPlace tools/xenstat/Makefile \
-        --replace /usr/include/curses.h ${ncurses}/include/curses.h
+        --replace /usr/include/curses.h ${ncurses.dev}/include/curses.h
 
       substituteInPlace tools/qemu-xen-traditional/xen-hooks.mak \
         --replace /usr/include/pci ${pciutils}/include/pci
diff --git a/pkgs/applications/window-managers/awesome/default.nix b/pkgs/applications/window-managers/awesome/default.nix
index 2b0d44e61c8a..b096375f2050 100644
--- a/pkgs/applications/window-managers/awesome/default.nix
+++ b/pkgs/applications/window-managers/awesome/default.nix
@@ -60,8 +60,8 @@ stdenv.mkDerivation rec {
 
   #cmakeFlags = "-DGENERATE_MANPAGES=ON";
 
-  LD_LIBRARY_PATH = "${cairo}/lib:${pango}/lib:${gobjectIntrospection}/lib";
-  GI_TYPELIB_PATH = "${pango}/lib/girepository-1.0";
+  LD_LIBRARY_PATH = "${stdenv.lib.makeLibraryPath [ cairo pango gobjectIntrospection ]}";
+  GI_TYPELIB_PATH = "${pango.out}/lib/girepository-1.0";
   LUA_CPATH = "${lgi}/lib/lua/${lua.luaversion}/?.so";
   LUA_PATH  = "${lgi}/share/lua/${lua.luaversion}/?.lua;${lgi}/share/lua/${lua.luaversion}/lgi/?.lua";
 
@@ -70,8 +70,8 @@ stdenv.mkDerivation rec {
       --prefix LUA_CPATH ";" '"${lgi}/lib/lua/${lua.luaversion}/?.so"' \
       --prefix LUA_PATH ";" '"${lgi}/share/lua/${lua.luaversion}/?.lua;${lgi}/share/lua/${lua.luaversion}/lgi/?.lua"' \
       --prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH" \
-      --prefix LD_LIBRARY_PATH : "${cairo}/lib:${pango}/lib:${gobjectIntrospection}/lib" \
-      --prefix PATH : "${compton}/bin:${unclutter}/bin:${procps}/bin:${iproute}/sbin:${coreutils}/bin:${curl}/bin:${alsaUtils}/bin:${findutils}/bin:${xterm}/bin"
+      --prefix LD_LIBRARY_PATH : "$LD_LIBRARY_PATH" \
+      --prefix PATH : "${compton}/bin:${unclutter}/bin:${procps}/bin:${iproute}/sbin:${coreutils}/bin:${curl.bin}/bin:${alsaUtils}/bin:${findutils}/bin:${xterm}/bin"
 
     wrapProgram $out/bin/awesome-client \
       --prefix PATH : "${which}/bin"
diff --git a/pkgs/applications/window-managers/fvwm/default.nix b/pkgs/applications/window-managers/fvwm/default.nix
index aded77a466da..77263293847c 100644
--- a/pkgs/applications/window-managers/fvwm/default.nix
+++ b/pkgs/applications/window-managers/fvwm/default.nix
@@ -1,7 +1,7 @@
 { gestures ? false
 , stdenv, fetchurl, pkgconfig
 , cairo, fontconfig, freetype, libXft, libXcursor, libXinerama
-, libXpm, librsvg, libpng, fribidi, perl
+, libXpm, libXt, librsvg, libpng, fribidi, perl
 , libstroke ? null
 }:
 
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
 
   buildInputs = [
     pkgconfig cairo fontconfig freetype
-    libXft libXcursor libXinerama libXpm
+    libXft libXcursor libXinerama libXpm libXt
     librsvg libpng fribidi perl
   ] ++ stdenv.lib.optional gestures libstroke;
 
diff --git a/pkgs/applications/window-managers/qtile/default.nix b/pkgs/applications/window-managers/qtile/default.nix
index 3f38be669274..8af46f52354a 100644
--- a/pkgs/applications/window-managers/qtile/default.nix
+++ b/pkgs/applications/window-managers/qtile/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, buildPythonPackage, python27Packages, pkgs }:
+{ stdenv, lib, fetchFromGitHub, buildPythonPackage, python27Packages, pkgs }:
 
 let cairocffi-xcffib = python27Packages.cairocffi.override {
     pythonPath = [ python27Packages.xcffib ];
@@ -24,9 +24,9 @@ buildPythonPackage rec {
 
   postPatch = ''
     substituteInPlace libqtile/manager.py --subst-var-by out $out
-    substituteInPlace libqtile/pangocffi.py --subst-var-by glib ${pkgs.glib}
-    substituteInPlace libqtile/pangocffi.py --subst-var-by pango ${pkgs.pango}
-    substituteInPlace libqtile/xcursors.py --subst-var-by xcb-cursor ${pkgs.xorg.xcbutilcursor}
+    substituteInPlace libqtile/pangocffi.py --subst-var-by glib ${pkgs.glib.out}
+    substituteInPlace libqtile/pangocffi.py --subst-var-by pango ${pkgs.pango.out}
+    substituteInPlace libqtile/xcursors.py --subst-var-by xcb-cursor ${pkgs.xorg.xcbutilcursor.out}
   '';
 
   buildInputs = [ pkgs.pkgconfig pkgs.glib pkgs.xorg.libxcb pkgs.cairo pkgs.pango python27Packages.xcffib ];
diff --git a/pkgs/applications/window-managers/weston/default.nix b/pkgs/applications/window-managers/weston/default.nix
index 862e8b0ea01e..0720368222dc 100644
--- a/pkgs/applications/window-managers/weston/default.nix
+++ b/pkgs/applications/window-managers/weston/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
   nativeBuildInputs = [ pkgconfig ];
   buildInputs = [
     wayland mesa libxkbcommon cairo libxcb libXcursor xlibsWrapper udev libdrm
-    mtdev libjpeg pam dbus.libs libinput pango libunwind freerdp vaapi libva
+    mtdev libjpeg pam dbus libinput pango libunwind freerdp vaapi libva
     libwebp
   ];
 
diff --git a/pkgs/build-support/buildenv/default.nix b/pkgs/build-support/buildenv/default.nix
index a9a4d95d7d8f..5de02c8ed25f 100644
--- a/pkgs/build-support/buildenv/default.nix
+++ b/pkgs/build-support/buildenv/default.nix
@@ -25,10 +25,6 @@
   # directories in the list is not symlinked.
   pathsToLink ? ["/"]
 
-, # The package outputs to include. By default, only the default
-  # output is included.
-  outputsToLink ? []
-
 , # Root the result in directory "$out${extraPrefix}", e.g. "/share".
   extraPrefix ? ""
 
@@ -47,9 +43,7 @@ runCommand name
     inherit manifest ignoreCollisions checkCollisionContents passthru
             meta pathsToLink extraPrefix postBuild buildInputs;
     pkgs = builtins.toJSON (map (drv: {
-      paths =
-        [ drv ]
-        ++ lib.concatMap (outputName: lib.optional (drv.${outputName}.outPath or null != null) drv.${outputName}) outputsToLink;
+      paths = [ drv ];
       priority = drv.meta.priority or 5;
     }) paths);
     preferLocalBuild = true;
diff --git a/pkgs/build-support/cc-wrapper/add-flags b/pkgs/build-support/cc-wrapper/add-flags
index d48361539047..59d9614fd21f 100644
--- a/pkgs/build-support/cc-wrapper/add-flags
+++ b/pkgs/build-support/cc-wrapper/add-flags
@@ -5,7 +5,7 @@ if [ -e @out@/nix-support/libc-cflags ]; then
     export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
 fi
 
-if [ -e @out@/nix-support/gcc-cflags ]; then
+if [ -e @out@/nix-support/cc-cflags ]; then
     export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE"
 fi
 
@@ -17,7 +17,7 @@ if [ -e @out@/nix-support/libc-ldflags ]; then
     export NIX_LDFLAGS+=" $(cat @out@/nix-support/libc-ldflags)"
 fi
 
-if [ -e @out@/nix-support/gcc-ldflags ]; then
+if [ -e @out@/nix-support/cc-ldflags ]; then
     export NIX_LDFLAGS+=" $(cat @out@/nix-support/cc-ldflags)"
 fi
 
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 110f51891417..0458eedc62bc 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -27,6 +27,13 @@ let
   ccVersion = (builtins.parseDrvName cc.name).version;
   ccName = (builtins.parseDrvName cc.name).name;
 
+  libc_bin = if nativeLibc then null else libc.bin or libc;
+  libc_dev = if nativeLibc then null else libc.dev or libc;
+  libc_lib = if nativeLibc then null else libc.out or libc;
+  cc_solib = cc.lib or cc;
+  binutils_bin = if nativeTools then "" else binutils.bin or binutils;
+  # The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
+  coreutils_bin = if nativeTools then "" else coreutils.bin or coreutils;
 in
 
 stdenv.mkDerivation {
@@ -36,15 +43,10 @@ stdenv.mkDerivation {
 
   preferLocalBuild = true;
 
-  inherit cc shell;
-  libc = if nativeLibc then null else libc;
-  binutils = if nativeTools then "" else binutils;
-  # The wrapper scripts use 'cat' and 'grep', so we may need coreutils
-  # and gnugrep.
-  coreutils = if nativeTools then "" else coreutils;
+  inherit cc shell libc_bin libc_dev libc_lib binutils_bin coreutils_bin;
   gnugrep = if nativeTools then "" else gnugrep;
 
-  passthru = { inherit nativeTools nativeLibc nativePrefix isGNU isClang; };
+  passthru = { inherit libc nativeTools nativeLibc nativePrefix isGNU isClang; };
 
   buildCommand =
     ''
@@ -60,11 +62,11 @@ stdenv.mkDerivation {
     ''
 
     + optionalString (!nativeLibc) (if (!stdenv.isDarwin) then ''
-      dynamicLinker="$libc/lib/$dynamicLinker"
+      dynamicLinker="${libc_lib}/lib/$dynamicLinker"
       echo $dynamicLinker > $out/nix-support/dynamic-linker
 
-      if [ -e $libc/lib/32/ld-linux.so.2 ]; then
-        echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
+      if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then
+        echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
       fi
 
       # The dynamic linker is passed in `ldflagsBefore' to allow
@@ -78,7 +80,7 @@ stdenv.mkDerivation {
     '')
 
     + optionalString (!nativeLibc) ''
-      # The "-B$libc/lib/" flag is a quick hack to force gcc to link
+      # The "-B${libc_lib}/lib/" flag is a quick hack to force gcc to link
       # against the crt1.o from our own glibc, rather than the one in
       # /usr/lib.  (This is only an issue when using an `impure'
       # compiler/linker, i.e., one that searches /usr/lib and so on.)
@@ -89,11 +91,11 @@ stdenv.mkDerivation {
       # compile, because it uses "#include_next <limits.h>" to find the
       # limits.h file in ../includes-fixed. To remedy the problem,
       # another -idirafter is necessary to add that directory again.
-      echo "-B$libc/lib/ -idirafter $libc/include -idirafter $cc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
+      echo "-B${libc_lib}/lib/ -idirafter ${libc_dev}/include -idirafter ${cc}/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
 
-      echo "-L$libc/lib" > $out/nix-support/libc-ldflags
+      echo "-L${libc_lib}/lib" > $out/nix-support/libc-ldflags
 
-      echo $libc > $out/nix-support/orig-libc
+      echo "${libc_lib}" > $out/nix-support/orig-libc
     ''
 
     + (if nativeTools then ''
@@ -102,23 +104,23 @@ stdenv.mkDerivation {
     '' else ''
       echo $cc > $out/nix-support/orig-cc
 
-      # GCC shows $cc/lib in `gcc -print-search-dirs', but not
-      # $cc/lib64 (even though it does actually search there...)..
+      # GCC shows ${cc_solib}/lib in `gcc -print-search-dirs', but not
+      # ${cc_solib}/lib64 (even though it does actually search there...)..
       # This confuses libtool.  So add it to the compiler tool search
       # path explicitly.
-      if [ -e "$cc/lib64" -a ! -L "$cc/lib64" ]; then
-        ccLDFlags+=" -L$cc/lib64"
-        ccCFlags+=" -B$cc/lib64"
+      if [ -e "${cc_solib}/lib64" -a ! -L "${cc_solib}/lib64" ]; then
+        ccLDFlags+=" -L${cc_solib}/lib64"
+        ccCFlags+=" -B${cc_solib}/lib64"
       fi
-      ccLDFlags+=" -L$cc/lib"
+      ccLDFlags+=" -L${cc_solib}/lib"
 
       ${optionalString cc.langVhdl or false ''
-        ccLDFlags+=" -L${zlib}/lib"
+        ccLDFlags+=" -L${zlib.out}/lib"
       ''}
 
       # Find the gcc libraries path (may work only without multilib).
       ${optionalString cc.langAda or false ''
-        basePath=`echo $cc/lib/*/*/*`
+        basePath=`echo ${cc_solib}/lib/*/*/*`
         ccCFlags+=" -B$basePath -I$basePath/adainclude"
         gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib"
         echo "$gnatCFlags" > $out/nix-support/gnat-cflags
@@ -134,13 +136,13 @@ stdenv.mkDerivation {
       echo "$ccLDFlags" > $out/nix-support/cc-ldflags
       echo "$ccCFlags" > $out/nix-support/cc-cflags
 
-      ccPath="$cc/bin"
-      ldPath="$binutils/bin"
+      ccPath="${cc}/bin"
+      ldPath="${binutils_bin}/bin"
 
       # Propagate the wrapped cc so that if you install the wrapper,
       # you get tools like gcov, the manpages, etc. as well (including
       # for binutils and Glibc).
-      echo $cc $binutils $libc > $out/nix-support/propagated-user-env-packages
+      echo ${cc} ${cc.man or ""} ${binutils_bin} ${libc_bin} > $out/nix-support/propagated-user-env-packages
 
       echo ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs
     ''
@@ -162,12 +164,12 @@ stdenv.mkDerivation {
 
       wrap ld ${./ld-wrapper.sh} ''${ld:-$ldPath/ld}
 
-      if [ -e $binutils/bin/ld.gold ]; then
-        wrap ld.gold ${./ld-wrapper.sh} $binutils/bin/ld.gold
+      if [ -e ${binutils_bin}/bin/ld.gold ]; then
+        wrap ld.gold ${./ld-wrapper.sh} ${binutils_bin}/bin/ld.gold
       fi
 
-      if [ -e $binutils/bin/ld.bfd ]; then
-        wrap ld.bfd ${./ld-wrapper.sh} $binutils/bin/ld.bfd
+      if [ -e ${binutils_bin}/bin/ld.bfd ]; then
+        wrap ld.bfd ${./ld-wrapper.sh} ${binutils_bin}/bin/ld.bfd
       fi
 
       export real_cc=cc
diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh
index 3d0b2fdfe8ae..d8fb88b41d18 100644
--- a/pkgs/build-support/cc-wrapper/setup-hook.sh
+++ b/pkgs/build-support/cc-wrapper/setup-hook.sh
@@ -26,16 +26,16 @@ if [ -n "@cc@" ]; then
     addToSearchPath PATH @cc@/bin
 fi
 
-if [ -n "@binutils@" ]; then
-    addToSearchPath PATH @binutils@/bin
+if [ -n "@binutils_bin@" ]; then
+    addToSearchPath PATH @binutils_bin@/bin
 fi
 
-if [ -n "@libc@" ]; then
-    addToSearchPath PATH @libc@/bin
+if [ -n "@libc_bin@" ]; then
+    addToSearchPath PATH @libc_bin@/bin
 fi
 
-if [ -n "@coreutils@" ]; then
-    addToSearchPath PATH @coreutils@/bin
+if [ -n "@coreutils_bin@" ]; then
+    addToSearchPath PATH @coreutils_bin@/bin
 fi
 
 if [ -z "$crossConfig" ]; then
diff --git a/pkgs/build-support/gcc-wrapper-old/builder.sh b/pkgs/build-support/gcc-wrapper-old/builder.sh
index 59cdd3f84ad2..1fa72deb234e 100644
--- a/pkgs/build-support/gcc-wrapper-old/builder.sh
+++ b/pkgs/build-support/gcc-wrapper-old/builder.sh
@@ -24,7 +24,7 @@ if test -z "$nativeLibc"; then
     # compile, because it uses "#include_next <limits.h>" to find the
     # limits.h file in ../includes-fixed. To remedy the problem,
     # another -idirafter is necessary to add that directory again.
-    echo "-B$libc/lib/ -idirafter $libc/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
+    echo "-B$libc/lib/ -idirafter $libc_dev/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
 
     echo "-L$libc/lib" > $out/nix-support/libc-ldflags
 
@@ -39,9 +39,9 @@ if test -n "$nativeTools"; then
     ldPath="$nativePrefix/bin"
 else
     if test -e "$gcc/lib64"; then
-        gccLDFlags="$gccLDFlags -L$gcc/lib64"
+        gccLDFlags="$gccLDFlags -L$gcc_lib/lib64"
     fi
-    gccLDFlags="$gccLDFlags -L$gcc/lib"
+    gccLDFlags="$gccLDFlags -L$gcc_lib/lib"
     if [ -n "$langVhdl" ]; then
         gccLDFlags="$gccLDFlags -L$zlib/lib"
     fi
@@ -95,6 +95,7 @@ doSubstitute() {
         -e "s^@binutils@^$binutils^g" \
         -e "s^@coreutils@^$coreutils^g" \
         -e "s^@libc@^$libc^g" \
+        -e "s^@libc_bin@^$libc_bin^g" \
         -e "s^@ld@^$ld^g" \
         < "$src" > "$dst" 
 }
@@ -210,5 +211,5 @@ cp -p $utils $out/nix-support/utils.sh
 # tools like gcov, the manpages, etc. as well (including for binutils
 # and Glibc).
 if test -z "$nativeTools"; then
-    echo $gcc $binutils $libc > $out/nix-support/propagated-user-env-packages
+    echo $gcc $binutils $libc $libc_bin > $out/nix-support/propagated-user-env-packages
 fi
diff --git a/pkgs/build-support/gcc-wrapper-old/default.nix b/pkgs/build-support/gcc-wrapper-old/default.nix
index 20f1bc97ad1b..f44aaec5d9d7 100644
--- a/pkgs/build-support/gcc-wrapper-old/default.nix
+++ b/pkgs/build-support/gcc-wrapper-old/default.nix
@@ -41,7 +41,10 @@ stdenv.mkDerivation {
   addFlags = ./add-flags;
 
   inherit nativeTools nativeLibc nativePrefix gcc;
+  gcc_lib = gcc.lib or gcc;
   libc = if nativeLibc then null else libc;
+  libc_dev = if nativeLibc then null else libc.dev or libc;
+  libc_bin = if nativeLibc then null else libc.bin or libc;
   binutils = if nativeTools then null else binutils;
   # The wrapper scripts use 'cat', so we may need coreutils
   coreutils = if nativeTools then null else coreutils;
diff --git a/pkgs/build-support/gcc-wrapper-old/setup-hook.sh b/pkgs/build-support/gcc-wrapper-old/setup-hook.sh
index 298ade21d1f5..d8bdf858ae58 100644
--- a/pkgs/build-support/gcc-wrapper-old/setup-hook.sh
+++ b/pkgs/build-support/gcc-wrapper-old/setup-hook.sh
@@ -25,7 +25,7 @@ if test -n "@binutils@"; then
 fi
 
 if test -n "@libc@"; then
-    addToSearchPath PATH @libc@/bin
+    addToSearchPath PATH @libc_bin@/bin
 fi
 
 if test -n "@coreutils@"; then
diff --git a/pkgs/build-support/grsecurity/default.nix b/pkgs/build-support/grsecurity/default.nix
index 841effcfca11..474dbfaff4d0 100644
--- a/pkgs/build-support/grsecurity/default.nix
+++ b/pkgs/build-support/grsecurity/default.nix
@@ -126,9 +126,9 @@ let
       buildInputs = args.buildInputs ++ [ pkgs.gmp ];
       preConfigure = ''
         ${args.preConfigure or ""}
-        sed -i 's|-I|-I${pkgs.gmp}/include -I|' scripts/gcc-plugin.sh
-        sed -i 's|HOST_EXTRACFLAGS +=|HOST_EXTRACFLAGS += -I${pkgs.gmp}/include|' tools/gcc/Makefile
-        sed -i 's|HOST_EXTRACXXFLAGS +=|HOST_EXTRACXXFLAGS += -I${pkgs.gmp}/include|' tools/gcc/Makefile
+        sed -i 's|-I|-I${pkgs.gmp.dev}/include -I|' scripts/gcc-plugin.sh
+        sed -i 's|HOST_EXTRACFLAGS +=|HOST_EXTRACFLAGS += -I${pkgs.gmp.dev}/include|' tools/gcc/Makefile
+        sed -i 's|HOST_EXTRACXXFLAGS +=|HOST_EXTRACXXFLAGS += -I${pkgs.gmp.dev}/include|' tools/gcc/Makefile
         rm localversion-grsec
         echo ${localver grkern} > localversion-grsec
       '';
diff --git a/pkgs/build-support/setup-hooks/compress-man-pages.sh b/pkgs/build-support/setup-hooks/compress-man-pages.sh
index 1dd9788419b8..f1d9cf3a3696 100644
--- a/pkgs/build-support/setup-hooks/compress-man-pages.sh
+++ b/pkgs/build-support/setup-hooks/compress-man-pages.sh
@@ -3,6 +3,7 @@ fixupOutputHooks+=('if [ -z "$dontGzipMan" ]; then compressManPages "$prefix"; f
 compressManPages() {
     local dir="$1"
 
+    if [ ! -d "$dir/share/man" ]; then return; fi
     echo "gzipping man pages in $dir"
 
     GLOBIGNORE=.:..:*.gz:*.bz2
diff --git a/pkgs/build-support/setup-hooks/move-docs.sh b/pkgs/build-support/setup-hooks/move-docs.sh
index 57b71c15691d..ef31dcdce274 100644
--- a/pkgs/build-support/setup-hooks/move-docs.sh
+++ b/pkgs/build-support/setup-hooks/move-docs.sh
@@ -2,7 +2,7 @@
 # $out/share/man to $man/share/man; and moves $out/share/doc to
 # $man/share/doc.
 
-preFixupHooks+=(_moveDocs)
+preFixupHooks+=(_moveToShare)
 
 _moveToShare() {
     forceShare=${forceShare:=man doc info}
@@ -21,31 +21,3 @@ _moveToShare() {
     done
 }
 
-_moveToOutput() {
-    local d="$1"
-    local dst="$2"
-    if [ -z "$dst" -a ! -e $dst/$d ]; then return; fi
-    local output
-    for output in $outputs; do
-        if [ "${!output}" = "$dst" ]; then continue; fi
-        if [ -d "${!output}/$d" ]; then
-            echo "moving ${!output}/$d to $dst/$d"
-            mkdir -p $dst/share
-            mv ${!output}/$d $dst/$d
-            break
-        fi
-    done
-}
-
-_moveDocs() {
-    _moveToShare
-    _moveToOutput share/man "$man"
-    _moveToOutput share/info "$info"
-    _moveToOutput share/doc "$doc"
-    _moveToOutput share/gtk-doc "$doc"
-
-    # Remove empty share directory.
-    if [ -d "$out/share" ]; then
-        rmdir $out/share 2> /dev/null || true
-    fi
-}
diff --git a/pkgs/build-support/setup-hooks/multiple-outputs.sh b/pkgs/build-support/setup-hooks/multiple-outputs.sh
new file mode 100644
index 000000000000..2cf08d42ae04
--- /dev/null
+++ b/pkgs/build-support/setup-hooks/multiple-outputs.sh
@@ -0,0 +1,177 @@
+# The base package for automatic multiple-output splitting. Used in stdenv as well.
+preConfigureHooks+=(_multioutConfig)
+preFixupHooks+=(_multioutDocs)
+preFixupHooks+=(_multioutDevs)
+postFixupHooks+=(_multioutPropagateDev)
+
+# Assign the first string containing nonempty variable to the variable named $1
+_assignFirst() {
+    local varName="$1"
+    local REMOVE=REMOVE # slightly hacky - we allow REMOVE (i.e. not a variable name)
+    shift
+    while [ $# -ge 1 ]; do
+        if [ -n "${!1}" ]; then eval "${varName}"="$1"; return; fi
+        shift
+    done
+    echo "Error: _assignFirst found no valid variant!"
+    return 1 # none found
+}
+# Same as _assignFirst, but only if "$1" = ""
+_overrideFirst() {
+    if [ -z "${!1}" ]; then
+        _assignFirst "$@"
+    fi
+}
+
+
+# Setup chains of sane default values with easy overridability.
+# The variables are global to be usable anywhere during the build.
+# Typical usage in package is defining outputBin = "dev";
+
+_overrideFirst outputDev "dev" "out"
+_overrideFirst outputBin "bin" "out"
+
+_overrideFirst outputInclude "$outputDev"
+
+# so-libs are often among the main things to keep, and so go to $out
+_overrideFirst outputLib "lib" "out"
+
+_overrideFirst outputDoc "doc" "out"
+_overrideFirst outputDocdev "docdev" REMOVE # documentation for developers
+# man and info pages are small and often useful to distribute with binaries
+_overrideFirst outputMan "man" "doc" "$outputBin"
+_overrideFirst outputInfo "info" "doc" "$outputMan"
+
+
+# Add standard flags to put files into the desired outputs.
+_multioutConfig() {
+    if [ "$outputs" = "out" ] || [ -z "${setOutputFlags-1}" ]; then return; fi;
+
+    configureFlags="\
+        --bindir=${!outputBin}/bin --sbindir=${!outputBin}/sbin \
+        --includedir=${!outputInclude}/include --oldincludedir=${!outputInclude}/include \
+        --mandir=${!outputMan}/share/man --infodir=${!outputInfo}/share/info \
+        --docdir=${!outputDoc}/share/doc \
+        --libdir=${!outputLib}/lib --libexecdir=${!outputLib}/libexec \
+        --localedir=${!outputLib}/share/locale \
+        $configureFlags"
+
+    installFlags="\
+        pkgconfigdir=${!outputDev}/lib/pkgconfig \
+        m4datadir=${!outputDev}/share/aclocal aclocaldir=${!outputDev}/share/aclocal \
+        $installFlags"
+}
+
+# Add rpath prefixes to library paths, and avoid stdenv doing it for $out.
+_addRpathPrefix "${!outputLib}"
+NIX_NO_SELF_RPATH=1
+
+
+# Move subpaths that match pattern $1 from under any output/ to the $2 output/
+# Beware: only globbing patterns are accepted, e.g.: * ? {foo,bar}
+# A special target "REMOVE" is allowed: moveToOutput foo REMOVE
+moveToOutput() {
+    local patt="$1"
+    local dstOut="$2"
+    local output
+    for output in $outputs; do
+        if [ "${!output}" = "$dstOut" ]; then continue; fi
+        local srcPath
+        for srcPath in "${!output}"/$patt; do
+            if [ ! -e "$srcPath" ]; then continue; fi
+
+            if [ "$dstOut" = REMOVE ]; then
+                echo "Removing $srcPath"
+                rm -r "$srcPath"
+            else
+                local dstPath="$dstOut${srcPath#${!output}}"
+                echo "Moving $srcPath to $dstPath"
+
+                if [ -d "$dstPath" ] && [ -d "$srcPath" ]
+                then # attempt directory merge
+                    # check the case of trying to move an empty directory
+                    rmdir "$srcPath" --ignore-fail-on-non-empty
+                    if [ -d "$srcPath" ]; then
+                      mv -t "$dstPath" "$srcPath"/*
+                      rmdir "$srcPath"
+                    fi
+                else # usual move
+                    mkdir -p "$(readlink -m "$dstPath/..")"
+                    mv "$srcPath" "$dstPath"
+                fi
+            fi
+
+            # remove empty directories, printing iff at least one gets removed
+            local srcParent="$(readlink -m "$srcPath/..")"
+            if rmdir "$srcParent"; then
+                echo "Removing empty $srcParent/ and (possibly) its parents"
+                rmdir -p --ignore-fail-on-non-empty "$(readlink -m "$srcParent/..")" \
+                    2> /dev/null || true # doesn't ignore failure for some reason
+            fi
+        done
+    done
+}
+
+# Move documentation to the desired outputs.
+_multioutDocs() {
+    local REMOVE=REMOVE # slightly hacky - we expand ${!outputFoo}
+
+    moveToOutput share/info "${!outputInfo}"
+    moveToOutput share/doc "${!outputDoc}"
+    moveToOutput share/gtk-doc "${!outputDocdev}"
+
+    # the default outputMan is in $bin
+    moveToOutput share/man "${!outputMan}"
+    moveToOutput share/man/man3 "${!outputDocdev}"
+}
+
+# Move development-only stuff to the desired outputs.
+_multioutDevs() {
+    if [ "$outputs" = "out" ] || [ -z "${moveToDev-1}" ]; then return; fi;
+    moveToOutput include "${!outputInclude}"
+    # these files are sometimes provided even without using the corresponding tool
+    moveToOutput lib/pkgconfig "${!outputDev}"
+    moveToOutput share/pkgconfig "${!outputDev}"
+    moveToOutput lib/cmake "${!outputDev}"
+    moveToOutput share/aclocal "${!outputDev}"
+    # don't move *.la, as libtool needs them in the directory of the library
+
+    for f in "${!outputDev}"/{lib,share}/pkgconfig/*.pc; do
+        echo "Patching '$f' includedir to output ${!outputInclude}"
+        sed -i "/^includedir=/s,=\${prefix},=${!outputInclude}," "$f"
+    done
+}
+
+# Make the first output (typically "dev") propagate other outputs needed for development.
+# Take the first, because that's what one gets when putting the package into buildInputs.
+# Note: during the build, probably only the "native" development packages are useful.
+# With current cross-building setup, all packages are "native" if not cross-building.
+_multioutPropagateDev() {
+    if [ "$outputs" = "out" ]; then return; fi;
+
+    local outputFirst
+    for outputFirst in $outputs; do
+        break
+    done
+
+    # Default value: propagate binaries, includes and libraries
+    if [ -z "${propagatedBuildOutputs+1}" ]; then
+        local po_dirty="$outputBin $outputInclude $outputLib"
+        set +o pipefail
+        propagatedBuildOutputs=`echo "$po_dirty" \
+            | tr -s ' ' '\n' | grep -v -F "$outputFirst" \
+            | sort -u | tr '\n' ' ' `
+        set -o pipefail
+    fi
+
+    # The variable was explicitly set to empty or we resolved it so
+    if [ -z "$propagatedBuildOutputs" ]; then
+        return
+    fi
+
+    mkdir -p "${!outputFirst}"/nix-support
+    for output in $propagatedBuildOutputs; do
+        echo -n " ${!output}" >> "${!outputFirst}"/nix-support/propagated-native-build-inputs
+    done
+}
+
diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix
index ebcbf8c87b5e..2311b0d2fec8 100644
--- a/pkgs/build-support/vm/default.nix
+++ b/pkgs/build-support/vm/default.nix
@@ -31,9 +31,9 @@ rec {
       mkdir -p $out/lib
 
       # Copy what we need from Glibc.
-      cp -p ${pkgs.stdenv.glibc}/lib/ld-linux*.so.? $out/lib
-      cp -p ${pkgs.stdenv.glibc}/lib/libc.so.* $out/lib
-      cp -p ${pkgs.stdenv.glibc}/lib/libm.so.* $out/lib
+      cp -p ${pkgs.stdenv.glibc.out}/lib/ld-linux*.so.? $out/lib
+      cp -p ${pkgs.stdenv.glibc.out}/lib/libc.so.* $out/lib
+      cp -p ${pkgs.stdenv.glibc.out}/lib/libm.so.* $out/lib
 
       # Copy BusyBox.
       cp -pd ${pkgs.busybox}/bin/* $out/bin
@@ -574,7 +574,7 @@ rec {
       buildCommand = ''
         ${createRootFS}
 
-        PATH=$PATH:${dpkg}/bin:${dpkg}/bin:${glibc}/bin:${lzma}/bin
+        PATH=$PATH:${dpkg}/bin:${dpkg}/bin:${glibc.bin}/bin:${lzma}/bin
 
         # Unpack the .debs.  We do this to prevent pre-install scripts
         # (which have lots of circular dependencies) from barfing.
diff --git a/pkgs/data/documentation/man-pages/default.nix b/pkgs/data/documentation/man-pages/default.nix
index 02b4518b63d9..c25883c70604 100644
--- a/pkgs/data/documentation/man-pages/default.nix
+++ b/pkgs/data/documentation/man-pages/default.nix
@@ -9,7 +9,10 @@ stdenv.mkDerivation rec {
     sha256 = "0v8zxq4scfixy3pjpw9ankvv5v8frv62khv4xm1jpkswyq6rbqcg";
   };
 
+  # keep developer docs separately (man2 and man3)
+  outputs = [ "out" "docdev" ];
   makeFlags = [ "MANDIR=$(out)/share/man" ];
+  postFixup = ''moveToOutput share/man/man2 "$docdev" '';
 
   meta = with stdenv.lib; {
     description = "Linux development manual pages";
diff --git a/pkgs/data/documentation/std-man-pages/default.nix b/pkgs/data/documentation/std-man-pages/default.nix
index 3b45da914d25..c438f839dbda 100644
--- a/pkgs/data/documentation/std-man-pages/default.nix
+++ b/pkgs/data/documentation/std-man-pages/default.nix
@@ -2,12 +2,14 @@
 
 stdenv.mkDerivation rec {
   name = "std-man-pages-4.4.0";
-  
+
   src = fetchurl {
     url = mirror://gcc/libstdc++/doxygen/libstdc++-man.4.4.0.tar.bz2;
     sha256 = "0153py77ll759jacq41dp2z2ksr08pdcfic0rwjd6pr84dk89y9v";
   };
 
+  outputDocdev = "out";
+
   installPhase = ''
     mkdir -p $out/share/man
     cp -R * $out/share/man
diff --git a/pkgs/data/documentation/stdman/default.nix b/pkgs/data/documentation/stdman/default.nix
index 33c002e98013..249e5b6841bf 100644
--- a/pkgs/data/documentation/stdman/default.nix
+++ b/pkgs/data/documentation/stdman/default.nix
@@ -11,13 +11,15 @@ stdenv.mkDerivation rec {
     sha256 = "09c5gjhcz97ghfrv9zkgfb1wckvmqnhbzga0xidbm1ir7640di8l";
   };
 
+  outputDocdev = "out";
+
   preConfigure = "
     patchShebangs ./configure
     patchShebangs ./do_install
   ";
 
   buildInputs = [ curl ];
-  
+
   meta = with stdenv.lib; {
     description = "Formatted C++11/14 stdlib man pages (cppreference)";
     longDescription = "stdman is a tool that parses archived HTML
diff --git a/pkgs/data/misc/media-player-info/default.nix b/pkgs/data/misc/media-player-info/default.nix
index 9abe5d6ea8e7..ddb53d728202 100644
--- a/pkgs/data/misc/media-player-info/default.nix
+++ b/pkgs/data/misc/media-player-info/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, pkgconfig, python3, udev }:
+{ stdenv, fetchurl, pkgconfig, python3, udev, systemd }:
 
 let
   name = "media-player-info-22";
@@ -12,7 +12,7 @@ in
       sha256 = "0di3gfx5z8c34yspzyllydr5snzg71r985kbqhrhb1il51qxgrvy";
     };
 
-    buildInputs = [ udev ];
+    buildInputs = [ udev systemd ];
     nativeBuildInputs = [ pkgconfig python3 ];
 
     postPatch = ''
diff --git a/pkgs/data/misc/tzdata/default.nix b/pkgs/data/misc/tzdata/default.nix
index 045a9eef00a6..ad80d0d2224e 100644
--- a/pkgs/data/misc/tzdata/default.nix
+++ b/pkgs/data/misc/tzdata/default.nix
@@ -1,8 +1,8 @@
 { stdenv, fetchurl }:
 
-let version = "2015g"; in
+let version = "2015g";
 
-stdenv.mkDerivation rec {
+self = stdenv.mkDerivation rec {
   name = "tzdata-${version}";
 
   srcs =
@@ -17,9 +17,9 @@ stdenv.mkDerivation rec {
     ];
 
   sourceRoot = ".";
-  outputs = [ "out" "lib" ];
+  #outputs = [ "out" "lib" ]; # TODO: maybe resurrect, and maybe install man pages?
 
-  makeFlags = "TOPDIR=$(out) TZDIR=$(out)/share/zoneinfo ETCDIR=$(TMPDIR)/etc LIBDIR=$(lib)/lib MANDIR=$(TMPDIR)/man AWK=awk CFLAGS=-DHAVE_LINK=0";
+  makeFlags = "TOPDIR=$(out) TZDIR=$(out)/share/zoneinfo ETCDIR=$(TMPDIR)/etc LIBDIR=$(out)/lib MANDIR=$(TMPDIR)/man AWK=awk CFLAGS=-DHAVE_LINK=0";
 
   postInstall =
     ''
@@ -27,8 +27,8 @@ stdenv.mkDerivation rec {
       ln -s . $out/share/zoneinfo/posix
       mv $out/share/zoneinfo-leaps $out/share/zoneinfo/right
 
-      mkdir -p "$lib/include"
-      cp tzfile.h "$lib/include/tzfile.h"
+      mkdir -p "$out/include"
+      cp tzfile.h "$out/include/tzfile.h"
     '';
 
   meta = {
@@ -37,3 +37,6 @@ stdenv.mkDerivation rec {
     platforms = stdenv.lib.platforms.all;
   };
 }
+
+;in self // { lib = self; }
+
diff --git a/pkgs/desktops/e19/efl.nix b/pkgs/desktops/e19/efl.nix
index aa662f1ed873..7caa5bdd1eb4 100644
--- a/pkgs/desktops/e19/efl.nix
+++ b/pkgs/desktops/e19/efl.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, pkgconfig, openssl, libjpeg, zlib, freetype, fontconfig, fribidi, SDL2, SDL, mesa, giflib, libpng, libtiff, glib, gst_all_1, libpulseaudio, libsndfile, xorg, libdrm, libxkbcommon, udev, utillinuxCurses, dbus, bullet, luajit, python27Packages, openjpeg, doxygen, expat, harfbuzz, jbig2dec, librsvg, dbus_libs, alsaLib, poppler, libraw, libspectre, xineLib, libwebp, curl, libinput }:
+{ stdenv, fetchurl, pkgconfig, openssl, libjpeg, zlib, freetype, fontconfig, fribidi, SDL2, SDL, mesa, giflib, libpng, libtiff, glib, gst_all_1, libpulseaudio, libsndfile, xorg, libdrm, libxkbcommon, udev, utillinuxCurses, dbus, bullet, luajit, python27Packages, openjpeg, doxygen, expat, harfbuzz, jbig2dec, librsvg, dbus_libs, alsaLib, poppler, libraw, libspectre, xineLib, libwebp, curl, libinput, systemd }:
 
 
 stdenv.mkDerivation rec {
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ pkgconfig openssl zlib freetype fontconfig fribidi SDL2 SDL mesa
     giflib libpng libtiff glib gst_all_1.gstreamer gst_all_1.gst-plugins-base
     gst_all_1.gst-libav libpulseaudio libsndfile xorg.libXcursor xorg.printproto
-    xorg.libX11 udev utillinuxCurses ];
+    xorg.libX11 udev utillinuxCurses systemd ];
 
   propagatedBuildInputs = [ libxkbcommon python27Packages.dbus dbus libjpeg xorg.libXcomposite
     xorg.libXdamage xorg.libXinerama xorg.libXp xorg.libXtst xorg.libXi xorg.libXext
@@ -28,7 +28,7 @@ stdenv.mkDerivation rec {
     "--disable-tslib" "--with-systemdunitdir=$out/systemd/user"
     "ac_ct_CXX=foo" ];
 
-  NIX_CFLAGS_COMPILE = [ "-I${xorg.libXtst}" "-I${dbus_libs}/include/dbus-1.0" "-I${dbus_libs}/lib/dbus-1.0/include" ];
+  NIX_CFLAGS_COMPILE = [ "-I${xorg.libXtst}" "-I${dbus_libs.dev}/include/dbus-1.0" "-I${dbus_libs.lib}/lib/dbus-1.0/include" ];
 
   patches = [ ./efl-elua.patch ];
 
diff --git a/pkgs/desktops/gnome-2/desktop/gnome-keyring/default.nix b/pkgs/desktops/gnome-2/desktop/gnome-keyring/default.nix
index f31875bed91c..50f2cd081332 100644
--- a/pkgs/desktops/gnome-2/desktop/gnome-keyring/default.nix
+++ b/pkgs/desktops/gnome-2/desktop/gnome-keyring/default.nix
@@ -9,7 +9,7 @@ stdenv.mkDerivation {
     sha256 = "02r9gv3a4a705jf3h7c0bizn33c73wz0iw2500m7z291nrnmqkmj";
   };
   
-  buildInputs = [ dbus.libs libgcrypt pam python gtk GConf libgnome_keyring ];
+  buildInputs = [ dbus libgcrypt pam python gtk GConf libgnome_keyring ];
 
   propagatedBuildInputs = [ glib libtasn1 ];
 
diff --git a/pkgs/desktops/gnome-3/3.16/apps/evolution/default.nix b/pkgs/desktops/gnome-3/3.16/apps/evolution/default.nix
index d77740d35075..1aa9dd62d41e 100644
--- a/pkgs/desktops/gnome-3/3.16/apps/evolution/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/apps/evolution/default.nix
@@ -32,7 +32,7 @@ in stdenv.mkDerivation rec {
   configureFlags = [ "--disable-spamassassin" "--disable-pst-import" "--disable-autoar"
                      "--disable-libcryptui" ];
 
-  NIX_CFLAGS_COMPILE = "-I${nspr}/include/nspr -I${nss}/include/nss -I${glib}/include/gio-unix-2.0";
+  NIX_CFLAGS_COMPILE = "-I${nspr.dev}/include/nspr -I${nss.dev}/include/nss -I${glib.dev}/include/gio-unix-2.0";
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/desktops/gnome-3/3.16/core/empathy/default.nix b/pkgs/desktops/gnome-3/3.16/core/empathy/default.nix
index 4c42c6c026d3..48b45f28522e 100644
--- a/pkgs/desktops/gnome-3/3.16/core/empathy/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/empathy/default.nix
@@ -35,9 +35,9 @@ stdenv.mkDerivation rec {
                   gnome3.defaultIconTheme gnome3.gsettings_desktop_schemas
                   file libtool librsvg ];
 
-  NIX_CFLAGS_COMPILE = [ "-I${dbus_glib}/include/dbus-1.0"
-                         "-I${dbus_libs}/include/dbus-1.0"
-                         "-I${dbus_libs}/lib/dbus-1.0/include" ];
+  NIX_CFLAGS_COMPILE = [ "-I${dbus_glib.dev}/include/dbus-1.0"
+                         "-I${dbus_libs.dev}/include/dbus-1.0"
+                         "-I${dbus_libs.lib}/lib/dbus-1.0/include" ];
 
   preFixup = ''
     for f in $out/bin/* $out/libexec/*; do
diff --git a/pkgs/desktops/gnome-3/3.16/core/epiphany/default.nix b/pkgs/desktops/gnome-3/3.16/core/epiphany/default.nix
index 7dcba4173644..73c877216415 100644
--- a/pkgs/desktops/gnome-3/3.16/core/epiphany/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/epiphany/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
                   gdk_pixbuf gnome3.defaultIconTheme librsvg which gnome_common
                   gcr avahi gnome3.gsettings_desktop_schemas makeWrapper ];
 
-  NIX_CFLAGS_COMPILE = "-I${nspr}/include/nspr -I${nss}/include/nss -I${glib}/include/gio-unix-2.0";
+  NIX_CFLAGS_COMPILE = "-I${nspr.dev}/include/nspr -I${nss.dev}/include/nss -I${glib.dev}/include/gio-unix-2.0";
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/desktops/gnome-3/3.16/core/evince/default.nix b/pkgs/desktops/gnome-3/3.16/core/evince/default.nix
index aa75b55358b5..483f5104d8d1 100644
--- a/pkgs/desktops/gnome-3/3.16/core/evince/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/evince/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
     "--enable-introspection"
   ];
 
-  NIX_CFLAGS_COMPILE = "-I${gnome3.glib}/include/gio-unix-2.0";
+  NIX_CFLAGS_COMPILE = "-I${gnome3.glib.dev}/include/gio-unix-2.0";
 
   preConfigure = with stdenv.lib;
     optionalString doCheck ''
@@ -45,7 +45,7 @@ stdenv.mkDerivation rec {
     # by `g_file_info_get_content_type ()'.
     wrapProgram "$out/bin/evince" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3}/share:${shared_mime_info}/share:$out/share:$GSETTINGS_SCHEMAS_PATH"
+      --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3.out}/share:${shared_mime_info}/share:$out/share:$GSETTINGS_SCHEMAS_PATH"
 
   '';
 
diff --git a/pkgs/desktops/gnome-3/3.16/core/folks/default.nix b/pkgs/desktops/gnome-3/3.16/core/folks/default.nix
index 6e200bdb3188..4385c6b6f75b 100644
--- a/pkgs/desktops/gnome-3/3.16/core/folks/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/folks/default.nix
@@ -23,8 +23,8 @@ stdenv.mkDerivation rec {
 
   configureFlags = "--disable-fatal-warnings";
 
-  NIX_CFLAGS_COMPILE = ["-I${nspr}/include/nspr" "-I${nss}/include/nss"
-                        "-I${dbus_glib}/include/dbus-1.0" "-I${dbus_libs}/include/dbus-1.0"];
+  NIX_CFLAGS_COMPILE = ["-I${nspr.dev}/include/nspr" "-I${nss.dev}/include/nss"
+                        "-I${dbus_glib.dev}/include/dbus-1.0" "-I${dbus_libs.dev}/include/dbus-1.0"];
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/desktops/gnome-3/3.16/core/gdm/3.16-wip/default.nix b/pkgs/desktops/gnome-3/3.16/core/gdm/3.16-wip/default.nix
index 51b67afb01fd..3749be2de27f 100644
--- a/pkgs/desktops/gnome-3/3.16/core/gdm/3.16-wip/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/gdm/3.16-wip/default.nix
@@ -11,9 +11,9 @@ stdenv.mkDerivation rec {
   };
 
   preConfigure = ''
-    substituteInPlace ./configure --replace "/usr/bin/X" "${xorg.xorgserver}/bin/X"
+    substituteInPlace ./configure --replace "/usr/bin/X" "${xorg.xorgserver.out}/bin/X"
     substituteInPlace daemon/gdm-simple-slave.c --replace 'BINDIR "/gnome-session' '"${gnome_session}/bin/gnome-session'
-    substituteInPlace daemon/gdm-launch-environment.c --replace 'BINDIR "/dbus-launch' '"${dbus.tools}/bin/dbus-launch'
+    substituteInPlace daemon/gdm-launch-environment.c --replace 'BINDIR "/dbus-launch' '"${dbus.dbus-launch}'
     substituteInPlace data/gdm.conf-custom.in --replace '#WaylandEnable=false' 'WaylandEnable=false'
     sed 's/#Enable=true/Enable=true/' -i data/gdm.conf-custom.in
  '';
diff --git a/pkgs/desktops/gnome-3/3.16/core/gdm/default.nix b/pkgs/desktops/gnome-3/3.16/core/gdm/default.nix
index d3d6f4e471c4..7759d21960cb 100644
--- a/pkgs/desktops/gnome-3/3.16/core/gdm/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/gdm/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
 
   # Only needed to make it build
   preConfigure = ''
-    substituteInPlace ./configure --replace "/usr/bin/X" "${xorg.xorgserver}/bin/X"
+    substituteInPlace ./configure --replace "/usr/bin/X" "${xorg.xorgserver.out}/bin/X"
   '';
 
   configureFlags = [ "--sysconfdir=/etc"
diff --git a/pkgs/desktops/gnome-3/3.16/core/gjs/default.nix b/pkgs/desktops/gnome-3/3.16/core/gjs/default.nix
index 792e34c7b148..ac53726bc537 100644
--- a/pkgs/desktops/gnome-3/3.16/core/gjs/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/gjs/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
   propagatedBuildInputs = [ spidermonkey_24 ];
 
   postInstall = ''
-    sed 's|-lreadline|-L${readline}/lib -lreadline|g' -i $out/lib/libgjs.la
+    sed 's|-lreadline|-L${readline.out}/lib -lreadline|g' -i $out/lib/libgjs.la
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.16/core/gnome-dictionary/default.nix b/pkgs/desktops/gnome-3/3.16/core/gnome-dictionary/default.nix
index 9e3906dbed13..18b89279696e 100644
--- a/pkgs/desktops/gnome-3/3.16/core/gnome-dictionary/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/gnome-dictionary/default.nix
@@ -24,7 +24,7 @@ stdenv.mkDerivation rec {
   preFixup = ''
     wrapProgram "$out/bin/gnome-dictionary" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --prefix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
+      --prefix XDG_DATA_DIRS : "${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.16/core/gnome-online-accounts/default.nix b/pkgs/desktops/gnome-3/3.16/core/gnome-online-accounts/default.nix
index ac285819e8f4..8bb21feb54ab 100644
--- a/pkgs/desktops/gnome-3/3.16/core/gnome-online-accounts/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/gnome-online-accounts/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
     sha256 = "1mpzj6fc42hhx77lki8cdycgfj9gjrm611rh0wsaqam4qq2c9a9c";
   };
 
-  NIX_CFLAGS_COMPILE = "-I${dbus_glib}/include/dbus-1.0 -I${dbus_libs}/include/dbus-1.0";
+  NIX_CFLAGS_COMPILE = "-I${dbus_glib.dev}/include/dbus-1.0 -I${dbus_libs.dev}/include/dbus-1.0";
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/desktops/gnome-3/3.16/core/gnome-screenshot/default.nix b/pkgs/desktops/gnome-3/3.16/core/gnome-screenshot/default.nix
index 8b4e7be9c411..0c1882608670 100644
--- a/pkgs/desktops/gnome-3/3.16/core/gnome-screenshot/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/gnome-screenshot/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
 
   doCheck = true;
 
-  NIX_CFLAGS_COMPILE = "-I${gnome3.glib}/include/gio-unix-2.0";
+  NIX_CFLAGS_COMPILE = "-I${gnome3.glib.dev}/include/gio-unix-2.0";
 
   propagatedUserEnvPkgs = [ gnome3.gnome_themes_standard ];
   propagatedBuildInputs = [ gdk_pixbuf gnome3.defaultIconTheme librsvg ];
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
   preFixup = ''
     wrapProgram "$out/bin/gnome-screenshot" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --prefix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
+      --prefix XDG_DATA_DIRS : "${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.16/core/gnome-system-log/default.nix b/pkgs/desktops/gnome-3/3.16/core/gnome-system-log/default.nix
index 716f92a072d4..50ee229cfa49 100644
--- a/pkgs/desktops/gnome-3/3.16/core/gnome-system-log/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/gnome-system-log/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
 
   doCheck = true;
 
-  NIX_CFLAGS_COMPILE = "-I${gnome3.glib}/include/gio-unix-2.0";
+  NIX_CFLAGS_COMPILE = "-I${gnome3.glib.dev}/include/gio-unix-2.0";
 
   propagatedUserEnvPkgs = [ gnome3.gnome_themes_standard ];
   propagatedBuildInputs = [ gdk_pixbuf gnome3.defaultIconTheme librsvg ];
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
   preFixup = ''
     wrapProgram "$out/bin/gnome-system-log" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --prefix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
+      --prefix XDG_DATA_DIRS : "${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.16/core/gnome-user-share/default.nix b/pkgs/desktops/gnome-3/3.16/core/gnome-user-share/default.nix
index 381f7d7c4168..cd02dcb821f8 100644
--- a/pkgs/desktops/gnome-3/3.16/core/gnome-user-share/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/gnome-user-share/default.nix
@@ -21,8 +21,8 @@ in stdenv.mkDerivation rec {
     sed -e 's,^LoadModule dnssd_module.\+,LoadModule dnssd_module ${mod_dnssd}/modules/mod_dnssd.so,' -i data/dav_user_2.2.conf 
   '';
 
-  configureFlags = [ "--with-httpd=${apacheHttpd_2_2}/bin/httpd"
-                     "--with-modules-path=${apacheHttpd_2_2}/modules"
+  configureFlags = [ "--with-httpd=${apacheHttpd_2_2.out}/bin/httpd"
+                     "--with-modules-path=${apacheHttpd_2_2.out}/modules"
                      "--disable-bluetooth"
                      "--with-nautilusdir=$(out)/lib/nautilus/extensions-3.0" ];
 
diff --git a/pkgs/desktops/gnome-3/3.16/core/libcroco/default.nix b/pkgs/desktops/gnome-3/3.16/core/libcroco/default.nix
index e8ddf7096e62..76d9118c4b95 100644
--- a/pkgs/desktops/gnome-3/3.16/core/libcroco/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/libcroco/default.nix
@@ -8,7 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "0w453f3nnkbkrly7spx5lx5pf6mwynzmd5qhszprq8amij2invpa";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
 
   configureFlags = stdenv.lib.optional stdenv.isDarwin "--disable-Bsymbolic";
 
diff --git a/pkgs/desktops/gnome-3/3.16/core/vte/2.90.nix b/pkgs/desktops/gnome-3/3.16/core/vte/2.90.nix
index 5ccca36bcaad..663d6b9e3524 100644
--- a/pkgs/desktops/gnome-3/3.16/core/vte/2.90.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/vte/2.90.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = true;
 
   postInstall = ''
-    substituteInPlace $out/lib/libvte2_90.la --replace "-lncurses" "-L${ncurses}/lib -lncurses"
+    substituteInPlace $out/lib/libvte2_90.la --replace "-lncurses" "-L${ncurses.lib}/lib -lncurses"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.16/core/vte/default.nix b/pkgs/desktops/gnome-3/3.16/core/vte/default.nix
index 89a1405f62b7..2f0062101f2e 100644
--- a/pkgs/desktops/gnome-3/3.16/core/vte/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/core/vte/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = true;
 
   postInstall = ''
-    substituteInPlace $out/lib/libvte2_90.la --replace "-lncurses" "-L${ncurses}/lib -lncurses"
+    substituteInPlace $out/lib/libvte2_90.la --replace "-lncurses" "-L${ncurses.lib}/lib -lncurses"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.16/misc/gitg/default.nix b/pkgs/desktops/gnome-3/3.16/misc/gitg/default.nix
index 998f1f5f735f..6295773d4587 100644
--- a/pkgs/desktops/gnome-3/3.16/misc/gitg/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/misc/gitg/default.nix
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
     wrapProgram "$out/bin/gitg" \
       --prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$GSETTINGS_SCHEMAS_PATH"
+      --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:$out/share:$GSETTINGS_SCHEMAS_PATH"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.16/misc/gnome-tweak-tool/default.nix b/pkgs/desktops/gnome-3/3.16/misc/gnome-tweak-tool/default.nix
index 6600345060f9..c790d41f1073 100644
--- a/pkgs/desktops/gnome-3/3.16/misc/gnome-tweak-tool/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/misc/gnome-tweak-tool/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
   preFixup = ''
     wrapProgram "$out/bin/gnome-tweak-tool" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --suffix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH" \
+      --suffix XDG_DATA_DIRS : "${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH" \
       --prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH" \
       --prefix PYTHONPATH : "$PYTHONPATH:$(toPythonPath $out)"
   '';
diff --git a/pkgs/desktops/gnome-3/3.16/misc/gpaste/default.nix b/pkgs/desktops/gnome-3/3.16/misc/gpaste/default.nix
index 6563f7979700..0d6551216cf8 100644
--- a/pkgs/desktops/gnome-3/3.16/misc/gpaste/default.nix
+++ b/pkgs/desktops/gnome-3/3.16/misc/gpaste/default.nix
@@ -11,7 +11,7 @@ stdenv.mkDerivation rec {
   };
 
   buildInputs = [ intltool autoreconfHook pkgconfig vala glib
-                  gtk3 gnome3.gnome_control_center dbus.libs
+                  gtk3 gnome3.gnome_control_center dbus
                   clutter pango appstream-glib makeWrapper ];
 
   preConfigure = "intltoolize -f";
diff --git a/pkgs/desktops/gnome-3/3.18/apps/evolution/default.nix b/pkgs/desktops/gnome-3/3.18/apps/evolution/default.nix
index a9bb87d4dddf..100dfbf3acec 100644
--- a/pkgs/desktops/gnome-3/3.18/apps/evolution/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/apps/evolution/default.nix
@@ -27,7 +27,7 @@ in stdenv.mkDerivation rec {
   configureFlags = [ "--disable-spamassassin" "--disable-pst-import" "--disable-autoar"
                      "--disable-libcryptui" ];
 
-  NIX_CFLAGS_COMPILE = "-I${nspr}/include/nspr -I${nss}/include/nss -I${glib}/include/gio-unix-2.0";
+  NIX_CFLAGS_COMPILE = "-I${nspr.dev}/include/nspr -I${nss.dev}/include/nss -I${glib.dev}/include/gio-unix-2.0";
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/desktops/gnome-3/3.18/core/empathy/default.nix b/pkgs/desktops/gnome-3/3.18/core/empathy/default.nix
index 4c42c6c026d3..48b45f28522e 100644
--- a/pkgs/desktops/gnome-3/3.18/core/empathy/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/empathy/default.nix
@@ -35,9 +35,9 @@ stdenv.mkDerivation rec {
                   gnome3.defaultIconTheme gnome3.gsettings_desktop_schemas
                   file libtool librsvg ];
 
-  NIX_CFLAGS_COMPILE = [ "-I${dbus_glib}/include/dbus-1.0"
-                         "-I${dbus_libs}/include/dbus-1.0"
-                         "-I${dbus_libs}/lib/dbus-1.0/include" ];
+  NIX_CFLAGS_COMPILE = [ "-I${dbus_glib.dev}/include/dbus-1.0"
+                         "-I${dbus_libs.dev}/include/dbus-1.0"
+                         "-I${dbus_libs.lib}/lib/dbus-1.0/include" ];
 
   preFixup = ''
     for f in $out/bin/* $out/libexec/*; do
diff --git a/pkgs/desktops/gnome-3/3.18/core/epiphany/default.nix b/pkgs/desktops/gnome-3/3.18/core/epiphany/default.nix
index ff21da4a28c8..76e860f5680e 100644
--- a/pkgs/desktops/gnome-3/3.18/core/epiphany/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/epiphany/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
                   gdk_pixbuf gnome3.defaultIconTheme librsvg which gnome_common
                   gcr avahi gnome3.gsettings_desktop_schemas makeWrapper ];
 
-  NIX_CFLAGS_COMPILE = "-I${nspr}/include/nspr -I${nss}/include/nss -I${glib}/include/gio-unix-2.0";
+  NIX_CFLAGS_COMPILE = "-I${nspr.dev}/include/nspr -I${nss.dev}/include/nss -I${glib.dev}/include/gio-unix-2.0";
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/desktops/gnome-3/3.18/core/evince/default.nix b/pkgs/desktops/gnome-3/3.18/core/evince/default.nix
index 154182eef887..bed67184eeb0 100644
--- a/pkgs/desktops/gnome-3/3.18/core/evince/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/evince/default.nix
@@ -40,7 +40,7 @@ stdenv.mkDerivation rec {
     # by `g_file_info_get_content_type ()'.
     wrapProgram "$out/bin/evince" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3}/share:${shared_mime_info}/share:$out/share:$GSETTINGS_SCHEMAS_PATH"
+      --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3.out}/share:${shared_mime_info}/share:$out/share:$GSETTINGS_SCHEMAS_PATH"
 
   '';
 
diff --git a/pkgs/desktops/gnome-3/3.18/core/folks/default.nix b/pkgs/desktops/gnome-3/3.18/core/folks/default.nix
index 6e200bdb3188..4385c6b6f75b 100644
--- a/pkgs/desktops/gnome-3/3.18/core/folks/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/folks/default.nix
@@ -23,8 +23,8 @@ stdenv.mkDerivation rec {
 
   configureFlags = "--disable-fatal-warnings";
 
-  NIX_CFLAGS_COMPILE = ["-I${nspr}/include/nspr" "-I${nss}/include/nss"
-                        "-I${dbus_glib}/include/dbus-1.0" "-I${dbus_libs}/include/dbus-1.0"];
+  NIX_CFLAGS_COMPILE = ["-I${nspr.dev}/include/nspr" "-I${nss.dev}/include/nss"
+                        "-I${dbus_glib.dev}/include/dbus-1.0" "-I${dbus_libs.dev}/include/dbus-1.0"];
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/desktops/gnome-3/3.18/core/gdm/3.16-wip/default.nix b/pkgs/desktops/gnome-3/3.18/core/gdm/3.16-wip/default.nix
index 51b67afb01fd..3749be2de27f 100644
--- a/pkgs/desktops/gnome-3/3.18/core/gdm/3.16-wip/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/gdm/3.16-wip/default.nix
@@ -11,9 +11,9 @@ stdenv.mkDerivation rec {
   };
 
   preConfigure = ''
-    substituteInPlace ./configure --replace "/usr/bin/X" "${xorg.xorgserver}/bin/X"
+    substituteInPlace ./configure --replace "/usr/bin/X" "${xorg.xorgserver.out}/bin/X"
     substituteInPlace daemon/gdm-simple-slave.c --replace 'BINDIR "/gnome-session' '"${gnome_session}/bin/gnome-session'
-    substituteInPlace daemon/gdm-launch-environment.c --replace 'BINDIR "/dbus-launch' '"${dbus.tools}/bin/dbus-launch'
+    substituteInPlace daemon/gdm-launch-environment.c --replace 'BINDIR "/dbus-launch' '"${dbus.dbus-launch}'
     substituteInPlace data/gdm.conf-custom.in --replace '#WaylandEnable=false' 'WaylandEnable=false'
     sed 's/#Enable=true/Enable=true/' -i data/gdm.conf-custom.in
  '';
diff --git a/pkgs/desktops/gnome-3/3.18/core/gdm/default.nix b/pkgs/desktops/gnome-3/3.18/core/gdm/default.nix
index 1db969651317..a13370e5c9a9 100644
--- a/pkgs/desktops/gnome-3/3.18/core/gdm/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/gdm/default.nix
@@ -7,7 +7,7 @@ stdenv.mkDerivation rec {
 
   # Only needed to make it build
   preConfigure = ''
-    substituteInPlace ./configure --replace "/usr/bin/X" "${xorg.xorgserver}/bin/X"
+    substituteInPlace ./configure --replace "/usr/bin/X" "${xorg.xorgserver.out}/bin/X"
   '';
 
   configureFlags = [ "--sysconfdir=/etc"
diff --git a/pkgs/desktops/gnome-3/3.18/core/gjs/default.nix b/pkgs/desktops/gnome-3/3.18/core/gjs/default.nix
index 792e34c7b148..ac53726bc537 100644
--- a/pkgs/desktops/gnome-3/3.18/core/gjs/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/gjs/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
   propagatedBuildInputs = [ spidermonkey_24 ];
 
   postInstall = ''
-    sed 's|-lreadline|-L${readline}/lib -lreadline|g' -i $out/lib/libgjs.la
+    sed 's|-lreadline|-L${readline.out}/lib -lreadline|g' -i $out/lib/libgjs.la
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.18/core/gnome-dictionary/default.nix b/pkgs/desktops/gnome-3/3.18/core/gnome-dictionary/default.nix
index 1d1f9d18c566..51e3f6ab3133 100644
--- a/pkgs/desktops/gnome-3/3.18/core/gnome-dictionary/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/gnome-dictionary/default.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
   preFixup = ''
     wrapProgram "$out/bin/gnome-dictionary" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --prefix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
+      --prefix XDG_DATA_DIRS : "${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.18/core/gnome-online-accounts/default.nix b/pkgs/desktops/gnome-3/3.18/core/gnome-online-accounts/default.nix
index d810fbb862b7..c6688fd30cd7 100644
--- a/pkgs/desktops/gnome-3/3.18/core/gnome-online-accounts/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/gnome-online-accounts/default.nix
@@ -7,7 +7,7 @@
 stdenv.mkDerivation rec {
   inherit (import ./src.nix fetchurl) name src;
 
-  NIX_CFLAGS_COMPILE = "-I${dbus_glib}/include/dbus-1.0 -I${dbus_libs}/include/dbus-1.0";
+  NIX_CFLAGS_COMPILE = "-I${dbus_glib.dev}/include/dbus-1.0 -I${dbus_libs.dev}/include/dbus-1.0";
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/desktops/gnome-3/3.18/core/gnome-screenshot/default.nix b/pkgs/desktops/gnome-3/3.18/core/gnome-screenshot/default.nix
index 763fc990bdab..15d93793088b 100644
--- a/pkgs/desktops/gnome-3/3.18/core/gnome-screenshot/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/gnome-screenshot/default.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation rec {
   preFixup = ''
     wrapProgram "$out/bin/gnome-screenshot" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --prefix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
+      --prefix XDG_DATA_DIRS : "${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.18/core/gnome-system-log/default.nix b/pkgs/desktops/gnome-3/3.18/core/gnome-system-log/default.nix
index 716f92a072d4..6b7b28ad4000 100644
--- a/pkgs/desktops/gnome-3/3.18/core/gnome-system-log/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/gnome-system-log/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
   preFixup = ''
     wrapProgram "$out/bin/gnome-system-log" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --prefix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
+      --prefix XDG_DATA_DIRS : "${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.18/core/gnome-user-share/default.nix b/pkgs/desktops/gnome-3/3.18/core/gnome-user-share/default.nix
index 49ad40912c66..e8f649835062 100644
--- a/pkgs/desktops/gnome-3/3.18/core/gnome-user-share/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/gnome-user-share/default.nix
@@ -14,8 +14,8 @@ stdenv.mkDerivation rec {
     sed -e 's,^LoadModule dnssd_module.\+,LoadModule dnssd_module ${mod_dnssd}/modules/mod_dnssd.so,' -i data/dav_user_2.2.conf 
   '';
 
-  configureFlags = [ "--with-httpd=${apacheHttpd_2_2}/bin/httpd"
-                     "--with-modules-path=${apacheHttpd_2_2}/modules"
+  configureFlags = [ "--with-httpd=${apacheHttpd_2_2.out}/bin/httpd"
+                     "--with-modules-path=${apacheHttpd_2_2.out}/modules"
                      "--disable-bluetooth"
                      "--with-nautilusdir=$(out)/lib/nautilus/extensions-3.0" ];
 
diff --git a/pkgs/desktops/gnome-3/3.18/core/libcroco/default.nix b/pkgs/desktops/gnome-3/3.18/core/libcroco/default.nix
index e8ddf7096e62..76d9118c4b95 100644
--- a/pkgs/desktops/gnome-3/3.18/core/libcroco/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/libcroco/default.nix
@@ -8,7 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "0w453f3nnkbkrly7spx5lx5pf6mwynzmd5qhszprq8amij2invpa";
   };
 
-  outputs = [ "out" "doc" ];
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
 
   configureFlags = stdenv.lib.optional stdenv.isDarwin "--disable-Bsymbolic";
 
diff --git a/pkgs/desktops/gnome-3/3.18/core/vte/2.90.nix b/pkgs/desktops/gnome-3/3.18/core/vte/2.90.nix
index 5ccca36bcaad..663d6b9e3524 100644
--- a/pkgs/desktops/gnome-3/3.18/core/vte/2.90.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/vte/2.90.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = true;
 
   postInstall = ''
-    substituteInPlace $out/lib/libvte2_90.la --replace "-lncurses" "-L${ncurses}/lib -lncurses"
+    substituteInPlace $out/lib/libvte2_90.la --replace "-lncurses" "-L${ncurses.lib}/lib -lncurses"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.18/core/vte/default.nix b/pkgs/desktops/gnome-3/3.18/core/vte/default.nix
index 86dfd953b48f..078ec871135b 100644
--- a/pkgs/desktops/gnome-3/3.18/core/vte/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/core/vte/default.nix
@@ -20,7 +20,7 @@ let baseAttrs = rec {
   enableParallelBuilding = true;
 
   postInstall = ''
-    substituteInPlace $out/lib/libvte2_90.la --replace "-lncurses" "-L${ncurses}/lib -lncurses"
+    substituteInPlace $out/lib/libvte2_90.la --replace "-lncurses" "-L${ncurses.lib}/lib -lncurses"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.18/misc/gitg/default.nix b/pkgs/desktops/gnome-3/3.18/misc/gitg/default.nix
index 19f340ac291e..e7f833bf7172 100644
--- a/pkgs/desktops/gnome-3/3.18/misc/gitg/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/misc/gitg/default.nix
@@ -30,7 +30,7 @@ stdenv.mkDerivation rec {
     wrapProgram "$out/bin/gitg" \
       --prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$GSETTINGS_SCHEMAS_PATH"
+      --prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS:${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:$out/share:$GSETTINGS_SCHEMAS_PATH"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/desktops/gnome-3/3.18/misc/gnome-tweak-tool/default.nix b/pkgs/desktops/gnome-3/3.18/misc/gnome-tweak-tool/default.nix
index 986d4058af92..d0c6674ad9bd 100644
--- a/pkgs/desktops/gnome-3/3.18/misc/gnome-tweak-tool/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/misc/gnome-tweak-tool/default.nix
@@ -22,7 +22,7 @@ stdenv.mkDerivation rec {
   preFixup = ''
     wrapProgram "$out/bin/gnome-tweak-tool" \
       --set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
-      --suffix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH" \
+      --suffix XDG_DATA_DIRS : "${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH" \
       --prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH" \
       --prefix PYTHONPATH : "$PYTHONPATH:$(toPythonPath $out)"
   '';
diff --git a/pkgs/desktops/gnome-3/3.18/misc/gpaste/default.nix b/pkgs/desktops/gnome-3/3.18/misc/gpaste/default.nix
index eeb2cee86cdd..fd7ecbea01ff 100644
--- a/pkgs/desktops/gnome-3/3.18/misc/gpaste/default.nix
+++ b/pkgs/desktops/gnome-3/3.18/misc/gpaste/default.nix
@@ -11,7 +11,7 @@ stdenv.mkDerivation rec {
   };
 
   buildInputs = [ intltool autoreconfHook pkgconfig vala glib
-                  gtk3 gnome3.gnome_control_center dbus.libs
+                  gtk3 gnome3.gnome_control_center dbus
                   clutter pango appstream-glib makeWrapper ];
 
   preConfigure = "intltoolize -f";
diff --git a/pkgs/desktops/kde-4.14/kde-runtime.nix b/pkgs/desktops/kde-4.14/kde-runtime.nix
index 655555cd140a..495ea242e0d0 100644
--- a/pkgs/desktops/kde-4.14/kde-runtime.nix
+++ b/pkgs/desktops/kde-4.14/kde-runtime.nix
@@ -16,7 +16,7 @@ kde {
 
   nativeBuildInputs = [ shared_mime_info ];
 
-  NIX_CFLAGS_COMPILE = "-I${ilmbase}/include/OpenEXR -I${glib}/include/glib-2.0 -I${glib}/lib/glib-2.0/include";
+  NIX_CFLAGS_COMPILE = "-I${ilmbase}/include/OpenEXR -I${glib.dev}/include/glib-2.0 -I${glib.out}/lib/glib-2.0/include";
 
   passthru.propagatedUserEnvPackages = [ virtuoso ];
 
diff --git a/pkgs/desktops/kde-4.14/kdenetwork/kopete.nix b/pkgs/desktops/kde-4.14/kdenetwork/kopete.nix
index 267c2b782129..f5750d60045f 100644
--- a/pkgs/desktops/kde-4.14/kdenetwork/kopete.nix
+++ b/pkgs/desktops/kde-4.14/kdenetwork/kopete.nix
@@ -9,6 +9,7 @@ kde {
 
   patches = [
     (fetchurl {
+      name = "kopete.patch";
       url = "https://bugs.kde.org/attachment.cgi?id=91567";
       sha256 = "0a44rjiqzn6v3sywm17d1741sygbvlfnbqadq7qbdj3amny014m1";
     })
diff --git a/pkgs/desktops/xfce/core/exo.nix b/pkgs/desktops/xfce/core/exo.nix
index 83610a4e4a65..4d3f09105433 100644
--- a/pkgs/desktops/xfce/core/exo.nix
+++ b/pkgs/desktops/xfce/core/exo.nix
@@ -1,4 +1,5 @@
-{ stdenv, fetchurl, pkgconfig, intltool, URI, glib, gtk, libxfce4ui, libxfce4util }:
+{ stdenv, fetchurl, pkgconfig, intltool, URI, glib, gtk, libxfce4ui, libxfce4util
+, hicolor_icon_theme }:
 
 stdenv.mkDerivation rec {
   p_name  = "exo";
@@ -11,9 +12,11 @@ stdenv.mkDerivation rec {
   };
   name = "${p_name}-${ver_maj}.${ver_min}";
 
-  buildInputs = [ pkgconfig intltool URI glib gtk libxfce4ui libxfce4util ];
+  outputs = [ "dev" "out" "docdev" ];
+    # lib/xfce4/exo-1/exo-compose-mail-1 is a perl script :-/
 
-  preFixup = "rm $out/share/icons/hicolor/icon-theme.cache";
+  nativeBuildInputs = [ pkgconfig intltool ];
+  buildInputs = [ URI glib gtk libxfce4ui libxfce4util hicolor_icon_theme ];
 
   meta = with stdenv.lib; {
     homepage = "http://www.xfce.org/projects/${p_name}";
diff --git a/pkgs/desktops/xfce/core/garcon.nix b/pkgs/desktops/xfce/core/garcon.nix
index 8f8cfff76cd4..4fffc9e1ec9f 100644
--- a/pkgs/desktops/xfce/core/garcon.nix
+++ b/pkgs/desktops/xfce/core/garcon.nix
@@ -1,22 +1,26 @@
 { stdenv, fetchurl, pkgconfig, intltool, glib, libxfce4util, libxfce4ui, gtk }:
-
-stdenv.mkDerivation rec {
+let
   p_name  = "garcon";
   ver_maj = "0.4";
   ver_min = "0";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "0wm9pjbwq53s3n3nwvsyf0q8lbmhiy2ln3bn5ncihr9vf5cwhzbq";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
+
+  outputs = [ "dev" "out" ];
 
   buildInputs = [ pkgconfig intltool glib libxfce4util gtk libxfce4ui ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.xfce.org/;
     description = "Xfce menu support library";
-    license = stdenv.lib.licenses.gpl2Plus;
-    platforms = stdenv.lib.platforms.linux;
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/libxfce4ui.nix b/pkgs/desktops/xfce/core/libxfce4ui.nix
index 2cb20febcb94..6bdeb50f8399 100644
--- a/pkgs/desktops/xfce/core/libxfce4ui.nix
+++ b/pkgs/desktops/xfce/core/libxfce4ui.nix
@@ -1,40 +1,38 @@
 { stdenv, fetchurl, pkgconfig, intltool, gtk, libxfce4util, xfconf
-, libglade, libstartup_notification
+, libglade, libstartup_notification, hicolor_icon_theme
 , withGtk3 ? false, gtk3
 }:
-
-with { inherit (stdenv.lib) optional; };
-
-stdenv.mkDerivation rec {
+let
   p_name  = "libxfce4ui";
   ver_maj = "4.12";
   ver_min = "1";
+  inherit (stdenv.lib) optional;
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "3d619811bfbe7478bb984c16543d980cadd08586365a7bc25e59e3ca6384ff43";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
 
-  #TODO: gladeui
-  # Install into our own prefix instead.
-  configureFlags = [
-    "--with-libglade-module-path=$out/lib/libglade/2.0"
-  ] ++ optional withGtk3 "--enable-gtk3";
+  outputs = [ "dev" "out" "docdev" ];
 
   buildInputs =
     [ pkgconfig intltool gtk libxfce4util xfconf libglade
-      libstartup_notification
+      libstartup_notification hicolor_icon_theme
     ] ++ optional withGtk3 gtk3;
 
-  preFixup = "rm $out/share/icons/hicolor/icon-theme.cache";
+  #TODO: glade?
+  configureFlags = optional withGtk3 "--enable-gtk3";
 
   enableParallelBuilding = true;
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.xfce.org/;
     description = "Basic GUI library for Xfce";
-    license = stdenv.lib.licenses.lgpl2Plus;
-    platforms = stdenv.lib.platforms.linux;
+    license = licenses.lgpl2Plus;
+    platforms = platforms.linux;
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/libxfce4util.nix b/pkgs/desktops/xfce/core/libxfce4util.nix
index 6893d7cfb20b..cab904f55107 100644
--- a/pkgs/desktops/xfce/core/libxfce4util.nix
+++ b/pkgs/desktops/xfce/core/libxfce4util.nix
@@ -1,15 +1,18 @@
 { stdenv, fetchurl, pkgconfig, glib, intltool }:
-
-stdenv.mkDerivation rec {
+let
   p_name  = "libxfce4util";
   ver_maj = "4.12";
   ver_min = "1";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "07c8r3xwx5is298zk77m3r784gmr5y4mh8bbca5zdjqk5vxdwsw7";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
+
+  outputs = [ "dev" "out" "docdev" ];
 
   buildInputs = [ pkgconfig glib intltool ];
 
@@ -20,3 +23,4 @@ stdenv.mkDerivation rec {
     platforms = stdenv.lib.platforms.linux;
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/libxfcegui4.nix b/pkgs/desktops/xfce/core/libxfcegui4.nix
index 32a320c779bf..d9e5cce25e85 100644
--- a/pkgs/desktops/xfce/core/libxfcegui4.nix
+++ b/pkgs/desktops/xfce/core/libxfcegui4.nix
@@ -1,31 +1,32 @@
 { stdenv, fetchurl, pkgconfig, intltool, gtk
-, libxfce4util, xfconf, libglade, libstartup_notification }:
-
-stdenv.mkDerivation rec {
+, libxfce4util, xfconf, libglade, libstartup_notification, hicolor_icon_theme }:
+let
   p_name  = "libxfcegui4";
   ver_maj = "4.10";
   ver_min = "0";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "0cs5im0ib0cmr1lhr5765yliqjfyxvk4kwy8h1l8bn3mj6bzk0ib";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
+
+  outputs = [ "dev" "out" "docdev" ];
 
   #TODO: gladeui
   # By default, libxfcegui4 tries to install into libglade's prefix.
   # Install into our own prefix instead.
-  preConfigure =
-    ''
-      configureFlags="--with-libglade-module-path=$out/lib/libglade/2.0"
-    '';
+  configureFlags = [
+    "--with-libglade-module-path=$(out)/lib/libglade/2.0"
+  ];
   #NOTE: missing keyboard library support is OK according to the mailing-list
 
   buildInputs =
     [ pkgconfig intltool gtk libxfce4util xfconf libglade
-      libstartup_notification
+      libstartup_notification hicolor_icon_theme
     ];
-  preFixup = "rm $out/share/icons/hicolor/icon-theme.cache";
 
   meta = {
     homepage = http://www.xfce.org/;
diff --git a/pkgs/desktops/xfce/core/tumbler.nix b/pkgs/desktops/xfce/core/tumbler.nix
index 1fc895ea412a..132003d3fc92 100644
--- a/pkgs/desktops/xfce/core/tumbler.nix
+++ b/pkgs/desktops/xfce/core/tumbler.nix
@@ -1,19 +1,24 @@
-{ stdenv, fetchurl, pkgconfig, intltool, dbus_glib, gdk_pixbuf, curl, freetype,
-libgsf, poppler, bzip2 }:
-
-stdenv.mkDerivation rec {
+{ stdenv, fetchurl, pkgconfig, intltool, dbus_glib, gdk_pixbuf, curl, freetype
+, libgsf, poppler, bzip2 }:
+let
   p_name  = "tumbler";
   ver_maj = "0.1";
   ver_min = "31";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "0wvip28gm2w061hn84zp2q4dv947ihylrppahn4cjspzff935zfh";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
 
-  buildInputs = [ pkgconfig intltool dbus_glib gdk_pixbuf curl freetype
-    poppler libgsf bzip2];
+  outputs = [ "dev" "out" "docdev" ];
+
+  buildInputs = [
+    pkgconfig intltool dbus_glib gdk_pixbuf curl freetype
+    poppler libgsf bzip2
+  ];
 
   configureFlags = [
     # Needs gst-tag
@@ -21,15 +26,16 @@ stdenv.mkDerivation rec {
 
     # Needs libffmpegthumbnailer
     # "--enable-ffmpeg-thumbnailer"
-    
+
     "--enable-odf-thumbnailer"
     "--enable-poppler-thumbnailer"
   ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://git.xfce.org/xfce/tumbler/;
     description = "A D-Bus thumbnailer service";
-    platforms = stdenv.lib.platforms.linux;
-    license = stdenv.lib.licenses.gpl2;
+    platforms = platforms.linux;
+    license = licenses.gpl2;
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/xfce4-appfinder.nix b/pkgs/desktops/xfce/core/xfce4-appfinder.nix
index 25bd04f9ec40..d39708dd523f 100644
--- a/pkgs/desktops/xfce/core/xfce4-appfinder.nix
+++ b/pkgs/desktops/xfce/core/xfce4-appfinder.nix
@@ -1,27 +1,29 @@
 { stdenv, fetchurl, pkgconfig, intltool, glib, gtk, libxfce4util
 , libxfce4ui, garcon, xfconf }:
-
-stdenv.mkDerivation rec {
+let
   p_name  = "xfce4-appfinder";
   ver_maj = "4.12";
   ver_min = "0";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "0ry5hin8xhgnkmm9vs7jq8blk1cnbyr0s18nm1j6nsm7360abm1a";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
 
   buildInputs =
     [ pkgconfig intltool glib gtk libxfce4util libxfce4ui garcon xfconf ];
 
   enableParallelBuilding = true;
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://docs.xfce.org/xfce/xfce4-appfinder/;
     description = "Xfce application finder, a tool to locate and launch programs on your system";
-    license = stdenv.lib.licenses.gpl2Plus;
-    platforms = stdenv.lib.platforms.linux;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.eelco ];
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/xfce4-dev-tools.nix b/pkgs/desktops/xfce/core/xfce4-dev-tools.nix
index 5541011a5019..da7369decc46 100644
--- a/pkgs/desktops/xfce/core/xfce4-dev-tools.nix
+++ b/pkgs/desktops/xfce/core/xfce4-dev-tools.nix
@@ -1,15 +1,16 @@
 { stdenv, fetchurl, pkgconfig, glib, autoconf, automake, libtool, intltool }:
-
-stdenv.mkDerivation rec {
+let
   p_name  = "xfce4-dev-tools";
   ver_maj = "4.12";
   ver_min = "0";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "1jxmyp80pwbfgmqmwpjxs7z5dmm6pyf3qj62z20xy44izraadqz2";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
 
   buildInputs = [ pkgconfig glib ];
 
@@ -22,3 +23,4 @@ stdenv.mkDerivation rec {
     license = stdenv.lib.licenses.gpl2Plus;
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/xfce4-panel.nix b/pkgs/desktops/xfce/core/xfce4-panel.nix
index 0f9066876c66..816bbc05735f 100644
--- a/pkgs/desktops/xfce/core/xfce4-panel.nix
+++ b/pkgs/desktops/xfce/core/xfce4-panel.nix
@@ -1,49 +1,50 @@
 { stdenv, fetchurl, pkgconfig, intltool, gtk, libxfce4util, libxfce4ui
 , libxfce4ui_gtk3, libwnck, exo, garcon, xfconf, libstartup_notification
-, makeWrapper, xfce4mixer
+, makeWrapper, xfce4mixer, hicolor_icon_theme
 , withGtk3 ? false, gtk3
 }:
-
-with { inherit (stdenv.lib) optional; };
-
-stdenv.mkDerivation rec {
+let
+  inherit (stdenv.lib) optional;
   p_name  = "xfce4-panel";
   ver_maj = "4.12";
   ver_min = "0";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "1c4p3ckghvsad1sj5v8wmar5mh9cbhail9mmhad2f9pwwb10z4ih";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
 
   patches = [ ./xfce4-panel-datadir.patch ];
   patchFlags = "-p1";
 
-  configureFlags = optional withGtk3 "--enable-gtk3";
+  outputs = [ "dev" "out" "docdev" ];
 
   buildInputs =
     [ pkgconfig intltool gtk libxfce4util exo libwnck
-      garcon xfconf libstartup_notification makeWrapper
+      garcon xfconf libstartup_notification makeWrapper hicolor_icon_theme
     ] ++ xfce4mixer.gst_plugins
       ++ optional withGtk3 gtk3;
 
   propagatedBuildInputs = [ (if withGtk3 then libxfce4ui_gtk3 else libxfce4ui) ];
 
+  configureFlags = optional withGtk3 "--enable-gtk3";
+
   postInstall = ''
     wrapProgram "$out/bin/xfce4-panel" \
       --prefix GST_PLUGIN_SYSTEM_PATH : "$GST_PLUGIN_SYSTEM_PATH"
   '';
 
-  preFixup = "rm $out/share/icons/hicolor/icon-theme.cache";
-
   enableParallelBuilding = true;
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.xfce.org/projects/xfce4-panel;
     description = "Xfce panel";
-    license = stdenv.lib.licenses.gpl2Plus;
-    platforms = stdenv.lib.platforms.linux;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.eelco ];
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/xfce4-power-manager.nix b/pkgs/desktops/xfce/core/xfce4-power-manager.nix
index 9a3116463c63..7695f906d317 100644
--- a/pkgs/desktops/xfce/core/xfce4-power-manager.nix
+++ b/pkgs/desktops/xfce/core/xfce4-power-manager.nix
@@ -1,29 +1,29 @@
 { stdenv, fetchurl, pkgconfig, intltool, gtk, dbus_glib, upower, xfconf
-, libxfce4ui, libxfce4util, libnotify, xfce4panel }:
-
-stdenv.mkDerivation rec {
+, libxfce4ui, libxfce4util, libnotify, xfce4panel, hicolor_icon_theme }:
+let
   p_name  = "xfce4-power-manager";
   ver_maj = "1.4";
   ver_min = "4";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "01rvqy1cif4s8lkidb7hhmsz7d9f2fwcwvc51xycaj3qgsmch3n5";
   };
 
-  name = "${p_name}-${ver_maj}.${ver_min}";
-
   buildInputs =
     [ pkgconfig intltool gtk dbus_glib upower xfconf libxfce4ui libxfce4util
-      libnotify xfce4panel
+      libnotify xfce4panel hicolor_icon_theme
     ];
-  preFixup = "rm $out/share/icons/hicolor/icon-theme.cache";
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://goodies.xfce.org/projects/applications/xfce4-power-manager;
     description = "A power manager for the Xfce Desktop Environment";
-    license = stdenv.lib.licenses.gpl2Plus;
-    platforms = stdenv.lib.platforms.linux;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.eelco ];
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/xfce4-session.nix b/pkgs/desktops/xfce/core/xfce4-session.nix
index 7599826e8f02..a0568b0dd395 100644
--- a/pkgs/desktops/xfce/core/xfce4-session.nix
+++ b/pkgs/desktops/xfce/core/xfce4-session.nix
@@ -1,25 +1,26 @@
 { stdenv, fetchurl, fetchpatch, pkgconfig, intltool, gtk, polkit
 , libxfce4util, libxfce4ui, xfce4panel, libwnck, dbus_glib, xfconf, libglade, xorg
+, hicolor_icon_theme
 }:
 
-#TODO: gnome stuff: gconf (assistive?), keyring
-
-stdenv.mkDerivation rec {
+let
   p_name  = "xfce4-session";
   ver_maj = "4.12";
   ver_min = "1";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "97d7f2a2d0af7f3623b68d1f04091e02913b28f9555dab8b0d26c8a1299d08fd";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
 
   buildInputs =
     [ pkgconfig intltool gtk libxfce4util libxfce4ui libwnck dbus_glib
-      xfconf xfce4panel libglade xorg.iceauth
-      polkit
-    ];
+      xfconf xfce4panel libglade xorg.iceauth xorg.libSM
+      polkit hicolor_icon_theme
+    ]; #TODO: upower-glib, gconf (assistive?), gnome keyring
 
   preBuild = ''
     sed '/^PATH=/d'        -i scripts/xflock4
@@ -28,13 +29,12 @@ stdenv.mkDerivation rec {
 
   configureFlags = [ "--with-xsession-prefix=$(out)" ];
 
-  preFixup = "rm $out/share/icons/hicolor/icon-theme.cache";
-
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.xfce.org/projects/xfce4-session;
     description = "Session manager for Xfce";
-    license = stdenv.lib.licenses.gpl2Plus;
-    platforms = stdenv.lib.platforms.linux;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.eelco ];
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/xfce4-settings.nix b/pkgs/desktops/xfce/core/xfce4-settings.nix
index 4c2de64561d5..f6f7c4c3a54b 100644
--- a/pkgs/desktops/xfce/core/xfce4-settings.nix
+++ b/pkgs/desktops/xfce/core/xfce4-settings.nix
@@ -1,33 +1,33 @@
 { stdenv, fetchurl, pkgconfig, intltool, exo, gtk, libxfce4util, libxfce4ui
 , libglade, xfconf, xorg, libwnck, libnotify, libxklavier, garcon, upower }:
-
-#TODO: optional packages
-stdenv.mkDerivation rec {
+let
   p_name  = "xfce4-settings";
   ver_maj = "4.12";
   ver_min = "0";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "108za1cmjslwzkdl76x9kwxkq8z734kg9nz8rxk057f10pqwxgh4";
   };
 
-  name = "${p_name}-${ver_maj}.${ver_min}";
-
   patches = [ ./xfce4-settings-default-icon-theme.patch ];
 
   buildInputs =
     [ pkgconfig intltool exo gtk libxfce4util libxfce4ui libglade upower
       xfconf xorg.libXi xorg.libXcursor libwnck libnotify libxklavier garcon
-    ];
+    ]; #TODO: optional packages
 
-  configureFlags = "--enable-pluggable-dialogs --enable-sound-settings";
+  configureFlags = [ "--enable-pluggable-dialogs" "--enable-sound-settings" ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.xfce.org/projects/xfce4-settings;
     description = "Settings manager for Xfce";
-    license = stdenv.lib.licenses.gpl2Plus;
-    platforms = stdenv.lib.platforms.linux;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.eelco ];
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/xfconf.nix b/pkgs/desktops/xfce/core/xfconf.nix
index f12f96895cd9..13902fa4428c 100644
--- a/pkgs/desktops/xfce/core/xfconf.nix
+++ b/pkgs/desktops/xfce/core/xfconf.nix
@@ -1,24 +1,28 @@
 { stdenv, fetchurl, pkgconfig, intltool, glib, libxfce4util, dbus_glib }:
-
-stdenv.mkDerivation rec {
+let
   p_name  = "xfconf";
   ver_maj = "4.12";
   ver_min = "0";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "0mmi0g30aln3x98y5p507g17pipq0dj0bwypshan8cq5hkmfl44r";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
+
+  outputs = [ "dev" "out" "docdev" ];
 
   #TODO: no perl bingings yet (ExtUtils::Depends, ExtUtils::PkgConfig, Glib)
   buildInputs = [ pkgconfig intltool glib libxfce4util ];
   propagatedBuildInputs = [ dbus_glib ];
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://docs.xfce.org/xfce/xfconf/start;
     description = "Simple client-server configuration storage and query system for Xfce";
-    license = stdenv.lib.licenses.gpl2;
-    platforms = stdenv.lib.platforms.linux;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/xfdesktop.nix b/pkgs/desktops/xfce/core/xfdesktop.nix
index e5d04879008e..8802862eddde 100644
--- a/pkgs/desktops/xfce/core/xfdesktop.nix
+++ b/pkgs/desktops/xfce/core/xfdesktop.nix
@@ -1,30 +1,32 @@
 { stdenv, fetchurl, pkgconfig, intltool, gtk, libxfce4util, libxfce4ui
-, libwnck, xfconf, libglade, xfce4panel, thunar, exo, garcon, libnotify }:
-
-stdenv.mkDerivation rec {
+, libwnck, xfconf, libglade, xfce4panel, thunar, exo, garcon, libnotify
+, hicolor_icon_theme }:
+let
   p_name  = "xfdesktop";
   ver_maj = "4.12";
   ver_min = "3";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "a8a8d93744d842ca6ac1f9bd2c8789ee178937bca7e170e5239cbdbef30520ac";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
 
   buildInputs =
     [ pkgconfig intltool gtk libxfce4util libxfce4ui libwnck xfconf
-      libglade xfce4panel thunar exo garcon libnotify
+      libglade xfce4panel thunar exo garcon libnotify hicolor_icon_theme
     ];
-  preFixup = "rm $out/share/icons/hicolor/icon-theme.cache";
 
   enableParallelBuilding = true;
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.xfce.org/projects/xfdesktop;
     description = "Xfce desktop manager";
-    license = stdenv.lib.licenses.gpl2Plus;
-    platforms = stdenv.lib.platforms.linux;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.eelco ];
   };
 }
+
diff --git a/pkgs/desktops/xfce/core/xfwm4.nix b/pkgs/desktops/xfce/core/xfwm4.nix
index dd18b1355f79..d861e5f2d557 100644
--- a/pkgs/desktops/xfce/core/xfwm4.nix
+++ b/pkgs/desktops/xfce/core/xfwm4.nix
@@ -1,16 +1,17 @@
 { stdenv, fetchurl, pkgconfig, gtk, intltool, libglade, libxfce4util
 , libxfce4ui, xfconf, libwnck, libstartup_notification, xorg }:
-
-stdenv.mkDerivation rec {
+let
   p_name  = "xfwm4";
   ver_maj = "4.12";
   ver_min = "3";
+in
+stdenv.mkDerivation rec {
+  name = "${p_name}-${ver_maj}.${ver_min}";
 
   src = fetchurl {
     url = "mirror://xfce/src/xfce/${p_name}/${ver_maj}/${name}.tar.bz2";
     sha256 = "f4a988fbc4e0df7e8583c781d271559e56fd28696092f94ae052e9e6edb09eac";
   };
-  name = "${p_name}-${ver_maj}.${ver_min}";
 
   buildInputs =
     [ pkgconfig intltool gtk libglade libxfce4util libxfce4ui xfconf
@@ -20,11 +21,12 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.xfce.org/projects/xfwm4;
     description = "Window manager for Xfce";
-    license = stdenv.lib.licenses.gpl2Plus;
-    platforms = stdenv.lib.platforms.linux;
-    maintainers = [ stdenv.lib.maintainers.eelco ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.eelco ];
   };
 }
+
diff --git a/pkgs/development/compilers/gcc-arm-embedded/default.nix b/pkgs/development/compilers/gcc-arm-embedded/default.nix
index b6f6ac51ba2a..3f9a2a1f2fbb 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.3/default.nix b/pkgs/development/compilers/gcc/4.3/default.nix
index 3db8ee5f3ea7..317bd5eb3ed5 100644
--- a/pkgs/development/compilers/gcc/4.3/default.nix
+++ b/pkgs/development/compilers/gcc/4.3/default.nix
@@ -142,8 +142,8 @@ stdenv.mkDerivation ({
 } // (if langJava then {
   postConfigure = ''
     make configure-gcc
-    sed -i gcc/Makefile -e 's@^CFLAGS = .*@& -I${zlib}/include@ ; s@^LDFLAGS = .*@& -L${zlib}/lib@'
-    sed -i gcc/Makefile -e 's@^CFLAGS = .*@& -I${boehmgc}/include@ ; s@^LDFLAGS = .*@& -L${boehmgc}/lib -lgc@'
+    sed -i gcc/Makefile -e 's@^CFLAGS = .*@& -I${zlib}/include@ ; s@^LDFLAGS = .*@& -L${zlib.out}/lib@'
+    sed -i gcc/Makefile -e 's@^CFLAGS = .*@& -I${boehmgc}/include@ ; s@^LDFLAGS = .*@& -L${boehmgc.out}/lib -lgc@'
   '';
 } else {})
 // (if langVhdl then rec {
diff --git a/pkgs/development/compilers/gcc/4.6/builder.sh b/pkgs/development/compilers/gcc/4.6/builder.sh
index af2e97b1e4e5..af36ec33b70a 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 b3caad11b716..bc968d1f66e3 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 fd80f4ec8c5f..09e3751580c5 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 add9b30fb629..b163b8fc9e92 100644
--- a/pkgs/development/compilers/gcc/4.9/default.nix
+++ b/pkgs/development/compilers/gcc/4.9/default.nix
@@ -197,7 +197,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
 
@@ -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 = "0zmnm00d2a1hsd41g34bhvxzvxisa2l584q3p447bd91lfjv4ci3";
@@ -218,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'
@@ -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/5/default.nix b/pkgs/development/compilers/gcc/5/default.nix
index 3b105143c0bf..20c60eac3097 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
@@ -197,7 +198,7 @@ let version = "5.3.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
 
@@ -209,8 +210,6 @@ stdenv.mkDerivation ({
 
   builder = ../builder.sh;
 
-  outputs = [ "out" "info" ];
-
   src = fetchurl {
     url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2";
     sha256 = "1ny4smkp5bzs3cp8ss7pl6lk8yss0d9m4av1mvdp72r1x695akxq";
@@ -218,6 +217,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'
@@ -358,7 +363,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 dd77c67a023e..8d33f88de171 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 96ec4e6c114a..5a3ddc97587e 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 d8157673fbc3..d8d25ef8082c 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 f6beaf3a0067..e8e9b55a8857 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 31df7f1fa355..874cf627864e 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 281e5ca66a2c..79b5f654ae9d 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 73fcd788c74f..7a1f7ec8c6bf 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.10.3.nix b/pkgs/development/compilers/ghc/7.10.3.nix
index 88d1bec4d42b..68ac1a9d99e4 100644
--- a/pkgs/development/compilers/ghc/7.10.3.nix
+++ b/pkgs/development/compilers/ghc/7.10.3.nix
@@ -39,8 +39,8 @@ stdenv.mkDerivation rec {
 
   configureFlags = [
     "--with-gcc=${stdenv.cc}/bin/cc"
-    "--with-gmp-includes=${gmp}/include" "--with-gmp-libraries=${gmp}/lib"
-    "--with-curses-includes=${ncurses}/include" "--with-curses-libraries=${ncurses}/lib"
+    "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
+    "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.lib}/lib"
   ] ++ stdenv.lib.optional stdenv.isDarwin [
     "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
   ];
diff --git a/pkgs/development/compilers/ghc/7.2.2.nix b/pkgs/development/compilers/ghc/7.2.2.nix
index 7276f413967f..20d80753afad 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 03dd4dcd35bb..70cd7d21c477 100644
--- a/pkgs/development/compilers/ghc/7.4.2-binary.nix
+++ b/pkgs/development/compilers/ghc/7.4.2-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@" {} \;
@@ -61,10 +61,10 @@ 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" {} \;
+          --set-rpath "$out/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
@@ -91,7 +91,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.4.2.nix b/pkgs/development/compilers/ghc/7.4.2.nix
index b2abcb08ec3a..46855e86d336 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 366c0044a67a..8e630641abfc 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 2e0f5ba07e4d..5d74af99dcaa 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 4323341dc4a4..9020df2f053a 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/8.0.1.nix b/pkgs/development/compilers/ghc/8.0.1.nix
index 7f337c019531..6e9f4691f73b 100644
--- a/pkgs/development/compilers/ghc/8.0.1.nix
+++ b/pkgs/development/compilers/ghc/8.0.1.nix
@@ -29,8 +29,8 @@ stdenv.mkDerivation rec {
 
   configureFlags = [
     "--with-gcc=${stdenv.cc}/bin/cc"
-    "--with-gmp-includes=${gmp}/include" "--with-gmp-libraries=${gmp}/lib"
-    "--with-curses-includes=${ncurses}/include" "--with-curses-libraries=${ncurses}/lib"
+    "--with-gmp-includes=${gmp}/include" "--with-gmp-libraries=${gmp.out}/lib"
+    "--with-curses-includes=${ncurses}/include" "--with-curses-libraries=${ncurses.lib}/lib"
   ] ++ stdenv.lib.optional stdenv.isDarwin [
     "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
   ];
diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix
index 9b360b609e43..8b6c371537bc 100644
--- a/pkgs/development/compilers/ghc/head.nix
+++ b/pkgs/development/compilers/ghc/head.nix
@@ -40,8 +40,8 @@ stdenv.mkDerivation rec {
 
   configureFlags = [
     "--with-gcc=${stdenv.cc}/bin/cc"
-    "--with-gmp-includes=${gmp}/include" "--with-gmp-libraries=${gmp}/lib"
-    "--with-curses-includes=${ncurses}/include" "--with-curses-libraries=${ncurses}/lib"
+    "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
+    "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.lib}/lib"
   ] ++ stdenv.lib.optional stdenv.isDarwin [
     "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
   ];
diff --git a/pkgs/development/compilers/ghc/nokinds.nix b/pkgs/development/compilers/ghc/nokinds.nix
index 6334759496f0..cad827060adf 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 5ddfdc419179..91570752380e 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 000000000000..0c6d41264149
--- /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 000000000000..0454ea96d892
--- /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 000000000000..a9a3c10584b0
--- /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 d25001697443..a31ef704e6a0 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 000000000000..c684d7d5ee5d
--- /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 393e889024be..be527d873754 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 7ff013b23441..573bf8210319 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 f6ab05bd29ba..af1ebd6a1967 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 381941acc20e..c4890c1ca886 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 a4dbfeac8342..f81370992a65 100644
--- a/pkgs/development/compilers/nim/default.nix
+++ b/pkgs/development/compilers/nim/default.nix
@@ -11,7 +11,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 9c6d07c4681e..ab71090b3580 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/opendylan/bin.nix b/pkgs/development/compilers/opendylan/bin.nix
index 4d18b8d328d6..492b1c4b3338 100644
--- a/pkgs/development/compilers/opendylan/bin.nix
+++ b/pkgs/development/compilers/opendylan/bin.nix
@@ -24,10 +24,10 @@ stdenv.mkDerivation {
     interpreter="$(cat "$NIX_CC"/nix-support/dynamic-linker)"
     for a in "$out"/bin/*; do 
       patchelf --set-interpreter "$interpreter" "$a"
-      patchelf --set-rpath "$out/lib:${boehmgc}/lib" "$a"
+      patchelf --set-rpath "$out/lib:${boehmgc.out}/lib" "$a"
     done
     for a in "$out"/lib/*.so; do 
-      patchelf --set-rpath "$out/lib:${boehmgc}/lib" "$a"
+      patchelf --set-rpath "$out/lib:${boehmgc.out}/lib" "$a"
     done
     sed -i -e "s|\-lgc|\-L${boehmgc}\/lib -lgc|" $out/lib/config.jam
     wrapProgram $out/bin/dylan-compiler --suffix PATH : ${gcc}/bin
diff --git a/pkgs/development/compilers/openjdk/7.nix b/pkgs/development/compilers/openjdk/7.nix
index 97ffbf9f0993..de803a5d90c5 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 45bef9819aab..7ba6b56a8f38 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 a9ca7673dfe9..48a22638813f 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 d60ad0d11ec9..1488736a4808 100644
--- a/pkgs/development/compilers/orc/default.nix
+++ b/pkgs/development/compilers/orc/default.nix
@@ -8,20 +8,25 @@ stdenv.mkDerivation rec {
     sha256 = "16ykgdrgxr6pfpy931p979cs68klvwmk3ii1k0a00wr4nn9x931k";
   };
 
-  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 d6112dcdfc48..694bdc8990fd 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/ponyc/default.nix b/pkgs/development/compilers/ponyc/default.nix
index c94ba203c0ff..076146095196 100644
--- a/pkgs/development/compilers/ponyc/default.nix
+++ b/pkgs/development/compilers/ponyc/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation {
   checkTarget = "test";
 
   patchPhase = ''
-    sed 's|/usr/lib/x86_64-linux-gnu/|${glibc}/lib/|g' -i src/libponyc/codegen/genexe.c
+    sed 's|/usr/lib/x86_64-linux-gnu/|${glibc.out}/lib/|g' -i src/libponyc/codegen/genexe.c
     sed 's|/lib/x86_64-linux-gnu/|${stdenv.cc.cc}/lib/|g' -i src/libponyc/codegen/genexe.c
   '';
 
@@ -26,7 +26,7 @@ stdenv.mkDerivation {
     '';
 
   preCheck = ''
-    export LIBRARY_PATH="$out/lib:${openssl}/lib:${pcre2}/lib"
+    export LIBRARY_PATH="$out/lib:${openssl.out}/lib:${pcre2}/lib"
   '';
 
   installPhase = ''
@@ -34,7 +34,7 @@ stdenv.mkDerivation {
     mv $out/bin/ponyc $out/bin/ponyc.wrapped
     makeWrapper $out/bin/ponyc.wrapped $out/bin/ponyc \
       --prefix LIBRARY_PATH : "$out/lib" \
-      --prefix LIBRARY_PATH : "${openssl}/lib" \
+      --prefix LIBRARY_PATH : "${openssl.out}/lib" \
       --prefix LIBRARY_PATH : "${pcre2}/lib"
   '';
 
diff --git a/pkgs/development/compilers/rustc/generic.nix b/pkgs/development/compilers/rustc/generic.nix
index d578facad698..b88782517d76 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 c9378451d1ff..9da1ef0dd9af 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 f99571c6a10b..5fbfd8a96ac9 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 642bde39e7e9..34e7bdc06a96 100644
--- a/pkgs/development/interpreters/elixir/default.nix
+++ b/pkgs/development/interpreters/elixir/default.nix
@@ -33,7 +33,7 @@ stdenv.mkDerivation rec {
      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 c4634de5d3f2..bb0ef7594a4f 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 fc1f01cb3730..b12c2c405780 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 0dbbaf8a1614..243abae331a6 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 8e148f1189cd..0d4a5ef2d6a6 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 c91a43963d49..60e0fa273a2f 100644
--- a/pkgs/development/interpreters/perl/5.20/default.nix
+++ b/pkgs/development/interpreters/perl/5.20/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,9 @@ stdenv.mkDerivation rec {
     sha256 = "0jlvpd5l5nk7lzfd4akdg1sw6vinbkj6izclyyr0lrbidfky691m";
   };
 
-  outputs = [ "out" "man" ];
+  # TODO: Add a "dev" output containing the header files.
+  outputs = [ "out" "man" "docdev" ];
+  setOutputFlags = false;
 
   patches =
     [ # Do not look in /usr etc. for dependencies.
@@ -37,17 +40,6 @@ stdenv.mkDerivation rec {
     ++ optional stdenv.isSunOS ./ld-shared.patch
     ++ stdenv.lib.optional stdenv.isDarwin [ ./cpp-precomp.patch ];
 
-  # There's an annoying bug on sandboxed Darwin in Perl's Cwd.pm where it looks for pwd
-  # in /bin/pwd and /usr/bin/pwd and then falls back on just "pwd" if it can't get them
-  # while at the same time erasing the PATH environment variable so it unconditionally
-  # fails. The code in question is guarded by a check for Mac OS, but the patch below
-  # doesn't have any runtime effect on other platforms.
-  postPatch = stdenv.lib.optional stdenv.isDarwin ''
-    pwd="$(type -P pwd)"
-    substituteInPlace dist/PathTools/Cwd.pm \
-      --replace "/bin/pwd" "$pwd"
-  '';
-
   sandboxProfile = stdenv.lib.sandbox.allow "ipc-sysv-sem";
 
   # Build a thread-safe Perl with a dynamic libperls.o.  We need the
@@ -61,8 +53,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";
@@ -73,13 +65,17 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
+  postPatch = ''
+    pwd="$(type -P pwd)"
+    substituteInPlace dist/PathTools/Cwd.pm \
+      --replace "pwd_cmd = 'pwd'" "pwd_cmd = '$pwd'"
+  '';
+
   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) ''
@@ -93,18 +89,26 @@ stdenv.mkDerivation rec {
       substituteInPlace dist/PathTools/Cwd.pm --replace "'/bin/pwd'" "'$(type -tP pwd)'"
     '';
 
-  # Inspired by nuke-references, which I can't depend on because it uses perl. Perhaps it should just use sed :)
-  postInstall = ''
-    self=$(echo $out | sed -n "s|^$NIX_STORE/\\([a-z0-9]\{32\}\\)-.*|\1|p")
-
-    sed -i "/$self/b; s|$NIX_STORE/[a-z0-9]\{32\}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" "$out"/lib/perl5/*/*/Config.pm
-    sed -i "/$self/b; s|$NIX_STORE/[a-z0-9]\{32\}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" "$out"/lib/perl5/*/*/Config_heavy.pl
-  '';
-
   setupHook = ./setup-hook.sh;
 
   passthru.libPrefix = "lib/perl5/site_perl";
 
+  # 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/perl/5.22/default.nix b/pkgs/development/interpreters/perl/5.22/default.nix
index 34a26023adf9..21100cc8eac3 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,9 @@ stdenv.mkDerivation rec {
     sha256 = "0g5bl8sdpzx9gx2g5jq3py4bj07z2ylk7s1qn0fvsss2yl3hhs8c";
   };
 
-  outputs = [ "out" "man" ];
+  # TODO: Add a "dev" output containing the header files.
+  outputs = [ "out" "man" "docdev" ];
+  setOutputFlags = false;
 
   patches =
     [ # Do not look in /usr etc. for dependencies.
@@ -37,6 +40,8 @@ stdenv.mkDerivation rec {
     ++ optional stdenv.isSunOS ./ld-shared.patch
     ++ stdenv.lib.optional stdenv.isDarwin [ ./cpp-precomp.patch ];
 
+  sandboxProfile = stdenv.lib.sandbox.allow "ipc-sysv-sem";
+
   # Build a thread-safe Perl with a dynamic libperls.o.  We need the
   # "installstyle" option to ensure that modules are put under
   # $out/lib/perl5 - this is the general default, but because $out
@@ -48,8 +53,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 +74,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 +95,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 +107,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 c963c01e65bf..3ce29440bf50 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 8abc1ac489cd..095e0b7db08e 100644
--- a/pkgs/development/interpreters/pypy/default.nix
+++ b/pkgs/development/interpreters/pypy/default.nix
@@ -25,17 +25,17 @@ let
       ++ stdenv.lib.optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc
       ++ stdenv.lib.optional zlibSupport zlib;
 
-    C_INCLUDE_PATH = stdenv.lib.concatStringsSep ":" (map (p: "${p}/include") buildInputs);
-    LIBRARY_PATH = stdenv.lib.concatStringsSep ":" (map (p: "${p}/lib") buildInputs);
-    LD_LIBRARY_PATH = stdenv.lib.concatStringsSep ":" (map (p: "${p}/lib")
+    C_INCLUDE_PATH = stdenv.lib.concatStringsSep ":" (map (p: "${p.dev or p}/include") buildInputs);
+    LIBRARY_PATH = stdenv.lib.concatStringsSep ":" (map (p: "${p.lib or p.out or p}/lib") buildInputs);
+    LD_LIBRARY_PATH = stdenv.lib.concatStringsSep ":" (map (p: "${p.lib or p.out or p}/lib")
       (stdenv.lib.filter (x : x.outPath != stdenv.cc.libc.outPath or "") buildInputs));
 
     preConfigure = ''
       # 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
@@ -44,7 +44,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
     '';
 
     buildPhase = ''
@@ -66,7 +66,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 32974778168b..96b44ddc17f3 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 a2c059da0607..1bcb0777e85c 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 f4103662316e..c0b5d3401ddd 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 a8953f38245a..a46ef7c056b2 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 ecada35a26e8..8d87c6abfbb4 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 0f4b6e744aca..4bc39f4c2b3a 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/gemconfig/default.nix b/pkgs/development/interpreters/ruby/gemconfig/default.nix
index 787c3be54e35..1f122ced83d5 100644
--- a/pkgs/development/interpreters/ruby/gemconfig/default.nix
+++ b/pkgs/development/interpreters/ruby/gemconfig/default.nix
@@ -63,8 +63,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"
     ];
   };
 
@@ -72,12 +72,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}";
   };
 
@@ -105,8 +105,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 0cc477c991ef..be79c5c957ab 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 ecaed5077121..99f66199d939 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 7573b546164b..5cc71b59d512 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 a036388f15ee..94f070d1a91d 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 3a9bd8ad7a46..5c4fc8508155 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 7006eb10f7ed..fbc446bcabcc 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 529c485930b3..1c260c2ba911 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 d7dcbeba330b..fb8edd27bf8b 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 d37d8926fbdc..4055708907b9 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 c123740f5c12..6f0956f1d1d1 100644
--- a/pkgs/development/libraries/apr-util/default.nix
+++ b/pkgs/development/libraries/apr-util/default.nix
@@ -22,6 +22,9 @@ stdenv.mkDerivation rec {
 
   patches = optional stdenv.isFreeBSD ./include-static-dependencies.patch;
 
+  outputs = [ "dev" "out" ];
+  outputBin = "dev";
+
   buildInputs = optional stdenv.isFreeBSD autoreconfHook;
 
   configureFlags = [ "--with-apr=${apr}" "--with-expat=${expat}" ]
@@ -42,7 +45,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 08fd1fe4d5f3..c6e505f43d23 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 808de07c52fd..e49569bc226a 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 = "0afn4x04j5l352vj0dccb2hkpzg3l2vhr8h1yv89fpqmjkfnm8md";
   };
 
-  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 dcb90aa16cd1..14e2e71c0bd0 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 8d87e2ee50dd..e4e9142b6328 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 158f4b227dd3..4839bedd8bb0 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 90e60d59da0c..30f24d0c3573 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 5add4e451297..5f705ea50a35 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 5eb12fe29989..ae202b093777 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 ce4fda5bd468..88bb67077490 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 a4a20fce023a..e45702090665 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 059b0ab0042a..21ad12869f9c 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.isFreeBSD autoreconfHook
@@ -39,6 +41,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 480dc61897bb..59d227f0e868 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 7f5e2f6311b2..83635d9739f1 100644
--- a/pkgs/development/libraries/dbus/default.nix
+++ b/pkgs/development/libraries/dbus/default.nix
@@ -1,5 +1,4 @@
-{ stdenv, fetchurl, pkgconfig, autoreconfHook
-, 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,108 +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
-        '';
-
-    nativeBuildInputs = [ pkgconfig autoreconfHook ];
-    propagatedBuildInputs = [ expat ];
-
-    preAutoreconf = ''
-      substituteInPlace tools/Makefile.am --replace 'install-localstatelibDATA:' 'disabled:'
+    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"'
     '';
 
-    preConfigure = ''
-      patchShebangs .
-    '';
+    outputs = [ "dev" "out" "lib" "doc" ];
+
+    nativeBuildInputs = [ pkgconfig ];
+    propagatedBuildInputs = [ expat ];
+    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 cf10d9775991..000000000000
--- 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 a07abcc15fb0..000000000000
--- 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 daffae90b127..009624096605 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 96d46649d916..774190278cb3 100644
--- a/pkgs/development/libraries/expat/default.nix
+++ b/pkgs/development/libraries/expat/default.nix
@@ -10,8 +10,13 @@ stdenv.mkDerivation rec {
 
   patches = [ ./CVE-2015-1283.patch ];
 
+  outputs = [ "dev" "out" ]; # TODO: fix referrers
+  outputBin = "dev";
+
   configureFlags = stdenv.lib.optional stdenv.isFreeBSD "--with-pic";
 
+  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 1113db5c1367..d2da77c7b0d6 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 dfa4541e34b7..a7a02521c69c 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 2951dbb44d4f..fea9efde1cfd 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 b03528de2d5d..6acf1ebce29c 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 2b02e0df7a04..2d0a21ea9ddf 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 61d8cb582a01..81e98056e90b 100644
--- a/pkgs/development/libraries/freetype/default.nix
+++ b/pkgs/development/libraries/freetype/default.nix
@@ -35,12 +35,16 @@ stdenv.mkDerivation rec {
         "0wcjf9hiymplgqm3szla633i417pb57vpzzs2dyl1dnmcxgqa2y8")
     ];
 
+  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.
diff --git a/pkgs/development/libraries/gdk-pixbuf/default.nix b/pkgs/development/libraries/gdk-pixbuf/default.nix
index 18562d1d12e3..756ebf816199 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 = "0cfh87aqyqbfcwpbv1ihgmgfcn66il5q2n8yjyl8gxkjmkqp2rrb";
   };
 
+  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 3d7cfc0ca310..cebcf4e014b5 100644
--- a/pkgs/development/libraries/gettext/default.nix
+++ b/pkgs/development/libraries/gettext/default.nix
@@ -47,7 +47,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 fc6116b39160..35d2e1a0950f 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 3c433511fc1a..4ec2903b9007 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 6bb3c8c1e5a2..fc4707aedb75 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 = "1cchmi08jpjypgmm9i7xzh5qfg2q5k61kry9ns8mhw3z44a440ym";
   };
 
+  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 9a3303684a15..db59befcb501 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,21 +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;
 
-  LIBELF_CFLAGS = optional stdenv.isFreeBSD "-I${libelf}";
-  LIBELF_LIBS = optional stdenv.isFreeBSD "-L${libelf} -lelf";
-
-  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.isFreeBSD || stdenv.isSunOS) "--with-libiconv=gnu"
     ++ optional stdenv.isSunOS "--disable-dtrace";
 
@@ -79,6 +80,9 @@ stdenv.mkDerivation rec {
       sed -i -e 's|inotify.h|foobar-inotify.h|g' configure
     '';
 
+  LIBELF_CFLAGS = optional stdenv.isFreeBSD "-I${libelf}";
+  LIBELF_LIBS = optional stdenv.isFreeBSD "-L${libelf} -lelf";
+
   preBuild = optionalString stdenv.isDarwin
     ''
       export MACOSX_DEPLOYMENT_TARGET=
@@ -87,6 +91,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"
@@ -108,8 +118,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 ca7e326bd02e..c5cf293902cd 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 2836063e3bf4..46f47d9b99c2 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 26d2f2454b45..8a13cb6fe608 100644
--- a/pkgs/development/libraries/glibc/common.nix
+++ b/pkgs/development/libraries/glibc/common.nix
@@ -126,7 +126,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 08eaf555e02d..26d2bda2aeb5 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 e4cdb42dd689..f57e52f7b7ad 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 cbf7af22cac1..0cf074323fb9 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 b5b4eabe9c74..0d7bed99f22f 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 6564fc511867..ee81aec07976 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 7b393067ff52..0768df60a794 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 5025557458cd..a7443c02c5b6 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 ebaef47ca140..3e9980e2fcf8 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 f429e1dc6c36..1a2ba3db29a9 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 d411ad69dc43..583d8475ec3b 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 4572387e2252..c60311423233 100644
--- a/pkgs/development/libraries/gpgme/default.nix
+++ b/pkgs/development/libraries/gpgme/default.nix
@@ -16,6 +16,9 @@ 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 ];
@@ -25,11 +28,11 @@ stdenv.mkDerivation rec {
     "--enable-fixed-path=${gpgStorePath}/bin"
   ];
 
-  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 efdaa37eba57..7d2b4caf2a58 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 dc39bddc232f..44e52b99d71b 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, libshout, libintlOrEmpty
+, glib, gstreamer, bzip2, libsoup, libshout, ncurses, libintlOrEmpty
 , # 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 015aa4e07f5d..bf061b4125b5 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 8830e1425b68..d4d4cddb4023 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 = "1f1ifv1ijrda4jx831l24d3ww65v5gf56r464fi11n6k02bcah87";
   };
 
+  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 248c4fa385e1..6c00a5df09f8 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 000000000000..c2b0ab502db7
--- /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 6145c8c49477..45f5217d3c91 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 d2a958faed8b..37403f50e2b1 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 d2546ebd496d..2d84b1e73a82 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.1.2";
+  inherit (stdenv.lib) optional optionals optionalString;
+in
 
-stdenv.mkDerivation rec {
-  name = "harfbuzz-1.1.2";
+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 = "07s6z3hbrb4rdfgzmln169wxz4nm5y7qbr02ik5c7drxpn85fb2a";
   };
 
-  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 98f6511f3917..0d0ff38fb47f 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 148e4f02a94f..199e2b8f962e 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 2fa9cf7dbf95..17395561eda5 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 ad425f2a3812..d5e0694e0516 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 f4ea47e633f9..b324494faff7 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 c98a01f6f70f..9365cf0b5f09 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 db82c943d7c2..7dea029491aa 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 a8948e8ae8c0..419ba8de9e4d 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 ff33043dbaea..467dd87f43e9 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 a9c83594179f..f2f31963d670 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 23b1402e3e7f..78b1eef2ccfc 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 c3059642382a..7a905d9c82a6 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 b441719d31cd..8e3523a27e9f 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 ccc0a1996549..f64174778b20 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 154277f9cc66..ad524ffeb027 100644
--- a/pkgs/development/libraries/libdrm/default.nix
+++ b/pkgs/development/libraries/libdrm/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "79cb8e988749794edfb2d777b298d5292eff353bbbb71ed813589e61d2bc2d76";
   };
 
+  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 6e8d85cb88d9..abd04849beb1 100644
--- a/pkgs/development/libraries/libedit/default.nix
+++ b/pkgs/development/libraries/libedit/default.nix
@@ -19,7 +19,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'
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/libraries/libelf/default.nix b/pkgs/development/libraries/libelf/default.nix
index 048902f4fc49..623256bb6b7b 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 bddda9f3eadd..b0b537ddb175 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 18387c904f83..2b6571290dfb 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 5c981e664cb4..962f716c120a 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" ];
 
   buildInputs = stdenv.lib.optional doCheck dejagnu;
 
@@ -21,9 +23,13 @@ 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 = with stdenv.lib; {
diff --git a/pkgs/development/libraries/libgcrypt/1.5.nix b/pkgs/development/libraries/libgcrypt/1.5.nix
index 990e73d0a63e..d77946e5ec37 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 cc23d47e2bf2..e03ed24e8fcd 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 19a6a8531bee..3279bf3d9fbe 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 2e3307b54bf5..8901fef21fd0 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/";
 
   postInstall = ''
     for bin in $out/bin/*; do
diff --git a/pkgs/development/libraries/libidn/default.nix b/pkgs/development/libraries/libidn/default.nix
index c3c6c13c98fc..b16dc8357414 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 3660a652e79d..79cf45a8005f 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 bf2ebb27f37f..025be2009599 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 f910741c446e..8baf4a77c362 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 3ef4ba77c31c..c68187945334 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 234f56863c09..b97ee6a4ced0 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 1e8ea0ffa138..2a4600f52045 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 13b405019336..671169b9ab3a 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/liboauth/default.nix b/pkgs/development/libraries/liboauth/default.nix
index 479a187cf87c..f62fb400199f 100644
--- a/pkgs/development/libraries/liboauth/default.nix
+++ b/pkgs/development/libraries/liboauth/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     substituteInPlace $out/lib/liboauth.la \
-      --replace "-lnss3" "-L${nss}/lib -lnss3"
+      --replace "-lnss3" "-L${nss.out}/lib -lnss3"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/libraries/libogg/default.nix b/pkgs/development/libraries/libogg/default.nix
index 407e218065bb..1aa4b8ad0453 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 43b1f3470934..754e308ac15b 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/libopus/default.nix b/pkgs/development/libraries/libopus/default.nix
index 460aaa2b0eca..b8951e66c8bd 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 7ae3d0e1d682..01e90cb19132 100644
--- a/pkgs/development/libraries/libpng/12.nix
+++ b/pkgs/development/libraries/libpng/12.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation rec {
     sha256 = "0zkra0b9lrpk2axassdgkqinmc2ba6b473sm52xbpyknaqs2fljy";
   };
 
+  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 4e18dcb680f9..6faed97aaee2 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 7085236feb52..0f0808506398 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 9699d67d7b87..82768cd350dd 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 3d564fc00f8b..031886d34516 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 ea1910733e7d..0768a21bf543 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 481d82c0c9ad..f0ff549c7168 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 48a2999e7af9..5be8730ba015 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 c6f10a5531c4..42450275ad5e 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 3d10e6135055..aa84c507c97a 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 --enable-vala=no" + stdenv.lib.optionalString (!gnomeSupport) " --without-gnome";
diff --git a/pkgs/development/libraries/libssh/default.nix b/pkgs/development/libraries/libssh/default.nix
index 3f6eeac892b1..e33d0c89b7d0 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 5e12ea734c18..26a4e1d504a5 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 1ae26c48fc21..5ac8cc94d044 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 da590adae062..129dface2d93 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 2c559d221abe..a506279c2a4a 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 d9c543efd6c3..70363b830255 100644
--- a/pkgs/development/libraries/libtoxcore/new-api/default.nix
+++ b/pkgs/development/libraries/libtoxcore/new-api/default.nix
@@ -23,8 +23,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 471fafdad38b..2fb5e93eab95 100644
--- a/pkgs/development/libraries/libtoxcore/old-api/default.nix
+++ b/pkgs/development/libraries/libtoxcore/old-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/libunwind/default.nix b/pkgs/development/libraries/libunwind/default.nix
index 3fc8b5085590..da09e2fcbe25 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 7aec64d596fc..b1872779b707 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 75d6bdb4cc6a..fe920bba411f 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 e8de6ac284eb..e04c3b9828d8 100644
--- a/pkgs/development/libraries/libva/default.nix
+++ b/pkgs/development/libraries/libva/default.nix
@@ -1,10 +1,9 @@
 { stdenv, lib, fetchurl, libX11, pkgconfig, libXext, libdrm, libXfixes, wayland, libffi
-, mesa_noglu ? null
+, mesa_noglu
+, minimal ? true, libva
 }:
 
-let
-  withMesa = mesa_noglu != null;
-in stdenv.mkDerivation rec {
+stdenv.mkDerivation rec {
   name = "libva-1.6.2";
 
   src = fetchurl {
@@ -12,16 +11,22 @@ in stdenv.mkDerivation rec {
     sha256 = "1l4bij21shqbfllbxicmqgmay4v509v9hpxyyia9wm7gvsfg05y4";
   };
 
-  buildInputs = [ libX11 libXext pkgconfig libdrm libXfixes wayland libffi mesa_noglu ];
+  outputs = [ "dev" "out" "bin" ];
 
-  configureFlags = lib.optionals withMesa [
+  nativeBuildInputs = [ pkgconfig ];
+
+  buildInputs = [ libdrm ]
+    ++ lib.optionals (!minimal) [ libva libX11 libXext libXfixes wayland libffi mesa_noglu ];
+  # TODO: share libs between minimal and !minimal - perhaps just symlink them
+
+  configureFlags = lib.optionals (!minimal) [
     "--with-drivers-path=${mesa_noglu.driverLink}/lib/dri"
-    "--enable-glx"
-  ];
+     "--enable-glx" 
+   ];
 
-  installFlags = lib.optional withMesa "DESTDIR=$(out)";
+   installFlags = lib.optional (!minimal) "DESTDIR=$(out)";
 
-  postInstall = lib.optionalString withMesa ''
+  postInstall = lib.optionalString (!minimal) ''
     cp -r $out/${mesa_noglu.driverLink}/* $out
     cp -r $out/$out/* $out
     rm -rf $out/run $out/$(echo "$out" | cut -d "/" -f2)
diff --git a/pkgs/development/libraries/libvdpau/default.nix b/pkgs/development/libraries/libvdpau/default.nix
index f38cc51f6c24..c2ec587a52e3 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 256d09b0edd5..feb460f2e8bb 100644
--- a/pkgs/development/libraries/libvirt/default.nix
+++ b/pkgs/development/libraries/libvirt/default.nix
@@ -1,7 +1,7 @@
 { stdenv, fetchurl, fetchpatch
 , pkgconfig, makeWrapper
 , 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, pmutils, libcap_ng
 , dnsmasq, libnl, libpcap, libxslt, xhtml1, numad, numactl, perlPackages
 , curl, libiconv, gmp, xen
@@ -24,14 +24,14 @@ stdenv.mkDerivation rec {
     gettext libtasn1 libgcrypt yajl
     libxslt xhtml1 perlPackages.XMLXPath curl libpcap
   ] ++ stdenv.lib.optionals stdenv.isLinux [
-    libpciaccess devicemapper lvm2 utillinux udev libcap_ng
+    libpciaccess devicemapper lvm2 utillinux systemd.udev.lib libcap_ng
     libnl numad numactl xen
   ] ++ stdenv.lib.optionals stdenv.isDarwin [
      libiconv gmp
   ];
 
   preConfigure = stdenv.lib.optionalString stdenv.isLinux ''
-    PATH=${iproute}/sbin:${iptables}/sbin:${ebtables}/sbin:${lvm2}/sbin:${udev}/sbin:$PATH
+    PATH=${iproute}/sbin:${iptables}/sbin:${ebtables}/sbin:${lvm2}/sbin:${systemd.udev.bin}/bin:$PATH
     substituteInPlace configure --replace 'as_dummy="/bin:/usr/bin:/usr/sbin"' 'as_dummy="${numad}/bin"'
   '' + ''
     PATH=${dnsmasq}/bin:$PATH
diff --git a/pkgs/development/libraries/libvorbis/default.nix b/pkgs/development/libraries/libvorbis/default.nix
index 68f1fe720856..0022799c88fe 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 6a4756670786..5c593dd1f75e 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 31b1c197e9ff..064fb807a214 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 6c6c0812c43c..a763af96667b 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 6a4479bdda38..bb5258120494 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 5543b05ce9d1..d11e2ed94396 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 d69276a070bb..f074b31bb682 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 cac8f10d37aa..f7e175373e12 100644
--- a/pkgs/development/libraries/libxml2/default.nix
+++ b/pkgs/development/libraries/libxml2/default.nix
@@ -1,10 +1,6 @@
-{ stdenv, fetchurl, zlib, xz, python ? null, pythonSupport ? true, findXMLCatalogs }:
+{ stdenv, fetchurl, zlib, xz, python, findXMLCatalogs }:
 
-assert pythonSupport -> python != null;
-
-#TODO: share most stuff between python and non-python builds, perhaps via multiple-output
-
-stdenv.mkDerivation (rec {
+stdenv.mkDerivation rec {
   name = "libxml2-${version}";
   version = "2.9.3";
 
@@ -13,9 +9,10 @@ stdenv.mkDerivation (rec {
     sha256 = "0bd17g6znn2r98gzpjppsqjg33iraky4px923j3k8kdl8qgy7sad";
   };
 
-  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.
@@ -23,10 +20,21 @@ stdenv.mkDerivation (rec {
 
   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";
@@ -34,14 +42,4 @@ 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 3579e99ec7a8..2784093d50aa 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 de82bd0243e9..f535b19bd0eb 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 367159b42537..00771f1f7276 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.1.1";
   # 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}";
@@ -50,7 +50,7 @@ stdenv.mkDerivation {
   ] ++ optional stdenv.isLinux
       (substituteAll {
         src = ./dlopen-absolute-paths.diff;
-        inherit udev;
+        libudev = libudev.out;
       });
 
   postPatch = ''
@@ -58,7 +58,7 @@ stdenv.mkDerivation {
       --replace _EGL_DRIVER_SEARCH_DIR '"${driverLink}"'
   '';
 
-  outputs = ["out" "drivers" "osmesa"];
+  outputs = [ "dev" "out" "drivers" "osmesa" ];
 
   configureFlags = [
     "--sysconfdir=/etc"
@@ -99,17 +99,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;
@@ -129,41 +129,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}"
   '';
-  #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 a4bb6a72b138..9a5226572239 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 581f956b0afd..8a964af01c80 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 8817e2c5523b..41d609db4785 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 3c439eb404cc..1bfb739712f4 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 f5f72c006c73..8a4b793cad79 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 e8d3fb3cdf28..9a1b5e313452 100644
--- a/pkgs/development/libraries/nspr/default.nix
+++ b/pkgs/development/libraries/nspr/default.nix
@@ -10,6 +10,9 @@ stdenv.mkDerivation {
     sha256 = "cb320a9eee7028275ac0fce7adc39dee36f14f02fd8432fce1b7e1aa5e3685c2";
   };
 
+  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 ee8e38a72965..96326bf1df05 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";
 
@@ -77,8 +78,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 278834190bbf..a81d95e6b987 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 7d836cd5a0df..f05693323917 100644
--- a/pkgs/development/libraries/openldap/default.nix
+++ b/pkgs/development/libraries/openldap/default.nix
@@ -20,7 +20,8 @@ stdenv.mkDerivation rec {
     )
   ];
 
-  outputs = [ "out" "man" ];
+  # TODO: separate "out" and "bin"
+  outputs = [ "dev" "out" "man" "docdev" ];
 
   buildInputs = [ openssl cyrus_sasl db groff ];
 
@@ -31,12 +32,10 @@ stdenv.mkDerivation rec {
       ++ stdenv.lib.optional (cyrus_sasl == null) "--without-cyrus-sasl"
       ++ stdenv.lib.optional stdenv.isFreeBSD "--with-pic";
 
-  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 4e009e5306d6..86d94b58d231 100644
--- a/pkgs/development/libraries/openssl/default.nix
+++ b/pkgs/development/libraries/openssl/default.nix
@@ -18,11 +18,12 @@ stdenv.mkDerivation rec {
     sha256 = "0iik7a3b0mrfrxzngdf7ywfscg9inbw77y0jp2ccw0gdap9xhjvq";
   };
 
-  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 eefed304134f..f2a9bdc12309 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 07a987c8ff66..3905d69e8d72 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 = "1dsf45m51i4rcyvh5wlxxrjfhvn5b67d5ckjc6vdcxbddjgmc80k";
   };
 
-  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 3370e910565e..0056ac3ffac6 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 c7c5aff24558..4ebb0cbcc260 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/polkit/default.nix b/pkgs/development/libraries/polkit/default.nix
index cdeaa0cb1d96..5744460008fd 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 92777f001695..ebcdcc2b3efd 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 46d512814015..5d8c2430ab9f 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 08d8f141deb0..40fa63d75caf 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 17e0485b29fe..07a7993a67fe 100644
--- a/pkgs/development/libraries/qt-4.x/4.8/default.nix
+++ b/pkgs/development/libraries/qt-4.x/4.8/default.nix
@@ -53,19 +53,24 @@ stdenv.mkDerivation rec {
       ./libressl.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";
@@ -113,7 +118,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
@@ -131,7 +136,7 @@ stdenv.mkDerivation rec {
   enableParallelBuilding = false;
 
   NIX_CFLAGS_COMPILE = optionalString (stdenv.isFreeBSD || 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.isFreeBSD || stdenv.isDarwin)
     "-lglib-2.0";
diff --git a/pkgs/development/libraries/qt-5/5.4/qtbase/default.nix b/pkgs/development/libraries/qt-5/5.4/qtbase/default.nix
index 36bd3822bf73..af9b3feb6df0 100644
--- a/pkgs/development/libraries/qt-5/5.4/qtbase/default.nix
+++ b/pkgs/development/libraries/qt-5/5.4/qtbase/default.nix
@@ -60,27 +60,27 @@ stdenv.mkDerivation {
       sed -i 's/PATHS.*NO_DEFAULT_PATH//' "qtbase/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in"
 
       substituteInPlace qtbase/src/network/kernel/qdnslookup_unix.cpp \
-        --replace "@glibc@" "${stdenv.cc.libc}"
+        --replace "@glibc@" "${stdenv.cc.libc.out}"
       substituteInPlace qtbase/src/network/kernel/qhostinfo_unix.cpp \
-        --replace "@glibc@" "${stdenv.cc.libc}"
+        --replace "@glibc@" "${stdenv.cc.libc.out}"
 
       substituteInPlace qtbase/src/plugins/platforms/xcb/qxcbcursor.cpp \
-        --replace "@libXcursor@" "${libXcursor}"
+        --replace "@libXcursor@" "${libXcursor.out}"
 
       substituteInPlace qtbase/src/network/ssl/qsslsocket_openssl_symbols.cpp \
-        --replace "@openssl@" "${openssl}"
+        --replace "@openssl@" "${openssl.out}"
 
       substituteInPlace qtbase/src/dbus/qdbus_symbols.cpp \
-        --replace "@dbus_libs@" "${dbus}"
+        --replace "@dbus_libs@" "${dbus.lib}"
 
       substituteInPlace \
         qtbase/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp \
-        --replace "@libX11@" "${libX11}"
+        --replace "@libX11@" "${libX11.out}"
     ''
     + lib.optionalString gtkStyle ''
-      substituteInPlace qtbase/src/widgets/styles/qgtk2painter.cpp --replace "@gtk@" "${gtk}"
+      substituteInPlace qtbase/src/widgets/styles/qgtk2painter.cpp --replace "@gtk@" "${gtk.out}"
       substituteInPlace qtbase/src/widgets/styles/qgtkstyle_p.cpp \
-        --replace "@gtk@" "${gtk}" \
+        --replace "@gtk@" "${gtk.out}" \
         --replace "@gnome_vfs@" "${gnome_vfs}" \
         --replace "@libgnomeui@" "${libgnomeui}" \
         --replace "@gconf@" "${GConf}"
@@ -88,8 +88,10 @@ stdenv.mkDerivation {
     + lib.optionalString mesaSupported ''
       substituteInPlace \
         qtbase/src/plugins/platforms/xcb/qglxintegration.cpp \
-        --replace "@mesa@" "${mesa}"
-      substituteInPlace qtbase/mkspecs/common/linux.conf --replace "@mesa@" "${mesa}"
+        --replace "@mesa_lib@" "${mesa.out}"
+      substituteInPlace qtbase/mkspecs/common/linux.conf \
+        --replace "@mesa_lib@" "${mesa.out}" \
+        --replace "@mesa_inc@" "${mesa.dev}"
     '';
 
   preConfigure = ''
@@ -172,11 +174,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 = lib.optionalString (postgresql != null) "-L${postgresql}/lib -lpq";
+  PSQL_LIBS = lib.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.4/qtbase/dlopen-gl.patch b/pkgs/development/libraries/qt-5/5.4/qtbase/dlopen-gl.patch
index d6e08cd24106..d5c4c2b97cb6 100644
--- a/pkgs/development/libraries/qt-5/5.4/qtbase/dlopen-gl.patch
+++ b/pkgs/development/libraries/qt-5/5.4/qtbase/dlopen-gl.patch
@@ -10,7 +10,7 @@ Index: qt-everywhere-opensource-src-5.4.2/qtbase/src/plugins/platforms/xcb/qglxi
                  QLibrary lib(QLatin1String("GL"));
 +                if (!lib.load()) {
 +                    // Fallback to Mesa driver
-+                    lib.setFileName(QLatin1String("@mesa@/lib/libGL"));
++                    lib.setFileName(QLatin1String("@mesa_lib@/lib/libGL"));
 +                }
                  glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB");
              }
diff --git a/pkgs/development/libraries/qt-5/5.4/qtbase/mkspecs-libgl.patch b/pkgs/development/libraries/qt-5/5.4/qtbase/mkspecs-libgl.patch
index 10115e8144ad..56ee0a411d4d 100644
--- a/pkgs/development/libraries/qt-5/5.4/qtbase/mkspecs-libgl.patch
+++ b/pkgs/development/libraries/qt-5/5.4/qtbase/mkspecs-libgl.patch
@@ -8,8 +8,8 @@ Index: qt-everywhere-opensource-src-5.5.1/qtbase/mkspecs/common/linux.conf
  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/qtserialport/0001-dlopen-serialport-udev.patch b/pkgs/development/libraries/qt-5/5.4/qtserialport/0001-dlopen-serialport-udev.patch
index 6636cc9265a8..3a813dc80074 100644
--- a/pkgs/development/libraries/qt-5/5.4/qtserialport/0001-dlopen-serialport-udev.patch
+++ b/pkgs/development/libraries/qt-5/5.4/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.4/qtserialport/default.nix b/pkgs/development/libraries/qt-5/5.4/qtserialport/default.nix
index fa7383fc1e76..072825dfe9ba 100644
--- a/pkgs/development/libraries/qt-5/5.4/qtserialport/default.nix
+++ b/pkgs/development/libraries/qt-5/5.4/qtserialport/default.nix
@@ -1,7 +1,13 @@
-{ 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.4/qtwebkit/0003-dlopen-webkit-udev.patch b/pkgs/development/libraries/qt-5/5.4/qtwebkit/0003-dlopen-webkit-udev.patch
index f3b9d407bd72..1c360cd81aa2 100644
--- a/pkgs/development/libraries/qt-5/5.4/qtwebkit/0003-dlopen-webkit-udev.patch
+++ b/pkgs/development/libraries/qt-5/5.4/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.4/qtwebkit/default.nix b/pkgs/development/libraries/qt-5/5.4/qtwebkit/default.nix
index 596c02d39afb..2620dcdf2d8a 100644
--- a/pkgs/development/libraries/qt-5/5.4/qtwebkit/default.nix
+++ b/pkgs/development/libraries/qt-5/5.4/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;
+          udev = libudev.out;
         };
     in optionals flashplayerFix [ dlopen-webkit-nsplugin dlopen-webkit-gtk ]
     ++ [ dlopen-webkit-udev ];
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 24e5ccb36f37..73fe320769cd 100644
--- a/pkgs/development/libraries/qt-5/5.5/qtbase/default.nix
+++ b/pkgs/development/libraries/qt-5/5.5/qtbase/default.nix
@@ -60,36 +60,38 @@ stdenv.mkDerivation {
       sed -i 's/PATHS.*NO_DEFAULT_PATH//' "qtbase/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in"
 
       substituteInPlace qtbase/src/network/kernel/qdnslookup_unix.cpp \
-        --replace "@glibc@" "${stdenv.cc.libc}"
+        --replace "@glibc@" "${stdenv.cc.libc.out}"
       substituteInPlace qtbase/src/network/kernel/qhostinfo_unix.cpp \
-        --replace "@glibc@" "${stdenv.cc.libc}"
+        --replace "@glibc@" "${stdenv.cc.libc.out}"
 
       substituteInPlace qtbase/src/plugins/platforms/xcb/qxcbcursor.cpp \
-        --replace "@libXcursor@" "${libXcursor}"
+        --replace "@libXcursor@" "${libXcursor.out}"
 
       substituteInPlace qtbase/src/network/ssl/qsslsocket_openssl_symbols.cpp \
-        --replace "@openssl@" "${openssl}"
+        --replace "@openssl@" "${openssl.out}"
 
       substituteInPlace qtbase/src/dbus/qdbus_symbols.cpp \
-        --replace "@dbus_libs@" "${dbus}"
+        --replace "@dbus_libs@" "${dbus.lib}"
 
       substituteInPlace \
         qtbase/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp \
-        --replace "@libX11@" "${libX11}"
+        --replace "@libX11@" "${libX11.out}"
     ''
     + lib.optionalString gtkStyle ''
-      substituteInPlace qtbase/src/widgets/styles/qgtk2painter.cpp --replace "@gtk@" "${gtk}"
+      substituteInPlace qtbase/src/widgets/styles/qgtk2painter.cpp --replace "@gtk@" "${gtk.out}"
       substituteInPlace qtbase/src/widgets/styles/qgtkstyle_p.cpp \
-        --replace "@gtk@" "${gtk}" \
-        --replace "@gnome_vfs@" "${gnome_vfs}" \
-        --replace "@libgnomeui@" "${libgnomeui}" \
+        --replace "@gtk@" "${gtk.out}" \
+        --replace "@gnome_vfs@" "${gnome_vfs.out}" \
+        --replace "@libgnomeui@" "${libgnomeui.out}" \
         --replace "@gconf@" "${GConf}"
     ''
     + lib.optionalString mesaSupported ''
       substituteInPlace \
         qtbase/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp \
-        --replace "@mesa@" "${mesa}"
-      substituteInPlace qtbase/mkspecs/common/linux.conf --replace "@mesa@" "${mesa}"
+        --replace "@mesa_lib@" "${mesa.out}"
+      substituteInPlace qtbase/mkspecs/common/linux.conf \
+        --replace "@mesa_lib@" "${mesa.out}" \
+        --replace "@mesa_inc@" "${mesa.dev}"
     '';
 
   preConfigure = ''
@@ -172,11 +174,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 = lib.optionalString (postgresql != null) "-L${postgresql}/lib -lpq";
+  PSQL_LIBS = lib.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
   ]
@@ -186,7 +188,7 @@ stdenv.mkDerivation {
   ++ lib.optional (cups != null) cups
   ++ lib.optional (mysql != null) mysql.lib
   ++ lib.optional (postgresql != null) postgresql
-  ++ lib.optionals gtkStyle [gnome_vfs libgnomeui gtk GConf];
+  ++ lib.optionals gtkStyle [gnome_vfs.out libgnomeui.out gtk GConf];
 
   buildInputs =
     [ bison flex gperf ruby ]
diff --git a/pkgs/development/libraries/qt-5/5.5/qtbase/dlopen-gl.patch b/pkgs/development/libraries/qt-5/5.5/qtbase/dlopen-gl.patch
index 14411a95f3ac..59f510ac54da 100644
--- a/pkgs/development/libraries/qt-5/5.5/qtbase/dlopen-gl.patch
+++ b/pkgs/development/libraries/qt-5/5.5/qtbase/dlopen-gl.patch
@@ -10,7 +10,7 @@ Index: qt-everywhere-opensource-src-5.5.1/qtbase/src/plugins/platforms/xcb/gl_in
                  QLibrary lib(QLatin1String("GL"));
 +                if (!lib.load()) {
 +                    // Fallback to Mesa driver
-+                    lib.setFileName(QLatin1String("@mesa@/lib/libGL"));
++                    lib.setFileName(QLatin1String("@mesa_lib@/lib/libGL"));
 +                }
                  glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB");
              }
diff --git a/pkgs/development/libraries/qt-5/5.5/qtbase/mkspecs-libgl.patch b/pkgs/development/libraries/qt-5/5.5/qtbase/mkspecs-libgl.patch
index 10115e8144ad..56ee0a411d4d 100644
--- a/pkgs/development/libraries/qt-5/5.5/qtbase/mkspecs-libgl.patch
+++ b/pkgs/development/libraries/qt-5/5.5/qtbase/mkspecs-libgl.patch
@@ -8,8 +8,8 @@ Index: qt-everywhere-opensource-src-5.5.1/qtbase/mkspecs/common/linux.conf
  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/qtserialport/0001-dlopen-serialport-udev.patch b/pkgs/development/libraries/qt-5/5.5/qtserialport/0001-dlopen-serialport-udev.patch
index 6636cc9265a8..3a813dc80074 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 fa7383fc1e76..32549c95344a 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 f3b9d407bd72..1c360cd81aa2 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 596c02d39afb..2e92391f4c08 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 947b06021cd2..32fff70ebfba 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 f770fabb35d3..11d4271b168b 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 33f5ba867d6a..2df7d0518942 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 7dcde2a09a8c..f88bd64f597b 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.out}/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 bf1f38fbb83d..e83718673aae 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 c2473ae2c5db..2f300abebbf1 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 0c6f40c8b143..bff4f393d1db 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 9a1c00e63b9d..8e3cf899e40b 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 7112afbea8a2..56b1900837ac 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 d9fbde9aa09c..1a6238192734 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/tokyo-cabinet/default.nix b/pkgs/development/libraries/tokyo-cabinet/default.nix
index 0b210a589d41..b8969588b3c5 100644
--- a/pkgs/development/libraries/tokyo-cabinet/default.nix
+++ b/pkgs/development/libraries/tokyo-cabinet/default.nix
@@ -12,8 +12,8 @@ stdenv.mkDerivation rec {
 
   postInstall =
     '' sed -i "$out/lib/pkgconfig/tokyocabinet.pc" \
-           -e 's|-lz|-L${zlib}/lib -lz|g;
-               s|-lbz2|-L${bzip2}/lib -lbz2|g'
+           -e 's|-lz|-L${zlib.out}/lib -lz|g;
+               s|-lbz2|-L${bzip2.out}/lib -lbz2|g'
     '';
 
   meta = {
diff --git a/pkgs/development/libraries/uid_wrapper/default.nix b/pkgs/development/libraries/uid_wrapper/default.nix
index 35d7f53173fb..0675ec68b4e8 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 8ad3fcd0428d..607c706fdb59 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 4df1ba71c11f..3637bec63ce6 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 8660d15e06a3..4dec0555ae9f 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 d7ca92f70d9b..90cc1d995a5a 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 6c541f1aa682..26e323145034 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 1598fec61948..1feba886764c 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 7a6f480215c7..59713bb8d205 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 "
@@ -58,13 +74,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 595c98f76aaa..0ae5fc3b5403 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 90994ae708e5..a38d2d6b33cf 100644
--- a/pkgs/development/mobile/androidenv/androidndk_r8e.nix
+++ b/pkgs/development/mobile/androidenv/androidndk_r8e.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 ${zlib.out}/lib:${ncurses.lib}/lib {} \;
     # fix ineffective PROGDIR / MYNDKDIR determination
     for i in ndk-build ndk-gdb ndk-gdb-py
     do
diff --git a/pkgs/development/mobile/androidenv/androidsdk.nix b/pkgs/development/mobile/androidenv/androidsdk.nix
index 01ba759f4f69..aa009cb301a3 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 2918acd8c15e..1f4bf6e4cfdf 100644
--- a/pkgs/development/mobile/androidenv/build-tools.nix
+++ b/pkgs/development/mobile/androidenv/build-tools.nix
@@ -27,7 +27,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
@@ -54,7 +54,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 1243ba429a39..1654b13d13b1 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/flashtool/default.nix b/pkgs/development/mobile/flashtool/default.nix
index d22eeb6c2138..b33fc13224a3 100644
--- a/pkgs/development/mobile/flashtool/default.nix
+++ b/pkgs/development/mobile/flashtool/default.nix
@@ -33,7 +33,7 @@ stdenv.mkDerivation rec {
   buildPhase = ''
     ln -s ${platformTools}/platform-tools/adb x10flasher_lib/adb.linux
     ln -s ${platformTools}/platform-tools/fastboot x10flasher_lib/fastboot.linux
-    ln -s ${libusb1}/lib/libusb-1.0.so.0 ./x10flasher_lib/linux/lib32/libusbx-1.0.so
+    ln -s ${libusb1.out}/lib/libusb-1.0.so.0 ./x10flasher_lib/linux/lib32/libusbx-1.0.so
 
     chmod +x x10flasher_lib/unyaffs.linux.x86 x10flasher_lib/bin2elf x10flasher_lib/bin2sin
     patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" x10flasher_lib/unyaffs.linux.x86
diff --git a/pkgs/development/ocaml-modules/camlzip/default.nix b/pkgs/development/ocaml-modules/camlzip/default.nix
index 2024f5a5ab8f..60590c6c1d5f 100644
--- a/pkgs/development/ocaml-modules/camlzip/default.nix
+++ b/pkgs/development/ocaml-modules/camlzip/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation {
   postPatch = ''
     substitute ${./META} META --subst-var-by VERSION "${version}"
     substituteInPlace Makefile \
-      --subst-var-by ZLIB_LIBDIR "${zlib}/lib" \
+      --subst-var-by ZLIB_LIBDIR "${zlib.out}/lib" \
       --subst-var-by ZLIB_INCLUDE "${zlib}/include"
   '';
 
diff --git a/pkgs/development/ocaml-modules/expat/default.nix b/pkgs/development/ocaml-modules/expat/default.nix
index f4837bd047f5..b6ee0d192e33 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/Compress-Raw-Zlib/default.nix b/pkgs/development/perl-modules/Compress-Raw-Zlib/default.nix
index 20362a51a7be..9314481cbcfe 100644
--- a/pkgs/development/perl-modules/Compress-Raw-Zlib/default.nix
+++ b/pkgs/development/perl-modules/Compress-Raw-Zlib/default.nix
@@ -12,7 +12,7 @@ buildPerlPackage rec {
     cat > config.in <<EOF
       BUILD_ZLIB   = False
       INCLUDE      = ${zlib}/include
-      LIB          = ${zlib}/lib
+      LIB          = ${zlib.out}/lib
       OLD_ZLIB     = False
       GZIP_OS_CODE = AUTO_DETECT
     EOF
diff --git a/pkgs/development/perl-modules/DBD-SQLite/default.nix b/pkgs/development/perl-modules/DBD-SQLite/default.nix
index 985e7946b6b4..13b633f4704e 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 9a20fa250399..1f90546b252c 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 7c51bf1b5917..9ee8be87c028 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 6cd4134cc9c4..91a004a7f686 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 6f7139330407..897210a4046c 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 68e9fc6b4585..7a7b603b449b 100644
--- a/pkgs/development/r-modules/default.nix
+++ b/pkgs/development/r-modules/default.nix
@@ -2311,7 +2311,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
         '';
     });
@@ -2383,7 +2383,7 @@ let
     });
 
     devEMF = old.devEMF.overrideDerivation (attrs: {
-      NIX_CFLAGS_LINK = "-L${pkgs.xorg.libXft}/lib -lXft";
+      NIX_CFLAGS_LINK = "-L${pkgs.xorg.libXft.out}/lib -lXft";
     });
 
     slfm = old.slfm.overrideDerivation (attrs: {
diff --git a/pkgs/development/tools/build-managers/cargo/snapshot.nix b/pkgs/development/tools/build-managers/cargo/snapshot.nix
index ad07148815bb..5a061e4b7c8d 100644
--- a/pkgs/development/tools/build-managers/cargo/snapshot.nix
+++ b/pkgs/development/tools/build-managers/cargo/snapshot.nix
@@ -38,8 +38,8 @@ stdenv.mkDerivation {
     mkdir -p "$out"
     ./install.sh "--prefix=$out"
   '' + (if stdenv.isLinux then ''
-    patchelf --interpreter "${stdenv.glibc}/lib/${stdenv.cc.dynamicLinker}" \
-             --set-rpath "${stdenv.cc.cc}/lib/:${stdenv.cc.cc}/lib64/:${zlib}/lib" \
+    patchelf --interpreter "${stdenv.glibc.out}/lib/${stdenv.cc.dynamicLinker}" \
+             --set-rpath "${stdenv.cc.cc}/lib/:${stdenv.cc.cc}/lib64/:${zlib.out}/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 60a941a66375..80fdce59607b 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 09e54d3dfa63..f97b7b432ea3 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 b0447e706071..0a2d4ad43ab7 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 9ac201070182..de6f96ce99f6 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/documentation/gtk-doc/default.nix b/pkgs/development/tools/documentation/gtk-doc/default.nix
index 6d93dc6def00..22a0278384af 100644
--- a/pkgs/development/tools/documentation/gtk-doc/default.nix
+++ b/pkgs/development/tools/documentation/gtk-doc/default.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation rec {
     sha256 = "12xmmcnq4138dlbhmqa45wqza8dky4lf856sp80h6xjwl2g7a85l";
   };
 
+  outputDocdev = "out";
+
   # maybe there is a better way to pass the needed dtd and xsl files
   # "-//OASIS//DTD DocBook XML V4.1.2//EN" and "http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl"
   preConfigure = ''
diff --git a/pkgs/development/tools/misc/autogen/default.nix b/pkgs/development/tools/misc/autogen/default.nix
index bba50b320892..d2ddcabc0b1e 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 86d69d8da8ce..8fcf0354d94c 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 = with stdenv.lib; {
     description = "Tools for manipulating binaries (linker, assembler, etc.)";
     longDescription = ''
diff --git a/pkgs/development/tools/misc/drush/default.nix b/pkgs/development/tools/misc/drush/default.nix
index cb534d511eaf..0751f51281de 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 97031a533fae..9f04e2837222 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 3b9eccb2ae65..2ffc0f71cc86 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 5d27b469680b..27ec2772e095 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 5aa81e46bed1..b3121ac7944d 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 c82a626336f6..c98bddf53c09 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 99582e0f8a3d..d01a2f9cdd06 100644
--- a/pkgs/development/tools/misc/texinfo/5.2.nix
+++ b/pkgs/development/tools/misc/texinfo/5.2.nix
@@ -10,7 +10,7 @@ stdenv.mkDerivation rec {
     sha256 = "1njfwh2z34r2c4r0iqa7v24wmjzvsfyz4vplzry8ln3479lfywal";
   };
 
-  buildInputs = [ perl xz ]
+  buildInputs = [ perl xz.bin ]
     ++ optional interactive ncurses
     ++ optional doCheck procps; # for tests
 
diff --git a/pkgs/development/tools/node-webkit/nw11.nix b/pkgs/development/tools/node-webkit/nw11.nix
index ed3b99aad009..2fe1ddf42d43 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 7492acb13678..4cacc75d7776 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 213b94102b0d..d8601865c6d1 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 77bc1e5a885f..8b6b655b6a56 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 8d9db34446d6..b2f566ece8de 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/selenium/server/default.nix b/pkgs/development/tools/selenium/server/default.nix
index 2efd85f84010..66d9668fe82d 100644
--- a/pkgs/development/tools/selenium/server/default.nix
+++ b/pkgs/development/tools/selenium/server/default.nix
@@ -29,7 +29,7 @@ in stdenv.mkDerivation rec {
     ${jdk}/bin/jar xf $src launchers/launcher-linux-amd64
     patchelf \
       --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-      --set-rpath "${gcc.cc}/lib/:${gcc.cc}/lib64:${xorg.libX11}/lib" \
+      --set-rpath "${gcc.cc}/lib/:${gcc.cc}/lib64:${xorg.libX11.out}/lib" \
       launchers/launcher-linux-${arch}
     ${jdk}/bin/jar uf $src launchers/launcher-linux-${arch}
   '';
diff --git a/pkgs/development/tools/vagrant/default.nix b/pkgs/development/tools/vagrant/default.nix
index c113dcbfb7b1..2284c25cf661 100644
--- a/pkgs/development/tools/vagrant/default.nix
+++ b/pkgs/development/tools/vagrant/default.nix
@@ -51,7 +51,7 @@ stdenv.mkDerivation rec {
 
     # curl: curl, curl-config
     rm opt/vagrant/embedded/bin/{curl,curl-config}
-    ln -s ${curl}/bin/curl opt/vagrant/embedded/bin
+    ln -s ${curl.bin}/bin/curl opt/vagrant/embedded/bin
     ln -s ${curl}/bin/curl-config opt/vagrant/embedded/bin
 
     # libarchive: bsdtar, bsdcpio
@@ -61,8 +61,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
     rm opt/vagrant/embedded/bin/{erb,gem,irb,rake,rdoc,ri,ruby}
@@ -80,14 +80,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 ad13d108803f..f58e5e41720b 100644
--- a/pkgs/development/web/nodejs/v4.nix
+++ b/pkgs/development/web/nodejs/v4.nix
@@ -43,13 +43,14 @@ in stdenv.mkDerivation {
 
   patches = stdenv.lib.optionals stdenv.isDarwin [ ./no-xcode.patch ./pkg-libpath.patch ];
 
+  buildInputs = [ python zlib libuv openssl python ]
+    ++ optionals stdenv.isLinux [ utillinux http-parser ];
+  nativeBuildInputs = [ pkgconfig ]
+    ++ optional stdenv.isDarwin libtool;
+
   postFixup = ''
     sed -i 's/raise.*No Xcode or CLT version detected.*/version = "7.0.0"/' $out/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py
   '';
-
-  buildInputs = [ python which zlib libuv openssl python ]
-    ++ optionals stdenv.isLinux [ utillinux http-parser ]
-    ++ optionals stdenv.isDarwin [ pkgconfig openssl libtool ];
   setupHook = ./setup-hook.sh;
 
   enableParallelBuilding = true;
diff --git a/pkgs/games/beret/default.nix b/pkgs/games/beret/default.nix
index e2e4f5af977a..81bdbed46e94 100644
--- a/pkgs/games/beret/default.nix
+++ b/pkgs/games/beret/default.nix
@@ -5,7 +5,7 @@ stdenv.mkDerivation {
 
   buildInputs = [ SDL SDL_image SDL_ttf SDL_mixer ];
 
-  NIX_CFLAGS_COMPILE = "-I${SDL}/include/SDL";
+  NIX_CFLAGS_COMPILE = "-I${SDL.dev}/include/SDL";
   NIX_CFLAGS_LINK = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
   NIX_LDFLAGS = stdenv.lib.optionalString stdenv.isDarwin
     "-framework CoreFoundation -framework OpenGL -framework Cocoa";
diff --git a/pkgs/games/bitsnbots/default.nix b/pkgs/games/bitsnbots/default.nix
index 57cd67fbb7ba..82e5ddb06d4d 100644
--- a/pkgs/games/bitsnbots/default.nix
+++ b/pkgs/games/bitsnbots/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
 
   makefile = "Makefile.linux";
 
-  NIX_CFLAGS_COMPILE = "-I${SDL}/include/SDL";
+  NIX_CFLAGS_COMPILE = "-I${SDL.dev}/include/SDL";
 
   NIX_LDFLAGS = "-lGL";
 
diff --git a/pkgs/games/extremetuxracer/default.nix b/pkgs/games/extremetuxracer/default.nix
index af80467c960d..f2417428880c 100644
--- a/pkgs/games/extremetuxracer/default.nix
+++ b/pkgs/games/extremetuxracer/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
   configureFlags = [ "--with-tcl=${tcl}/lib" ];
 
   preConfigure = ''
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${SDL}/include/SDL"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${SDL.dev}/include/SDL"
   '';
 
   meta = {
diff --git a/pkgs/games/gemrb/default.nix b/pkgs/games/gemrb/default.nix
index 86da7686eefd..42d80f86e828 100644
--- a/pkgs/games/gemrb/default.nix
+++ b/pkgs/games/gemrb/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
   # TODO: make libpng, libvorbis, sdl_mixer, freetype, vlc, glew (and other gl reqs) optional
 
   # Necessary to find libdl.
-  CMAKE_LIBRARY_PATH = "${stdenv.cc.libc}/lib";
+  CMAKE_LIBRARY_PATH = "${stdenv.cc.libc.out}/lib";
 
   # Can't have -werror because of the Vorbis header files.
   cmakeFlags = "-DDISABLE_WERROR=ON -DCMAKE_VERBOSE_MAKEFILE=ON";
diff --git a/pkgs/games/hedgewars/default.nix b/pkgs/games/hedgewars/default.nix
index f5d4627c5c08..9909c0428144 100644
--- a/pkgs/games/hedgewars/default.nix
+++ b/pkgs/games/hedgewars/default.nix
@@ -28,11 +28,11 @@ stdenv.mkDerivation rec {
                                      -rpath ${SDL_mixer}/lib
                                      -rpath ${SDL_net}/lib
                                      -rpath ${SDL_ttf}/lib
-                                     -rpath ${SDL}/lib
-                                     -rpath ${libpng}/lib
+                                     -rpath ${SDL.out}/lib
+                                     -rpath ${libpng.out}/lib
                                      -rpath ${lua5_1}/lib
                                      -rpath ${mesa}/lib
-                                     -rpath ${zlib}/lib
+                                     -rpath ${zlib.out}/lib
                                      "
   '';
 
diff --git a/pkgs/games/jamp/default.nix b/pkgs/games/jamp/default.nix
index be7abc75915d..0fbd79e77b00 100644
--- a/pkgs/games/jamp/default.nix
+++ b/pkgs/games/jamp/default.nix
@@ -16,7 +16,7 @@ rec {
   preBuild = a.fullDepEntry (''
     sed -e "s@/usr/games@$out/bin@g" -i Makefile
     sed -e "s@/usr/@$out/@g" -i Makefile
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${a.SDL}/include/SDL"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${a.SDL.dev}/include/SDL"
   '') ["minInit" "addInputs" "doUnpack"];
 
   /* doConfigure should be removed if not needed */
diff --git a/pkgs/games/liquidwar/default.nix b/pkgs/games/liquidwar/default.nix
index ce346459201d..f97c0ec412fc 100644
--- a/pkgs/games/liquidwar/default.nix
+++ b/pkgs/games/liquidwar/default.nix
@@ -25,7 +25,7 @@ stdenv.mkDerivation rec {
   ];
 
   # To avoid problems finding SDL_types.h.
-  configureFlags = [ "CFLAGS=-I${SDL}/include/SDL" ];
+  configureFlags = [ "CFLAGS=-I${SDL.dev}/include/SDL" ];
 
   meta = with stdenv.lib; {
     description = "Quick tactics game";
diff --git a/pkgs/games/micropolis/default.nix b/pkgs/games/micropolis/default.nix
index 55a02e08003d..a294128969c5 100644
--- a/pkgs/games/micropolis/default.nix
+++ b/pkgs/games/micropolis/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation {
   preConfigure =
     ''
       cd src
-      sed -i "s@^CFLAGS.*\$@&\nCFLAGS += -I${libXpm}/include/X11@" tk/makefile
+      sed -i "s@^CFLAGS.*\$@&\nCFLAGS += -I${libXpm.dev}/include/X11@" tk/makefile
       sed -i "s@^INCLUDES.*\$@&\n\t-I$PWD/tcl \\\\@" sim/makefile
     '';
 
diff --git a/pkgs/games/minetest/default.nix b/pkgs/games/minetest/default.nix
index ecd468eaf582..1b201daa371b 100644
--- a/pkgs/games/minetest/default.nix
+++ b/pkgs/games/minetest/default.nix
@@ -25,7 +25,7 @@ in stdenv.mkDerivation {
   cmakeFlags = [
     "-DENABLE_FREETYPE=1"
     "-DENABLE_GETTEXT=1"
-    "-DCURL_INCLUDE_DIR=${curl}/include/curl"
+    "-DCURL_INCLUDE_DIR=${curl.dev}/include/curl"
     "-DIRRLICHT_INCLUDE_DIR=${irrlicht}/include/irrlicht"
   ];
 
diff --git a/pkgs/games/nexuiz/default.nix b/pkgs/games/nexuiz/default.nix
index e40dec3c23fc..0bfebd510c94 100644
--- a/pkgs/games/nexuiz/default.nix
+++ b/pkgs/games/nexuiz/default.nix
@@ -36,14 +36,14 @@ in stdenv.mkDerivation {
   '';
 
   NIX_LDFLAGS = ''
-    -rpath ${zlib}/lib
-    -rpath ${curl}/lib
-    -rpath ${libjpeg}/lib
-    -rpath ${libpng}/lib
-    -rpath ${libvorbis}/lib
-    -rpath ${libtheora}/lib
-    -rpath ${libogg}/lib
-    -rpath ${libmodplug}/lib
+    -rpath ${zlib.out}/lib
+    -rpath ${curl.out}/lib
+    -rpath ${libjpeg.out}/lib
+    -rpath ${libpng.out}/lib
+    -rpath ${libvorbis.out}/lib
+    -rpath ${libtheora.out}/lib
+    -rpath ${libogg.out}/lib
+    -rpath ${libmodplug.out}/lib
   '';
 
   buildPhase = ''
diff --git a/pkgs/games/oilrush/default.nix b/pkgs/games/oilrush/default.nix
index d75f02c5e941..ec9c928b7982 100644
--- a/pkgs/games/oilrush/default.nix
+++ b/pkgs/games/oilrush/default.nix
@@ -1,6 +1,8 @@
 { stdenv, config, fetchurl, libX11, libXext, libXinerama, libXrandr
 , libXrender, fontconfig, freetype, openal }:
 
+with { inherit (stdenv.lib) makeLibraryPath; };
+
 stdenv.mkDerivation {
   name = "oilrush";
   src = 
@@ -25,25 +27,25 @@ stdenv.mkDerivation {
     do
       patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $f
     done
-    patchelf --set-rpath ${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib:${libX11}/lib:${libXext}/lib:${libXrender}/lib:${fontconfig}/lib:${freetype}/lib\
+    patchelf --set-rpath ${stdenv.cc.cc}/lib64:${makeLibraryPath [ stdenv.cc.cc libX11 libXext libXrender fontconfig freetype ]}\
              launcher_$arch
     patchelf --set-rpath ${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib\
              libNetwork_$arch.so
     patchelf --set-rpath ${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib\
              libQtCoreUnigine_$arch.so.4
-    patchelf --set-rpath ${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib:${libX11}/lib:${libXext}/lib:${libXrender}/lib:${fontconfig}/lib:${freetype}/lib\
+    patchelf --set-rpath ${stdenv.cc.cc}/lib64:${makeLibraryPath [ stdenv.cc.cc libX11 libXext libXrender fontconfig freetype ]}\
              libQtGuiUnigine_$arch.so.4
     patchelf --set-rpath ${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib\
              libQtNetworkUnigine_$arch.so.4
-    patchelf --set-rpath ${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib:${libX11}/lib:${libXext}/lib:${libXrender}/lib:${fontconfig}/lib:${freetype}/lib\
+    patchelf --set-rpath ${stdenv.cc.cc}/lib64:${makeLibraryPath [ stdenv.cc.cc libX11 libXext libXrender fontconfig freetype ]}\
              libQtWebKitUnigine_$arch.so.4
     patchelf --set-rpath ${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib\
              libQtXmlUnigine_$arch.so.4
     patchelf --set-rpath ${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib\
              libRakNet_$arch.so
-    patchelf --set-rpath ${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib:${libX11}/lib:${libXext}/lib:${libXinerama}/lib:${libXrandr}/lib\
+    patchelf --set-rpath ${stdenv.cc.cc}/lib64:${makeLibraryPath [ stdenv.cc.cc libX11 libXext libXinerama libXrandr ]}\
              libUnigine_$arch.so
-    patchelf --set-rpath ${stdenv.cc.cc}/lib64:${stdenv.cc.cc}/lib:${libX11}/lib:${libXext}/lib:${libXinerama}/lib:${libXrandr}/lib\
+    patchelf --set-rpath ${stdenv.cc.cc}/lib64:${makeLibraryPath [ stdenv.cc.cc libX11 libXext libXinerama libXrandr ]}\
              OilRush_$arch
   '';
   installPhase = ''
@@ -53,7 +55,7 @@ stdenv.mkDerivation {
     mkdir -p "$out/bin"
     cat << EOF > "$out/bin/oilrush"
     #! /bin/sh
-    LD_LIBRARY_PATH=.:${openal}/lib:\$LD_LIBRARY_PATH
+    LD_LIBRARY_PATH=.:${makeLibraryPath [ openal ]}:\$LD_LIBRARY_PATH
     cd "$out/opt/oilrush"
     exec ./launcher_$arch.sh "\$@"
     EOF
diff --git a/pkgs/games/openarena/default.nix b/pkgs/games/openarena/default.nix
index 1926afaeb3b6..1e396318bbbd 100644
--- a/pkgs/games/openarena/default.nix
+++ b/pkgs/games/openarena/default.nix
@@ -15,6 +15,7 @@ stdenv.mkDerivation rec {
   installPhase = let
     gameDir = "$out/openarena-$version";
     interpreter = "$(< \"$NIX_CC/nix-support/dynamic-linker\")";
+    libPath = stdenv.lib.makeLibraryPath [ SDL libogg libvorbis ];
   in ''
     mkdir -pv $out/bin
     cd $out
@@ -23,11 +24,11 @@ stdenv.mkDerivation rec {
     ${if stdenv.system == "x86_64-linux" then ''
       patchelf --set-interpreter "${interpreter}" "${gameDir}/openarena.x86_64"
       makeWrapper "${gameDir}/openarena.x86_64" "$out/bin/openarena" \
-        --prefix LD_LIBRARY_PATH : "${SDL}/lib:${libogg}/lib:${libvorbis}/lib"
+        --prefix LD_LIBRARY_PATH : "${libPath}"
     '' else ''
       patchelf --set-interpreter "${interpreter}" "${gameDir}/openarena.i386"
       makeWrapper "${gameDir}/openarena.i386" "$out/bin/openarena" \
-        --prefix LD_LIBRARY_PATH : "${SDL}/lib:${libogg}/lib:${libvorbis}/lib"
+        --prefix LD_LIBRARY_PATH : "${libPath}"
     ''}
   '';
 
diff --git a/pkgs/games/openlierox/default.nix b/pkgs/games/openlierox/default.nix
index 2dc4dece75f3..04b74b4214fa 100644
--- a/pkgs/games/openlierox/default.nix
+++ b/pkgs/games/openlierox/default.nix
@@ -9,7 +9,7 @@ stdenv.mkDerivation {
     sha256 = "1k35xppfqi3qfysv81xq3hj4qdy9j2ciinbkfdcmwclcsf3nh94z";
   };
 
-  NIX_CFLAGS_COMPILE = "-I${libxml2}/include/libxml2";
+  NIX_CFLAGS_COMPILE = "-I${libxml2.dev}/include/libxml2";
 
   # The breakpad fails to build on x86_64, and it's only to report bugs upstream
   cmakeFlags = [ "-DBREAKPAD=0" ];
diff --git a/pkgs/games/openttd/default.nix b/pkgs/games/openttd/default.nix
index 65fab09d04dd..7411c161146e 100644
--- a/pkgs/games/openttd/default.nix
+++ b/pkgs/games/openttd/default.nix
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
   prefixKey = "--prefix-dir=";
 
   configureFlags = [
-    "--with-zlib=${zlib}/lib/libz.a"
+    "--with-zlib=${zlib.static}/lib/libz.a"
     "--without-liblzo2"
   ];
 
diff --git a/pkgs/games/planetaryannihilation/default.nix b/pkgs/games/planetaryannihilation/default.nix
index ed682e7bed93..cf968c08287e 100644
--- a/pkgs/games/planetaryannihilation/default.nix
+++ b/pkgs/games/planetaryannihilation/default.nix
@@ -34,12 +34,12 @@ stdenv.mkDerivation {
     ln -s ${systemd}/lib/libudev.so.1 $out/lib/libudev.so.0
 
     patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$out/PA"
-    patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" --set-rpath "${stdenv.lib.makeLibraryPath [ stdenv.cc.cc xorg.libXdamage xorg.libXfixes gtk glib stdenv.glibc "$out" xorg.libXext pango udev xorg.libX11 xorg.libXcomposite alsaLib atk nspr fontconfig cairo pango nss freetype gnome3.gconf gdk_pixbuf xorg.libXrender ]}:{stdenv.cc.cc}/lib64:${stdenv.glibc}/lib64" "$out/host/CoherentUI_Host" 
+    patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" --set-rpath "${stdenv.lib.makeLibraryPath [ stdenv.cc.cc.lib xorg.libXdamage xorg.libXfixes gtk glib stdenv.glibc.out "$out" xorg.libXext pango udev xorg.libX11 xorg.libXcomposite alsaLib atk nspr fontconfig cairo pango nss freetype gnome3.gconf gdk_pixbuf xorg.libXrender ]}:{stdenv.cc.cc.lib}/lib64:${stdenv.glibc.out}/lib64" "$out/host/CoherentUI_Host" 
 
-    wrapProgram $out/PA --prefix LD_LIBRARY_PATH : "${stdenv.lib.makeLibraryPath [ stdenv.cc.cc stdenv.glibc xorg.libX11 xorg.libXcursor gtk glib curl "$out" ]}:${stdenv.cc.cc}/lib64:${stdenv.glibc}/lib64"
+    wrapProgram $out/PA --prefix LD_LIBRARY_PATH : "${stdenv.lib.makeLibraryPath [ stdenv.cc.cc.lib stdenv.glibc.out xorg.libX11 xorg.libXcursor gtk glib curl "$out" ]}:${stdenv.cc.cc.lib}/lib64:${stdenv.glibc.out}/lib64"
 
     for f in $out/lib/*; do
-      patchelf --set-rpath "${stdenv.lib.makeLibraryPath [ stdenv.cc.cc curl xorg.libX11 stdenv.glibc xorg.libXcursor "$out" ]}:${stdenv.cc.cc}/lib64:${stdenv.glibc}/lib64" $f
+      patchelf --set-rpath "${stdenv.lib.makeLibraryPath [ stdenv.cc.cc.lib curl xorg.libX11 stdenv.glibc.out xorg.libXcursor "$out" ]}:${stdenv.cc.cc.lib}/lib64:${stdenv.glibc.out}/lib64" $f
     done
   '';
 
diff --git a/pkgs/games/quantumminigolf/default.nix b/pkgs/games/quantumminigolf/default.nix
index 940351790166..1b0755077965 100644
--- a/pkgs/games/quantumminigolf/default.nix
+++ b/pkgs/games/quantumminigolf/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation {
     inherit (s) url sha256;
   };
   preBuild = ''
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${SDL}/include/SDL"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${SDL.dev}/include/SDL"
 
     sed -re 's@"(gfx|fonts|tracks)/@"'"$out"'/share/quantumminigolf/\1/@g' -i *.cpp
   '';
diff --git a/pkgs/games/rili/default.nix b/pkgs/games/rili/default.nix
index 7d1273328453..e0e6de6b8efe 100644
--- a/pkgs/games/rili/default.nix
+++ b/pkgs/games/rili/default.nix
@@ -10,7 +10,7 @@ stdenv.mkDerivation {
 
   patches = [ ./moderinze_cpp.patch ];
 
-  CPPFLAGS = "-I${SDL}/include -I${SDL}/include/SDL -I${SDL_mixer}/include";
+  CPPFLAGS = "-I${SDL.dev}/include -I${SDL.dev}/include/SDL -I${SDL_mixer}/include";
 
   buildInputs = [ SDL SDL_mixer autoreconfHook ];
 
diff --git a/pkgs/games/sdlmame/default.nix b/pkgs/games/sdlmame/default.nix
index 15b7f87ed10f..5e52a92e621a 100644
--- a/pkgs/games/sdlmame/default.nix
+++ b/pkgs/games/sdlmame/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
   installPhase = ''
     patchelf \
       --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-      --set-rpath "${alsaLib}/lib:${qt48}/lib:${SDL}/lib:${fontconfig}/lib:${freetype}/lib:${SDL_ttf}/lib:${xorg.libX11}/lib:${xorg.libXinerama}/lib:${stdenv.cc.cc}/lib" \
+      --set-rpath "${stdenv.lib.makeLibraryPath [ alsaLib qt48 SDL fontconfig freetype SDL_ttf xorg.libX11 xorg.libXinerama stdenv.cc.cc ]}" \
       share/sdlmame/sdlmame
 
     mkdir -p "$out/bin"
diff --git a/pkgs/games/tibia/default.nix b/pkgs/games/tibia/default.nix
index c1f533276d6e..1af750f462a9 100644
--- a/pkgs/games/tibia/default.nix
+++ b/pkgs/games/tibia/default.nix
@@ -24,7 +24,7 @@ stdenv.mkDerivation {
     mkdir -pv $out/res
     cp -r * $out/res
 
-    patchelf --set-interpreter ${glibc}/lib/ld-linux.so.2 \
+    patchelf --set-interpreter ${glibc.out}/lib/ld-linux.so.2 \
              --set-rpath ${stdenv.cc.cc}/lib:${libX11}/lib:${mesa}/lib \
              "$out/res/Tibia"
 
@@ -41,7 +41,7 @@ stdenv.mkDerivation {
     cat << EOF > "$out/bin/Tibia"
     #!${stdenv.shell}
     cd $out/res
-    ${glibc}/lib/ld-linux.so.2 --library-path \$LD_LIBRARY_PATH ./Tibia "\$@"
+    ${glibc.out}/lib/ld-linux.so.2 --library-path \$LD_LIBRARY_PATH ./Tibia "\$@"
     EOF
 
     chmod +x $out/bin/Tibia
diff --git a/pkgs/games/trackballs/default.nix b/pkgs/games/trackballs/default.nix
index 22d8c944fa8b..7cf741f2faba 100644
--- a/pkgs/games/trackballs/default.nix
+++ b/pkgs/games/trackballs/default.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
   postUnpack = optionalString debug
     "mkdir -p $out/src; cp -R * $out/src ; cd $out/src";
 
-  NIX_CFLAGS_COMPILE = "-iquote ${SDL}/include/SDL";
+  NIX_CFLAGS_COMPILE = "-iquote ${SDL.dev}/include/SDL";
   configureFlags = optionalString debug "--enable-debug";
 
   patchPhase = ''
diff --git a/pkgs/games/ue4demos/default.nix b/pkgs/games/ue4demos/default.nix
index ed2ea23d4158..026f974ff932 100644
--- a/pkgs/games/ue4demos/default.nix
+++ b/pkgs/games/ue4demos/default.nix
@@ -20,7 +20,7 @@ let
         cd $out
         unzip $src
 
-        interpreter=$(echo ${stdenv.glibc}/lib/ld-linux*.so.2)
+        interpreter=$(echo ${stdenv.glibc.out}/lib/ld-linux*.so.2)
         binary=$(find . -executable -type f)
         patchelf \
           --set-interpreter $interpreter \
diff --git a/pkgs/games/ultrastardx/default.nix b/pkgs/games/ultrastardx/default.nix
index 3eabaa090bb0..5027abedcf4f 100644
--- a/pkgs/games/ultrastardx/default.nix
+++ b/pkgs/games/ultrastardx/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   # The fpc is not properly wrapped to add -rpath. I add this manually.
   # I even do a trick on lib/lib64 for libgcc, that I expect it will work.
   preBuild = ''
-    export NIX_LDFLAGS="$NIX_LDFLAGS -rpath ${SDL}/lib -rpath ${SDL_image}/lib -rpath ${libpng}/lib -rpath ${freetype}/lib -rpath ${portaudio}/lib -rpath ${ffmpeg}/lib -rpath ${zlib}/lib -rpath ${sqlite}/lib -rpath ${libX11}/lib -rpath ${pcre}/lib -rpath ${lua}/lib -rpath ${stdenv.cc.cc}/lib64 -rpath ${stdenv.cc.cc}/lib"
+    export NIX_LDFLAGS="$NIX_LDFLAGS -rpath ${SDL.out}/lib -rpath ${SDL_image}/lib -rpath ${libpng.out}/lib -rpath ${freetype.out}/lib -rpath ${portaudio}/lib -rpath ${ffmpeg.out}/lib -rpath ${zlib.out}/lib -rpath ${sqlite.out}/lib -rpath ${libX11.out}/lib -rpath ${pcre.out}/lib -rpath ${lua}/lib -rpath ${stdenv.cc.cc.out}/lib64 -rpath ${stdenv.cc.cc.out}/lib"
 
     sed -i 414,424d Makefile
   '';
diff --git a/pkgs/games/warsow/default.nix b/pkgs/games/warsow/default.nix
index b525e3cb0f89..9f2dfbab2ecd 100644
--- a/pkgs/games/warsow/default.nix
+++ b/pkgs/games/warsow/default.nix
@@ -37,7 +37,7 @@ stdenv.mkDerivation rec {
     cp -rv basewsw libs $dest
     # Since 1.03 some modules are _always_ downloaded from server, thus
     makeWrapper $dest/warsow $out/bin/warsow \
-      --suffix-each LD_LIBRARY_PATH ':' "${freetype}/lib"
+      --suffix-each LD_LIBRARY_PATH ':' "${freetype.out}/lib"
     makeWrapper $dest/wsw_server $out/bin/wsw_server
     makeWrapper $dest/wswtv_server $out/bin/wswtv_server
   '';
diff --git a/pkgs/games/xonotic/default.nix b/pkgs/games/xonotic/default.nix
index 7fb7c11694fd..e45bbb20d3a7 100644
--- a/pkgs/games/xonotic/default.nix
+++ b/pkgs/games/xonotic/default.nix
@@ -32,9 +32,9 @@ stdenv.mkDerivation rec {
   #'';
 
   NIX_LDFLAGS = ''
-    -rpath ${zlib}/lib
-    -rpath ${libvorbis}/lib
-    -rpath ${curl}/lib
+    -rpath ${zlib.out}/lib
+    -rpath ${libvorbis.out}/lib
+    -rpath ${curl.out}/lib
   '';
 
   buildPhase = ''
diff --git a/pkgs/games/xsokoban/default.nix b/pkgs/games/xsokoban/default.nix
index e6686a658a90..502771e18ee6 100644
--- a/pkgs/games/xsokoban/default.nix
+++ b/pkgs/games/xsokoban/default.nix
@@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
 
   preConfigure = ''
     sed -e 's/getline/my_getline/' -i score.c
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${libXpm}/include/X11"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${libXpm.dev}/include/X11"
     for i in  $NIX_CFLAGS_COMPILE; do echo $i; ls ''${i#-I}; done
     chmod a+rw config.h
     cat >>config.h <<EOF
diff --git a/pkgs/games/zdoom/default.nix b/pkgs/games/zdoom/default.nix
index 0bc63855299e..de0f9c4db831 100644
--- a/pkgs/games/zdoom/default.nix
+++ b/pkgs/games/zdoom/default.nix
@@ -14,10 +14,10 @@ stdenv.mkDerivation {
 
   cmakeFlags = [
     "-DFMOD_LIBRARY=${fmod}/lib/libfmodex.so"
-    "-DSDL_INCLUDE_DIR=${SDL}/include"
+    "-DSDL_INCLUDE_DIR=${SDL.dev}/include"
   ];
 
-  NIX_CFLAGS_COMPILE = [ "-I ${SDL}/include/SDL" ];
+  NIX_CFLAGS_COMPILE = [ "-I ${SDL.dev}/include/SDL" ];
    
   preConfigure = ''
     sed s@zdoom.pk3@$out/share/zdoom.pk3@ -i src/version.h
diff --git a/pkgs/misc/cups/default.nix b/pkgs/misc/cups/default.nix
index 7dedf26096df..43c2d63bddb7 100644
--- a/pkgs/misc/cups/default.nix
+++ b/pkgs/misc/cups/default.nix
@@ -16,8 +16,11 @@ stdenv.mkDerivation {
     sha256 = "1bc1y8fjgh54ryh520gk63i5rbagn6jijsrskcqlibhfm0xwmc5s";
   };
 
+  # FIXME: the cups libraries contains some $out/share strings so can't be split.
+  outputs = [ "dev" "out" "doc" "man" ]; # TODO: above
+
   buildInputs = [ pkgconfig zlib libjpeg libpng libtiff libusb gnutls libpaper ]
-    ++ optionals stdenv.isLinux [ avahi pam dbus.libs acl ]
+    ++ optionals stdenv.isLinux [ avahi pam dbus acl ]
     ++ optionals stdenv.isDarwin (with darwin; [
       configd apple_sdk.frameworks.ApplicationServices
     ]);
@@ -66,6 +69,9 @@ stdenv.mkDerivation {
       # Delete obsolete stuff that conflicts with cups-filters.
       rm -rf $out/share/cups/banners $out/share/cups/data/testprint
 
+      mkdir $dev/bin
+      mv $out/bin/cups-config $dev/bin/
+
       # Rename systemd files provided by CUPS
       for f in $out/lib/systemd/system/*; do
         substituteInPlace "$f" \
diff --git a/pkgs/misc/cups/drivers/canon/default.nix b/pkgs/misc/cups/drivers/canon/default.nix
index 4c31e8d37d25..779cf9656863 100644
--- a/pkgs/misc/cups/drivers/canon/default.nix
+++ b/pkgs/misc/cups/drivers/canon/default.nix
@@ -202,10 +202,10 @@ stdenv.mkDerivation rec {
       cp libs/ThLB* $out/share/ufr2filter
     )
 
-    patchelf --set-rpath "$out/lib32:${i686_libxml2}/lib" $out/lib32/libcanonufr2.so.1.0.0
+    patchelf --set-rpath "$out/lib32:${i686_libxml2.out}/lib" $out/lib32/libcanonufr2.so.1.0.0
 
     patchelf --interpreter "$(cat ${i686_NIX_GCC}/nix-support/dynamic-linker)" --set-rpath "$out/lib32" $out/bin/cnpkmoduleufr2
-    patchelf --interpreter "$(cat ${i686_NIX_GCC}/nix-support/dynamic-linker)" --set-rpath "$out/lib32:${i686_libxml2}/lib" $out/bin/cnpkbidi
+    patchelf --interpreter "$(cat ${i686_NIX_GCC}/nix-support/dynamic-linker)" --set-rpath "$out/lib32:${i686_libxml2.out}/lib" $out/bin/cnpkbidi
 
     makeWrapper "${ghostscript}/bin/gs" "$out/bin/gs" \
       --prefix LD_LIBRARY_PATH ":" "$out/lib" \
diff --git a/pkgs/misc/cups/drivers/mfcj470dw/default.nix b/pkgs/misc/cups/drivers/mfcj470dw/default.nix
index d1a1b239371a..b61344d1280e 100644
--- a/pkgs/misc/cups/drivers/mfcj470dw/default.nix
+++ b/pkgs/misc/cups/drivers/mfcj470dw/default.nix
@@ -33,8 +33,8 @@ stdenv.mkDerivation rec {
 
     sed -i '/GHOST_SCRIPT=/c\GHOST_SCRIPT=gs' $out/opt/brother/Printers/mfcj470dw/lpd/psconvertij2
 
-    patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux.so.2 $out/opt/brother/Printers/mfcj470dw/lpd/brmfcj470dwfilter
-    patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux.so.2 $out/opt/brother/Printers/mfcj470dw/cupswrapper/brcupsconfpt1
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/opt/brother/Printers/mfcj470dw/lpd/brmfcj470dwfilter
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/opt/brother/Printers/mfcj470dw/cupswrapper/brcupsconfpt1
 
     mkdir -p $out/lib/cups/filter/
     ln -s $out/opt/brother/Printers/mfcj470dw/lpd/filtermfcj470dw $out/lib/cups/filter/brother_lpdwrapper_mfcj470dw
diff --git a/pkgs/misc/drivers/foo2zjs/default.nix b/pkgs/misc/drivers/foo2zjs/default.nix
index 2417b0e566de..2547baec4f12 100644
--- a/pkgs/misc/drivers/foo2zjs/default.nix
+++ b/pkgs/misc/drivers/foo2zjs/default.nix
@@ -1,5 +1,5 @@
 x@{builderDefsPackage
-  , foomatic_filters, bc, unzip, ghostscript, udev, vim
+  , foomatic_filters, bc, unzip, ghostscript, systemd, vim
   , ...}:
 builderDefsPackage
 (a :  
@@ -36,7 +36,7 @@ rec {
       ''PIXMAPS=$out/share/pixmaps''
       ''UDEVBIN=$out/bin''
       ''UDEVDIR=$out/etc/udev/rules.d''
-      ''UDEVD=${udev}/sbin/udevd''
+      ''UDEVD=${systemd.udev.bin}/sbin/udevd''
       ''LIBUDEVDIR=$out/lib/udev/rules.d''
       ''USBDIR=$out/etc/hotplug/usb''
       ''FOODB=$out/share/foomatic/db/source''
diff --git a/pkgs/misc/emulators/retroarch/cores.nix b/pkgs/misc/emulators/retroarch/cores.nix
index 07d665503791..219a04e4f028 100644
--- a/pkgs/misc/emulators/retroarch/cores.nix
+++ b/pkgs/misc/emulators/retroarch/cores.nix
@@ -182,7 +182,7 @@ in
 
     extraBuildInputs = [ libpng SDL ];
   }).override {
-    patchPhase = "sed -i -e 's,SDL_CONFIG=\".*\",SDL_CONFIG=\"${SDL}/bin/sdl-config\",' configure";
+    patchPhase = "sed -i -e 's,SDL_CONFIG=\".*\",SDL_CONFIG=\"${SDL.dev}/bin/sdl-config\",' configure";
     configurePhase = "./configure";
   };
 
diff --git a/pkgs/os-specific/darwin/binutils/default.nix b/pkgs/os-specific/darwin/binutils/default.nix
index abe4aa67b143..d671c7c72303 100644
--- a/pkgs/os-specific/darwin/binutils/default.nix
+++ b/pkgs/os-specific/darwin/binutils/default.nix
@@ -32,7 +32,7 @@ stdenv.mkDerivation {
 
     # FIXME: this will give us incorrect man pages for bits of cctools
     ln -s ${binutils-raw}/share $out/share
-    ln -s ${binutils-raw}/lib $out/lib
+    ln -s ${binutils-raw.out}/lib $out/lib
 
     ln -s ${cctools}/libexec $out/libexec
   '';
diff --git a/pkgs/os-specific/linux/alsa-lib/default.nix b/pkgs/os-specific/linux/alsa-lib/default.nix
index ed72e7011663..8f46bb29c1fb 100644
--- a/pkgs/os-specific/linux/alsa-lib/default.nix
+++ b/pkgs/os-specific/linux/alsa-lib/default.nix
@@ -25,6 +25,8 @@ stdenv.mkDerivation rec {
     sed -i -e 's/u_int\([0-9]*\)_t/uint\1_t/g' include/pcm.h
   '';
 
+  outputs = [ "dev" "out" ];
+
   crossAttrs = {
     patchPhase = ''
       sed -i s/extern/static/g include/iatomic.h
diff --git a/pkgs/os-specific/linux/apparmor/2.9/default.nix b/pkgs/os-specific/linux/apparmor/2.9/default.nix
new file mode 100644
index 000000000000..5e8ccc756918
--- /dev/null
+++ b/pkgs/os-specific/linux/apparmor/2.9/default.nix
@@ -0,0 +1,183 @@
+{ stdenv, fetchurl, autoconf, automake, libtool, pkgconfig, perl, which
+, glibc, flex, bison, python27, swig, dbus, pam
+}:
+
+let
+  apparmor-series = "2.9";
+  apparmor-patchver = "2";
+  apparmor-version = "${apparmor-series}.${apparmor-patchver}";
+
+  apparmor-meta = component: with stdenv.lib; {
+      homepage = http://apparmor.net/;
+      description = "Linux application security system - ${component}";
+      license = licenses.gpl2;
+      maintainers = with maintainers; [ phreedom thoughtpolice joachifm ];
+      platforms = platforms.linux;
+  };
+
+  apparmor-sources = fetchurl {
+    url = "https://launchpad.net/apparmor/${apparmor-series}/${apparmor-version}/+download/apparmor-${apparmor-version}.tar.gz";
+    sha256 = "1mayly7d7w959fya7z8q6kab2x3jcwhqhkpx36jsvpjhxkhmc4fh";
+  };
+
+  prePatchCommon = ''
+    substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2man" "${perl}/bin/pod2man"
+    substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2html" "${perl}/bin/pod2html"
+    substituteInPlace ./common/Make.rules --replace "/usr/include/linux/capability.h" "${glibc.dev}/include/linux/capability.h"
+    substituteInPlace ./common/Make.rules --replace "/usr/share/man" "share/man"
+  '';
+
+  libapparmor = stdenv.mkDerivation {
+    name = "libapparmor-${apparmor-version}";
+    src = apparmor-sources;
+
+    buildInputs = [
+      autoconf
+      automake
+      bison
+      flex
+      dbus # requires patch to dbus ...
+      glibc
+      libtool
+      perl
+      pkgconfig
+      python27
+      swig
+      which
+    ];
+
+    prePatch = prePatchCommon + ''
+      substituteInPlace ./libraries/libapparmor/src/Makefile.am --replace "/usr/include/netinet/in.h" "${glibc.dev}/include/netinet/in.h"
+      substituteInPlace ./libraries/libapparmor/src/Makefile.in --replace "/usr/include/netinet/in.h" "${glibc.dev}/include/netinet/in.h"
+      '';
+
+    buildPhase = ''
+      cd ./libraries/libapparmor
+      ./autogen.sh
+      ./configure --prefix="$out" --with-python --with-perl
+      make
+      '';
+
+    installPhase = ''
+      make install
+    '';
+
+    meta = apparmor-meta "library";
+  };
+
+  apparmor-utils = stdenv.mkDerivation {
+    name = "apparmor-utils-${apparmor-version}";
+    src = apparmor-sources;
+
+    buildInputs = [
+      python27
+      libapparmor
+      which
+    ];
+
+    prePatch = prePatchCommon;
+
+    buildPhase = ''
+      cd ./utils
+      make LANGS=""
+    '';
+
+    installPhase = ''
+      make install LANGS="" DESTDIR="$out" BINDIR="$out/bin" VIM_INSTALL_PATH="$out/share" PYPREFIX=""
+    '';
+
+    meta = apparmor-meta "user-land utilities";
+  };
+
+  apparmor-parser = stdenv.mkDerivation {
+    name = "apparmor-parser-${apparmor-version}";
+    src = apparmor-sources;
+
+    buildInputs = [
+      libapparmor
+      bison
+      flex
+      which
+    ];
+
+    prePatch = prePatchCommon + ''
+      substituteInPlace ./parser/Makefile --replace "/usr/bin/bison" "${bison}/bin/bison"
+      substituteInPlace ./parser/Makefile --replace "/usr/bin/flex" "${flex}/bin/flex"
+      substituteInPlace ./parser/Makefile --replace "/usr/include/linux/capability.h" "${glibc.dev}/include/linux/capability.h"
+      ## techdoc.pdf still doesn't build ...
+      substituteInPlace ./parser/Makefile --replace "manpages htmlmanpages pdf" "manpages htmlmanpages"
+    '';
+
+    buildPhase = ''
+      cd ./parser
+      make LANGS="" USE_SYSTEM=1 INCLUDEDIR=${libapparmor}/include
+    '';
+
+    installPhase = ''
+      make install LANGS="" USE_SYSTEM=1 INCLUDEDIR=${libapparmor}/include DESTDIR="$out" DISTRO="unknown"
+    '';
+
+    meta = apparmor-meta "rule parser";
+  };
+
+  apparmor-pam = stdenv.mkDerivation {
+    name = "apparmor-pam-${apparmor-version}";
+    src = apparmor-sources;
+
+    buildInputs = [
+      libapparmor
+      pam
+      pkgconfig
+      which
+    ];
+
+    buildPhase = ''
+      cd ./changehat/pam_apparmor
+      make USE_SYSTEM=1
+    '';
+
+    installPhase = ''
+      make install DESTDIR="$out"
+    '';
+
+    meta = apparmor-meta "PAM service";
+  };
+
+  apparmor-profiles = stdenv.mkDerivation {
+    name = "apparmor-profiles-${apparmor-version}";
+    src = apparmor-sources;
+
+    buildInputs = [ which ];
+
+    buildPhase = ''
+      cd ./profiles
+      make
+    '';
+
+    installPhase = ''
+      make install DESTDIR="$out" EXTRAS_DEST="$out/share/apparmor/extra-profiles"
+    '';
+
+    meta = apparmor-meta "profiles";
+  };
+
+  apparmor-kernel-patches = stdenv.mkDerivation {
+    name = "apparmor-kernel-patches-${apparmor-version}";
+    src = apparmor-sources;
+
+    phases = ''unpackPhase installPhase'';
+
+    installPhase = ''
+      mkdir "$out"
+      cp -R ./kernel-patches "$out"
+    '';
+
+    meta = apparmor-meta "kernel patches";
+  };
+
+in
+
+{
+  inherit libapparmor apparmor-utils apparmor-parser apparmor-pam
+  apparmor-profiles apparmor-kernel-patches;
+}
diff --git a/pkgs/os-specific/linux/apparmor/default.nix b/pkgs/os-specific/linux/apparmor/default.nix
index 64c6f66575b6..49fdbab24caa 100644
--- a/pkgs/os-specific/linux/apparmor/default.nix
+++ b/pkgs/os-specific/linux/apparmor/default.nix
@@ -22,7 +22,7 @@ let
   prePatchCommon = ''
     substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2man" "${perl}/bin/pod2man"
     substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2html" "${perl}/bin/pod2html"
-    substituteInPlace ./common/Make.rules --replace "/usr/include/linux/capability.h" "${glibc}/include/linux/capability.h"
+    substituteInPlace ./common/Make.rules --replace "/usr/include/linux/capability.h" "${glibc.dev}/include/linux/capability.h"
     substituteInPlace ./common/Make.rules --replace "/usr/share/man" "share/man"
   '';
 
@@ -49,8 +49,8 @@ let
     dontDisableStatic = true;
 
     prePatch = prePatchCommon + ''
-      substituteInPlace ./libraries/libapparmor/src/Makefile.am --replace "/usr/include/netinet/in.h" "${glibc}/include/netinet/in.h"
-      substituteInPlace ./libraries/libapparmor/src/Makefile.in --replace "/usr/include/netinet/in.h" "${glibc}/include/netinet/in.h"
+      substituteInPlace ./libraries/libapparmor/src/Makefile.am --replace "/usr/include/netinet/in.h" "${glibc.dev}/include/netinet/in.h"
+      substituteInPlace ./libraries/libapparmor/src/Makefile.in --replace "/usr/include/netinet/in.h" "${glibc.dev}/include/netinet/in.h"
       '';
 
     postPatch = "cd ./libraries/libapparmor";
@@ -104,7 +104,7 @@ let
     prePatch = prePatchCommon + ''
       substituteInPlace ./parser/Makefile --replace "/usr/bin/bison" "${bison}/bin/bison"
       substituteInPlace ./parser/Makefile --replace "/usr/bin/flex" "${flex}/bin/flex"
-      substituteInPlace ./parser/Makefile --replace "/usr/include/linux/capability.h" "${glibc}/include/linux/capability.h"
+      substituteInPlace ./parser/Makefile --replace "/usr/include/linux/capability.h" "${glibc.dev}/include/linux/capability.h"
       ## techdoc.pdf still doesn't build ...
       substituteInPlace ./parser/Makefile --replace "manpages htmlmanpages pdf" "manpages htmlmanpages"
     '';
diff --git a/pkgs/os-specific/linux/ati-drivers/default.nix b/pkgs/os-specific/linux/ati-drivers/default.nix
index 377297feaf75..78903da1f1a1 100644
--- a/pkgs/os-specific/linux/ati-drivers/default.nix
+++ b/pkgs/os-specific/linux/ati-drivers/default.nix
@@ -85,15 +85,17 @@ stdenv.mkDerivation {
 
   inherit glibc /* glibc only used for setting interpreter */;
 
+  # outputs TODO: probably many fixes are needed;
+  # this in particular would be much better by lib.makeLibraryPath
   LD_LIBRARY_PATH = stdenv.lib.concatStringsSep ":"
-    [ "${xorg.libXrandr}/lib/"
-      "${xorg.libXrender}/lib/"
-      "${xorg.libXext}/lib/"
-      "${xorg.libX11}/lib/"
-      "${xorg.libXinerama}/lib/"
-      "${xorg.libSM}/lib/"
-      "${xorg.libICE}/lib/"
-      "${stdenv.cc.cc}/lib/"
+    [ "${xorg.libXrandr.out}/lib/"
+      "${xorg.libXrender.out}/lib/"
+      "${xorg.libXext.out}/lib/"
+      "${xorg.libX11.out}/lib/"
+      "${xorg.libXinerama.out}/lib/"
+      "${xorg.libSM.out}/lib/"
+      "${xorg.libICE.out}/lib/"
+      "${stdenv.cc.cc.out}/lib/"
     ];
 
   # without this some applications like blender don't start, but they start
diff --git a/pkgs/os-specific/linux/bluez/bluez5.nix b/pkgs/os-specific/linux/bluez/bluez5.nix
index cc132ddc397e..20fa830e3201 100644
--- a/pkgs/os-specific/linux/bluez/bluez5.nix
+++ b/pkgs/os-specific/linux/bluez/bluez5.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
     [ pythonDBus pygobject pygobject3 recursivePthLoader ];
 
   buildInputs =
-    [ pkgconfig dbus.libs glib alsaLib python pythonPackages.wrapPython
+    [ pkgconfig dbus glib alsaLib python pythonPackages.wrapPython
       readline libsndfile udev libical
       # Disables GStreamer; not clear what it gains us other than a
       # zillion extra dependencies.
diff --git a/pkgs/os-specific/linux/bluez/bluez5_28.nix b/pkgs/os-specific/linux/bluez/bluez5_28.nix
index 7f5a30144c8b..ba3f478ddc22 100644
--- a/pkgs/os-specific/linux/bluez/bluez5_28.nix
+++ b/pkgs/os-specific/linux/bluez/bluez5_28.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
     [ pythonDBus pygobject pygobject3 recursivePthLoader ];
 
   buildInputs =
-    [ pkgconfig dbus.libs glib alsaLib python pythonPackages.wrapPython
+    [ pkgconfig dbus glib alsaLib python pythonPackages.wrapPython
       readline libsndfile udev libical
       # Disables GStreamer; not clear what it gains us other than a
       # zillion extra dependencies.
diff --git a/pkgs/os-specific/linux/bluez/default.nix b/pkgs/os-specific/linux/bluez/default.nix
index 23e5171d1780..4f30bc19caf8 100644
--- a/pkgs/os-specific/linux/bluez/default.nix
+++ b/pkgs/os-specific/linux/bluez/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
   };
 
   buildInputs =
-    [ pkgconfig dbus.libs glib libusb alsaLib python makeWrapper
+    [ pkgconfig dbus glib libusb alsaLib python makeWrapper
       readline libsndfile
       # Disables GStreamer; not clear what it gains us other than a
       # zillion extra dependencies.
diff --git a/pkgs/os-specific/linux/checksec/default.nix b/pkgs/os-specific/linux/checksec/default.nix
index b423dc3a0862..60468538be24 100644
--- a/pkgs/os-specific/linux/checksec/default.nix
+++ b/pkgs/os-specific/linux/checksec/default.nix
@@ -21,7 +21,7 @@ stdenv.mkDerivation rec {
     cp checksec.sh $out/bin/checksec
     chmod +x $out/bin/checksec
     substituteInPlace $out/bin/checksec --replace /bin/bash ${stdenv.shell}
-    substituteInPlace $out/bin/checksec --replace /lib/libc.so.6 ${glibc}/lib/libc.so.6
+    substituteInPlace $out/bin/checksec --replace /lib/libc.so.6 ${glibc.out}/lib/libc.so.6
     substituteInPlace $out/bin/checksec --replace find ${findutils}/bin/find
     substituteInPlace $out/bin/checksec --replace "file $" "${file}/bin/file $"
     substituteInPlace $out/bin/checksec --replace "xargs file" "xargs ${file}/bin/file"
diff --git a/pkgs/os-specific/linux/drbd/default.nix b/pkgs/os-specific/linux/drbd/default.nix
index 4c945a7fbac7..95c851da30f8 100644
--- a/pkgs/os-specific/linux/drbd/default.nix
+++ b/pkgs/os-specific/linux/drbd/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, flex, udev, perl }:
+{ stdenv, fetchurl, flex, systemd, perl }:
 
 assert stdenv.isLinux;
 
@@ -18,7 +18,7 @@ stdenv.mkDerivation rec {
 
   preConfigure =
     ''
-      export PATH=${udev}/sbin:$PATH
+      export PATH=${systemd.udev.bin}/sbin:$PATH
       substituteInPlace user/Makefile.in --replace /sbin/ $out/sbin/
       substituteInPlace user/legacy/Makefile.in \
         --replace /sbin/ $out/sbin/ \
diff --git a/pkgs/os-specific/linux/fusionio/util.nix b/pkgs/os-specific/linux/fusionio/util.nix
index e2f8d423a61d..e77d596dc6f8 100644
--- a/pkgs/os-specific/linux/fusionio/util.nix
+++ b/pkgs/os-specific/linux/fusionio/util.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation {
     cp -r $TMPDIR/{etc,usr/{bin,lib,share}} $out
     for BIN in $(find $out/bin -type f); do
       echo Patching $BIN
-      patchelf --set-interpreter "${glibc}/lib/ld-linux-x86-64.so.2" --set-rpath "${glibc}/lib:${gcc.cc}/lib:${libuuid}/lib:$out/lib" $BIN
+      patchelf --set-interpreter "${glibc.out}/lib/ld-linux-x86-64.so.2" --set-rpath "${glibc.out}/lib:${gcc.cc}/lib:${libuuid}/lib:$out/lib" $BIN
 
       # Test our binary to see if it was correctly patched
       set +e
diff --git a/pkgs/os-specific/linux/kbd/default.nix b/pkgs/os-specific/linux/kbd/default.nix
index bb2915958f7c..fddaa84a8240 100644
--- a/pkgs/os-specific/linux/kbd/default.nix
+++ b/pkgs/os-specific/linux/kbd/default.nix
@@ -40,7 +40,7 @@ stdenv.mkDerivation rec {
       # Fix the path to gzip/bzip2.
       substituteInPlace src/libkeymap/findfile.c \
         --replace gzip ${gzip}/bin/gzip \
-        --replace bzip2 ${bzip2}/bin/bzip2 \
+        --replace bzip2 ${bzip2.bin}/bin/bzip2 \
 
       # We get a warning in armv5tel-linux and the fuloong2f, so we
       # disable -Werror in it.
diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix
index 4a826ff7ae3d..3882638ee954 100644
--- a/pkgs/os-specific/linux/kernel/manual-config.nix
+++ b/pkgs/os-specific/linux/kernel/manual-config.nix
@@ -74,7 +74,7 @@ let
 
       installsFirmware = (config.isEnabled "FW_LOADER") &&
         (isModular || (config.isDisabled "FIRMWARE_IN_KERNEL"));
-    in (optionalAttrs isModular { outputs = [ "out" "dev" ]; }) // {
+    in (optionalAttrs isModular { outputs = [ "out" "dev" ]; propagatedBuildOutputs = ""; }) // {
       passthru = {
         inherit version modDirVersion config kernelPatches configfile;
       };
diff --git a/pkgs/os-specific/linux/klibc/shrunk.nix b/pkgs/os-specific/linux/klibc/shrunk.nix
index 066b4fcb4e06..2ce833d104fd 100644
--- a/pkgs/os-specific/linux/klibc/shrunk.nix
+++ b/pkgs/os-specific/linux/klibc/shrunk.nix
@@ -8,10 +8,10 @@ stdenv.mkDerivation {
   name = "${klibc.name}";
   buildCommand = ''
     mkdir -p $out/lib
-    cp -prd ${klibc}/lib/klibc/bin $out/
-    cp -p ${klibc}/lib/*.so $out/lib/
+    cp -prd ${klibc.out}/lib/klibc/bin $out/
+    cp -p ${klibc.out}/lib/*.so $out/lib/
     chmod +w $out/*
-    old=$(echo ${klibc}/lib/klibc-*.so)
+    old=$(echo ${klibc.out}/lib/klibc-*.so)
     new=$(echo $out/lib/klibc-*.so)
     for i in $out/bin/*; do
       echo $i
diff --git a/pkgs/os-specific/linux/libcap/default.nix b/pkgs/os-specific/linux/libcap/default.nix
index 8157270d67d7..c8484babcdf8 100644
--- a/pkgs/os-specific/linux/libcap/default.nix
+++ b/pkgs/os-specific/linux/libcap/default.nix
@@ -3,12 +3,14 @@
 stdenv.mkDerivation rec {
   name = "libcap-${version}";
   version = "2.24";
-  
+
   src = fetchurl {
     url = "mirror://kernel/linux/libs/security/linux-privs/libcap2/${name}.tar.xz";
     sha256 = "0rbc9qbqs5bp9am9s9g83wxj5k4ixps2agy9dxr1v1fwg27mdr6f";
   };
-  
+
+  outputs = [ "dev" "out" ];
+
   nativeBuildInputs = [ perl ];
   propagatedBuildInputs = [ attr ];
 
@@ -16,14 +18,11 @@ stdenv.mkDerivation rec {
 
   makeFlags = "lib=lib prefix=$(out)";
 
-  passthru = {
-    postinst = n : ''
-      mkdir -p $out/share/doc/${n}
-      cp ../License $out/share/doc/${n}/License
-    '';
-  };
-
-  postInstall = passthru.postinst name;
+  postInstall = ''
+    rm "$out"/lib/*.a
+    mkdir -p "$dev/share/doc/${name}"
+    cp ../License "$dev/share/doc/${name}/License"
+  '';
 
   meta = {
     description = "Library for working with POSIX capabilities";
diff --git a/pkgs/os-specific/linux/libcap/man.nix b/pkgs/os-specific/linux/libcap/man.nix
index 9aac3c4e1f5a..eeb780f095bd 100644
--- a/pkgs/os-specific/linux/libcap/man.nix
+++ b/pkgs/os-specific/linux/libcap/man.nix
@@ -10,6 +10,4 @@ stdenv.mkDerivation rec {
   makeFlags = "MANDIR=$(out)/share/man";
 
   preConfigure = "cd doc";
-
-  postInstall = libcap.postinst name;
 }
diff --git a/pkgs/os-specific/linux/libcap/pam.nix b/pkgs/os-specific/linux/libcap/pam.nix
index b78f32dccbb4..3dd7cd947af2 100644
--- a/pkgs/os-specific/linux/libcap/pam.nix
+++ b/pkgs/os-specific/linux/libcap/pam.nix
@@ -12,6 +12,4 @@ stdenv.mkDerivation rec {
   preConfigure = "cd pam_cap";
 
   makeFlags = "${libcap.makeFlags} PAM_CAP=yes";
-
-  postInstall = libcap.postinst name;
 }
diff --git a/pkgs/os-specific/linux/libcap/progs.nix b/pkgs/os-specific/linux/libcap/progs.nix
index ae4446c82e6c..e3871f15f885 100644
--- a/pkgs/os-specific/linux/libcap/progs.nix
+++ b/pkgs/os-specific/linux/libcap/progs.nix
@@ -21,5 +21,8 @@ stdenv.mkDerivation rec {
 
   installFlags = "RAISE_SETFCAP=no";
 
-  postInstall = libcap.postinst name;
+  postInstall = ''
+    mkdir -p "$out/share/doc/${name}"
+    cp ../License "$out/share/doc/${name}/"
+  '';
 }
diff --git a/pkgs/os-specific/linux/libnl/default.nix b/pkgs/os-specific/linux/libnl/default.nix
index afd9695420e3..1e1ed0a6112c 100644
--- a/pkgs/os-specific/linux/libnl/default.nix
+++ b/pkgs/os-specific/linux/libnl/default.nix
@@ -11,6 +11,8 @@ stdenv.mkDerivation {
     owner = "thom311";
   };
 
+  outputs = [ "dev" "bin" "out" "man" ];
+
   nativeBuildInputs = [ autoreconfHook bison flex pkgconfig ];
 
   meta = {
diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix
index 351c2f609814..9147cb813714 100644
--- a/pkgs/os-specific/linux/lvm2/default.nix
+++ b/pkgs/os-specific/linux/lvm2/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, pkgconfig, udev, utillinux, coreutils, enable_dmeventd ? false }:
+{ stdenv, fetchurl, pkgconfig, systemd, libudev, utillinux, coreutils, enable_dmeventd ? false }:
 
 let
   version = "2.02.140";
@@ -22,7 +22,7 @@ stdenv.mkDerivation {
   ] ++ stdenv.lib.optional enable_dmeventd " --enable-dmeventd";
 
   nativeBuildInputs = [ pkgconfig ];
-  buildInputs = [ udev ];
+  buildInputs = [ libudev ];
 
   preConfigure =
     ''
@@ -30,7 +30,7 @@ stdenv.mkDerivation {
         --replace /usr/bin/tr ${coreutils}/bin/tr
       substituteInPlace scripts/lvm2_activation_generator_systemd_red_hat.c \
         --replace /usr/sbin/lvm $out/sbin/lvm \
-        --replace /usr/bin/udevadm ${udev}/bin/udevadm
+        --replace /usr/bin/udevadm ${systemd.udev.bin}/bin/udevadm
 
       sed -i /DEFAULT_SYS_DIR/d Makefile.in
       sed -i /DEFAULT_PROFILE_DIR/d conf/Makefile.in
diff --git a/pkgs/os-specific/linux/mdadm/default.nix b/pkgs/os-specific/linux/mdadm/default.nix
index 465dc58199ed..3fe9d462412c 100644
--- a/pkgs/os-specific/linux/mdadm/default.nix
+++ b/pkgs/os-specific/linux/mdadm/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
 
   # This is to avoid self-references, which causes the initrd to explode
   # in size and in turn prevents mdraid systems from booting.
-  allowedReferences = [ stdenv.glibc ];
+  allowedReferences = [ stdenv.glibc.out ];
 
   patches = [ ./no-self-references.patch ];
 
diff --git a/pkgs/os-specific/linux/module-init-tools/default.nix b/pkgs/os-specific/linux/module-init-tools/default.nix
index 1302d7b1fef0..2d6875d506a7 100644
--- a/pkgs/os-specific/linux/module-init-tools/default.nix
+++ b/pkgs/os-specific/linux/module-init-tools/default.nix
@@ -20,6 +20,8 @@ stdenv.mkDerivation {
     })
   ];
 
+  buildInputs = [ stdenv.glibc.dev stdenv.glibc.static ];
+
   SGML_CATALOG_FILES = "${docbook_sgml_dtd_41}/sgml/dtd/docbook-4.1/docbook.cat";
 
   patches = [ ./module-dir.patch ./docbook2man.patch ];
diff --git a/pkgs/os-specific/linux/nfs-utils/default.nix b/pkgs/os-specific/linux/nfs-utils/default.nix
index 0dde3bca4e47..504d3790d868 100644
--- a/pkgs/os-specific/linux/nfs-utils/default.nix
+++ b/pkgs/os-specific/linux/nfs-utils/default.nix
@@ -21,7 +21,7 @@ stdenv.mkDerivation rec {
       "--with-statedir=/var/lib/nfs"
       "--with-tirpcinclude=${libtirpc}/include/tirpc"
     ]
-    ++ stdenv.lib.optional (stdenv ? glibc) "--with-rpcgen=${stdenv.glibc}/bin/rpcgen";
+    ++ stdenv.lib.optional (stdenv ? glibc) "--with-rpcgen=${stdenv.glibc.bin}/bin/rpcgen";
 
   patchPhase =
     ''
diff --git a/pkgs/os-specific/linux/pam/default.nix b/pkgs/os-specific/linux/pam/default.nix
index f7cadd469d70..d84c6224eebe 100644
--- a/pkgs/os-specific/linux/pam/default.nix
+++ b/pkgs/os-specific/linux/pam/default.nix
@@ -9,10 +9,14 @@ stdenv.mkDerivation rec {
     sha256 = "1n9lnf9gjs72kbj1g354v1xhi2j27aqaah15vykh7cnkq08i4arl";
   };
 
+  outputs = [ "out" "doc" "man" /* "modules" */ ];
+
   nativeBuildInputs = [ flex ];
 
   buildInputs = [ cracklib ];
 
+  enableParallelBuilding = true;
+
   crossAttrs = {
     propagatedBuildInputs = [ flex.crossDrv cracklib.crossDrv ];
     preConfigure = preConfigure + ''
@@ -31,7 +35,14 @@ stdenv.mkDerivation rec {
   postInstall = ''
     mv -v $out/sbin/unix_chkpwd{,.orig}
     ln -sv /var/setuid-wrappers/unix_chkpwd $out/sbin/unix_chkpwd
-  '';
+  ''; /*
+    rm -rf $out/etc
+    mkdir -p $modules/lib
+    mv $out/lib/security $modules/lib/
+  '';*/
+  # don't move modules, because libpam needs to (be able to) find them,
+  # which is done by dlopening $out/lib/security/pam_foo.so
+  # $out/etc was also missed: pam_env(login:session): Unable to open config file
 
   preConfigure = ''
     configureFlags="$configureFlags --includedir=$out/include/security"
diff --git a/pkgs/os-specific/linux/shadow/default.nix b/pkgs/os-specific/linux/shadow/default.nix
index f928dc8e657c..321e94e3aaf4 100644
--- a/pkgs/os-specific/linux/shadow/default.nix
+++ b/pkgs/os-specific/linux/shadow/default.nix
@@ -37,7 +37,7 @@ stdenv.mkDerivation rec {
 
   preBuild = assert glibc != null;
     ''
-      substituteInPlace lib/nscd.c --replace /usr/sbin/nscd ${glibc}/sbin/nscd
+      substituteInPlace lib/nscd.c --replace /usr/sbin/nscd ${glibc.bin}/bin/nscd
     '';
 
   postInstall =
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index d13417ad032b..b164693612df 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -1,5 +1,5 @@
-{ stdenv, fetchFromGitHub, pkgconfig, intltool, gperf, libcap, dbus, kmod
-, xz, pam, acl, cryptsetup, libuuid, m4, utillinux
+{ stdenv, fetchFromGitHub, pkgconfig, intltool, gperf, libcap, kmod
+, zlib, xz, pam, acl, cryptsetup, libuuid, m4, utillinux, libffi
 , glib, kbd, libxslt, coreutils, libgcrypt, libapparmor, audit, lz4
 , kexectools, libmicrohttpd, linuxHeaders, libseccomp
 , autoreconfHook, gettext, docbook_xsl, docbook_xml_dtd_42, docbook_xml_dtd_45
@@ -19,18 +19,27 @@ stdenv.mkDerivation rec {
     sha256 = "0wca8zkn39914c232andvf3v0ni6ylv154kz3s9fcvg47rhpd5n1";
   };
 
-  outputs = [ "out" "man" "doc" ];
+  patches = [ ./hwdb-location.diff ];
+
+  /* gave up for now!
+  outputs = [ "out" "libudev" "doc" ]; # maybe: "dev"
+  # note: there are many references to ${systemd}/...
+  outputDev = "out";
+  propagatedBuildOutputs = "libudev";
+  */
+  outputs = [ "out" "man" ];
 
   buildInputs =
     [ linuxHeaders pkgconfig intltool gperf libcap kmod xz pam acl
       /* cryptsetup */ libuuid m4 glib libxslt libgcrypt
-      libmicrohttpd kexectools libseccomp audit lz4 libapparmor
+      libmicrohttpd kexectools libseccomp libffi audit lz4 libapparmor
       /* FIXME: we may be able to prevent the following dependencies
          by generating an autoconf'd tarball, but that's probably not
          worth it. */
       autoreconfHook gettext docbook_xsl docbook_xml_dtd_42 docbook_xml_dtd_45
     ];
 
+
   configureFlags =
     [ "--localstatedir=/var"
       "--sysconfdir=/etc"
@@ -74,14 +83,15 @@ stdenv.mkDerivation rec {
       for i in src/remount-fs/remount-fs.c src/core/mount.c src/core/swap.c src/fsck/fsck.c units/emergency.service.in units/rescue.service.in src/journal/cat.c src/core/shutdown.c src/nspawn/nspawn.c src/shared/generator.c; do
         test -e $i
         substituteInPlace $i \
-          --replace /usr/bin/getent ${stdenv.glibc}/bin/getent \
-          --replace /bin/mount ${utillinux}/bin/mount \
-          --replace /bin/umount ${utillinux}/bin/umount \
-          --replace /sbin/swapon ${utillinux}/sbin/swapon \
-          --replace /sbin/swapoff ${utillinux}/sbin/swapoff \
+          --replace /usr/bin/getent ${stdenv.glibc.bin}/bin/getent \
+          --replace /bin/mount ${utillinux.bin}/bin/mount \
+          --replace /bin/umount ${utillinux.bin}/bin/umount \
+          --replace /sbin/swapon ${utillinux.bin}/sbin/swapon \
+          --replace /sbin/swapoff ${utillinux.bin}/sbin/swapoff \
+          --replace /sbin/fsck ${utillinux.bin}/sbin/fsck \
           --replace /bin/echo ${coreutils}/bin/echo \
           --replace /bin/cat ${coreutils}/bin/cat \
-          --replace /sbin/sulogin ${utillinux}/sbin/sulogin \
+          --replace /sbin/sulogin ${utillinux.bin}/sbin/sulogin \
           --replace /usr/lib/systemd/systemd-fsck $out/lib/systemd/systemd-fsck
       done
 
@@ -89,12 +99,24 @@ stdenv.mkDerivation rec {
         --replace /usr/lib/systemd/catalog/ $out/lib/systemd/catalog/
 
       configureFlagsArray+=("--with-ntp-servers=0.nixos.pool.ntp.org 1.nixos.pool.ntp.org 2.nixos.pool.ntp.org 3.nixos.pool.ntp.org")
+
+      #export NIX_CFLAGS_LINK+=" -Wl,-rpath,$libudev/lib"
     '';
 
+  /*
+  makeFlags = [
+    "udevlibexecdir=$(libudev)/lib/udev"
+    # udev rules refer to $out, and anything but libs should probably go to $out
+    "udevrulesdir=$(out)/lib/udev/rules.d"
+    "udevhwdbdir=$(out)/lib/udev/hwdb.d"
+  ];
+  */
+
+
   PYTHON_BINARY = "${coreutils}/bin/env python"; # don't want a build time dependency on Python
 
   NIX_CFLAGS_COMPILE =
-    [ # Can't say ${polkit}/bin/pkttyagent here because that would
+    [ # Can't say ${polkit.bin}/bin/pkttyagent here because that would
       # lead to a cyclic dependency.
       "-UPOLKIT_AGENT_BINARY_PATH" "-DPOLKIT_AGENT_BINARY_PATH=\"/run/current-system/sw/bin/pkttyagent\""
       "-fno-stack-protector"
@@ -107,13 +129,6 @@ stdenv.mkDerivation rec {
       "-USYSTEMD_BINARY_PATH" "-DSYSTEMD_BINARY_PATH=\"/run/current-system/systemd/lib/systemd/systemd\""
     ];
 
-  # Use /var/lib/udev rather than /etc/udev for the generated hardware
-  # database.  Upstream doesn't want this (see commit
-  # 1e1954f53386cb773e2a152748dd31c4d36aa2d8) because using /var is
-  # forbidden in early boot, but in NixOS the initrd guarantees that
-  # /var is mounted.
-  makeFlags = "hwdb_bin=/var/lib/udev/hwdb.bin";
-
   installFlags =
     [ "localstatedir=$(TMPDIR)/var"
       "sysconfdir=$(out)/etc"
@@ -154,8 +169,30 @@ stdenv.mkDerivation rec {
       # "kernel-install" shouldn't be used on NixOS.
       find $out -name "*kernel-install*" -exec rm {} \;
     ''; # */
+  /*
+      # Move lib(g)udev to a separate output. TODO: maybe split them up
+      #   to avoid libudev pulling glib
+      mkdir -p "$libudev/lib"
+      mv "$out"/lib/lib{,g}udev* "$libudev/lib/"
+
+      for i in "$libudev"/lib/*.la; do
+        substituteInPlace $i --replace "$out" "$libudev"
+      done
+      for i in "$out"/lib/pkgconfig/{libudev,gudev-1.0}.pc; do
+        substituteInPlace $i --replace "libdir=$out" "libdir=$libudev"
+      done
+  */
 
   enableParallelBuilding = true;
+  /*
+  # some libs fail to link to liblzma and/or libffi
+  postFixup = let extraLibs = stdenv.lib.makeLibraryPath [ xz.out libffi.out zlib.out ];
+    in ''
+      for f in "$out"/lib/*.so.0.*; do
+        patchelf --set-rpath `patchelf --print-rpath "$f"`':${extraLibs}' "$f"
+      done
+    '';
+  */
 
   # The interface version prevents NixOS from switching to an
   # incompatible systemd at runtime.  (Switching across reboots is
@@ -172,3 +209,4 @@ stdenv.mkDerivation rec {
     maintainers = [ stdenv.lib.maintainers.eelco stdenv.lib.maintainers.simons ];
   };
 }
+
diff --git a/pkgs/os-specific/linux/systemd/hwdb-location.diff b/pkgs/os-specific/linux/systemd/hwdb-location.diff
new file mode 100644
index 000000000000..31e7a027f50d
--- /dev/null
+++ b/pkgs/os-specific/linux/systemd/hwdb-location.diff
@@ -0,0 +1,19 @@
+diff --git a/src/libsystemd/sd-hwdb/sd-hwdb.c b/src/libsystemd/sd-hwdb/sd-hwdb.c
+index 06c9831..e74825c 100644
+--- a/src/libsystemd/sd-hwdb/sd-hwdb.c
++++ b/src/libsystemd/sd-hwdb/sd-hwdb.c
+@@ -268,13 +268,8 @@ static int trie_search_f(sd_hwdb *hwdb, const char *search) {
+ }
+ 
+ static const char hwdb_bin_paths[] =
+-        "/etc/systemd/hwdb/hwdb.bin\0"
+         "/etc/udev/hwdb.bin\0"
+-        "/usr/lib/systemd/hwdb/hwdb.bin\0"
+-#ifdef HAVE_SPLIT_USR
+-        "/lib/systemd/hwdb/hwdb.bin\0"
+-#endif
+-        UDEVLIBEXECDIR "/hwdb.bin\0";
++        ;
+ 
+ _public_ int sd_hwdb_new(sd_hwdb **ret) {
+         _cleanup_hwdb_unref_ sd_hwdb *hwdb = NULL;
diff --git a/pkgs/os-specific/linux/systemd/libudev.nix b/pkgs/os-specific/linux/systemd/libudev.nix
new file mode 100644
index 000000000000..0fe45aee9164
--- /dev/null
+++ b/pkgs/os-specific/linux/systemd/libudev.nix
@@ -0,0 +1,19 @@
+{ stdenv, systemd }:
+
+stdenv.mkDerivation {
+  name = "libudev-${systemd.version}";
+
+  unpackPhase = ":";
+  outputs = [ "dev" "out" ];
+  installPhase = ''
+    mkdir -p "$out/lib" "$dev/lib/pkgconfig" "$dev/include"
+    cp -P "${systemd}"/lib/libudev.* "$out/lib/"
+    cp -P "${systemd}"/lib/pkgconfig/libudev.pc "$dev/lib/pkgconfig/"
+    cp -P "${systemd}"/include/libudev.h "$dev/include/"
+
+    substituteInPlace "$dev"/lib/pkgconfig/*.pc \
+      --replace "${systemd}" "$out"
+    sed "/^includedir=/cincludedir=$dev/include" -i "$dev"/lib/pkgconfig/*.pc
+  '';
+}
+
diff --git a/pkgs/os-specific/linux/udev/145.nix b/pkgs/os-specific/linux/udev/145.nix
new file mode 100644
index 000000000000..6dd551e1ce13
--- /dev/null
+++ b/pkgs/os-specific/linux/udev/145.nix
@@ -0,0 +1,53 @@
+{ stdenv, fetchurl, gperf, pkgconfig, glib, acl, libusb, usbutils, pciutils }:
+
+assert stdenv ? glibc;
+
+stdenv.mkDerivation rec {
+  name = "udev-145";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/utils/kernel/hotplug/${name}.tar.bz2";
+    sha256 = "1zmibp6n7d582fqx8vmg9vb2a1435hghfpz36056bc25ccwf7yiv";
+  };
+
+  buildInputs = [gperf pkgconfig glib acl libusb usbutils];
+
+  configureFlags = "--with-pci-ids-path=${pciutils}/share/pci.ids";
+
+  preConfigure =
+    ''
+      substituteInPlace extras/keymap/Makefile.in \
+        --replace /usr/include ${stdenv.glibc.dev}/include
+    '';
+
+  postInstall =
+    ''
+      # Install some rules that really should be installed by default.
+      for i in 40-alsa.rules 40-infiniband.rules 40-isdn.rules 40-pilot-links.rules 64-device-mapper.rules 64-md-raid.rules; do
+        cp rules/packages/$i $out/libexec/rules.d/
+      done
+
+      # The path to rule_generator.functions in write_cd_rules and
+      # write_net_rules is broken.  Also, don't store the mutable
+      # persistant rules in /etc/udev/rules.d but in
+      # /var/lib/udev/rules.d.
+      for i in $out/libexec/write_cd_rules $out/libexec/write_net_rules; do
+        substituteInPlace $i \
+          --replace /lib/udev $out/libexec \
+          --replace /etc/udev/rules.d /var/lib/udev/rules.d
+      done
+
+      # Don't set PATH to /bin:/sbin; won't work in NixOS.
+      substituteInPlace $out/libexec/rule_generator.functions \
+        --replace 'PATH=' '#PATH='
+
+      # Don't hardcore the FIRMWARE_DIRS variable; obtain it from the
+      # environment of the caller.
+      sed '3,4d' -i $out/libexec/firmware.sh
+    '';
+
+  meta = {
+    homepage = http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html;
+    description = "Udev manages the /dev filesystem";
+  };
+}
diff --git a/pkgs/os-specific/linux/util-linux/default.nix b/pkgs/os-specific/linux/util-linux/default.nix
index bcd9aa58bccf..ec5c77699ecb 100644
--- a/pkgs/os-specific/linux/util-linux/default.nix
+++ b/pkgs/os-specific/linux/util-linux/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, zlib, ncurses ? null, perl ? null, pam }:
+{ stdenv, fetchurl, pkgconfig, zlib, ncurses ? null, perl ? null, pam }:
 
 stdenv.mkDerivation rec {
   name = "util-linux-2.27.1";
@@ -8,12 +8,15 @@ stdenv.mkDerivation rec {
     sha256 = "1452hz5zx56a3mad8yrg5wb0vy5zi19mpjp6zx1yr6p9xp6qz08a";
   };
 
-  outputs = [ "out" "man" ];
-
   patches = [
     ./rtcwake-search-PATH-for-shutdown.patch
   ];
 
+  outputs = [ "bin" "out" "man" ]; # TODO: $bin is kept the first for now
+  # due to lots of ${utillinux}/bin occurences and headers being rather small
+  outputDev = "bin";
+
+
   #FIXME: make it also work on non-nixos?
   postPatch = ''
     # Substituting store paths would create a circular dependency on systemd
@@ -40,21 +43,25 @@ stdenv.mkDerivation rec {
     ${if ncurses == null then "--without-ncurses" else ""}
   '';
 
+  makeFlags = "usrbin_execdir=$(bin)/bin usrsbin_execdir=$(bin)/sbin";
+
+  nativeBuildInputs = [ pkgconfig ];
   buildInputs =
     [ zlib pam ]
     ++ stdenv.lib.optional (ncurses != null) ncurses
     ++ stdenv.lib.optional (perl != null) perl;
 
   postInstall = ''
-    rm $out/bin/su # su should be supplied by the su package (shadow)
+    rm "$bin/bin/su" # su should be supplied by the su package (shadow)
   '';
 
   enableParallelBuilding = true;
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.kernel.org/pub/linux/utils/util-linux/;
     description = "A set of system utilities for Linux";
-    platforms = stdenv.lib.platforms.linux;
+    license = licenses.gpl2; # also contains parts under more permissive licenses
+    platforms = platforms.linux;
     priority = 6; # lower priority than coreutils ("kill") and shadow ("login" etc.) packages
   };
 }
diff --git a/pkgs/servers/dns/nsd/default.nix b/pkgs/servers/dns/nsd/default.nix
index 2bd755d03246..4acd90fba0fe 100644
--- a/pkgs/servers/dns/nsd/default.nix
+++ b/pkgs/servers/dns/nsd/default.nix
@@ -35,7 +35,7 @@ stdenv.mkDerivation rec {
      ++ edf rootServer       "root-server"
      ++ edf rrtypes          "draft-rrtypes"
      ++ edf zoneStats        "zone-stats"
-     ++ [ "--with-ssl=${openssl}" "--with-libevent=${libevent}" ];
+     ++ [ "--with-ssl=${openssl.dev}" "--with-libevent=${libevent.dev}" ];
 
   meta = with stdenv.lib; {
     homepage = http://www.nlnetlabs.nl;
diff --git a/pkgs/servers/http/apache-httpd/2.2.nix b/pkgs/servers/http/apache-httpd/2.2.nix
index 99d6fe12aa1c..bb4fa9782d6a 100644
--- a/pkgs/servers/http/apache-httpd/2.2.nix
+++ b/pkgs/servers/http/apache-httpd/2.2.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, openssl, perl, zlib
+{ stdenv, fetchurl, pkgconfig, openssl, perl, zlib
 , sslSupport, proxySupport ? true
 , apr, aprutil, pcre
 , ldapSupport ? true, openldap
@@ -20,17 +20,24 @@ stdenv.mkDerivation rec {
     sha256 = "1b165zi7jrrlz5wmyy3b34lcs3dl4g0dymfb0qxwdnimylcrsbzk";
   };
 
-  buildInputs = [perl apr aprutil pcre] ++
-    stdenv.lib.optional sslSupport openssl;
+  # FIXME: -dev depends on -doc
+  outputs = [ "dev" "out" "doc" ];
+  setOutputFlags = false; # it would move $out/modules, etc.
 
-  # An apr-util header file includes an apr header file
-  # through #include "" (quotes)
-  # passing simply CFLAGS did not help, then I go by NIX_CFLAGS_COMPILE
-  NIX_CFLAGS_COMPILE = "-iquote ${apr}/include/apr-1";
+  propagatedBuildInputs = [ apr ]; # otherwise mod_* fail to find includes often
+  buildInputs = [ pkgconfig perl aprutil pcre zlib ] ++
+    stdenv.lib.optional sslSupport openssl;
 
   # Required for ‘pthread_cancel’.
   NIX_LDFLAGS = (if stdenv.isDarwin then "" else "-lgcc_s");
 
+  patchPhase = ''
+    sed -i config.layout -e "s|installbuilddir:.*|installbuilddir: $dev/share/build|"
+  '';
+
+  preConfigure = ''
+    configureFlags="$configureFlags --includedir=$dev/include"
+  '';
   configureFlags = ''
     --with-z=${zlib}
     --with-pcre=${pcre}
@@ -44,13 +51,18 @@ stdenv.mkDerivation rec {
     --enable-disk-cache
     --enable-file-cache
     --enable-mem-cache
+    --docdir=$(doc)/share/doc
   '';
 
   enableParallelBuilding = true;
 
+  stripDebugList = "lib modules bin";
+
   postInstall = ''
-    echo "removing manual"
-    rm -rf $out/manual
+    mkdir -p $doc/share/doc/httpd
+    mv $out/manual $doc/share/doc/httpd
+    mkdir -p $dev/bin
+    mv $out/bin/apxs $dev/bin/apxs
   '';
 
   passthru = {
diff --git a/pkgs/servers/http/apache-httpd/2.4.nix b/pkgs/servers/http/apache-httpd/2.4.nix
index ddb1ec443a06..9b2d86715bf7 100644
--- a/pkgs/servers/http/apache-httpd/2.4.nix
+++ b/pkgs/servers/http/apache-httpd/2.4.nix
@@ -22,14 +22,26 @@ stdenv.mkDerivation rec {
     sha256 = "0k7xm6ldzvakzq39nw6b39190ihlkc28all2gkvckxa1vr8b0i06";
   };
 
+  # FIXME: -dev depends on -doc
+  outputs = [ "dev" "out" "doc" ];
+  setOutputFlags = false; # it would move $out/modules, etc.
+
   buildInputs = [perl] ++
+    optional sslSupport openssl ++
     optional ldapSupport openldap ++    # there is no --with-ldap flag
     optional libxml2Support libxml2 ++
     optional stdenv.isDarwin libiconv;
 
+  patchPhase = ''
+    sed -i config.layout -e "s|installbuilddir:.*|installbuilddir: $dev/share/build|"
+  '';
+
   # Required for ‘pthread_cancel’.
   NIX_LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
 
+  preConfigure = ''
+    configureFlags="$configureFlags --includedir=$dev/include"
+  '';
   configureFlags = ''
     --with-apr=${apr}
     --with-apr-util=${aprutil}
@@ -43,18 +55,21 @@ stdenv.mkDerivation rec {
     --enable-imagemap
     --enable-cgi
     ${optionalString proxySupport "--enable-proxy"}
-    ${optionalString sslSupport "--enable-ssl --with-ssl=${openssl}"}
+    ${optionalString sslSupport "--enable-ssl"}
     ${optionalString luaSupport "--enable-lua --with-lua=${lua5}"}
-    ${optionalString libxml2Support "--with-libxml2=${libxml2}/include/libxml2"}
+    ${optionalString libxml2Support "--with-libxml2=${libxml2.dev}/include/libxml2"}
+    --docdir=$(doc)/share/doc
   '';
 
+  enableParallelBuilding = true;
+
   postInstall = ''
-    echo "removing manual"
-    rm -rf $out/manual
+    mkdir -p $doc/share/doc/httpd
+    mv $out/manual $doc/share/doc/httpd
+    mkdir -p $dev/bin
+    mv $out/bin/apxs $dev/bin/apxs
   '';
 
-  enableParallelBuilding = true;
-
   passthru = {
     inherit apr aprutil sslSupport proxySupport ldapSupport;
   };
diff --git a/pkgs/servers/http/apache-modules/mod_fastcgi/default.nix b/pkgs/servers/http/apache-modules/mod_fastcgi/default.nix
index e70c3105408f..178900570d07 100644
--- a/pkgs/servers/http/apache-modules/mod_fastcgi/default.nix
+++ b/pkgs/servers/http/apache-modules/mod_fastcgi/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
 
   preBuild = ''
     cp Makefile.AP2 Makefile
-    makeFlags="top_dir=${apacheHttpd} prefix=$out"
+    makeFlags="top_dir=${apacheHttpd}/share prefix=$out"
   '';
 
   meta = {
diff --git a/pkgs/servers/http/nginx/default.nix b/pkgs/servers/http/nginx/default.nix
index 6944a89477ad..f7789dff5a9c 100644
--- a/pkgs/servers/http/nginx/default.nix
+++ b/pkgs/servers/http/nginx/default.nix
@@ -51,7 +51,7 @@ stdenv.mkDerivation rec {
         [ "--with-file-aio" "--with-aio_module" ]
     ++ map (mod: "--add-module=${mod.src}") modules;
 
-  NIX_CFLAGS_COMPILE = [ "-I${libxml2}/include/libxml2" ] ++ optional stdenv.isDarwin "-Wno-error=deprecated-declarations -Wno-error=conditional-uninitialized";
+  NIX_CFLAGS_COMPILE = [ "-I${libxml2.dev}/include/libxml2" ] ++ optional stdenv.isDarwin "-Wno-error=deprecated-declarations -Wno-error=conditional-uninitialized";
 
   preConfigure = concatMapStringsSep "\n" (mod: mod.preConfigure or "") modules;
 
diff --git a/pkgs/servers/http/nginx/unstable.nix b/pkgs/servers/http/nginx/unstable.nix
index 994a3a294801..cfc55c0f55db 100644
--- a/pkgs/servers/http/nginx/unstable.nix
+++ b/pkgs/servers/http/nginx/unstable.nix
@@ -49,7 +49,7 @@ stdenv.mkDerivation rec {
     ++ optional (elem stdenv.system (with platforms; linux ++ freebsd)) "--with-file-aio"
     ++ map (mod: "--add-module=${mod.src}") modules;
 
-  NIX_CFLAGS_COMPILE = [ "-I${libxml2}/include/libxml2" ] ++ optional stdenv.isDarwin "-Wno-error=deprecated-declarations";
+  NIX_CFLAGS_COMPILE = [ "-I${libxml2.dev}/include/libxml2" ] ++ optional stdenv.isDarwin "-Wno-error=deprecated-declarations";
 
   preConfigure = concatMapStringsSep "\n" (mod: mod.preConfigure or "") modules;
 
diff --git a/pkgs/servers/http/openresty/default.nix b/pkgs/servers/http/openresty/default.nix
index 14f95761cfb1..147e24c014d2 100644
--- a/pkgs/servers/http/openresty/default.nix
+++ b/pkgs/servers/http/openresty/default.nix
@@ -46,8 +46,8 @@ stdenv.mkDerivation rec {
   '';
 
   preConfigure = ''
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${libxml2}/include/libxml2 $additionalFlags"
-    export PATH="$PATH:${stdenv.cc.libc}/sbin"
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${libxml2.dev}/include/libxml2 $additionalFlags"
+    export PATH="$PATH:${stdenv.cc.libc.bin}/bin"
     patchShebangs .
   '';
 
diff --git a/pkgs/servers/mail/opensmtpd/default.nix b/pkgs/servers/mail/opensmtpd/default.nix
index cb098a84a94f..03367c7b50d9 100644
--- a/pkgs/servers/mail/opensmtpd/default.nix
+++ b/pkgs/servers/mail/opensmtpd/default.nix
@@ -26,7 +26,7 @@ stdenv.mkDerivation rec {
     "--with-privsep-user=smtpd"
     "--with-queue-user=smtpq"
     "--with-ca-file=/etc/ssl/certs/ca-certificates.crt"
-    "--with-libevent-dir=${libevent}"
+    "--with-libevent-dir=${libevent.dev}"
   ];
 
   installFlags = [
diff --git a/pkgs/servers/meteor/default.nix b/pkgs/servers/meteor/default.nix
index 5e13b4520c9b..7412378f3dec 100644
--- a/pkgs/servers/meteor/default.nix
+++ b/pkgs/servers/meteor/default.nix
@@ -40,7 +40,7 @@ stdenv.mkDerivation rec {
     popd
     substituteInPlace $out/tools/cli/main.js \
       --replace "@INTERPRETER@" "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-      --replace "@RPATH@" "${stdenv.cc.cc}/lib:${zlib}/lib" \
+      --replace "@RPATH@" "${stdenv.cc.cc}/lib:${zlib.out}/lib" \
       --replace "@PATCHELF@" "${patchelf}/bin/patchelf"
 
     # Patch node.
@@ -54,7 +54,7 @@ stdenv.mkDerivation rec {
     for p in $devBundle/mongodb/bin/mongo{,d}; do
       patchelf \
         --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
-        --set-rpath "$(patchelf --print-rpath $p):${stdenv.cc.cc}/lib:${zlib}/lib" \
+        --set-rpath "$(patchelf --print-rpath $p):${stdenv.cc.cc}/lib:${zlib.out}/lib" \
         $p
     done
 
diff --git a/pkgs/servers/monitoring/net-snmp/default.nix b/pkgs/servers/monitoring/net-snmp/default.nix
index f2533c99b083..816ac1bdb25e 100644
--- a/pkgs/servers/monitoring/net-snmp/default.nix
+++ b/pkgs/servers/monitoring/net-snmp/default.nix
@@ -31,6 +31,12 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
+  postInstall = ''
+    for f in $out/lib/*.la $out/bin/net-snmp-config $out/bin/net-snmp-create-v3-user; do
+      sed 's|-L${openssl}|-L${openssl.out}|g' -i $f
+    done
+  '';
+
   meta = with stdenv.lib; {
     description = "Clients and server for the SNMP network monitoring protocol";
     homepage = http://net-snmp.sourceforge.net/;
diff --git a/pkgs/servers/nosql/arangodb/default.nix b/pkgs/servers/nosql/arangodb/default.nix
index 4ff12f630c9b..473b5d717dea 100644
--- a/pkgs/servers/nosql/arangodb/default.nix
+++ b/pkgs/servers/nosql/arangodb/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
     openssl zlib python gyp go readline
   ];
 
-  configureFlagsArray = [ "--with-openssl-lib=${openssl}/lib" ];
+  configureFlagsArray = [ "--with-openssl-lib=${openssl.out}/lib" ];
 
   patchPhase = ''
     substituteInPlace 3rdParty/V8-3.31.74.1/build/gyp/gyp --replace /bin/bash ${bash}/bin/bash
diff --git a/pkgs/servers/nosql/eventstore/default.nix b/pkgs/servers/nosql/eventstore/default.nix
index a42212ade084..b300ad5b806d 100644
--- a/pkgs/servers/nosql/eventstore/default.nix
+++ b/pkgs/servers/nosql/eventstore/default.nix
@@ -23,8 +23,8 @@ stdenv.mkDerivation rec {
 
   buildPhase = ''
     ln -s ${v8}/lib/libv8.so src/libs/libv8.so
-    ln -s ${icu}/lib/libicui18n.so src/libs/libicui18n.so
-    ln -s ${icu}/lib/libicuuc.so src/libs/libicuuc.so
+    ln -s ${icu.out}/lib/libicui18n.so src/libs/libicui18n.so
+    ln -s ${icu.out}/lib/libicuuc.so src/libs/libicuuc.so
 
     patchShebangs build.sh
     ./build.sh js1
diff --git a/pkgs/servers/openafs-client/default.nix b/pkgs/servers/openafs-client/default.nix
index 5d8e255f47f1..cfeafed0da20 100644
--- a/pkgs/servers/openafs-client/default.nix
+++ b/pkgs/servers/openafs-client/default.nix
@@ -30,7 +30,7 @@ stdenv.mkDerivation {
     for i in `grep -l -R '/usr/\(include\|src\)' .`; do
       echo "Patch /usr/include and /usr/src in $i"
       substituteInPlace $i \
-        --replace "/usr/include" "${glibc}/include" \
+        --replace "/usr/include" "${glibc.dev}/include" \
         --replace "/usr/src" "$TMP"
     done
 
diff --git a/pkgs/servers/plex/default.nix b/pkgs/servers/plex/default.nix
index 2aeb9379e10f..d88f7a89493d 100644
--- a/pkgs/servers/plex/default.nix
+++ b/pkgs/servers/plex/default.nix
@@ -27,12 +27,12 @@ stdenv.mkDerivation rec {
     # Now we need to patch up the executables and libraries to work on Nix.
     # Side note: PLEASE don't put spaces in your binary names. This is stupid.
     for bin in "Plex Media Server" "Plex DLNA Server" "Plex Media Scanner"; do
-      patchelf --set-interpreter "${glibc}/lib/ld-linux-x86-64.so.2" "$out/usr/lib/plexmediaserver/$bin"
+      patchelf --set-interpreter "${glibc.out}/lib/ld-linux-x86-64.so.2" "$out/usr/lib/plexmediaserver/$bin"
       patchelf --set-rpath "$out/usr/lib/plexmediaserver" "$out/usr/lib/plexmediaserver/$bin"
     done
 
     find $out/usr/lib/plexmediaserver/Resources -type f -a -perm -0100 \
-        -print -exec patchelf --set-interpreter "${glibc}/lib/ld-linux-x86-64.so.2" '{}' \;
+        -print -exec patchelf --set-interpreter "${glibc.out}/lib/ld-linux-x86-64.so.2" '{}' \;
 
     # executables need libstdc++.so.6
     ln -s "${stdenv.lib.makeLibraryPath [ stdenv.cc.cc ]}/libstdc++.so.6" "$out/usr/lib/plexmediaserver/libstdc++.so.6"
diff --git a/pkgs/servers/pulseaudio/default.nix b/pkgs/servers/pulseaudio/default.nix
index 392d16c6e548..66ed31bab7b9 100644
--- a/pkgs/servers/pulseaudio/default.nix
+++ b/pkgs/servers/pulseaudio/default.nix
@@ -43,6 +43,8 @@ stdenv.mkDerivation rec {
 
   patches = [ ./caps-fix.patch ];
 
+  outputs = [ "dev" "out" ];
+
   nativeBuildInputs = [ pkgconfig intltool autoreconfHook ];
 
   propagatedBuildInputs =
@@ -50,7 +52,7 @@ stdenv.mkDerivation rec {
 
   buildInputs =
     [ json_c libsndfile speexdsp fftwFloat ]
-    ++ lib.optionals stdenv.isLinux [ glib dbus.libs ]
+    ++ lib.optionals stdenv.isLinux [ glib dbus ]
     ++ lib.optionals (!libOnly) (
       [ libasyncns webrtc-audio-processing ]
       ++ lib.optional jackaudioSupport libjack2
@@ -110,8 +112,9 @@ stdenv.mkDerivation rec {
 
   postInstall = lib.optionalString libOnly ''
     rm -rf $out/{bin,share,etc,lib/{pulse-*,systemd}}
-    sed 's|-lltdl|-L${libtool}/lib -lltdl|' -i $out/lib/libpulsecore-${version}.la
-  '';
+    sed 's|-lltdl|-L${libtool.lib}/lib -lltdl|' -i $out/lib/libpulsecore-${version}.la
+  ''
+    + ''moveToOutput lib/cmake "$dev" '';
 
   meta = {
     description = "Sound server for POSIX and Win32 systems";
diff --git a/pkgs/servers/shellinabox/default.nix b/pkgs/servers/shellinabox/default.nix
index 0a651762f185..6df4905af2cd 100644
--- a/pkgs/servers/shellinabox/default.nix
+++ b/pkgs/servers/shellinabox/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     wrapProgram $out/bin/shellinaboxd \
-      --prefix LD_LIBRARY_PATH : ${openssl}/lib
+      --prefix LD_LIBRARY_PATH : ${openssl.out}/lib
     mkdir -p $out/lib
     cp shellinabox/* $out/lib
   '';
diff --git a/pkgs/servers/shishi/default.nix b/pkgs/servers/shishi/default.nix
index e26fd6ca749e..85dfa805fc14 100644
--- a/pkgs/servers/shishi/default.nix
+++ b/pkgs/servers/shishi/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl
+{ stdenv, fetchurl, pkgconfig
 , libgcrypt, libgpgerror, libtasn1
 
 # Optional Dependencies
@@ -31,6 +31,7 @@ stdenv.mkDerivation rec {
   # Fixes support for gcrypt 1.6+
   patches = [ ./gcrypt-fix.patch ./freebsd-unistd.patch ];
 
+  nativeBuildInputs = [ pkgconfig ];
   buildInputs = [ libgcrypt libgpgerror libtasn1 optPam optLibidn optGnutls ];
 
   configureFlags = [
@@ -60,13 +61,13 @@ stdenv.mkDerivation rec {
   postInstall = ''
     sed -i $out/lib/libshi{sa,shi}.la \
   '' + optionalString (optLibidn != null) ''
-      -e 's,\(-lidn\),-L${optLibidn}/lib \1,' \
+      -e 's,\(-lidn\),-L${optLibidn.out}/lib \1,' \
   '' + optionalString (optGnutls != null) ''
-      -e 's,\(-lgnutls\),-L${optGnutls}/lib \1,' \
+      -e 's,\(-lgnutls\),-L${optGnutls.out}/lib \1,' \
   '' + ''
-      -e 's,\(-lgcrypt\),-L${libgcrypt}/lib \1,' \
-      -e 's,\(-lgpg-error\),-L${libgpgerror}/lib \1,' \
-      -e 's,\(-ltasn1\),-L${libtasn1}/lib \1,'
+      -e 's,\(-lgcrypt\),-L${libgcrypt.out}/lib \1,' \
+      -e 's,\(-lgpg-error\),-L${libgpgerror.out}/lib \1,' \
+      -e 's,\(-ltasn1\),-L${libtasn1.out}/lib \1,'
   '';
 
   meta = {
diff --git a/pkgs/servers/sql/mariadb/default.nix b/pkgs/servers/sql/mariadb/default.nix
index eb132a0be22f..340e29e94b3e 100644
--- a/pkgs/servers/sql/mariadb/default.nix
+++ b/pkgs/servers/sql/mariadb/default.nix
@@ -60,13 +60,15 @@ stdenv.mkDerivation rec {
   ] ++ stdenv.lib.optionals stdenv.isDarwin [
     "-DWITHOUT_OQGRAPH_STORAGE_ENGINE=1"
     "-DWITHOUT_TOKUDB=1"
-    "-DCURSES_LIBRARY=${ncurses}/lib/libncurses.dylib"
+    "-DCURSES_LIBRARY=${ncurses.lib}/lib/libncurses.dylib"
   ];
 
   # fails to find lex_token.h sometimes
   enableParallelBuilding = true;
 
   outputs = [ "out" "lib" ];
+  setOutputFlags = false;
+  moveToDev = false;
 
   prePatch = ''
     substituteInPlace cmake/libutils.cmake \
@@ -112,8 +114,8 @@ stdenv.mkDerivation rec {
   '' + ''
     # Fix the mysql_config
     sed -i $out/bin/mysql_config \
-      -e 's,-lz,-L${zlib}/lib -lz,g' \
-      -e 's,-lssl,-L${openssl}/lib -lssl,g'
+      -e 's,-lz,-L${zlib.out}/lib -lz,g' \
+      -e 's,-lssl,-L${openssl.out}/lib -lssl,g'
 
     # Add mysql_config to libs since configure scripts use it
     mkdir -p $lib/bin
diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix
index 9a5b07e9f89a..c5daaa626a7a 100644
--- a/pkgs/servers/sql/postgresql/default.nix
+++ b/pkgs/servers/sql/postgresql/default.nix
@@ -10,7 +10,8 @@ let
       inherit sha256;
     };
 
-    outputs = [ "out" "doc" ];
+    outputs = [ "out" "lib" "doc" ];
+    setOutputFlags = false; # $out retains configureFlags :-/
 
     buildInputs =
       [ zlib readline openssl ]
@@ -20,8 +21,11 @@ let
 
     makeFlags = [ "world" ];
 
-    configureFlags =
-      [ "--with-openssl" ]
+    configureFlags = [
+      "--with-openssl"
+      "--sysconfdir=/etc"
+      "--libdir=$(lib)/lib"
+    ]
       ++ lib.optional (stdenv.isDarwin)  "--with-uuid=e2fs"
       ++ lib.optional (!stdenv.isDarwin) "--with-ossp-uuid";
 
@@ -36,8 +40,12 @@ let
 
     postInstall =
       ''
+        moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it
+        moveToOutput "lib/*.a" "$out"
+        moveToOutput "lib/libecpg*" "$out"
+
         # Prevent a retained dependency on gcc-wrapper.
-        substituteInPlace $out/lib/pgxs/src/Makefile.global --replace ${stdenv.cc}/bin/ld ld
+        substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv.cc}/bin/ld ld
       '';
 
     disallowedReferences = [ stdenv.cc ];
diff --git a/pkgs/servers/x11/xorg/builder.sh b/pkgs/servers/x11/xorg/builder.sh
index f5b8803a98a3..c9e53f3800d3 100644
--- a/pkgs/servers/x11/xorg/builder.sh
+++ b/pkgs/servers/x11/xorg/builder.sh
@@ -10,7 +10,7 @@ postInstall() {
 
     local r p requires
     set +o pipefail
-    requires=$(grep "Requires:" $out/lib/pkgconfig/*.pc | \
+    requires=$(grep "Requires:" ${!outputDev}/lib/pkgconfig/*.pc | \
         sed "s/Requires://" | sed "s/,/ /g")
     set -o pipefail
 
@@ -33,10 +33,6 @@ postInstall() {
             done
         fi
     done
-
-    mkdir -p "$out/nix-support"
-    echo "$propagatedBuildInputs" > "$out/nix-support/propagated-build-inputs"
-    echo "$propagatedNativeBuildInputs" > "$out/nix-support/propagated-native-build-inputs"
 }
 
 
diff --git a/pkgs/servers/x11/xorg/default.nix b/pkgs/servers/x11/xorg/default.nix
index b9ea5d7c5828..22b4e750772a 100644
--- a/pkgs/servers/x11/xorg/default.nix
+++ b/pkgs/servers/x11/xorg/default.nix
@@ -2347,6 +2347,21 @@ let
     meta.platforms = stdenv.lib.platforms.unix;
   }) // {inherit dri2proto dri3proto renderproto libdrm openssl libX11 libXau libXaw libxcb xcbutil xcbutilwm xcbutilimage xcbutilkeysyms xcbutilrenderutil libXdmcp libXfixes libxkbfile libXmu libXpm libXrender libXres libXt ;};
 
+  # TODO:
+  # With the current state of ./generate-expr-from-tarballs.pl,
+  # this will get overwritten when next invoked.
+  # Could add a special case to ./generate-expr-from-tarballs.pl,
+  # or perhaps there's a cleaner solution.
+  #xquartz = (mkDerivation "xquartz" {
+  #  name = "xorg-server-1.14.6";
+  #  builder = ./builder.sh;
+  #  src = fetchurl {
+  #    url = mirror://xorg/individual/xserver/xorg-server-1.14.6.tar.bz2;
+  #    sha256 = "0c57vp1z0p38dj5gfipkmlw6bvbz1mrr0sb3sbghdxxdyq4kzcz8";
+  #  };
+  #  buildInputs = [pkgconfig renderproto libdrm openssl libX11 libXau libXaw libXdmcp libXfixes libxkbfile libXmu libXpm libXrender libXres libXt libXv ];
+  #}) // {inherit renderproto libdrm openssl libX11 libXau libXaw libXdmcp libXfixes libxkbfile libXmu libXpm libXrender libXres libXt libXv ;};
+
   xorgsgmldoctools = (mkDerivation "xorgsgmldoctools" {
     name = "xorg-sgml-doctools-1.11";
     builder = ./builder.sh;
diff --git a/pkgs/servers/x11/xorg/imake-cc-wrapper-uberhack.patch b/pkgs/servers/x11/xorg/imake-cc-wrapper-uberhack.patch
new file mode 100644
index 000000000000..fe079eeb42a7
--- /dev/null
+++ b/pkgs/servers/x11/xorg/imake-cc-wrapper-uberhack.patch
@@ -0,0 +1,13 @@
+diff --git a/imake.c b/imake.c
+index c20cd4a..ec2589b 100644
+--- a/imake.c
++++ b/imake.c
+@@ -959,7 +959,7 @@ get_libc_version(FILE *inFile)
+ {
+   char aout[4096], *tmpdir;
+   FILE *fp;
+-  const char *format = "%s -o %s -x c -";
++  const char *format = "f=$(mktemp imakeXXXXXX.c); cat > $f; %s $f -o %s";
+   char *cc;
+   int len;
+   char *command;
diff --git a/pkgs/servers/x11/xorg/overrides.nix b/pkgs/servers/x11/xorg/overrides.nix
index 7bd179067cd0..a0405ec077f3 100644
--- a/pkgs/servers/x11/xorg/overrides.nix
+++ b/pkgs/servers/x11/xorg/overrides.nix
@@ -48,7 +48,7 @@ in
   imake = attrs: attrs // {
     inherit (xorg) xorgcffiles;
     x11BuildHook = ./imake.sh;
-    patches = [./imake.patch];
+    patches = [./imake.patch ./imake-cc-wrapper-uberhack.patch];
     setupHook = if stdenv.isDarwin then ./darwin-imake-setup-hook.sh else null;
     CFLAGS = [ "-DIMAKE_COMPILETIME_CPP=\\\"${if stdenv.isDarwin
       then "${args.tradcpp}/bin/cpp"
@@ -73,7 +73,7 @@ in
   libxcb = attrs : attrs // {
     nativeBuildInputs = [ args.python ];
     configureFlags = "--enable-xkb --enable-xinput";
-    outputs = [ "out" "doc" "man" ];
+    outputs = [ "dev" "out" "doc" ];
   };
 
   xcbproto = attrs : attrs // {
@@ -81,6 +81,7 @@ in
   };
 
   libX11 = attrs: attrs // {
+    outputs = [ "dev" "out" "man" ];
     preConfigure = setMalloc0ReturnsNullCrossCompiling + ''
       sed 's,^as_dummy.*,as_dummy="\$PATH",' -i configure
     '';
@@ -90,7 +91,6 @@ in
         rm -rf $out/share/doc
       '';
     CPP = stdenv.lib.optionalString stdenv.isDarwin "clang -E -";
-    outputs = [ "out" "man" ];
   };
 
   libAppleWM = attrs: attrs // {
@@ -100,7 +100,16 @@ in
     '';
   };
 
+  libXau = attrs: attrs // {
+    outputs = [ "dev" "out" ];
+  };
+
+  libXdmcp = attrs: attrs // {
+    outputs = [ "dev" "out" "doc" ];
+  };
+
   libXfont = attrs: attrs // {
+    outputs = [ "dev" "out" ];
     propagatedBuildInputs = [ args.freetype ]; # propagate link reqs. like bzip2
     # prevents "misaligned_stack_error_entering_dyld_stub_binder"
     configureFlags = lib.optionals isDarwin [
@@ -109,14 +118,10 @@ in
   };
 
   libXxf86vm = attrs: attrs // {
+    outputs = [ "dev" "out" ];
     preConfigure = setMalloc0ReturnsNullCrossCompiling;
   };
 
-  libXrandr = attrs: attrs // {
-    preConfigure = setMalloc0ReturnsNullCrossCompiling;
-    propagatedBuildInputs = [xorg.libXrender];
-  };
-
   # Propagate some build inputs because of header file dependencies.
   # Note: most of these are in Requires.private, so maybe builder.sh
   # should propagate them automatically.
@@ -126,7 +131,7 @@ in
     '';
     propagatedBuildInputs = [ xorg.libSM ];
     CPP = stdenv.lib.optionalString stdenv.isDarwin "clang -E -";
-    outputs = [ "out" "doc" "man" ];
+    outputs = [ "dev" "out" "docdev" ];
   };
 
   # See https://bugs.freedesktop.org/show_bug.cgi?id=47792
@@ -139,44 +144,106 @@ in
     propagatedBuildInputs = [ xorg.fixesproto ];
   };
 
+  libICE = attrs: attrs // {
+    outputs = [ "dev" "out" "doc" ];
+  };
+
   libXcomposite = attrs: attrs // {
+    outputs = [ "dev" "out" ];
     propagatedBuildInputs = [ xorg.libXfixes ];
   };
 
   libXaw = attrs: attrs // {
+    outputs = [ "dev" "out" "docdev" ];
     propagatedBuildInputs = [ xorg.libXmu ];
   };
 
+  libXcursor = attrs: attrs // {
+    outputs = [ "dev" "out" ];
+  };
+
+  libXdamage = attrs: attrs // {
+    outputs = [ "dev" "out" ];
+  };
+
   libXft = attrs: attrs // {
+    outputs = [ "dev" "out" ];
     propagatedBuildInputs = [ xorg.libXrender args.freetype args.fontconfig ];
     preConfigure = setMalloc0ReturnsNullCrossCompiling;
     # the include files need ft2build.h, and Requires.private isn't enough for us
     postInstall = ''
-      sed "/^Requires:/s/$/, freetype2/" -i "$out/lib/pkgconfig/xft.pc"
+      sed "/^Requires:/s/$/, freetype2/" -i "$dev/lib/pkgconfig/xft.pc"
     '';
   };
 
   libXext = attrs: attrs // {
+    outputs = [ "dev" "out" "doc" ];
     propagatedBuildInputs = [ xorg.xproto xorg.libXau ];
     preConfigure = setMalloc0ReturnsNullCrossCompiling;
   };
 
-  libSM = attrs: attrs
-    // { propagatedBuildInputs = [ xorg.libICE ]; };
+  libXfixes = attrs: attrs // {
+    outputs = [ "dev" "out" ];
+  };
+
+  libXi = attrs: attrs // {
+    outputs = [ "dev" "out" "doc" ];
+  };
+
+  libXinerama = attrs: attrs // {
+    outputs = [ "dev" "out" ];
+  };
+
+  libXmu = attrs: attrs // {
+    outputs = [ "dev" "out" "doc" ];
+    buildFlags = ''BITMAP_DEFINES=-DBITMAPDIR=\"/no-such-path\"'';
+  };
+
+  libXrandr = attrs: attrs // {
+    outputs = [ "dev" "out" ];
+    preConfigure = setMalloc0ReturnsNullCrossCompiling;
+    propagatedBuildInputs = [xorg.libXrender];
+  };
+
+  libSM = attrs: attrs // {
+    outputs = [ "dev" "out" "doc" ];
+    propagatedBuildInputs = [ xorg.libICE ];
+  };
 
-  libXrender = attrs: attrs
-    // { preConfigure = setMalloc0ReturnsNullCrossCompiling; };
+  libXrender = attrs: attrs // {
+    outputs = [ "dev" "out" "doc" ];
+    preConfigure = setMalloc0ReturnsNullCrossCompiling;
+  };
 
-  libXvMC = attrs: attrs
-    // { buildInputs = attrs.buildInputs ++ [xorg.renderproto]; };
+  libXres = attrs: attrs // {
+    outputs = [ "dev" "out" "docdev" ];
+  };
+
+  libXv = attrs: attrs // {
+    outputs = [ "dev" "out" "docdev" ];
+  };
+
+  libXvMC = attrs: attrs // {
+    outputs = [ "dev" "out" "doc" ];
+    buildInputs = attrs.buildInputs ++ [xorg.renderproto];
+  };
 
   libXpm = attrs: attrs // {
+    outputs = [ "dev" "out" "bin" ]; # tiny man in $bin
     patchPhase = "sed -i '/USE_GETTEXT_TRUE/d' sxpm/Makefile.in cxpm/Makefile.in";
   };
 
   libXpresent = attrs: attrs
     // { buildInputs = with xorg; attrs.buildInputs ++ [ libXext libXfixes libXrandr ]; };
 
+  libxkbfile = attrs: attrs // {
+    outputs = [ "dev" "out" ]; # mainly to avoid propagation
+  };
+
+  libxshmfence = attrs: attrs // {
+    outputs = [ "dev" "out" ]; # mainly to avoid propagation
+  };
+
   setxkbmap = attrs: attrs // {
     postInstall =
       ''
@@ -193,10 +260,30 @@ in
     buildInputs = attrs.buildInputs ++ [ args.freetype args.fontconfig ];
   };
 
+  xcbutil = attrs: attrs // {
+    outputs = [ "dev" "out" ];
+  };
+
   xcbutilcursor = attrs: attrs // {
     meta.maintainers = [ stdenv.lib.maintainers.lovek323 ];
   };
 
+  xcbutilimage = attrs: attrs // {
+    outputs = [ "dev" "out" ]; # mainly to get rid of propagating others
+  };
+
+  xcbutilkeysyms = attrs: attrs // {
+    outputs = [ "dev" "out" ]; # mainly to get rid of propagating others
+  };
+
+  xcbutilrenderutil = attrs: attrs // {
+    outputs = [ "dev" "out" ]; # mainly to get rid of propagating others
+  };
+
+  xcbutilwm = attrs: attrs // {
+    outputs = [ "dev" "out" ]; # mainly to get rid of propagating others
+  };
+
   xf86inputevdev = attrs: attrs // {
     preBuild = "sed -e '/motion_history_proc/d; /history_size/d;' -i src/*.c";
     installFlags = "sdkdir=\${out}/include/xorg";
@@ -280,7 +367,7 @@ in
       version = (builtins.parseDrvName attrs.name).version;
       commonBuildInputs = attrs.buildInputs ++ [ xtrans ];
       commonPropagatedBuildInputs = [
-        args.zlib args.mesa args.dbus.libs
+        args.zlib args.mesa args.dbus
         xf86bigfontproto glproto xf86driproto
         compositeproto scrnsaverproto resourceproto
         xf86dgaproto
@@ -307,6 +394,7 @@ in
     in
       if (!isDarwin)
       then {
+        outputs = [ "dev" "out" ];
         buildInputs = [ makeWrapper ] ++ commonBuildInputs;
         propagatedBuildInputs = [ libpciaccess ] ++ commonPropagatedBuildInputs ++ lib.optionals stdenv.isLinux [
           args.udev
@@ -329,6 +417,12 @@ in
             --set XKB_BINDIR "${xorg.xkbcomp}/bin" \
             --set XORG_DRI_DRIVER_PATH ${args.mesa}/lib/dri \
             --add-flags "-xkbdir ${xorg.xkeyboardconfig}/share/X11/xkb"
+          ( # assert() keeps runtime reference xorgserver-dev in xf86-video-intel and others
+            cd "$dev"
+            for f in include/xorg/*.h; do
+              sed "1i#line 1 \"${attrs.name}/$f\"" -i "$f"
+            done
+          )
         '';
         passthru.version = version; # needed by virtualbox guest additions
       } else {
@@ -402,7 +496,7 @@ in
     stdenv = if isDarwin then args.clangStdenv else stdenv;
     buildInputs = attrs.buildInputs ++ lib.optional isDarwin args.bootstrap_cmds;
     configureFlags = [
-      "--with-xserver=${xorg.xorgserver}/bin/X"
+      "--with-xserver=${xorg.xorgserver.out}/bin/X"
     ] ++ lib.optionals isDarwin [
       "--with-bundle-id-prefix=org.nixos.xquartz"
       "--with-launchdaemons-dir=\${out}/LaunchDaemons"
diff --git a/pkgs/servers/x11/xquartz/default.nix b/pkgs/servers/x11/xquartz/default.nix
index 920b66147f26..db0c446617af 100644
--- a/pkgs/servers/x11/xquartz/default.nix
+++ b/pkgs/servers/x11/xquartz/default.nix
@@ -159,7 +159,7 @@ in stdenv.mkDerivation {
       --replace "@ENCODINGSDIR@"    "${xorg.encodings}/share/fonts/X11/encodings" \
       --replace "@MKFONTDIR@"       "${xorg.mkfontdir}/bin/mkfontdir" \
       --replace "@MKFONTSCALE@"     "${xorg.mkfontscale}/bin/mkfontscale" \
-      --replace "@FC_CACHE@"        "${fontconfig}/bin/fc-cache" \
+      --replace "@FC_CACHE@"        "${fontconfig.bin}/bin/fc-cache" \
       --replace "@FONTCONFIG_FILE@" "$fontsConfPath"
 
     cp ${./xinitrc} $out/etc/X11/xinit/xinitrc
diff --git a/pkgs/shells/bash/default.nix b/pkgs/shells/bash/default.nix
index 60504ecaa9bc..e49e7ef5da49 100644
--- a/pkgs/shells/bash/default.nix
+++ b/pkgs/shells/bash/default.nix
@@ -9,6 +9,8 @@ let
   shortName = "bash43";
   baseConfigureFlags = if interactive then "--with-installed-readline" else "--disable-readline";
   sha256 = "1m14s1f61mf6bijfibcjm9y6pkyvz6gibyl8p4hxq90fisi8gimg";
+
+  inherit (stdenv.lib) optional optionalString;
 in
 
 stdenv.mkDerivation rec {
@@ -41,17 +43,17 @@ stdenv.mkDerivation rec {
         };
     in
       import ./bash-4.3-patches.nix patch) 
-      ++ stdenv.lib.optional stdenv.isCygwin ./cygwin-bash-4.3.33-1.src.patch;
+      ++ optional stdenv.isCygwin ./cygwin-bash-4.3.33-1.src.patch;
 
   crossAttrs = {
     configureFlags = baseConfigureFlags +
       " bash_cv_job_control_missing=nomissing bash_cv_sys_named_pipes=nomissing" +
-      stdenv.lib.optionalString stdenv.isCygwin ''
+      optionalString stdenv.isCygwin ''
         --without-libintl-prefix --without-libiconv-prefix
         --with-installed-readline
         bash_cv_dev_stdin=present
         bash_cv_dev_fd=standard
-        bash_cv_termcap_lib=libncurses 
+        bash_cv_termcap_lib=libncurses
       '';
   };
 
@@ -59,20 +61,29 @@ stdenv.mkDerivation rec {
 
   # Note: Bison is needed because the patches above modify parse.y.
   nativeBuildInputs = [bison]
-    ++ stdenv.lib.optional (texinfo != null) texinfo
-    ++ stdenv.lib.optional interactive readline
-    ++ stdenv.lib.optional stdenv.isDarwin binutils;
+    ++ optional (texinfo != null) texinfo
+    ++ optional interactive readline
+    ++ optional stdenv.isDarwin binutils;
 
   # Bash randomly fails to build because of a recursive invocation to
   # build `version.h'.
   enableParallelBuilding = false;
 
   postInstall = ''
-    # Add an `sh' -> `bash' symlink.
     ln -s bash "$out/bin/sh"
   '';
 
-  meta = {
+  postFixup = if interactive
+    then ''
+      substituteInPlace "$out/bin/bashbug" \
+        --replace '${stdenv.shell}' "$out/bin/bash"
+    ''
+    # most space is taken by locale data
+    else ''
+      rm -r "$out/share" "$out/bin/bashbug"
+    '';
+
+  meta = with stdenv.lib; {
     homepage = http://www.gnu.org/software/bash/;
     description =
       "GNU Bourne-Again Shell, the de facto standard shell on Linux" +
@@ -89,11 +100,11 @@ stdenv.mkDerivation rec {
       Bash without modification.
     '';
 
-    license = stdenv.lib.licenses.gpl3Plus;
+    license = licenses.gpl3Plus;
 
-    platforms = stdenv.lib.platforms.all;
+    platforms = platforms.all;
 
-    maintainers = [ stdenv.lib.maintainers.simons ];
+    maintainers = [ maintainers.simons ];
   };
 
   passthru = {
diff --git a/pkgs/stdenv/common-path.nix b/pkgs/stdenv/common-path.nix
index cff6fd0a3eed..da468d56a2cd 100644
--- a/pkgs/stdenv/common-path.nix
+++ b/pkgs/stdenv/common-path.nix
@@ -7,9 +7,9 @@
   pkgs.gawk
   pkgs.gnutar
   pkgs.gzip
-  pkgs.bzip2
+  pkgs.bzip2.bin
   pkgs.gnumake
   pkgs.bash
   pkgs.patch
-  pkgs.xz
+  pkgs.xz.bin
 ]
diff --git a/pkgs/stdenv/darwin/make-bootstrap-tools.nix b/pkgs/stdenv/darwin/make-bootstrap-tools.nix
index d9d501ca0f51..dc52015c52dc 100644
--- a/pkgs/stdenv/darwin/make-bootstrap-tools.nix
+++ b/pkgs/stdenv/darwin/make-bootstrap-tools.nix
@@ -30,9 +30,9 @@ rec {
 
       cp -rL ${darwin.Libsystem}/include $out
       chmod -R u+w $out/include
-      cp -rL ${icu}/include*             $out/include
+      cp -rL ${icu.dev}/include*             $out/include
       cp -rL ${libiconv}/include/*       $out/include
-      cp -rL ${gnugrep.pcre}/include/*   $out/include
+      cp -rL ${gnugrep.pcre.dev}/include/*   $out/include
       mv $out/include $out/include-Libsystem
 
       # Copy coreutils, bash, etc.
@@ -49,23 +49,23 @@ rec {
       cp -d ${gawk}/bin/awk $out/bin
       cp ${gnutar}/bin/tar $out/bin
       cp ${gzip}/bin/gzip $out/bin
-      cp ${bzip2}/bin/bzip2 $out/bin
+      cp ${bzip2.bin}/bin/bzip2 $out/bin
       cp -d ${gnumake}/bin/* $out/bin
       cp -d ${patch}/bin/* $out/bin
-      cp -d ${xz}/bin/xz $out/bin
+      cp -d ${xz.bin}/bin/xz $out/bin
 
       # This used to be in-nixpkgs, but now is in the bundle
       # because I can't be bothered to make it partially static
-      cp ${curl}/bin/curl $out/bin
-      cp -d ${curl}/lib/libcurl*.dylib $out/lib
-      cp -d ${libssh2}/lib/libssh*.dylib $out/lib
-      cp -d ${openssl}/lib/*.dylib $out/lib
+      cp ${curl.bin}/bin/curl $out/bin
+      cp -d ${curl.out}/lib/libcurl*.dylib $out/lib
+      cp -d ${libssh2.out}/lib/libssh*.dylib $out/lib
+      cp -d ${openssl.out}/lib/*.dylib $out/lib
 
-      cp -d ${gnugrep.pcre}/lib/libpcre*.dylib $out/lib
-      cp -d ${libiconv}/lib/lib*.dylib $out/lib
+      cp -d ${gnugrep.pcre.out}/lib/libpcre*.dylib $out/lib
+      cp -d ${libiconv.lib}/lib/lib*.dylib $out/lib
       cp -d ${gettext}/lib/libintl*.dylib $out/lib
       chmod +x $out/lib/libintl*.dylib
-      cp -d ${ncurses}/lib/libncurses*.dylib $out/lib
+      cp -d ${ncurses.lib}/lib/libncurses*.dylib $out/lib
 
       # Copy what we need of clang
       cp -d ${llvmPackages.clang-unwrapped}/bin/clang $out/bin
@@ -80,10 +80,10 @@ rec {
       mkdir $out/include
       cp -rd ${libcxx}/include/c++     $out/include
 
-      cp -d ${icu}/lib/libicu*.dylib $out/lib
-      cp -d ${zlib}/lib/libz.*       $out/lib
-      cp -d ${gmpxx}/lib/libgmp*.*   $out/lib
-      cp -d ${xz}/lib/liblzma*.*     $out/lib
+      cp -d ${icu.out}/lib/libicu*.dylib $out/lib
+      cp -d ${zlib.out}/lib/libz.*       $out/lib
+      cp -d ${gmpxx.out}/lib/libgmp*.*   $out/lib
+      cp -d ${xz.out}/lib/liblzma*.*     $out/lib
 
       # Copy binutils.
       for i in as ld ar ranlib nm strip otool install_name_tool dsymutil; do
@@ -138,7 +138,7 @@ rec {
       cp ${stdenv.shell} $out/on-server/sh
       cp ${cpio}/bin/cpio $out/on-server
       cp ${coreutils_}/bin/mkdir $out/on-server
-      cp ${bzip2}/bin/bzip2 $out/on-server
+      cp ${bzip2.bin}/bin/bzip2 $out/on-server
 
       chmod u+w $out/on-server/*
       strip $out/on-server/*
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index 6dc2553db386..8395394f5a87 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -82,6 +82,7 @@ let
       ../../build-support/setup-hooks/compress-man-pages.sh
       ../../build-support/setup-hooks/strip.sh
       ../../build-support/setup-hooks/patch-shebangs.sh
+      ../../build-support/setup-hooks/multiple-outputs.sh
       ../../build-support/setup-hooks/move-sbin.sh
       ../../build-support/setup-hooks/move-lib64.sh
       ../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index 102a8f2f71c5..2255bbfe669f 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -174,12 +174,21 @@ ensureDir() {
 }
 
 
-installBin() {
-    mkdir -p $out/bin
-    cp "$@" $out/bin
+# Add $1/lib* into rpaths.
+# The function is used in multiple-outputs.sh hook,
+# so it is defined here but tried after the hook.
+_addRpathPrefix() {
+    if [ "$NIX_NO_SELF_RPATH" != 1 ]; then
+        export NIX_LDFLAGS="-rpath $1/lib $NIX_LDFLAGS"
+        if [ -n "$NIX_LIB64_IN_SELF_RPATH" ]; then
+            export NIX_LDFLAGS="-rpath $1/lib64 $NIX_LDFLAGS"
+        fi
+        if [ -n "$NIX_LIB32_IN_SELF_RPATH" ]; then
+            export NIX_LDFLAGS="-rpath $1/lib32 $NIX_LDFLAGS"
+        fi
+    fi
 }
 
-
 ######################################################################
 # Initialisation.
 
@@ -309,16 +318,7 @@ for i in $crossPkgs; do
 done
 
 
-# Add the output as an rpath.
-if [ "$NIX_NO_SELF_RPATH" != 1 ]; then
-    export NIX_LDFLAGS="-rpath $out/lib $NIX_LDFLAGS"
-    if [ -n "$NIX_LIB64_IN_SELF_RPATH" ]; then
-        export NIX_LDFLAGS="-rpath $out/lib64 $NIX_LDFLAGS"
-    fi
-    if [ -n "$NIX_LIB32_IN_SELF_RPATH" ]; then
-        export NIX_LDFLAGS="-rpath $out/lib32 $NIX_LDFLAGS"
-    fi
-fi
+_addRpathPrefix "$out"
 
 
 # Set the TZ (timezone) environment variable, otherwise commands like
@@ -633,7 +633,7 @@ configurePhase() {
         done
     fi
 
-    if [ -z "$dontAddPrefix" ]; then
+    if [ -z "$dontAddPrefix" -a -n "$prefix" ]; then
         configureFlags="${prefixKey:---prefix=}$prefix $configureFlags"
     fi
 
@@ -698,7 +698,9 @@ checkPhase() {
 installPhase() {
     runHook preInstall
 
-    mkdir -p "$prefix"
+    if [ -n "$prefix" ]; then
+        mkdir -p "$prefix"
+    fi
 
     installTargets=${installTargets:-install}
     echo "install flags: $installTargets $makeFlags ${makeFlagsArray[@]} $installFlags ${installFlagsArray[@]}"
@@ -727,24 +729,29 @@ fixupPhase() {
         prefix=${!output} runHook fixupOutput
     done
 
+
+    # Propagate build inputs and setup hook into the development output.
+
     if [ -n "$propagatedBuildInputs" ]; then
-        mkdir -p "$out/nix-support"
-        echo "$propagatedBuildInputs" > "$out/nix-support/propagated-build-inputs"
+        mkdir -p "${!outputDev}/nix-support"
+        echo "$propagatedBuildInputs" > "${!outputDev}/nix-support/propagated-build-inputs"
     fi
 
     if [ -n "$propagatedNativeBuildInputs" ]; then
-        mkdir -p "$out/nix-support"
-        echo "$propagatedNativeBuildInputs" > "$out/nix-support/propagated-native-build-inputs"
+        mkdir -p "${!outputDev}/nix-support"
+        echo "$propagatedNativeBuildInputs" > "${!outputDev}/nix-support/propagated-native-build-inputs"
     fi
 
-    if [ -n "$propagatedUserEnvPkgs" ]; then
-        mkdir -p "$out/nix-support"
-        echo "$propagatedUserEnvPkgs" > "$out/nix-support/propagated-user-env-packages"
+    if [ -n "$setupHook" ]; then
+        mkdir -p "${!outputDev}/nix-support"
+        substituteAll "$setupHook" "${!outputDev}/nix-support/setup-hook"
     fi
 
-    if [ -n "$setupHook" ]; then
-        mkdir -p "$out/nix-support"
-        substituteAll "$setupHook" "$out/nix-support/setup-hook"
+    # Propagate user-env packages into the output with binaries, TODO?
+
+    if [ -n "$propagatedUserEnvPkgs" ]; then
+        mkdir -p "${!outputBin}/nix-support"
+        echo "$propagatedUserEnvPkgs" > "${!outputBin}/nix-support/propagated-user-env-packages"
     fi
 
     runHook postFixup
diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix
index ac7d8f5c706c..b1e7e6e11ecf 100644
--- a/pkgs/stdenv/linux/default.nix
+++ b/pkgs/stdenv/linux/default.nix
@@ -214,14 +214,13 @@ rec {
       gmp = pkgs.gmp.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
       mpfr = pkgs.mpfr.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
       libmpc = pkgs.libmpc.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
-      isl_0_11 = pkgs.isl_0_11.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
-      cloog_0_18_0 = pkgs.cloog_0_18_0.override {
+      isl = pkgs.isl.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
+      cloog = pkgs.cloog.override {
         stdenv = pkgs.makeStaticLibraries pkgs.stdenv;
-        isl = isl_0_11;
+        inherit isl;
       };
       gccPlain = pkgs.gcc.cc.override {
-        isl = isl_0_11;
-        cloog = cloog_0_18_0;
+        inherit isl cloog;
       };
     };
     extraBuildInputs = [ stage2.pkgs.patchelf stage2.pkgs.paxctl ];
@@ -294,11 +293,13 @@ rec {
       shellPackage = stage4.pkgs.bash;
     };
 
+    /* outputs TODO
     allowedRequisites = with stage4.pkgs;
       [ gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
         glibc gnumake gnused gnutar gnugrep gnupatch patchelf attr acl
         paxctl zlib pcre linuxHeaders ed gcc gcc.cc libsigsegv
       ];
+      */
 
     overrides = pkgs: {
       gcc = cc;
diff --git a/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix b/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix
index bf060329be6d..6b562eef53c2 100644
--- a/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix
+++ b/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix
@@ -130,20 +130,20 @@ rec {
         mkdir -p $out/bin $out/lib $out/libexec
 
         # Copy what we need of Glibc.
-        cp -d ${glibc}/lib/ld-*.so* $out/lib
-        cp -d ${glibc}/lib/libc*.so* $out/lib
-        cp -d ${glibc}/lib/libc_nonshared.a $out/lib
-        cp -d ${glibc}/lib/libm*.so* $out/lib
-        cp -d ${glibc}/lib/libdl*.so* $out/lib
-        cp -d ${glibc}/lib/librt*.so*  $out/lib
-        cp -d ${glibc}/lib/libpthread*.so* $out/lib
-        cp -d ${glibc}/lib/libnsl*.so* $out/lib
-        cp -d ${glibc}/lib/libutil*.so* $out/lib
-        cp -d ${glibc}/lib/libnss*.so* $out/lib
-        cp -d ${glibc}/lib/libresolv*.so* $out/lib
-        cp -d ${glibc}/lib/crt?.o $out/lib
+        cp -d ${glibc.out}/lib/ld-*.so* $out/lib
+        cp -d ${glibc.out}/lib/libc*.so* $out/lib
+        cp -d ${glibc.out}/lib/libc_nonshared.a $out/lib
+        cp -d ${glibc.out}/lib/libm*.so* $out/lib
+        cp -d ${glibc.out}/lib/libdl*.so* $out/lib
+        cp -d ${glibc.out}/lib/librt*.so*  $out/lib
+        cp -d ${glibc.out}/lib/libpthread*.so* $out/lib
+        cp -d ${glibc.out}/lib/libnsl*.so* $out/lib
+        cp -d ${glibc.out}/lib/libutil*.so* $out/lib
+        cp -d ${glibc.out}/lib/libnss*.so* $out/lib
+        cp -d ${glibc.out}/lib/libresolv*.so* $out/lib
+        cp -d ${glibc.out}/lib/crt?.o $out/lib
         
-        cp -rL ${glibc}/include $out
+        cp -rL ${glibc.dev}/include $out
         chmod -R u+w $out/include
         
         # Hopefully we won't need these.
@@ -199,9 +199,9 @@ rec {
         rm -rf $out/include/c++/*/ext/parallel
 
         cp -d ${gmpxx}/lib/libgmp*.so* $out/lib
-        cp -d ${mpfr}/lib/libmpfr*.so* $out/lib
+        cp -d ${mpfr.out}/lib/libmpfr*.so* $out/lib
         cp -d ${libmpc}/lib/libmpc*.so* $out/lib
-        cp -d ${zlib}/lib/libz.so* $out/lib
+        cp -d ${zlib.out}/lib/libz.so* $out/lib
         cp -d ${libelf}/lib/libelf.so* $out/lib
         
         # TBD: Why are these needed for cross but not native tools?
@@ -213,7 +213,7 @@ rec {
         for i in as ld ar ranlib nm strip readelf objdump; do
           cp ${binutils}/bin/$i $out/bin
         done
-        cp -d ${binutils}/lib/lib*.so* $out/lib
+        cp -d ${binutils.out}/lib/lib*.so* $out/lib
 
         chmod -R u+w $out
         
diff --git a/pkgs/stdenv/linux/make-bootstrap-tools.nix b/pkgs/stdenv/linux/make-bootstrap-tools.nix
index e31fed39843d..d33d8f9fb663 100644
--- a/pkgs/stdenv/linux/make-bootstrap-tools.nix
+++ b/pkgs/stdenv/linux/make-bootstrap-tools.nix
@@ -43,20 +43,20 @@ rec {
         mkdir -p $out/bin $out/lib $out/libexec
 
         # Copy what we need of Glibc.
-        cp -d ${glibc}/lib/ld*.so* $out/lib
-        cp -d ${glibc}/lib/libc*.so* $out/lib
-        cp -d ${glibc}/lib/libc_nonshared.a $out/lib
-        cp -d ${glibc}/lib/libm*.so* $out/lib
-        cp -d ${glibc}/lib/libdl*.so* $out/lib
-        cp -d ${glibc}/lib/librt*.so*  $out/lib
-        cp -d ${glibc}/lib/libpthread*.so* $out/lib
-        cp -d ${glibc}/lib/libnsl*.so* $out/lib
-        cp -d ${glibc}/lib/libutil*.so* $out/lib
-        cp -d ${glibc}/lib/libnss*.so* $out/lib
-        cp -d ${glibc}/lib/libresolv*.so* $out/lib
-        cp -d ${glibc}/lib/crt?.o $out/lib
-
-        cp -rL ${glibc}/include $out
+        cp -d ${glibc.out}/lib/ld*.so* $out/lib
+        cp -d ${glibc.out}/lib/libc*.so* $out/lib
+        cp -d ${glibc.out}/lib/libc_nonshared.a $out/lib
+        cp -d ${glibc.out}/lib/libm*.so* $out/lib
+        cp -d ${glibc.out}/lib/libdl*.so* $out/lib
+        cp -d ${glibc.out}/lib/librt*.so*  $out/lib
+        cp -d ${glibc.out}/lib/libpthread*.so* $out/lib
+        cp -d ${glibc.out}/lib/libnsl*.so* $out/lib
+        cp -d ${glibc.out}/lib/libutil*.so* $out/lib
+        cp -d ${glibc.out}/lib/libnss*.so* $out/lib
+        cp -d ${glibc.out}/lib/libresolv*.so* $out/lib
+        cp -d ${glibc.out}/lib/crt?.o $out/lib
+
+        cp -rL ${glibc.dev}/include $out
         chmod -R u+w $out/include
 
         # Hopefully we won't need these.
@@ -86,7 +86,7 @@ rec {
         cp ${curlMinimal}/bin/curl $out/bin
         cp -d ${curlMinimal}/lib/libcurl* $out/lib
 
-        cp -d ${gnugrep.pcre}/lib/libpcre*.so* $out/lib # needed by grep
+        cp -d ${gnugrep.pcre.out}/lib/libpcre*.so* $out/lib # needed by grep
 
         # Copy what we need of GCC.
         cp -d ${gcc.cc}/bin/gcc $out/bin
@@ -112,16 +112,16 @@ rec {
         rm -rf $out/include/c++/*/ext/parallel
 
         cp -d ${gmpxx}/lib/libgmp*.so* $out/lib
-        cp -d ${mpfr}/lib/libmpfr*.so* $out/lib
+        cp -d ${mpfr.out}/lib/libmpfr*.so* $out/lib
         cp -d ${libmpc}/lib/libmpc*.so* $out/lib
-        cp -d ${zlib}/lib/libz.so* $out/lib
+        cp -d ${zlib.out}/lib/libz.so* $out/lib
         cp -d ${libelf}/lib/libelf.so* $out/lib
 
         # Copy binutils.
         for i in as ld ar ranlib nm strip readelf objdump; do
           cp ${binutils}/bin/$i $out/bin
         done
-        cp -d ${binutils}/lib/lib*.so* $out/lib
+        cp -d ${binutils.out}/lib/lib*.so* $out/lib
 
         chmod -R u+w $out
 
diff --git a/pkgs/test/openftd/default.nix b/pkgs/test/openftd/default.nix
index 91042fe05911..13b6b01f3259 100644
--- a/pkgs/test/openftd/default.nix
+++ b/pkgs/test/openftd/default.nix
@@ -45,5 +45,5 @@ stdenv.mkDerivation {
     glib gtk pkgconfig dbus_glib realCurl pcre libsexy libgnomeui gtkspell libnotify libgtkhtml
   ];
 
-  configureFlags="--with-libcurl-libraries=${curl}/lib --with-libcurl-headers=${curl}/include --with-pcre_libraries=${pcre}/lib --with-pcre_headers=${pcre}/include";  
+  configureFlags="--with-libcurl-libraries=${curl.out}/lib --with-libcurl-headers=${curl.dev}/include --with-pcre_libraries=${pcre.out}/lib --with-pcre_headers=${pcre.dev}/include";
 }
diff --git a/pkgs/tools/X11/xlaunch/default.nix b/pkgs/tools/X11/xlaunch/default.nix
index 06dfd28b7399..ccf998951a34 100644
--- a/pkgs/tools/X11/xlaunch/default.nix
+++ b/pkgs/tools/X11/xlaunch/default.nix
@@ -45,7 +45,7 @@ EOF
       else
         RESET_OPTION=\"-noreset\"
       fi;
-      XCMD=\"\$(egrep \"^Environment=\" /etc/systemd/system/display-manager.service | sed -e \"s/Environment=/ export /\" | sed -e '\\''s/#.*//'\\'' ; echo export _XARGS_=\\\$\\( grep xserver_arguments \\\$SLIM_CFGFILE \\| sed -e s/xserver_arguments// \\| sed -e s/:0/:\${_display}/ \\| sed -e s/vt7/vt\$((7+_display))/ \\) ; echo ${xorgserver}/bin/X \\\$_XARGS_ \$RESET_OPTION )\" 
+      XCMD=\"\$(egrep \"^Environment=\" /etc/systemd/system/display-manager.service | sed -e \"s/Environment=/ export /\" | sed -e '\\''s/#.*//'\\'' ; echo export _XARGS_=\\\$\\( grep xserver_arguments \\\$SLIM_CFGFILE \\| sed -e s/xserver_arguments// \\| sed -e s/:0/:\${_display}/ \\| sed -e s/vt7/vt\$((7+_display))/ \\) ; echo ${xorgserver.out}/bin/X \\\$_XARGS_ \$RESET_OPTION )\" 
       PRE_XCMD=\"\$(egrep \"^ExecStartPre=\" /etc/systemd/system/display-manager.service | sed -e \"\s/ExecStartPre=//\")\"
       echo \"\$PRE_XCMD\" 
       echo \"\$PRE_XCMD\" | bash
diff --git a/pkgs/tools/X11/xpra/default.nix b/pkgs/tools/X11/xpra/default.nix
index c5b8db591c4c..a71457927ec0 100644
--- a/pkgs/tools/X11/xpra/default.nix
+++ b/pkgs/tools/X11/xpra/default.nix
@@ -49,14 +49,14 @@ buildPythonPackage rec {
       --set XKB_BINDIR "${xkbcomp}/bin" \
       --set FONTCONFIG_FILE "${fontsConf}" \
       --prefix LD_LIBRARY_PATH : ${libfakeXinerama}/lib \
-      --prefix PATH : ${getopt}/bin:${xorgserver}/bin:${xauth}/bin:${which}/bin:${utillinux}/bin
+      --prefix PATH : ${getopt}/bin:${xorgserver.out}/bin:${xauth}/bin:${which}/bin:${utillinux}/bin
   '';
 
   #TODO: replace postInstall with postFixup to avoid double wrapping of xpra; needs more work though
   #postFixup = ''
   #  sed -i '2iexport XKB_BINDIR="${xkbcomp}/bin"' $out/bin/xpra
   #  sed -i '3iexport FONTCONFIG_FILE="${fontsConf}"' $out/bin/xpra
-  #  sed -i '4iexport PATH=${getopt}/bin:${xorgserver}/bin:${xauth}/bin:${which}/bin:${utillinux}/bin\${PATH:+:}\$PATH' $out/bin/xpra
+  #  sed -i '4iexport PATH=${getopt}/bin:${xorgserver.out}/bin:${xauth}/bin:${which}/bin:${utillinux}/bin\${PATH:+:}\$PATH' $out/bin/xpra
   #'';
 
 
diff --git a/pkgs/tools/X11/xpra/gtk3.nix b/pkgs/tools/X11/xpra/gtk3.nix
index 6e485dc0a052..f5927a695c08 100644
--- a/pkgs/tools/X11/xpra/gtk3.nix
+++ b/pkgs/tools/X11/xpra/gtk3.nix
@@ -50,14 +50,14 @@ buildPythonPackage rec {
       --set XKB_BINDIR "${xkbcomp}/bin" \
       --set FONTCONFIG_FILE "${fontsConf}" \
       --prefix LD_LIBRARY_PATH : ${libfakeXinerama}/lib \
-      --prefix PATH : ${getopt}/bin:${xorgserver}/bin:${xauth}/bin:${which}/bin:${utillinux}/bin
+      --prefix PATH : ${getopt}/bin:${xorgserver.out}/bin:${xauth}/bin:${which}/bin:${utillinux}/bin
   '';
 
   #TODO: replace postInstall with postFixup to avoid double wrapping of xpra; needs more work though
   #postFixup = ''
   #  sed -i '2iexport XKB_BINDIR="${xkbcomp}/bin"' $out/bin/xpra
   #  sed -i '3iexport FONTCONFIG_FILE="${fontsConf}"' $out/bin/xpra
-  #  sed -i '4iexport PATH=${getopt}/bin:${xorgserver}/bin:${xauth}/bin:${which}/bin:${utillinux}/bin\${PATH:+:}\$PATH' $out/bin/xpra
+  #  sed -i '4iexport PATH=${getopt}/bin:${xorgserver.out}/bin:${xauth}/bin:${which}/bin:${utillinux}/bin\${PATH:+:}\$PATH' $out/bin/xpra
   #'';
 
 
diff --git a/pkgs/tools/admin/gtk-vnc/default.nix b/pkgs/tools/admin/gtk-vnc/default.nix
index fddb9505c984..657d08026e4a 100644
--- a/pkgs/tools/admin/gtk-vnc/default.nix
+++ b/pkgs/tools/admin/gtk-vnc/default.nix
@@ -31,7 +31,7 @@ stdenv.mkDerivation rec {
 
   # Fix broken .la files
   preFixup = ''
-    sed 's,-lgpg-error,-L${libgpgerror}/lib -lgpg-error,' -i $out/lib/*.la
+    sed 's,-lgpg-error,-L${libgpgerror.out}/lib -lgpg-error,' -i $out/lib/*.la
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/tools/archivers/gnutar/default.nix b/pkgs/tools/archivers/gnutar/default.nix
index 71b43bf2de9a..6b5717ab2970 100644
--- a/pkgs/tools/archivers/gnutar/default.nix
+++ b/pkgs/tools/archivers/gnutar/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, autoreconfHook }:
+{ stdenv, fetchurl, autoreconfHook, acl }:
 
 stdenv.mkDerivation rec {
   name = "gnutar-${version}";
@@ -24,7 +24,10 @@ stdenv.mkDerivation rec {
     substituteInPlace src/system.c --replace '_(' 'N_('
   '';
 
-  buildInputs = stdenv.lib.optional stdenv.isDarwin autoreconfHook;
+  outputs = [ "out" "info" ];
+
+  buildInputs = [ acl ]
+    ++ stdenv.lib.optional stdenv.isDarwin autoreconfHook;
 
   # May have some issues with root compilation because the bootstrap tool
   # cannot be used as a login shell for now.
diff --git a/pkgs/tools/archivers/unrar/default.nix b/pkgs/tools/archivers/unrar/default.nix
index 49638ced16a2..86ad4a4c1453 100644
--- a/pkgs/tools/archivers/unrar/default.nix
+++ b/pkgs/tools/archivers/unrar/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation {
   '';
 
   installPhase = ''
-    installBin unrar
+    install -Dt "$out/bin" unrar
 
     mkdir -p $out/share/doc/unrar
     cp acknow.txt license.txt \
diff --git a/pkgs/tools/audio/qastools/default.nix b/pkgs/tools/audio/qastools/default.nix
index 920f6913d090..3743b38a2103 100644
--- a/pkgs/tools/audio/qastools/default.nix
+++ b/pkgs/tools/audio/qastools/default.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation {
 
   cmakeFlags = [
     "-DCMAKE_INSALL_PREFIX=$out"
-    "-DALSA_INCLUDE=${alsaLib}/include/alsa/version.h"
+    "-DALSA_INCLUDE=${alsaLib.dev}/include/alsa/version.h"
   ];
 
   meta = with stdenv.lib; {
diff --git a/pkgs/tools/bluetooth/blueman/default.nix b/pkgs/tools/bluetooth/blueman/default.nix
index 5330dfb82bd2..7acb8ce2eb0b 100644
--- a/pkgs/tools/bluetooth/blueman/default.nix
+++ b/pkgs/tools/bluetooth/blueman/default.nix
@@ -28,7 +28,7 @@ stdenv.mkDerivation rec {
       for i in $out/bin/* $out/libexec/*; do
           wrapProgram $i \
               --set PYTHONPATH "$(toPythonPath $out):$PYTHONPATH" \
-              --set LD_LIBRARY_PATH "${libpulseaudio}/lib:" \
+              --set LD_LIBRARY_PATH "${libpulseaudio.out}/lib:" \
               --prefix PATH : ${xdg_utils}/bin
       done
 
diff --git a/pkgs/tools/bluetooth/obex-data-server/default.nix b/pkgs/tools/bluetooth/obex-data-server/default.nix
index 53e854c34ebc..15167ee57b13 100644
--- a/pkgs/tools/bluetooth/obex-data-server/default.nix
+++ b/pkgs/tools/bluetooth/obex-data-server/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
 
   preConfigure = ''
   addToSearchPath PKG_CONFIG_PATH ${openobex}/lib64/pkgconfig
-  export PKG_CONFIG_PATH="${dbus_libs}/lib/pkgconfig:$PKG_CONFIG_PATH"
+  export PKG_CONFIG_PATH="${dbus_libs.dev}/lib/pkgconfig:$PKG_CONFIG_PATH"
   '';
 
   meta = {
diff --git a/pkgs/tools/bluetooth/obexd/default.nix b/pkgs/tools/bluetooth/obexd/default.nix
index f900a81caa0e..a3486569b518 100644
--- a/pkgs/tools/bluetooth/obexd/default.nix
+++ b/pkgs/tools/bluetooth/obexd/default.nix
@@ -8,7 +8,7 @@ stdenv.mkDerivation rec {
     sha256 = "1i20dnibvnq9lnkkhajr5xx3kxlwf9q5c4jm19kyb0q1klzgzlb8";
   };
 
-  buildInputs = [ glib dbus.libs openobex bluez libical ];
+  buildInputs = [ glib dbus openobex bluez libical ];
 
   nativeBuildInputs = [ pkgconfig ];
 
diff --git a/pkgs/tools/compression/bzip2/default.nix b/pkgs/tools/compression/bzip2/default.nix
index bb04049d8a66..ea2ee660a2ce 100644
--- a/pkgs/tools/compression/bzip2/default.nix
+++ b/pkgs/tools/compression/bzip2/default.nix
@@ -37,6 +37,8 @@ in stdenv.mkDerivation {
     postInstall = "";
   };
 
+  outputs = [ "dev" "bin" "static" ] ++ stdenv.lib.optional sharedLibrary "out";
+
   preBuild = stdenv.lib.optionalString sharedLibrary ''
     make -f Makefile-libbz2_so
   '';
@@ -50,12 +52,15 @@ in stdenv.mkDerivation {
     )
   '';
 
-  installFlags = [ "PREFIX=$(out)" ];
+  installFlags = [ "PREFIX=$(bin)" ];
 
   postInstall = ''
-    rm $out/bin/bunzip2* $out/bin/bzcat*
-    ln -s bzip2 $out/bin/bunzip2
-    ln -s bzip2 $out/bin/bzcat
+    rm $bin/bin/bunzip2* $bin/bin/bzcat*
+    ln -s bzip2 $bin/bin/bunzip2
+    ln -s bzip2 $bin/bin/bzcat
+
+    mkdir "$static"
+    mv "$bin/lib" "$static/"
   '';
 
   patchPhase = ''
diff --git a/pkgs/tools/compression/gzip/default.nix b/pkgs/tools/compression/gzip/default.nix
index 6772e21cb0cb..009246b69a08 100644
--- a/pkgs/tools/compression/gzip/default.nix
+++ b/pkgs/tools/compression/gzip/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl }:
+{ stdenv, fetchurl, xz }:
 
 stdenv.mkDerivation rec {
   name = "gzip-1.6";
@@ -8,8 +8,12 @@ stdenv.mkDerivation rec {
     sha256 = "0ivqnbhiwd12q8hp3qw6rpsrpw2jg5y2mymk8cn22lsx90dfvprp";
   };
 
+  outputs = [ "out" "man" "info" ];
+
   enableParallelBuilding = true;
 
+  buildInputs = [ xz.bin ];
+
   preConfigure = if stdenv.isCygwin then ''
     sed -i lib/fpending.h -e 's,include <stdio_ext.h>,,'
   '' else null;
diff --git a/pkgs/tools/compression/kzipmix/default.nix b/pkgs/tools/compression/kzipmix/default.nix
index f768189040b5..6fcff7b29280 100644
--- a/pkgs/tools/compression/kzipmix/default.nix
+++ b/pkgs/tools/compression/kzipmix/default.nix
@@ -12,8 +12,8 @@ stdenv.mkDerivation {
     mkdir -p $out/bin
     cp kzip zipmix $out/bin
     
-    patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux.so.2 $out/bin/kzip
-    patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux.so.2 $out/bin/zipmix
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/bin/kzip
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/bin/zipmix
   '';
 
   meta = {
diff --git a/pkgs/tools/compression/xz/default.nix b/pkgs/tools/compression/xz/default.nix
index 5f5ee28ca063..5d6a8634b1ba 100644
--- a/pkgs/tools/compression/xz/default.nix
+++ b/pkgs/tools/compression/xz/default.nix
@@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "1da071wyx921pyx3zkxlnbpp14p6km98pnp66mg1arwi9dxgbxbg";
   };
 
+  outputs = [ "dev" "out" "bin" "man" "doc" ];
+
   doCheck = true;
 
   # In stdenv-linux, prevent a dependency on bootstrap-tools.
diff --git a/pkgs/tools/filesystems/e2fsprogs/default.nix b/pkgs/tools/filesystems/e2fsprogs/default.nix
index a53e93960aef..c091158bff63 100644
--- a/pkgs/tools/filesystems/e2fsprogs/default.nix
+++ b/pkgs/tools/filesystems/e2fsprogs/default.nix
@@ -8,7 +8,11 @@ stdenv.mkDerivation rec {
     sha256 = "1m72lk90b5i3h9qnmss6aygrzyn8x2avy3hyaq2fb0jglkrkz6ar";
   };
 
-  buildInputs = [ pkgconfig libuuid ];
+  outputs = [ "bin" "out" "man" ];
+  outputDev = "bin"; # just for *.pc
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libuuid ];
 
   crossAttrs = {
     preConfigure = ''
@@ -16,14 +20,19 @@ stdenv.mkDerivation rec {
     '';
   };
 
-  # libuuid, libblkid, uuidd and fsck are in util-linux-ng (the "libuuid" dependency).
-  configureFlags = "--enable-elf-shlibs --disable-libuuid --disable-libblkid --disable-uuidd --disable-fsck --enable-symlink-install";
-
-  enableParallelBuilding = true;
+  configureFlags = [
+    "--enable-elf-shlibs" "--enable-symlink-install" "--enable-relative-symlinks"
+    # libuuid, libblkid, uuidd and fsck are in util-linux-ng (the "libuuid" dependency).
+    "--disable-libuuid" "--disable-uuidd" "--disable-libblkid" "--disable-fsck"
+  ];
 
-  preInstall = "installFlagsArray=('LN=ln -s')";
+  # hacky way to make it install *.pc
+  postInstall = ''
+    make install-libs
+    rm "$out"/lib/*.a
+  '';
 
-  postInstall = "make install-libs";
+  enableParallelBuilding = true;
 
   meta = {
     homepage = http://e2fsprogs.sourceforge.net/;
diff --git a/pkgs/tools/filesystems/nixpart/0.4/blivet.nix b/pkgs/tools/filesystems/nixpart/0.4/blivet.nix
index d4129f4d390a..1776c30ecae0 100644
--- a/pkgs/tools/filesystems/nixpart/0.4/blivet.nix
+++ b/pkgs/tools/filesystems/nixpart/0.4/blivet.nix
@@ -1,9 +1,9 @@
 { stdenv, fetchurl, buildPythonPackage, pykickstart, pyparted, pyblock
 , libselinux, cryptsetup, multipath_tools, lsof, utillinux
-, useNixUdev ? true, udev ? null
+, useNixUdev ? true, libudev ? null
 }:
 
-assert useNixUdev -> udev != null;
+assert useNixUdev -> libudev != null;
 
 buildPythonPackage rec {
   name = "blivet-${version}";
@@ -21,21 +21,21 @@ buildPythonPackage rec {
     sed -i -e 's|"multipath"|"${multipath_tools}/sbin/multipath"|' \
       blivet/devicelibs/mpath.py blivet/devices.py
     sed -i -e '/"wipefs"/ {
-      s|wipefs|${utillinux}/sbin/wipefs|
+      s|wipefs|${utillinux.bin}/sbin/wipefs|
       s/-f/--force/
     }' blivet/formats/__init__.py
     sed -i -e 's|"lsof"|"${lsof}/bin/lsof"|' blivet/formats/fs.py
-    sed -i -r -e 's|"(u?mount)"|"${utillinux}/bin/\1"|' blivet/util.py
+    sed -i -r -e 's|"(u?mount)"|"${utillinux.bin}/bin/\1"|' blivet/util.py
     sed -i '/pvscan/s/, *"--cache"//' blivet/devicelibs/lvm.py
   '' + stdenv.lib.optionalString useNixUdev ''
     sed -i -e '/find_library/,/find_library/ {
-      c libudev = "${udev}/lib/libudev.so.1"
+      c libudev = "${libudev.out}/lib/libudev.so.1"
     }' blivet/pyudev.py
   '';
 
   propagatedBuildInputs = [
     pykickstart pyparted pyblock libselinux cryptsetup
-  ] ++ stdenv.lib.optional useNixUdev udev;
+  ] ++ stdenv.lib.optional useNixUdev libudev;
 
   # tests are currently _heavily_ broken upstream
   doCheck = false;
diff --git a/pkgs/tools/filesystems/nixpart/0.4/default.nix b/pkgs/tools/filesystems/nixpart/0.4/default.nix
index 01a3caafc5dd..cbedf6a70a5d 100644
--- a/pkgs/tools/filesystems/nixpart/0.4/default.nix
+++ b/pkgs/tools/filesystems/nixpart/0.4/default.nix
@@ -12,7 +12,7 @@ let
     inherit stdenv fetchurl buildPythonPackage;
     inherit pykickstart pyparted pyblock cryptsetup multipath_tools;
     inherit useNixUdev;
-    inherit (pkgs) lsof utillinux udev;
+    inherit (pkgs) lsof utillinux libudev;
     libselinux = pkgs.libselinux.override { enablePython = true; };
   };
 
@@ -29,12 +29,12 @@ let
 
   lvm2 = import ./lvm2.nix {
     inherit stdenv fetchurl;
-    inherit (pkgs) pkgconfig utillinux udev coreutils;
+    inherit (pkgs) pkgconfig utillinux libudev systemd coreutils;
   };
 
   multipath_tools = import ./multipath-tools.nix {
     inherit stdenv fetchurl lvm2;
-    inherit (pkgs) readline udev libaio gzip;
+    inherit (pkgs) readline systemd libaio gzip;
   };
 
   parted = import ./parted.nix {
diff --git a/pkgs/tools/filesystems/nixpart/0.4/lvm2.nix b/pkgs/tools/filesystems/nixpart/0.4/lvm2.nix
index 9e2b0c900794..b92c40ba99e6 100644
--- a/pkgs/tools/filesystems/nixpart/0.4/lvm2.nix
+++ b/pkgs/tools/filesystems/nixpart/0.4/lvm2.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, pkgconfig, udev, utillinux, coreutils }:
+{ stdenv, fetchurl, pkgconfig, libudev, systemd, utillinux, coreutils }:
 
 let
   v = "2.02.106";
@@ -15,7 +15,7 @@ stdenv.mkDerivation {
   configureFlags =
     "--disable-readline --enable-udev_rules --enable-udev_sync --enable-pkgconfig --enable-applib";
 
-  buildInputs = [ pkgconfig udev ];
+  buildInputs = [ pkgconfig libudev ];
 
   preConfigure =
     ''
@@ -23,7 +23,7 @@ stdenv.mkDerivation {
         --replace /usr/bin/tr ${coreutils}/bin/tr
       substituteInPlace scripts/lvm2_activation_generator_systemd_red_hat.c \
         --replace /usr/sbin/lvm $out/sbin/lvm \
-        --replace /usr/bin/udevadm ${udev}/bin/udevadm
+        --replace /usr/bin/udevadm ${systemd.udev.bin}/bin/udevadm
 
       sed -i /DEFAULT_SYS_DIR/d Makefile.in
       sed -i /DEFAULT_PROFILE_DIR/d conf/Makefile.in
@@ -42,7 +42,7 @@ stdenv.mkDerivation {
   postInstall =
     ''
       substituteInPlace $out/lib/udev/rules.d/13-dm-disk.rules \
-        --replace $out/sbin/blkid ${utillinux}/sbin/blkid
+        --replace $out/sbin/blkid ${utillinux.bin}/sbin/blkid
 
       # Systemd stuff
       mkdir -p $out/etc/systemd/system $out/lib/systemd/system-generators
diff --git a/pkgs/tools/filesystems/nixpart/0.4/multipath-tools.nix b/pkgs/tools/filesystems/nixpart/0.4/multipath-tools.nix
index 90722d74ace1..b78605504bf8 100644
--- a/pkgs/tools/filesystems/nixpart/0.4/multipath-tools.nix
+++ b/pkgs/tools/filesystems/nixpart/0.4/multipath-tools.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, lvm2, libaio, gzip, readline, udev }:
+{ stdenv, fetchurl, lvm2, libaio, gzip, readline, systemd }:
 
 stdenv.mkDerivation rec {
   name = "multipath-tools-0.4.9";
@@ -22,8 +22,8 @@ stdenv.mkDerivation rec {
       substituteInPlace kpartx/kpartx.rules --replace /sbin/kpartx $out/sbin/kpartx
       substituteInPlace kpartx/kpartx_id --replace /sbin/dmsetup ${lvm2}/sbin/dmsetup
 
-      substituteInPlace libmultipath/defaults.h --replace /lib/udev/scsi_id ${udev}/lib/udev/scsi_id
-      substituteInPlace libmultipath/hwtable.c --replace /lib/udev/scsi_id ${udev}/lib/udev/scsi_id
+      substituteInPlace libmultipath/defaults.h --replace /lib/udev/scsi_id ${systemd.udev.lib}/lib/udev/scsi_id
+      substituteInPlace libmultipath/hwtable.c --replace /lib/udev/scsi_id ${systemd.udev.lib}/lib/udev/scsi_id
     '';
 
   meta = {
diff --git a/pkgs/tools/filesystems/svnfs/default.nix b/pkgs/tools/filesystems/svnfs/default.nix
index fba066d0f4cb..333714182177 100644
--- a/pkgs/tools/filesystems/svnfs/default.nix
+++ b/pkgs/tools/filesystems/svnfs/default.nix
@@ -12,10 +12,10 @@ stdenv.mkDerivation {
 
   # why is this required?
   preConfigure=''
-    export LD_LIBRARY_PATH=${subversion}/lib
+    export LD_LIBRARY_PATH=${subversion.out}/lib
   '';
 
-  NIX_CFLAGS_COMPILE="-I ${subversion}/include/subversion-1";
+  NIX_CFLAGS_COMPILE="-I ${subversion.dev}/include/subversion-1";
   NIX_LDFLAGS="-lsvn_client-1";
 
   meta = {
diff --git a/pkgs/tools/filesystems/xfsprogs/default.nix b/pkgs/tools/filesystems/xfsprogs/default.nix
index de61809a1aea..e30f67af3e95 100644
--- a/pkgs/tools/filesystems/xfsprogs/default.nix
+++ b/pkgs/tools/filesystems/xfsprogs/default.nix
@@ -26,7 +26,7 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ gettext libuuid readline ];
 
-  outputs = [ "out" "lib" ];
+  outputs = [ "dev" "out" "bin" ]; # TODO: review xfs
 
   preConfigure = ''
     NIX_LDFLAGS="$(echo $NIX_LDFLAGS | sed "s,$out,$lib,g")"
@@ -39,8 +39,6 @@ stdenv.mkDerivation rec {
     "XGETTEXT=xgettext"
     "--disable-lib64"
     "--enable-readline"
-    "--includedir=$(lib)/include"
-    "--libdir=$(lib)/lib"
   ];
 
   installFlags = [ "install-dev" ];
diff --git a/pkgs/tools/filesystems/xtreemfs/default.nix b/pkgs/tools/filesystems/xtreemfs/default.nix
index 8f090c297813..556cb674212d 100644
--- a/pkgs/tools/filesystems/xtreemfs/default.nix
+++ b/pkgs/tools/filesystems/xtreemfs/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
       --replace "/usr/local" "${valgrind}"
 
     substituteInPlace cpp/CMakeLists.txt \
-      --replace '"/lib64" "/usr/lib64"' '"${attr}/lib" "${fuse}/lib"'
+      --replace '"/lib64" "/usr/lib64"' '"${attr.out}/lib" "${fuse}/lib"'
 
     export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${fuse}/include"
     export NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK -L${fuse}/lib"
diff --git a/pkgs/tools/filesystems/yandex-disk/default.nix b/pkgs/tools/filesystems/yandex-disk/default.nix
index 42308947c07b..df3cca854ed0 100644
--- a/pkgs/tools/filesystems/yandex-disk/default.nix
+++ b/pkgs/tools/filesystems/yandex-disk/default.nix
@@ -43,7 +43,7 @@ stdenv.mkDerivation rec {
 
     ${patchelf}/bin/patchelf \
       --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-      --set-rpath "${zlib}/lib:${p.gcclib}" \
+      --set-rpath "${zlib.out}/lib:${p.gcclib}" \
       $out/bin/yandex-disk
   '';
 
diff --git a/pkgs/tools/graphics/cuneiform/default.nix b/pkgs/tools/graphics/cuneiform/default.nix
index 138ae58da064..cb37d893378e 100644
--- a/pkgs/tools/graphics/cuneiform/default.nix
+++ b/pkgs/tools/graphics/cuneiform/default.nix
@@ -25,7 +25,7 @@ rec {
     mkdir -p $PWD/builddir
     cd builddir
     export NIX_LDFLAGS="$NIX_LDFLAGS -ldl -L$out/lib"
-    cmake .. -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=$out -DDL_LIB=${libc}/lib
+    cmake .. -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=$out -DDL_LIB=${libc.out}/lib
   '') ["minInit" "addInputs" "doUnpack" "defEnsureDir"];
 
   needLib64 = a.stdenv.system == "x86_64-linux";
diff --git a/pkgs/tools/graphics/gnuplot/default.nix b/pkgs/tools/graphics/gnuplot/default.nix
index 8a9df4982a3e..2b78f1fba405 100644
--- a/pkgs/tools/graphics/gnuplot/default.nix
+++ b/pkgs/tools/graphics/gnuplot/default.nix
@@ -46,7 +46,7 @@ stdenv.mkDerivation rec {
     wrapProgram $out/bin/gnuplot \
        --prefix PATH : '${gnused}/bin' \
        --prefix PATH : '${coreutils}/bin' \
-       --prefix PATH : '${fontconfig}/bin' \
+       --prefix PATH : '${fontconfig.bin}/bin' \
        --run '. ${./set-gdfontpath-from-fontconfig.sh}'
   '';
 
diff --git a/pkgs/tools/graphics/graphviz/2.0.nix b/pkgs/tools/graphics/graphviz/2.0.nix
index 04fff8053819..02b700111de3 100644
--- a/pkgs/tools/graphics/graphviz/2.0.nix
+++ b/pkgs/tools/graphics/graphviz/2.0.nix
@@ -16,11 +16,11 @@ stdenv.mkDerivation rec {
   
   configureFlags =
     [ "--with-pngincludedir=${libpng}/include"
-      "--with-pnglibdir=${libpng}/lib"
+      "--with-pnglibdir=${libpng.out}/lib"
       "--with-jpegincludedir=${libjpeg}/include"
-      "--with-jpeglibdir=${libjpeg}/lib"
+      "--with-jpeglibdir=${libjpeg.out}/lib"
       "--with-expatincludedir=${expat}/include"
-      "--with-expatlibdir=${expat}/lib"
+      "--with-expatlibdir=${expat.out}/lib"
     ]
     ++ stdenv.lib.optional (xlibsWrapper == null) "--without-x";
 
diff --git a/pkgs/tools/graphics/graphviz/2.32.nix b/pkgs/tools/graphics/graphviz/2.32.nix
index 2743bd78aa7c..8da3ea0a1749 100644
--- a/pkgs/tools/graphics/graphviz/2.32.nix
+++ b/pkgs/tools/graphics/graphviz/2.32.nix
@@ -17,15 +17,15 @@ stdenv.mkDerivation rec {
     ] ++ stdenv.lib.optionals (xorg != null) [ xorg.xlibsWrapper xorg.libXrender ]
     ++ stdenv.lib.optional (stdenv.system == "x86_64-darwin") gettext;
 
-  CPPFLAGS = stdenv.lib.optionalString (stdenv.system == "x86_64-darwin") "-I${cairo}/include/cairo";
+  CPPFLAGS = stdenv.lib.optionalString (stdenv.system == "x86_64-darwin") "-I${cairo.dev}/include/cairo";
 
   configureFlags =
     [ "--with-pngincludedir=${libpng}/include"
-      "--with-pnglibdir=${libpng}/lib"
+      "--with-pnglibdir=${libpng.out}/lib"
       "--with-jpegincludedir=${libjpeg}/include"
-      "--with-jpeglibdir=${libjpeg}/lib"
+      "--with-jpeglibdir=${libjpeg.out}/lib"
       "--with-expatincludedir=${expat}/include"
-      "--with-expatlibdir=${expat}/lib"
+      "--with-expatlibdir=${expat.out}/lib"
       "--with-cgraph=no"
       "--with-sparse=no"
     ]
diff --git a/pkgs/tools/graphics/graphviz/default.nix b/pkgs/tools/graphics/graphviz/default.nix
index 5635e3a69ff7..78784580eacc 100644
--- a/pkgs/tools/graphics/graphviz/default.nix
+++ b/pkgs/tools/graphics/graphviz/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, pkgconfig, libpng, libjpeg, expat, libXaw
+{ stdenv, fetchurl, pkgconfig, libpng, libjpeg, expat
 , yacc, libtool, fontconfig, pango, gd, xorg, gts, libdevil, gettext, cairo
 , flex
 }:
@@ -22,21 +22,14 @@ stdenv.mkDerivation rec {
 
   buildInputs =
     [ pkgconfig libpng libjpeg expat yacc libtool fontconfig gd gts libdevil flex
-    ] ++ stdenv.lib.optionals (xorg != null) [ xorg.xlibsWrapper xorg.libXrender pango libXaw ]
+    ] ++ stdenv.lib.optionals (xorg != null)
+      (with xorg; [ xlibsWrapper libXrender pango libXaw libXpm ])
     ++ stdenv.lib.optional (stdenv.system == "x86_64-darwin") gettext;
 
   CPPFLAGS = stdenv.lib.optionalString (xorg != null && stdenv.system == "x86_64-darwin")
-    "-I${cairo}/include/cairo";
+    "-I${cairo.dev}/include/cairo";
 
-  configureFlags =
-    [ "--with-pngincludedir=${libpng}/include"
-      "--with-pnglibdir=${libpng}/lib"
-      "--with-jpegincludedir=${libjpeg}/include"
-      "--with-jpeglibdir=${libjpeg}/lib"
-      "--with-expatincludedir=${expat}/include"
-      "--with-expatlibdir=${expat}/lib"
-    ]
-    ++ stdenv.lib.optional (xorg == null) "--without-x";
+  configureFlags = stdenv.lib.optional (xorg == null) "--without-x";
 
   postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
     for foo in cmd/dot/Makefile.in cmd/edgepaint/Makefile.in \
diff --git a/pkgs/tools/graphics/netpbm/default.nix b/pkgs/tools/graphics/netpbm/default.nix
index e69a73ff321e..b39ae1dfd08f 100644
--- a/pkgs/tools/graphics/netpbm/default.nix
+++ b/pkgs/tools/graphics/netpbm/default.nix
@@ -25,7 +25,7 @@ stdenv.mkDerivation rec {
     cp config.mk.in config.mk
     echo "STATICLIB_TOO = n" >> config.mk
     substituteInPlace "config.mk" \
-        --replace "TIFFLIB = NONE" "TIFFLIB = ${libtiff}/lib/libtiff.so" \
+        --replace "TIFFLIB = NONE" "TIFFLIB = ${libtiff.out}/lib/libtiff.so" \
         --replace "TIFFHDR_DIR =" "TIFFHDR_DIR = ${libtiff}/include"
   '';
 
diff --git a/pkgs/tools/graphics/pdfread/default.nix b/pkgs/tools/graphics/pdfread/default.nix
index 69ab7f27e343..a4184fd9514b 100644
--- a/pkgs/tools/graphics/pdfread/default.nix
+++ b/pkgs/tools/graphics/pdfread/default.nix
@@ -39,7 +39,7 @@ stdenv.mkDerivation {
     cp -R *.py pylrs $PYDIR
 
     wrapProgram $out/bin/pdfread.py --prefix PYTHONPATH : $PYTHONPATH:${pillow}/$LIBSUFFIX/PIL:$PYDIR \
-      --prefix PATH : ${ghostscript}/bin:${pngnq}/bin:${djvulibre}/bin:${unrar}/bin:${optipng}/bin
+      --prefix PATH : ${ghostscript}/bin:${pngnq}/bin:${djvulibre.bin}/bin:${unrar}/bin:${optipng}/bin
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/tools/graphics/pngcheck/default.nix b/pkgs/tools/graphics/pngcheck/default.nix
index 160badaf668b..d288e7018e60 100644
--- a/pkgs/tools/graphics/pngcheck/default.nix
+++ b/pkgs/tools/graphics/pngcheck/default.nix
@@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
   # '';
 
   makefile = "Makefile.unx";
-  makeFlags = "ZPATH=${zlib}/lib";
+  makeFlags = "ZPATH=${zlib.out}/lib";
 
   buildInputs = [ zlib ];
 
diff --git a/pkgs/tools/graphics/pngout/default.nix b/pkgs/tools/graphics/pngout/default.nix
index 471823ed9235..afc1a2519fe1 100644
--- a/pkgs/tools/graphics/pngout/default.nix
+++ b/pkgs/tools/graphics/pngout/default.nix
@@ -18,9 +18,9 @@ stdenv.mkDerivation {
     cp ${folder}/pngout $out/bin
     
     ${if stdenv.system == "i686-linux" then ''
-        patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux.so.2 $out/bin/pngout
+        patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/bin/pngout
       '' else if stdenv.system == "x86_64-linux" then ''
-        patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux-x86-64.so.2 $out/bin/pngout
+        patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux-x86-64.so.2 $out/bin/pngout
       '' else ""}
   '';
 
diff --git a/pkgs/tools/graphics/quirc/default.nix b/pkgs/tools/graphics/quirc/default.nix
index d84989d4372b..6da565b292f9 100644
--- a/pkgs/tools/graphics/quirc/default.nix
+++ b/pkgs/tools/graphics/quirc/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation {
   src = fetchgit {
     inherit (s) url sha256 rev;
   };
-  NIX_CFLAGS_COMPILE="-I${SDL}/include/SDL";
+  NIX_CFLAGS_COMPILE="-I${SDL.dev}/include/SDL";
   configurePhase = ''
     sed -e 's/-[og] root//g' -i Makefile
   '';
diff --git a/pkgs/tools/inputmethods/ibus/default.nix b/pkgs/tools/inputmethods/ibus/default.nix
index 3e17e721f7be..b62f81ba8fec 100644
--- a/pkgs/tools/inputmethods/ibus/default.nix
+++ b/pkgs/tools/inputmethods/ibus/default.nix
@@ -28,7 +28,7 @@ stdenv.mkDerivation rec {
     for f in "$out"/bin/*; do
       wrapProgram "$f" --prefix XDG_DATA_DIRS : "$out/share:$GSETTINGS_SCHEMAS_PATH" \
                        --prefix PYTHONPATH : "$(toPythonPath ${pygobject3})" \
-                       --prefix LD_LIBRARY_PATH : "${gnome3.gtk3}/lib:${atk}/lib:$out/lib" \
+                       --prefix LD_LIBRARY_PATH : "${gnome3.gtk3.out}/lib:${atk.out}/lib:$out/lib" \
                        --prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH:$out/lib/girepository-1.0" \
                        --prefix GIO_EXTRA_MODULES : "${gnome3.dconf}/lib/gio/modules"
     done
diff --git a/pkgs/tools/misc/coreutils/default.nix b/pkgs/tools/misc/coreutils/default.nix
index baa3900ad97a..4d9adc6c6886 100644
--- a/pkgs/tools/misc/coreutils/default.nix
+++ b/pkgs/tools/misc/coreutils/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, perl, gmp ? null
+{ stdenv, fetchurl, perl, xz, gmp ? null
 , aclSupport ? false, acl ? null
 , selinuxSupport? false, libselinux ? null, libsepol ? null
 , autoconf, automake114x, texinfo
@@ -37,9 +37,11 @@ let
          touch -r src/stat.c src/tail.c
        '';
 
+    outputs = [ "out" "info" ];
+
+    nativeBuildInputs = [ perl xz.bin ];
     configureFlags = optionalString stdenv.isSunOS "ac_cv_func_inotify_init=no";
 
-    nativeBuildInputs = [ perl ];
     buildInputs = [ gmp ]
       ++ optional aclSupport acl
       ++ optionals stdenv.isCygwin [ autoconf automake114x texinfo ]   # due to patch
diff --git a/pkgs/tools/misc/debian-devscripts/default.nix b/pkgs/tools/misc/debian-devscripts/default.nix
index 9a4dcae7dd26..ffd01dcdc19e 100644
--- a/pkgs/tools/misc/debian-devscripts/default.nix
+++ b/pkgs/tools/misc/debian-devscripts/default.nix
@@ -28,7 +28,7 @@ stdenv.mkDerivation rec {
       -e "s@/usr/(s|)bin/sendmail@${sendmailPath}@g" \
       -e "s@/usr/bin/diff@${diffutils}/bin/diff@g" \
       -e "s@/usr/bin/gpgv(2|)@${gnupg}/bin/gpgv2@g" \
-      -e "s@(command -v|/usr/bin/)curl@${curl}/bin/curl@g" \
+      -e "s@(command -v|/usr/bin/)curl@${curl.bin}/bin/curl@g" \
       -i {} +
     sed -e "s@/usr/share/sgml/[^ ]*/manpages/docbook.xsl@${docbook_xsl}/xml/xsl/docbook/manpages/docbook.xsl@" -i scripts/Makefile
     sed -r \
diff --git a/pkgs/tools/misc/entr/default.nix b/pkgs/tools/misc/entr/default.nix
index 8770a5858875..ae402e35c2eb 100644
--- a/pkgs/tools/misc/entr/default.nix
+++ b/pkgs/tools/misc/entr/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
   postPatch = ''
     substituteInPlace Makefile.bsd --replace /bin/echo echo
     substituteInPlace entr.c --replace /bin/cat ${coreutils}/bin/cat
-    substituteInPlace entr.c --replace /usr/bin/clear ${ncurses}/bin/clear
+    substituteInPlace entr.c --replace /usr/bin/clear ${ncurses.dev}/bin/clear
     substituteInPlace entr.1 --replace /bin/cat cat
     substituteInPlace entr.1 --replace /usr/bin/clear clear
   '';
diff --git a/pkgs/tools/misc/findutils/default.nix b/pkgs/tools/misc/findutils/default.nix
index 16d53c9f436a..c59283fb7c39 100644
--- a/pkgs/tools/misc/findutils/default.nix
+++ b/pkgs/tools/misc/findutils/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl, coreutils}:
+{ stdenv, fetchurl, coreutils }:
 
 stdenv.mkDerivation rec {
   name = "findutils-4.4.2";
@@ -12,6 +12,8 @@ stdenv.mkDerivation rec {
 
   patches = [ ./findutils-path.patch ./change_echo_path.patch ./disable-test-canonicalize.patch ];
 
+  outputs = [ "out" "info" ];
+
   doCheck = true;
 
   crossAttrs = {
diff --git a/pkgs/tools/misc/grub/2.0x.nix b/pkgs/tools/misc/grub/2.0x.nix
index 8e52adc76991..ae1df626fe5d 100644
--- a/pkgs/tools/misc/grub/2.0x.nix
+++ b/pkgs/tools/misc/grub/2.0x.nix
@@ -98,6 +98,9 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     paxmark pms $out/sbin/grub-{probe,bios-setup}
+
+    # Avoid a runtime reference to gcc
+    sed -i $out/lib/grub/*/modinfo.sh -e "/grub_target_cppflags=/ s|'.*'|' '|"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/tools/misc/kde-gtk-config/default.nix b/pkgs/tools/misc/kde-gtk-config/default.nix
index 809d0c65c6ec..bf868790de2d 100644
--- a/pkgs/tools/misc/kde-gtk-config/default.nix
+++ b/pkgs/tools/misc/kde-gtk-config/default.nix
@@ -22,8 +22,8 @@ stdenv.mkDerivation {
   ];
 
   cmakeFlags = ''
-    -DGTK2_GLIBCONFIG_INCLUDE_DIR=${glib}/lib/glib-2.0/include
-    -DGTK2_GDKCONFIG_INCLUDE_DIR=${gtk2}/lib/gtk-2.0/include
+    -DGTK2_GLIBCONFIG_INCLUDE_DIR=${glib.out}/lib/glib-2.0/include
+    -DGTK2_GDKCONFIG_INCLUDE_DIR=${gtk2.out}/lib/gtk-2.0/include
     -DGTK2_INCLUDE_DIRS=${gtk2}/include/gtk-2.0
     -DKDE4_LIBEXEC_INSTALL_DIR=lib/kde4/libexec
   '';
diff --git a/pkgs/tools/misc/pipelight/default.nix b/pkgs/tools/misc/pipelight/default.nix
index b79f43cfbc35..77fcb186ef1d 100644
--- a/pkgs/tools/misc/pipelight/default.nix
+++ b/pkgs/tools/misc/pipelight/default.nix
@@ -32,7 +32,7 @@ in stdenv.mkDerivation rec {
       --wine-path=${wine_custom} \
       --gpg-exec=${gnupg}/bin/gpg2 \
       --bash-interp=${bash}/bin/bash \
-      --downloader=${curl}/bin/curl
+      --downloader=${curl.bin}/bin/curl
       $configureFlags
   '';
 
diff --git a/pkgs/tools/misc/plowshare/default.nix b/pkgs/tools/misc/plowshare/default.nix
index 40540ad1c20d..a1a12a82471d 100644
--- a/pkgs/tools/misc/plowshare/default.nix
+++ b/pkgs/tools/misc/plowshare/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
     make PREFIX="$out" install
 
     for fn in plow{del,down,list,up}; do
-      wrapProgram "$out/bin/$fn" --prefix PATH : "${curl}/bin:${spidermonkey}/bin"
+      wrapProgram "$out/bin/$fn" --prefix PATH : "${curl.bin}/bin:${spidermonkey.out}/bin"
     done
   '';
 
diff --git a/pkgs/tools/misc/profile-cleaner/default.nix b/pkgs/tools/misc/profile-cleaner/default.nix
index 55c44770c3e1..2c1f3d77def3 100644
--- a/pkgs/tools/misc/profile-cleaner/default.nix
+++ b/pkgs/tools/misc/profile-cleaner/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
   installPhase = ''
     PREFIX=\"\" DESTDIR=$out make install
     wrapProgram $out/bin/profile-cleaner \
-      --prefix PATH : "${parallel}/bin:${sqlite}/bin"
+      --prefix PATH : "${parallel}/bin:${sqlite.bin}/bin"
   '';
 
   meta = {
diff --git a/pkgs/tools/misc/trash-cli/default.nix b/pkgs/tools/misc/trash-cli/default.nix
index 1c8a2e495b69..bd1d8501eeaa 100644
--- a/pkgs/tools/misc/trash-cli/default.nix
+++ b/pkgs/tools/misc/trash-cli/default.nix
@@ -19,7 +19,7 @@ python2Packages.buildPythonPackage rec {
       src = ./nix-paths.patch;
       df = "${coreutils}/bin/df";
       python = "${python2}/bin/${python2.executable}";
-      libc = "${stdenv.cc.libc}/lib/libc.so.6";
+      libc = "${stdenv.cc.libc.out}/lib/libc.so.6";
     })
 
     # Apply https://github.com/JaviMerino/trash-cli/commit/4f45a37a3
diff --git a/pkgs/tools/misc/xdummy/default.nix b/pkgs/tools/misc/xdummy/default.nix
index 30aba19930c7..1f4dbc863327 100644
--- a/pkgs/tools/misc/xdummy/default.nix
+++ b/pkgs/tools/misc/xdummy/default.nix
@@ -18,7 +18,7 @@ let
     EndSection
 
     Section "Files"
-      ModulePath "${xorg.xorgserver}/lib/xorg/modules"
+      ModulePath "${xorg.xorgserver.out}/lib/xorg/modules"
       ModulePath "${xorg.xf86videodummy}/lib/xorg/modules"
       XkbDir "${xkeyboard_config}/share/X11/xkb"
       FontPath "${xorg.fontadobe75dpi}/lib/X11/fonts/75dpi"
@@ -75,7 +75,7 @@ let
 in writeScriptBin "xdummy" ''
   #!${stdenv.shell}
   export XKB_BINDIR="${xorg.xkbcomp}/bin"
-  exec ${xorg.xorgserver}/bin/Xorg \
+  exec ${xorg.xorgserver.out}/bin/Xorg \
     -noreset \
     -logfile /dev/null \
     "$@" \
diff --git a/pkgs/tools/misc/xvfb-run/default.nix b/pkgs/tools/misc/xvfb-run/default.nix
index 162fb73b3f00..f1cf04424349 100644
--- a/pkgs/tools/misc/xvfb-run/default.nix
+++ b/pkgs/tools/misc/xvfb-run/default.nix
@@ -17,6 +17,6 @@ stdenv.mkDerivation {
     wrapProgram $out/bin/xvfb-run \
       --set XKB_BINDIR "${xkbcomp}/bin" \
       --set FONTCONFIG_FILE "${fontsConf}" \
-      --prefix PATH : ${getopt}/bin:${xorgserver}/bin:${xauth}/bin:${which}/bin:${utillinux}/bin
+      --prefix PATH : ${getopt}/bin:${xorgserver.out}/bin:${xauth}/bin:${which}/bin:${utillinux}/bin
   '';
 }
diff --git a/pkgs/tools/misc/youtube-dl/default.nix b/pkgs/tools/misc/youtube-dl/default.nix
index 8baa5cc91740..f3bfa218df4a 100644
--- a/pkgs/tools/misc/youtube-dl/default.nix
+++ b/pkgs/tools/misc/youtube-dl/default.nix
@@ -23,7 +23,7 @@ buildPythonPackage rec {
 
   # Ensure ffmpeg is available in $PATH for post-processing & transcoding support.
   postInstall = stdenv.lib.optionalString (ffmpeg != null)
-    ''wrapProgram $out/bin/youtube-dl --prefix PATH : "${ffmpeg}/bin"'';
+    ''wrapProgram $out/bin/youtube-dl --prefix PATH : "${ffmpeg.bin}/bin"'';
 
   # Requires network
   doCheck = false;
diff --git a/pkgs/tools/networking/cjdns/default.nix b/pkgs/tools/networking/cjdns/default.nix
index 906ca5f39dd3..a3719570e894 100644
--- a/pkgs/tools/networking/cjdns/default.nix
+++ b/pkgs/tools/networking/cjdns/default.nix
@@ -16,13 +16,13 @@ stdenv.mkDerivation {
 
   buildInputs = [ which python27 nodejs ] ++
     # for flock
-    stdenv.lib.optional stdenv.isLinux [ utillinux ];
+    stdenv.lib.optional stdenv.isLinux utillinux;
 
   buildPhase =
     stdenv.lib.optionalString stdenv.isArm "Seccomp_NO=1 "
     + "bash do";
   installPhase = ''
-    installBin cjdroute makekeys privatetopublic publictoip6
+    install -Dt "$out/bin/" cjdroute makekeys privatetopublic publictoip6
     sed -i 's,/usr/bin/env node,'$(type -P node), \
       $(find contrib -name "*.js")
     sed -i 's,/usr/bin/env python,'$(type -P python), \
diff --git a/pkgs/tools/networking/curl/default.nix b/pkgs/tools/networking/curl/default.nix
index 3c77d2a6c8d6..5e283943baf4 100644
--- a/pkgs/tools/networking/curl/default.nix
+++ b/pkgs/tools/networking/curl/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl
+{ stdenv, fetchurl, pkgconfig
 , idnSupport ? false, libidn ? null
 , ldapSupport ? false, openldap ? null
 , zlibSupport ? false, zlib ? null
@@ -23,6 +23,9 @@ stdenv.mkDerivation rec {
     sha256 = "1slq5c0v9wa8hajgimhkxhvsrd07jmih8sa3gjsl597qp5k4w5b5";
   };
 
+  outputs = [ "dev" "out" "bin" "man" "docdev" ];
+
+  nativeBuildInputs = [ pkgconfig ];
   # Zlib and OpenSSL must be propagated because `libcurl.la' contains
   # "-lz -lssl", which aren't necessary direct build inputs of
   # applications that use Curl.
@@ -60,6 +63,11 @@ stdenv.mkDerivation rec {
   CXX = "g++";
   CXXCPP = "g++ -E";
 
+  postInstall = ''
+    moveToOutput bin/curl-config "$dev"
+    sed '/^dependency_libs/s|${libssh2.dev}|${libssh2.out}|' -i "$out"/lib/*.la
+  '';
+
   crossAttrs = {
     # We should refer to the cross built openssl
     # For the 'urandom', maybe it should be a cross-system option
diff --git a/pkgs/tools/networking/gupnp-tools/default.nix b/pkgs/tools/networking/gupnp-tools/default.nix
index af6eff5c31e9..f846a711aa4a 100644
--- a/pkgs/tools/networking/gupnp-tools/default.nix
+++ b/pkgs/tools/networking/gupnp-tools/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   postInstall = ''
     for program in gupnp-av-cp gupnp-universal-cp; do
       wrapProgram "$out/bin/$program" \
-        --prefix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:${gnome2.gnome_icon_theme}/share:$out/share"
+        --prefix XDG_DATA_DIRS : "${gtk3.out}/share:${gnome3.gnome_themes_standard}/share:${gnome2.gnome_icon_theme}/share:$out/share"
     done
   '';
 
diff --git a/pkgs/tools/networking/inetutils/default.nix b/pkgs/tools/networking/inetutils/default.nix
index eca416b53d4e..a92c34328579 100644
--- a/pkgs/tools/networking/inetutils/default.nix
+++ b/pkgs/tools/networking/inetutils/default.nix
@@ -10,7 +10,7 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ ncurses /* for `talk' */ ];
 
-  configureFlags = "--with-ncurses-include-dir=${ncurses}/include";
+  configureFlags = "--with-ncurses-include-dir=${ncurses.dev}/include";
 
   # Test fails with "UNIX socket name too long", probably because our
   # $TMPDIR is too long.
diff --git a/pkgs/tools/networking/megatools/default.nix b/pkgs/tools/networking/megatools/default.nix
index 10a951f84fc1..7c2a437ab658 100644
--- a/pkgs/tools/networking/megatools/default.nix
+++ b/pkgs/tools/networking/megatools/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
   postInstall = ''
     for i in $(find $out/bin/ -type f); do
       wrapProgram "$i" \
-            --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules" \
+            --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules" \
             --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH"
     done
   '';
diff --git a/pkgs/tools/networking/netsniff-ng/default.nix b/pkgs/tools/networking/netsniff-ng/default.nix
index b83b7927679d..3705745b957f 100644
--- a/pkgs/tools/networking/netsniff-ng/default.nix
+++ b/pkgs/tools/networking/netsniff-ng/default.nix
@@ -22,7 +22,7 @@ stdenv.mkDerivation rec {
   configurePhase = ''
     patchShebangs configure
     substituteInPlace configure --replace "which" "command -v"
-    NACL_INC_DIR=${libsodium}/include/sodium NACL_LIB=sodium ./configure
+    NACL_INC_DIR=${libsodium.dev}/include/sodium NACL_LIB=sodium ./configure
   '';
 
   enableParallelBuilding = true;
diff --git a/pkgs/tools/networking/network-manager-applet/default.nix b/pkgs/tools/networking/network-manager-applet/default.nix
index 93ab1266c6ba..e089f69ebd82 100644
--- a/pkgs/tools/networking/network-manager-applet/default.nix
+++ b/pkgs/tools/networking/network-manager-applet/default.nix
@@ -39,7 +39,7 @@ stdenv.mkDerivation rec {
 
   preFixup = ''
     wrapProgram "$out/bin/nm-applet" \
-      --prefix GIO_EXTRA_MODULES : "${glib_networking}/lib/gio/modules:${gnome3.dconf}/lib/gio/modules" \
+      --prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules:${gnome3.dconf}/lib/gio/modules" \
       --prefix XDG_DATA_DIRS : "${gnome3.gtk}/share:$out/share:$GSETTINGS_SCHEMAS_PATH" \
       --set GCONF_CONFIG_SOURCE "xml::~/.gconf" \
       --prefix PATH ":" "${gnome3.gconf}/bin"
diff --git a/pkgs/tools/networking/network-manager/default.nix b/pkgs/tools/networking/network-manager/default.nix
index c86b59d48354..82134634e872 100644
--- a/pkgs/tools/networking/network-manager/default.nix
+++ b/pkgs/tools/networking/network-manager/default.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchurl, intltool, wirelesstools, pkgconfig, dbus_glib, xz
-, udev, libgudev, libnl, libuuid, polkit, gnutls, ppp, dhcp, dhcpcd, iptables
+, systemd, libgudev, libnl, libuuid, polkit, gnutls, ppp, dhcp, dhcpcd, iptables
 , libgcrypt, dnsmasq, avahi, bind, perl, bluez5, substituteAll, readline
 , gobjectIntrospection, modemmanager, openresolv, libndp, newt, libsoup
 , ethtool, gnused }:
@@ -48,7 +48,7 @@ stdenv.mkDerivation rec {
     "--with-libsoup=yes"
   ];
 
-  buildInputs = [ wirelesstools udev libgudev libnl libuuid polkit ppp libndp
+  buildInputs = [ wirelesstools systemd libgudev libnl libuuid polkit ppp libndp
                   xz bluez5 dnsmasq gobjectIntrospection modemmanager readline newt libsoup ];
 
   propagatedBuildInputs = [ dbus_glib gnutls libgcrypt ];
diff --git a/pkgs/tools/networking/nylon/default.nix b/pkgs/tools/networking/nylon/default.nix
index daeb7ffb57bb..fc89ea8db51b 100644
--- a/pkgs/tools/networking/nylon/default.nix
+++ b/pkgs/tools/networking/nylon/default.nix
@@ -1,5 +1,11 @@
-{ stdenv, fetchurl, libevent }:
-
+{ stdenv, fetchurl, libevent, buildEnv }:
+let
+  # failed to find a better way to make it work
+  libevent-comb = buildEnv {
+    inherit (libevent.out) name;
+    paths = [ libevent.dev libevent.out ];
+  };
+in
 stdenv.mkDerivation {
   name = "nylon-1.21";
   src = fetchurl {
@@ -9,7 +15,7 @@ stdenv.mkDerivation {
 
   patches = [ ./configure-use-solib.patch ];
 
-  configureFlags = [ "--with-libevent=${libevent}" ];
+  configureFlags = [ "--with-libevent=${libevent-comb}" ];
 
   buildInputs = [ libevent ];
 
diff --git a/pkgs/tools/networking/openconnect.nix b/pkgs/tools/networking/openconnect.nix
index 54239b766174..43e48e9a4cdf 100644
--- a/pkgs/tools/networking/openconnect.nix
+++ b/pkgs/tools/networking/openconnect.nix
@@ -18,8 +18,8 @@ stdenv.mkDerivation rec {
 
   preConfigure = ''
       export PKG_CONFIG=${pkgconfig}/bin/pkg-config
-      export LIBXML2_CFLAGS="-I ${libxml2}/include/libxml2"
-      export LIBXML2_LIBS="-L${libxml2}/lib -lxml2"
+      export LIBXML2_CFLAGS="-I ${libxml2.dev}/include/libxml2"
+      export LIBXML2_LIBS="-L${libxml2.out}/lib -lxml2"
     '';
 
   configureFlags = [
diff --git a/pkgs/tools/networking/p2p/gtk-gnutella/default.nix b/pkgs/tools/networking/p2p/gtk-gnutella/default.nix
index 5f335c8f76a9..ec2821f4d818 100644
--- a/pkgs/tools/networking/p2p/gtk-gnutella/default.nix
+++ b/pkgs/tools/networking/p2p/gtk-gnutella/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation {
   nativeBuildInputs = [ bison pkgconfig ];
   buildInputs = [ glib gtk libxml2 gettext zlib ];
 
-  NIX_LDFLAGS = "-rpath ${zlib}/lib";
+  NIX_LDFLAGS = "-rpath ${zlib.out}/lib";
   configureScript = "./Configure";
   dontAddPrefix = true;
   configureFlags = "-d -e -D prefix=$out -D gtkversion=2 -D official=true";
diff --git a/pkgs/tools/networking/p2p/seeks/default.nix b/pkgs/tools/networking/p2p/seeks/default.nix
index 28dce0f567e9..621e71c9eae2 100644
--- a/pkgs/tools/networking/p2p/seeks/default.nix
+++ b/pkgs/tools/networking/p2p/seeks/default.nix
@@ -1,4 +1,4 @@
-{ fetchgit, stdenv, zlib, docbook2x, pcre, curl, libxml2, libevent, perl
+{ fetchgit, stdenv, zlib, bzip2, docbook2x, pcre, curl, libxml2, libevent, perl
 , pkgconfig, protobuf, tokyocabinet, tokyotyrant, opencv, autoconf, automake
 , libtool, seeks_confDir ? ""
 }:
@@ -13,14 +13,14 @@ stdenv.mkDerivation {
   };
 
   buildInputs =
-    [ zlib docbook2x pcre curl libxml2 libevent perl pkgconfig
+    [ zlib bzip2 docbook2x pcre curl libxml2 libevent perl pkgconfig
       protobuf tokyocabinet tokyotyrant opencv autoconf automake libtool
     ];
 
   configureFlags =
     [ # Enable the built-in web server providing a web search interface.
       "--enable-httpserv-plugin=yes"
-      "--with-libevent=${libevent}"
+      "--with-libevent=${libevent.dev}"
     ];
 
   preConfigure = ''
diff --git a/pkgs/tools/networking/plasma-nm/default.nix b/pkgs/tools/networking/plasma-nm/default.nix
index 0c10e6655b8e..f0f379d38295 100644
--- a/pkgs/tools/networking/plasma-nm/default.nix
+++ b/pkgs/tools/networking/plasma-nm/default.nix
@@ -14,7 +14,7 @@ stdenv.mkDerivation {
     sha256 = "0xj14isvjq8ll70b6q66n8adm8ff4j9ng195ndk2gmavjf6bb751";
   };
 
-  NIX_CFLAGS_COMPILE = "-I${glib}/include/glib-2.0 -I${glib}/lib/glib-2.0/include";
+  NIX_CFLAGS_COMPILE = "-I${glib.dev}/include/glib-2.0 -I${glib.out}/lib/glib-2.0/include";
 
   nativeBuildInputs = [ automoc4 cmake gettext perl pkgconfig ];
 
diff --git a/pkgs/tools/networking/ppp/default.nix b/pkgs/tools/networking/ppp/default.nix
index 43349178211f..7d3ced17b40c 100644
--- a/pkgs/tools/networking/ppp/default.nix
+++ b/pkgs/tools/networking/ppp/default.nix
@@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
     [ ( substituteAll {
         src = ./nix-purity.patch;
         inherit libpcap;
-        glibc = stdenv.cc.libc;
+        glibc = stdenv.cc.libc.dev;
       })
       # Without nonpriv.patch, pppd --version doesn't work when not run as
       # root.
diff --git a/pkgs/tools/networking/unbound/default.nix b/pkgs/tools/networking/unbound/default.nix
index b15473ddf4c9..51b7285e3e8a 100644
--- a/pkgs/tools/networking/unbound/default.nix
+++ b/pkgs/tools/networking/unbound/default.nix
@@ -9,21 +9,29 @@ stdenv.mkDerivation rec {
     sha256 = "1jly2apag4yg649w3flaq73wdrcfyxnhx5py9j73y7adxmswigbn";
   };
 
+  outputs = [ "out" "lib" "man" ]; # "dev" would only split ~20 kB
+
   buildInputs = [ openssl expat libevent ];
 
   configureFlags = [
-    "--with-ssl=${openssl}"
+    "--with-ssl=${openssl.dev}"
     "--with-libexpat=${expat}"
-    "--with-libevent=${libevent}"
+    "--with-libevent=${libevent.dev}"
     "--localstatedir=/var"
     "--sysconfdir=/etc"
   ];
 
   installFlags = [ "configfile=\${out}/etc/unbound/unbound.conf" ];
 
-  meta = {
+  # get rid of runtime dependencies on $dev outputs
+  postInstall = ''substituteInPlace "$lib/lib/libunbound.la" ''
+    + stdenv.lib.concatMapStrings
+      (pkg: " --replace '-L${pkg.dev}/lib' '-L${pkg.out}/lib' ")
+      [ openssl expat libevent ];
+
+  meta = with stdenv.lib; {
     description = "Validating, recursive, and caching DNS resolver";
-    license = stdenv.lib.licenses.bsd3;
+    license = licenses.bsd3;
     homepage = http://www.unbound.net;
     maintainers = [ stdenv.lib.maintainers.ehmry ];
     platforms = stdenv.lib.platforms.unix;
diff --git a/pkgs/tools/networking/uwimap/default.nix b/pkgs/tools/networking/uwimap/default.nix
index 1da9ca969841..e2c83bcb975c 100644
--- a/pkgs/tools/networking/uwimap/default.nix
+++ b/pkgs/tools/networking/uwimap/default.nix
@@ -18,8 +18,9 @@ stdenv.mkDerivation {
     ++ stdenv.lib.optional (!stdenv.isDarwin) pam;
 
   patchPhase = ''
-    sed -i -e s,/usr/local/ssl,${openssl}, \
-      src/osdep/unix/Makefile
+    sed -i src/osdep/unix/Makefile -e 's,/usr/local/ssl,${openssl},'
+    sed -i src/osdep/unix/Makefile -e 's,^SSLCERTS=.*,SSLCERTS=/etc/ssl/certs,'
+    sed -i src/osdep/unix/Makefile -e 's,^SSLLIB=.*,SSLLIB=${openssl.out}/lib,'
   '';
 
   NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin
diff --git a/pkgs/tools/networking/wget/default.nix b/pkgs/tools/networking/wget/default.nix
index a6d2913abf66..9b9909a89432 100644
--- a/pkgs/tools/networking/wget/default.nix
+++ b/pkgs/tools/networking/wget/default.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation rec {
     sha256 = "1jcpvl5sxb2ag8yahpy370c5jlfb097a21k2mhsidh4wxdhrnmgy";
   };
 
+  patches = [ ./remove-runtime-dep-on-openssl-headers.patch ];
+
   preConfigure = ''
     for i in "doc/texi2pod.pl" "util/rmold.pl"; do
       sed -i "$i" -e 's|/usr/bin.*perl|${perl}/bin/perl|g'
diff --git a/pkgs/tools/networking/wget/remove-runtime-dep-on-openssl-headers.patch b/pkgs/tools/networking/wget/remove-runtime-dep-on-openssl-headers.patch
new file mode 100644
index 000000000000..a6a1fcfcb37b
--- /dev/null
+++ b/pkgs/tools/networking/wget/remove-runtime-dep-on-openssl-headers.patch
@@ -0,0 +1,17 @@
+diff --git a/src/Makefile.in b/src/Makefile.in
+index 1a36a9b..e279c84 100644
+--- a/src/Makefile.in
++++ b/src/Makefile.in
+@@ -2211,10 +2211,9 @@ version.c:  $(wget_SOURCES) ../lib/libgnu.a
+ 	echo '' >> $@
+ 	echo '#include "version.h"' >> $@
+ 	echo 'const char *version_string = "@VERSION@";' >> $@
+-	echo 'const char *compilation_string = "'$(COMPILE)'";' \
++	echo 'const char *compilation_string = 0;' \
+ 	    | $(ESCAPEQUOTE) >> $@
+-	echo 'const char *link_string = "'$(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+-	$(AM_LDFLAGS) $(LDFLAGS) $(LIBS) $(wget_LDADD)'";' \
++	echo 'const char *link_string = 0;' \
+ 	    | $(ESCAPEQUOTE) >> $@
+ 
+ css.c: $(srcdir)/css.l
diff --git a/pkgs/tools/networking/zerotierone/default.nix b/pkgs/tools/networking/zerotierone/default.nix
index d9a50d7dc696..63531a85ffc1 100644
--- a/pkgs/tools/networking/zerotierone/default.nix
+++ b/pkgs/tools/networking/zerotierone/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ openssl lzo zlib gcc iproute ];
 
   installPhase = ''
-    installBin zerotier-one
+    install -Dt "$out/bin/" zerotier-one
     ln -s $out/bin/zerotier-one $out/bin/zerotier-idtool
     ln -s $out/bin/zerotier-one $out/bin/zerotier-cli
   '';
diff --git a/pkgs/tools/package-management/checkinstall/default.nix b/pkgs/tools/package-management/checkinstall/default.nix
index dc3373c3b6fc..8ab9001573a2 100644
--- a/pkgs/tools/package-management/checkinstall/default.nix
+++ b/pkgs/tools/package-management/checkinstall/default.nix
@@ -51,7 +51,7 @@ stdenv.mkDerivation {
     substituteInPlace checkinstallrc-dist --replace /usr/local $out
 
     substituteInPlace installwatch/create-localdecls \
-      --replace /usr/include/unistd.h ${stdenv.glibc}/include/unistd.h
+      --replace /usr/include/unistd.h ${stdenv.glibc.dev}/include/unistd.h
   '';
 
   postInstall =
diff --git a/pkgs/tools/package-management/nix-prefetch-scripts/default.nix b/pkgs/tools/package-management/nix-prefetch-scripts/default.nix
index 5b98bcbbe12b..f315ca478765 100644
--- a/pkgs/tools/package-management/nix-prefetch-scripts/default.nix
+++ b/pkgs/tools/package-management/nix-prefetch-scripts/default.nix
@@ -35,8 +35,8 @@ in rec {
   nix-prefetch-cvs = mkPrefetchScript "cvs" ../../../build-support/fetchcvs/nix-prefetch-cvs [cvs];
   nix-prefetch-git = mkPrefetchScript "git" ../../../build-support/fetchgit/nix-prefetch-git [git coreutils];
   nix-prefetch-hg  = mkPrefetchScript "hg"  ../../../build-support/fetchhg/nix-prefetch-hg   [mercurial];
-  nix-prefetch-svn = mkPrefetchScript "svn" ../../../build-support/fetchsvn/nix-prefetch-svn [subversion];
-  nix-prefetch-zip = mkPrefetchScript "zip" ../../../build-support/fetchzip/nix-prefetch-zip [unzip curl];
+  nix-prefetch-svn = mkPrefetchScript "svn" ../../../build-support/fetchsvn/nix-prefetch-svn [subversion.out];
+  nix-prefetch-zip = mkPrefetchScript "zip" ../../../build-support/fetchzip/nix-prefetch-zip [unzip curl.bin];
 
   nix-prefetch-scripts = buildEnv {
     name = "nix-prefetch-scripts";
diff --git a/pkgs/tools/package-management/nix/default.nix b/pkgs/tools/package-management/nix/default.nix
index d615ac10646a..3a7158994a9c 100644
--- a/pkgs/tools/package-management/nix/default.nix
+++ b/pkgs/tools/package-management/nix/default.nix
@@ -22,8 +22,8 @@ let
     # would end up using the wrong bzip2 when cross-compiling.
     # XXX: The right thing would be to reinstate `--with-bzip2' in Nix.
     postUnpack =
-      '' export CPATH="${bzip2}/include"
-         export LIBRARY_PATH="${bzip2}/lib"
+      '' export CPATH="${bzip2.dev}/include"
+         export LIBRARY_PATH="${bzip2.out}/lib"
          export CXXFLAGS="-Wno-error=reserved-user-defined-literal"
       '';
 
diff --git a/pkgs/tools/package-management/nix/unstable.nix b/pkgs/tools/package-management/nix/unstable.nix
new file mode 100644
index 000000000000..88bd8f460375
--- /dev/null
+++ b/pkgs/tools/package-management/nix/unstable.nix
@@ -0,0 +1,76 @@
+{ lib, stdenv, fetchurl, perl, curl, bzip2, sqlite, openssl ? null
+, pkgconfig, boehmgc, perlPackages, libsodium
+, storeDir ? "/nix/store"
+, stateDir ? "/nix/var"
+}:
+
+stdenv.mkDerivation rec {
+  name = "nix-1.9pre4100_4bbcfaf";
+
+  src = fetchurl {
+    url = "http://hydra.nixos.org/build/21565942/download/4/${name}.tar.xz";
+    sha256 = "1jcy0n8mi17k5vk89vammfh74lvsgnm4gjsk23cq1shspjnbbgxs";
+  };
+
+  nativeBuildInputs = [ perl pkgconfig ];
+
+  buildInputs = [ curl openssl sqlite ] ++ lib.optional stdenv.isLinux libsodium;
+
+  propagatedBuildInputs = [ boehmgc ];
+
+  # Note: bzip2 is not passed as a build input, because the unpack phase
+  # would end up using the wrong bzip2 when cross-compiling.
+  # XXX: The right thing would be to reinstate `--with-bzip2' in Nix.
+  postUnpack =
+    '' export CPATH="${bzip2.dev}/include"
+       export LIBRARY_PATH="${bzip2.out}/lib"
+       export CXXFLAGS="-Wno-error=reserved-user-defined-literal"
+    '';
+
+  configureFlags =
+    ''
+      --with-store-dir=${storeDir} --localstatedir=${stateDir} --sysconfdir=/etc
+      --with-dbi=${perlPackages.DBI}/${perl.libPrefix}
+      --with-dbd-sqlite=${perlPackages.DBDSQLite}/${perl.libPrefix}
+      --with-www-curl=${perlPackages.WWWCurl}/${perl.libPrefix}
+      --disable-init-state
+      --enable-gc
+    '';
+
+  makeFlags = "profiledir=$(out)/etc/profile.d";
+
+  installFlags = "sysconfdir=$(out)/etc";
+
+  doInstallCheck = true;
+
+  crossAttrs = {
+    postUnpack =
+      '' export CPATH="${bzip2.crossDrv}/include"
+         export NIX_CROSS_LDFLAGS="-L${bzip2.crossDrv}/lib -rpath-link ${bzip2.crossDrv}/lib $NIX_CROSS_LDFLAGS"
+      '';
+
+    configureFlags =
+      ''
+        --with-store-dir=${storeDir} --localstatedir=${stateDir}
+        --with-dbi=${perlPackages.DBI}/${perl.libPrefix}
+        --with-dbd-sqlite=${perlPackages.DBDSQLite}/${perl.libPrefix}
+        --with-www-curl=${perlPackages.WWWCurl}/${perl.libPrefix}
+        --disable-init-state
+        --enable-gc
+      '' + stdenv.lib.optionalString (
+          stdenv.cross ? nix && stdenv.cross.nix ? system
+      ) ''--with-system=${stdenv.cross.nix.system}'';
+
+    doInstallCheck = false;
+  };
+
+  enableParallelBuilding = true;
+
+  meta = {
+    description = "The Nix Deployment System";
+    homepage = http://nixos.org/;
+    license = stdenv.lib.licenses.lgpl2Plus;
+    maintainers = [ stdenv.lib.maintainers.eelco ];
+    platforms = stdenv.lib.platforms.all;
+  };
+}
diff --git a/pkgs/tools/package-management/rpm/default.nix b/pkgs/tools/package-management/rpm/default.nix
index 7b5281220fab..24346fb0eb70 100644
--- a/pkgs/tools/package-management/rpm/default.nix
+++ b/pkgs/tools/package-management/rpm/default.nix
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
 
   # Note: we don't add elfutils to buildInputs, since it provides a
   # bad `ld' and other stuff.
-  NIX_CFLAGS_COMPILE = "-I${nspr}/include/nspr -I${nss}/include/nss -I${elfutils}/include";
+  NIX_CFLAGS_COMPILE = "-I${nspr.dev}/include/nspr -I${nss.dev}/include/nss -I${elfutils}/include";
 
   NIX_CFLAGS_LINK = "-L${elfutils}/lib";
 
diff --git a/pkgs/tools/security/chntpw/default.nix b/pkgs/tools/security/chntpw/default.nix
index 814fb0ea0ecc..1f999e9d726d 100644
--- a/pkgs/tools/security/chntpw/default.nix
+++ b/pkgs/tools/security/chntpw/default.nix
@@ -10,7 +10,8 @@ stdenv.mkDerivation rec {
     sha256 = "1k1cxsj0221dpsqi5yibq2hr7n8xywnicl8yyaicn91y8h2hkqln";
   };
 
-  buildInputs = [ unzip ];
+  buildInputs = [ unzip ]
+    ++ stdenv.lib.optionals stdenv.isLinux [ stdenv.glibc.out stdenv.glibc.static ];
 
   patches = [
     ./00-chntpw-build-arch-autodetect.patch
diff --git a/pkgs/tools/security/modsecurity/default.nix b/pkgs/tools/security/modsecurity/default.nix
index 2f3101cffea8..09754f53a9ed 100644
--- a/pkgs/tools/security/modsecurity/default.nix
+++ b/pkgs/tools/security/modsecurity/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, fetchurl
+{ stdenv, lib, fetchurl, pkgconfig
 , curl, apacheHttpd, pcre, apr, aprutil, libxml2 }:
 
 with lib;
@@ -12,6 +12,7 @@ stdenv.mkDerivation rec {
     sha256 = "e2bbf789966c1f80094d88d9085a81bde082b2054f8e38e0db571ca49208f434";
   };
 
+  nativeBuildInputs = [ pkgconfig ];
   buildInputs = [ curl apacheHttpd pcre apr aprutil libxml2 ];
   configureFlags = [
     "--enable-standalone-module"
diff --git a/pkgs/tools/security/mpw/default.nix b/pkgs/tools/security/mpw/default.nix
index 15937a6792e6..a565c3b96e14 100644
--- a/pkgs/tools/security/mpw/default.nix
+++ b/pkgs/tools/security/mpw/default.nix
@@ -27,7 +27,7 @@ in stdenv.mkDerivation {
     patchShebangs .
   '';
 
-  NIX_CFLAGS_COMPILE = "-I${libxml2}/include/libxml2";
+  NIX_CFLAGS_COMPILE = "-I${libxml2.dev}/include/libxml2";
 
   buildInputs = [ autoconf automake openssl libxml2 ];
 
diff --git a/pkgs/tools/security/prey/default.nix b/pkgs/tools/security/prey/default.nix
index b36c11cf9345..f9bd6ea50e8d 100644
--- a/pkgs/tools/security/prey/default.nix
+++ b/pkgs/tools/security/prey/default.nix
@@ -34,7 +34,7 @@ in stdenv.mkDerivation rec {
     cp -R . $out
     cp -R ${modulesSrc}/* $out/modules/
     wrapProgram "$out/prey.sh" \
-      --prefix PATH ":" "${xawtv}/bin:${imagemagick}/bin:${curl}/bin:${scrot}/bin:${inetutils}/bin:${coreutils}/bin" \
+      --prefix PATH ":" "${xawtv}/bin:${imagemagick}/bin:${curl.bin}/bin:${scrot}/bin:${inetutils}/bin:${coreutils}/bin" \
       --set CURL_CA_BUNDLE "/etc/ssl/certs/ca-certificates.crt"
   '';
 
diff --git a/pkgs/tools/security/thc-hydra/default.nix b/pkgs/tools/security/thc-hydra/default.nix
index c06636dc3677..a06754cb58d2 100644
--- a/pkgs/tools/security/thc-hydra/default.nix
+++ b/pkgs/tools/security/thc-hydra/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, openssl, libidn, ncurses, pcre, libssh, postgresql92 }:
+{ stdenv, fetchurl, pkgconfig, openssl, libidn, ncurses, pcre, libssh, postgresql92 }:
 
 with stdenv.lib;
 
@@ -12,10 +12,11 @@ stdenv.mkDerivation rec {
   };
 
   preConfigure = ''
-   substituteInPlace configure --replace "\$LIBDIRS" "${openssl}/lib ${pcre}/lib ${libssh}/lib ${postgresql92}/lib"
-   substituteInPlace configure --replace "\$INCDIRS" "${openssl}/include ${pcre}/include ${libssh}/include ${postgresql92}/include"
+   substituteInPlace configure --replace "\$LIBDIRS" "${openssl.out}/lib ${pcre.out}/lib ${libssh.out}/lib ${postgresql92.lib}/lib"
+   substituteInPlace configure --replace "\$INCDIRS" "${openssl.dev}/include ${pcre.dev}/include ${libssh.dev}/include ${postgresql92}/include"
   '';
 
+  nativeBuildInputs = [ pkgconfig ];
   buildInputs = [ openssl libidn ncurses pcre libssh ];
 
   meta = {
diff --git a/pkgs/tools/security/tor/tor-arm.nix b/pkgs/tools/security/tor/tor-arm.nix
index 6c4d61d825f9..365379c8f6a8 100644
--- a/pkgs/tools/security/tor/tor-arm.nix
+++ b/pkgs/tools/security/tor/tor-arm.nix
@@ -37,7 +37,7 @@ stdenv.mkDerivation rec {
     for i in $(cd $out/bin && ls); do
       wrapProgram $out/bin/$i \
         --prefix PYTHONPATH : "$(toPythonPath $out):$(toPythonPath ${pythonPackages.curses}):$out/libexec:$PYTHONPATH" \
-        --set TERMINFO "${ncurses}/share/terminfo" \
+        --set TERMINFO "${ncurses.out}/share/terminfo" \
         --set TERM     "xterm"
     done
   '';
diff --git a/pkgs/tools/security/trousers/default.nix b/pkgs/tools/security/trousers/default.nix
index e910241113b9..d57aa8c63a92 100644
--- a/pkgs/tools/security/trousers/default.nix
+++ b/pkgs/tools/security/trousers/default.nix
@@ -21,7 +21,7 @@ stdenv.mkDerivation rec {
 
   # Fix broken libtool file
   preFixup = stdenv.lib.optionalString (!stdenv.isDarwin) ''
-    sed 's,-lcrypto,-L${openssl}/lib -lcrypto,' -i $out/lib/libtspi.la
+    sed 's,-lcrypto,-L${openssl.out}/lib -lcrypto,' -i $out/lib/libtspi.la
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/tools/system/gptfdisk/default.nix b/pkgs/tools/system/gptfdisk/default.nix
index 264dbf1eb279..940383a6bc65 100644
--- a/pkgs/tools/system/gptfdisk/default.nix
+++ b/pkgs/tools/system/gptfdisk/default.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
     substituteInPlace Makefile.mac --replace \
       " -I/opt/local/include -I /usr/local/include -I/opt/local/include" ""
     substituteInPlace Makefile.mac --replace \
-      "/opt/local/lib/libncurses.a" "${ncurses}/lib/libncurses.dylib"
+      "/opt/local/lib/libncurses.a" "${ncurses.lib}/lib/libncurses.dylib"
   '';
 
   buildPhase = stdenv.lib.optionalString stdenv.isDarwin "make -f Makefile.mac";
diff --git a/pkgs/tools/system/monit/default.nix b/pkgs/tools/system/monit/default.nix
index 1b15fbbb6281..0ee32a49c07b 100644
--- a/pkgs/tools/system/monit/default.nix
+++ b/pkgs/tools/system/monit/default.nix
@@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
 
   configureFlags = [
     "--with-ssl-incl-dir=${openssl}/include"
-    "--with-ssl-lib-dir=${openssl}/lib"
+    "--with-ssl-lib-dir=${openssl.out}/lib"
   ] ++ stdenv.lib.optionals (! usePAM) [ "--without-pam" ];
 
   meta = {
diff --git a/pkgs/tools/system/plan9port/builder.sh b/pkgs/tools/system/plan9port/builder.sh
index 2434889581ed..15fcdcf6c9dd 100644
--- a/pkgs/tools/system/plan9port/builder.sh
+++ b/pkgs/tools/system/plan9port/builder.sh
@@ -5,8 +5,8 @@ export PLAN9_TARGET=$PLAN9
 
 configurePhase()
 {
-    echo CFLAGS=\"-I${fontconfig}/include -I${libXt}/include\" > LOCAL.config
-    echo X11=\"${libXt}/include\" >> LOCAL.config
+    echo CFLAGS=\"-I${fontconfig_dev}/include -I${libXt_dev}/include\" > LOCAL.config
+    echo X11=\"${libXt_dev}/include\" >> LOCAL.config
 
     for f in `grep -l -r /usr/local/plan9`; do
         sed "s,/usr/local/plan9,${PLAN9},g" -i $f
diff --git a/pkgs/tools/system/plan9port/default.nix b/pkgs/tools/system/plan9port/default.nix
index 3a78cb2baf63..70f792953b85 100644
--- a/pkgs/tools/system/plan9port/default.nix
+++ b/pkgs/tools/system/plan9port/default.nix
@@ -47,6 +47,6 @@ stdenv.mkDerivation rec {
     platforms = platforms.unix;
   };
 
-  inherit libXt;
-  inherit fontconfig;
+  libXt_dev = libXt.dev;
+  fontconfig_dev = fontconfig.dev;
 }
diff --git a/pkgs/tools/system/storebrowse/default.nix b/pkgs/tools/system/storebrowse/default.nix
index 041dd96e1ca8..aa510a28c231 100644
--- a/pkgs/tools/system/storebrowse/default.nix
+++ b/pkgs/tools/system/storebrowse/default.nix
@@ -28,9 +28,9 @@ stdenv.mkDerivation rec {
     GOSQLITE=$GOPATH/src/code.google.com/p/gosqlite
     mkdir -p $GOSQLITE
     cp -R $srcGoSqlite/* $GOSQLITE/
-    export CGO_CFLAGS=-I${sqlite}/include
-    export CGO_LDFLAGS=-L${sqlite}/lib
-    go build -ldflags "-r ${sqlite}/lib" -o storebrowse
+    export CGO_CFLAGS=-I${sqlite.dev}/include
+    export CGO_LDFLAGS=-L${sqlite.out}/lib
+    go build -ldflags "-r ${sqlite.out}/lib" -o storebrowse
   '';
 
   installPhase = ''
diff --git a/pkgs/tools/system/syslog-ng/default.nix b/pkgs/tools/system/syslog-ng/default.nix
index 4fcc0680ada6..d98f05c6aabb 100644
--- a/pkgs/tools/system/syslog-ng/default.nix
+++ b/pkgs/tools/system/syslog-ng/default.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchurl, eventlog, pkgconfig, glib, python, systemd, perl
-, riemann_c_client, protobufc, yacc }:
+, riemann_c_client, protobufc, pcre, yacc }:
 
 stdenv.mkDerivation rec {
   name = "syslog-ng-${version}";
@@ -11,7 +11,7 @@ stdenv.mkDerivation rec {
     sha256 = "0qc21mwajk6xrra3gqy2nvaza5gq62psamq4ayphj7lqabdglizg";
   };
 
-  buildInputs = [ eventlog pkgconfig glib python systemd perl riemann_c_client protobufc yacc ];
+  buildInputs = [ eventlog pkgconfig glib python systemd perl riemann_c_client protobufc yacc pcre ];
 
   configureFlags = [
     "--enable-dynamic-linking"
diff --git a/pkgs/tools/system/thermald/default.nix b/pkgs/tools/system/thermald/default.nix
index 9fe9adaedadb..dd28d5b2b1da 100644
--- a/pkgs/tools/system/thermald/default.nix
+++ b/pkgs/tools/system/thermald/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   patchPhase = ''sed -e 's/upstartconfdir = \/etc\/init/upstartconfdir = $(out)\/etc\/init/' -i data/Makefile.am'';
 
   preConfigure = ''
-                   export PKG_CONFIG_PATH="${dbus_libs}/lib/pkgconfig:$PKG_CONFIG_PATH"
+                   export PKG_CONFIG_PATH="${dbus_libs.dev}/lib/pkgconfig:$PKG_CONFIG_PATH"
                    ./autogen.sh #--prefix="$out"
                  '';
 
diff --git a/pkgs/tools/text/diffutils/default.nix b/pkgs/tools/text/diffutils/default.nix
index f8413b9a0d0f..70a3bdeb7984 100644
--- a/pkgs/tools/text/diffutils/default.nix
+++ b/pkgs/tools/text/diffutils/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, coreutils ? null }:
+{ stdenv, fetchurl, xz, coreutils ? null }:
 
 stdenv.mkDerivation rec {
   name = "diffutils-3.3";
@@ -8,8 +8,10 @@ stdenv.mkDerivation rec {
     sha256 = "1761vymxbp4wb5rzjvabhdkskk95pghnn67464byvzb5mfl8jpm2";
   };
 
+  outputs = [ "out" "info" ];
+
   /* If no explicit coreutils is given, use the one from stdenv. */
-  nativeBuildInputs = [ coreutils ];
+  nativeBuildInputs = [ xz.bin coreutils ];
 
   meta = {
     homepage = http://www.gnu.org/software/diffutils/diffutils.html;
diff --git a/pkgs/tools/text/gawk/default.nix b/pkgs/tools/text/gawk/default.nix
index e2856b7acaa4..8578960b9875 100644
--- a/pkgs/tools/text/gawk/default.nix
+++ b/pkgs/tools/text/gawk/default.nix
@@ -1,6 +1,9 @@
-{ stdenv, fetchurl, libsigsegv, readline, readlineSupport ? false
+{ stdenv, fetchurl, xz, libsigsegv, readline, interactive ? false
 , locale ? null }:
 
+let
+  inherit (stdenv.lib) optional;
+in
 stdenv.mkDerivation rec {
   name = "gawk-4.1.3";
 
@@ -9,6 +12,9 @@ stdenv.mkDerivation rec {
     sha256 = "09d6pmx6h3i2glafm0jd1v1iyrs03vcyv2rkz12jisii3vlmbkz3";
   };
 
+  # When we do build separate interactive version, it makes sense to always include man.
+  outputs = [ "out" "info" ] ++ stdenv.lib.optional (!interactive) "man";
+
   doCheck = !(
        stdenv.isCygwin # XXX: `test-dup2' segfaults on Cygwin 6.1
     || stdenv.isDarwin # XXX: `locale' segfaults
@@ -16,18 +22,17 @@ stdenv.mkDerivation rec {
     || stdenv.isFreeBSD
   );
 
-  buildInputs = stdenv.lib.optional (stdenv.system != "x86_64-cygwin") libsigsegv
-    ++ stdenv.lib.optional readlineSupport readline
+  buildInputs = [ xz.bin ]
+    ++ stdenv.lib.optional (stdenv.system != "x86_64-cygwin") libsigsegv
+    ++ stdenv.lib.optional interactive readline
     ++ stdenv.lib.optional stdenv.isDarwin locale;
 
   configureFlags = stdenv.lib.optional (stdenv.system != "x86_64-cygwin") "--with-libsigsegv-prefix=${libsigsegv}"
-    ++ stdenv.lib.optional readlineSupport "--with-readline=${readline}"
-      # only darwin where reported, seems OK on non-chrooted Fedora (don't rebuild stdenv)
-    ++ stdenv.lib.optional (!readlineSupport && stdenv.isDarwin) "--without-readline";
+    ++ [(if interactive then "--with-readline=${readline}" else "--without-readline")];
 
   postInstall = "rm $out/bin/gawk-*";
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.gnu.org/software/gawk/;
     description = "GNU implementation of the Awk programming language";
 
@@ -45,8 +50,11 @@ stdenv.mkDerivation rec {
       lines of code.
     '';
 
-    license = stdenv.lib.licenses.gpl3Plus;
+    license = licenses.gpl3Plus;
+
+    platforms = platforms.unix;
 
     maintainers = [ ];
   };
 }
+
diff --git a/pkgs/tools/text/gnugrep/default.nix b/pkgs/tools/text/gnugrep/default.nix
index 8ef67674cd21..d618f842a4a5 100644
--- a/pkgs/tools/text/gnugrep/default.nix
+++ b/pkgs/tools/text/gnugrep/default.nix
@@ -12,6 +12,8 @@ stdenv.mkDerivation {
 
   # Perl is needed for testing
   nativeBuildInputs = [ perl ];
+  outputs = [ "out" "info" ]; # the man pages are rather small
+
   buildInputs = [ pcre libiconv ];
 
   # cygwin: FAIL: multibyte-white-space
@@ -38,7 +40,7 @@ stdenv.mkDerivation {
       chmod +x $out/bin/egrep $out/bin/fgrep
     '';
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://www.gnu.org/software/grep/;
     description = "GNU implementation of the Unix grep command";
 
@@ -48,10 +50,10 @@ stdenv.mkDerivation {
       prints the matching lines.
     '';
 
-    license = stdenv.lib.licenses.gpl3Plus;
+    license = licenses.gpl3Plus;
 
-    maintainers = [ stdenv.lib.maintainers.eelco ];
-    platforms = stdenv.lib.platforms.all;
+    maintainers = [ maintainers.eelco ];
+    platforms = platforms.all;
   };
 
   passthru = {inherit pcre;};
diff --git a/pkgs/tools/text/gnused/default.nix b/pkgs/tools/text/gnused/default.nix
index b1c5910029dd..037c2f17a63b 100644
--- a/pkgs/tools/text/gnused/default.nix
+++ b/pkgs/tools/text/gnused/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl}:
+{ stdenv, fetchurl }:
 
 stdenv.mkDerivation {
   name = "gnused-4.2.2";
@@ -8,6 +8,8 @@ stdenv.mkDerivation {
     sha256 = "f048d1838da284c8bc9753e4506b85a1e0cc1ea8999d36f6995bcb9460cddbd7";
   };
 
+  outputs = [ "out" "info" ];
+
   meta = {
     homepage = http://www.gnu.org/software/sed/;
     description = "GNU sed, a batch stream editor";
diff --git a/pkgs/tools/text/groff/default.nix b/pkgs/tools/text/groff/default.nix
index 039bff8c655a..e08c10fd9ed2 100644
--- a/pkgs/tools/text/groff/default.nix
+++ b/pkgs/tools/text/groff/default.nix
@@ -35,9 +35,9 @@ stdenv.mkDerivation rec {
   postInstall = ''
       # Remove example output with (random?) colors to 
       # avoid non-determinism in the output
-      rm $out/share/doc/${name}/examples/hdtbl/*color*ps
+      rm $doc/share/doc/examples/hdtbl/*color*ps
       # Remove creation date
-      find $out/share/doc/${name} -type f -print0 | xargs -0 sed -i -e 's/%%CreationDate: .*//'
+      find $doc/share/doc/ -type f -print0 | xargs -0 sed -i -e 's/%%CreationDate: .*//'
     '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/tools/text/multitran/data/default.nix b/pkgs/tools/text/multitran/data/default.nix
index d0e39add665a..57a375d2a17b 100644
--- a/pkgs/tools/text/multitran/data/default.nix
+++ b/pkgs/tools/text/multitran/data/default.nix
@@ -3,7 +3,7 @@
 # This package requires a locale ru_RU.cp1251 locale entry.
 # Waiting for a better idea, I created it modifying a store file using:
 #   localedef -f CP1251 -i ru_RU ru_RU.CP1251
-# The store file mentioned is in "${glibc}/lib/locale/locale-archive"
+# The store file mentioned is in "${glibc.out}/lib/locale/locale-archive"
 
 stdenv.mkDerivation {
   name = "multitran-data-0.3";
diff --git a/pkgs/tools/text/xidel/default.nix b/pkgs/tools/text/xidel/default.nix
index 89adcc75b195..000584a50e10 100644
--- a/pkgs/tools/text/xidel/default.nix
+++ b/pkgs/tools/text/xidel/default.nix
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
   installPhase = ''
     mkdir -p "$out/bin"
     cp -a usr/* "$out/"
-    interpreter="$(echo ${stdenv.glibc}/lib/ld-linux*)"
+    interpreter="$(echo ${stdenv.glibc.out}/lib/ld-linux*)"
     patchelf --set-interpreter "$interpreter" "$out/bin/xidel"
     patchelf --set-rpath "${stdenv.lib.makeLibraryPath [stdenv.glibc]}" "$out/bin/xidel"
   '';
diff --git a/pkgs/tools/typesetting/asciidoc/default.nix b/pkgs/tools/typesetting/asciidoc/default.nix
index b26582a6cc71..7c393c524151 100644
--- a/pkgs/tools/typesetting/asciidoc/default.nix
+++ b/pkgs/tools/typesetting/asciidoc/default.nix
@@ -237,12 +237,12 @@ stdenv.mkDerivation rec {
     # We can remove PATH= when those impurities are fixed.
     sed -e "s|^ENV =.*|ENV = dict(XML_CATALOG_FILES='${docbook_xml_dtd_45}/xml/dtd/docbook/catalog.xml ${docbook5_xsl}/xml/xsl/docbook/catalog.xml ${docbook_xsl}/xml/xsl/docbook/catalog.xml', PATH='${tetex}/bin:${coreutils}/bin:${gnused}/bin')|" \
         -e "s|^ASCIIDOC =.*|ASCIIDOC = '$out/bin/asciidoc'|" \
-        -e "s|^XSLTPROC =.*|XSLTPROC = '${libxslt}/bin/xsltproc'|" \
+        -e "s|^XSLTPROC =.*|XSLTPROC = '${libxslt.bin}/bin/xsltproc'|" \
         -e "s|^DBLATEX =.*|DBLATEX = '${dblatexFull}/bin/dblatex'|" \
         -e "s|^FOP =.*|FOP = '${fop}/bin/fop'|" \
         -e "s|^W3M =.*|W3M = '${w3m}/bin/w3m'|" \
         -e "s|^LYNX =.*|LYNX = '${lynx}/bin/lynx'|" \
-        -e "s|^XMLLINT =.*|XMLLINT = '${libxml2}/bin/xmllint'|" \
+        -e "s|^XMLLINT =.*|XMLLINT = '${libxml2.bin}/bin/xmllint'|" \
         -e "s|^EPUBCHECK =.*|EPUBCHECK = 'nixpkgs_is_missing_epubcheck'|" \
         -i a2x.py
   '' + ''
diff --git a/pkgs/tools/typesetting/tex/dblatex/default.nix b/pkgs/tools/typesetting/tex/dblatex/default.nix
index 408ef8ae263c..18f9c99ee240 100644
--- a/pkgs/tools/typesetting/tex/dblatex/default.nix
+++ b/pkgs/tools/typesetting/tex/dblatex/default.nix
@@ -37,16 +37,16 @@ stdenv.mkDerivation rec {
     sed -i 's|self.install_layout == "deb"|False|' setup.py
   '' + stdenv.lib.optionalString enableAllFeatures ''
     for file in $(find -name "*.py"); do
-        sed -e 's|cmd = \["xsltproc|cmd = \["${libxslt}/bin/xsltproc|g' \
-            -e 's|Popen(\["xsltproc|Popen(\["${libxslt}/bin/xsltproc|g' \
+        sed -e 's|cmd = \["xsltproc|cmd = \["${libxslt.bin}/bin/xsltproc|g' \
+            -e 's|Popen(\["xsltproc|Popen(\["${libxslt.bin}/bin/xsltproc|g' \
             -e 's|cmd = \["texindy|cmd = ["nixpkgs_is_missing_texindy|g' \
             -e 's|cmd = "epstopdf|cmd = "${tex}/bin/epstopdf|g' \
             -e 's|cmd = \["makeindex|cmd = ["${tex}/bin/makeindex|g' \
             -e 's|doc.program = "pdflatex"|doc.program = "${tex}/bin/pdflatex"|g' \
             -e 's|self.program = "latex"|self.program = "${tex}/bin/latex"|g' \
             -e 's|Popen("pdflatex|Popen("${tex}/bin/pdflatex|g' \
-            -e 's|"fc-match"|"${fontconfig}/bin/fc-match"|g' \
-            -e 's|"fc-list"|"${fontconfig}/bin/fc-list"|g' \
+            -e 's|"fc-match"|"${fontconfig.bin}/bin/fc-match"|g' \
+            -e 's|"fc-list"|"${fontconfig.bin}/bin/fc-list"|g' \
             -e 's|cmd = "inkscape|cmd = "${inkscape}/bin/inkscape|g' \
             -e 's|cmd = "fig2dev|cmd = "${transfig}/bin/fig2dev|g' \
             -e 's|cmd = \["ps2pdf|cmd = ["${ghostscript}/bin/ps2pdf|g' \
diff --git a/pkgs/tools/typesetting/tex/texlive-new/bin.nix b/pkgs/tools/typesetting/tex/texlive-new/bin.nix
index 431f3926a13e..f833cc2f82b1 100644
--- a/pkgs/tools/typesetting/tex/texlive-new/bin.nix
+++ b/pkgs/tools/typesetting/tex/texlive-new/bin.nix
@@ -99,7 +99,8 @@ core = stdenv.mkDerivation rec {
     cp ../texk/texlive/linked_scripts/scripts.lst "$out/share/texmf-dist/scripts/texlive/"
   '' + /* doc location identical with individual TeX pkgs */ ''
     mkdir -p "$doc/doc"
-    mv "$out"/share/{man,info} "$doc"/doc
+    mv "$doc"/share/{man,info} "$doc"/doc
+    rmdir "$doc"/share
   '' + cleanBrokenLinks;
 
   setupHook = ./setup-hook.sh; # TODO: maybe texmf-nix -> texmf (and all references)
diff --git a/pkgs/tools/typesetting/tex/texlive/aggregate.nix b/pkgs/tools/typesetting/tex/texlive/aggregate.nix
index 56b093f921d1..550870b0a6a9 100644
--- a/pkgs/tools/typesetting/tex/texlive/aggregate.nix
+++ b/pkgs/tools/typesetting/tex/texlive/aggregate.nix
@@ -66,7 +66,7 @@ rec {
     # did the same thing in texLive, but couldn't get it to carry to the
     # binaries installed by texLiveFull
     for prog in $out/bin/*; do
-      wrapProgram "$prog" --prefix DYLD_LIBRARY_PATH : "${poppler}/lib"
+      wrapProgram "$prog" --prefix DYLD_LIBRARY_PATH : "${poppler.out}/lib"
     done
   '' ) [ "minInit" "defEnsureDir" "addInputs" ];
 
diff --git a/pkgs/tools/typesetting/tex/texlive/default.nix b/pkgs/tools/typesetting/tex/texlive/default.nix
index 74b3829cf89f..48a5ae8d6499 100644
--- a/pkgs/tools/typesetting/tex/texlive/default.nix
+++ b/pkgs/tools/typesetting/tex/texlive/default.nix
@@ -30,7 +30,7 @@ rec {
   setupHook = ./setup-hook.sh;
 
   doMainBuild = fullDepEntry ( stdenv.lib.optionalString stdenv.isDarwin ''
-    export DYLD_LIBRARY_PATH="${poppler}/lib"
+    export DYLD_LIBRARY_PATH="${poppler.out}/lib"
   '' + ''
     mkdir -p $out
     mkdir -p $out/nix-support
@@ -54,7 +54,7 @@ rec {
     # sed -e s@ncurses/curses.h@curses.h@g -i $(grep ncurses/curses.h -rl . )
     sed -e '1i\#include <string.h>\n\#include <stdlib.h>' -i $( find libs/teckit -name '*.cpp' -o -name '*.c' )
 
-    NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${icu}/include/layout";
+    NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${icu.dev}/include/layout";
 
     ./Build --prefix="$out" --datadir="$out/share" --mandir="$out/share/man" --infodir="$out/share/info" \
       ${args.lib.concatStringsSep " " configureFlags}
@@ -106,7 +106,7 @@ rec {
     PATH=$PATH:$out/bin mktexlsr $out/share/texmf*
   '' + stdenv.lib.optionalString stdenv.isDarwin ''
     for prog in $out/bin/*; do
-      wrapProgram "$prog" --prefix DYLD_LIBRARY_PATH : "${poppler}/lib"
+      wrapProgram "$prog" --prefix DYLD_LIBRARY_PATH : "${poppler.out}/lib"
     done
   '' ) [ "minInit" "defEnsureDir" "doUnpack" "doMakeInstall" "promoteLibexec" "patchShebangsInterim"];
 
@@ -119,7 +119,7 @@ rec {
     "patchShebangsInterimLibexec" "patchShebangsInterimTexmfDist"
     "patchShebangsInterimShareTexmfDist"];
 
-  buildInputs = [ zlib bzip2 ncurses libpng flex bison libX11 libICE xproto
+  buildInputs = [ zlib bzip2 ncurses libpng flex bison libX11.out libICE xproto
     freetype t1lib gd libXaw icu ghostscript ed libXt libXpm libXmu libXext
     xextproto perl libSM ruby expat curl libjpeg python fontconfig xz pkgconfig
     poppler libpaper graphite2 lesstif zziplib harfbuzz texinfo potrace gmp mpfr
diff --git a/pkgs/tools/typesetting/xmlto/default.nix b/pkgs/tools/typesetting/xmlto/default.nix
index 49fe7dc681fe..f99c14720760 100644
--- a/pkgs/tools/typesetting/xmlto/default.nix
+++ b/pkgs/tools/typesetting/xmlto/default.nix
@@ -24,7 +24,7 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     wrapProgram "$out/bin/xmlto" \
-       --prefix PATH : "${libxslt}/bin:${libxml2}/bin:${getopt}/bin"
+       --prefix PATH : "${libxslt.bin}/bin:${libxml2.bin}/bin:${getopt}/bin"
 
     # `w3m' is needed for HTML to text conversions.
     substituteInPlace "$out/share/xmlto/format/docbook/txt" \
diff --git a/pkgs/tools/virtualization/aws/default.nix b/pkgs/tools/virtualization/aws/default.nix
index 123dbf647f0d..efce0c92b78f 100644
--- a/pkgs/tools/virtualization/aws/default.nix
+++ b/pkgs/tools/virtualization/aws/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation {
   installPhase =
     ''
       mkdir -p $out/bin
-      sed 's|\[curl|[${curl}/bin/curl|g' $src > $out/bin/aws
+      sed 's|\[curl|[${curl.bin}/bin/curl|g' $src > $out/bin/aws
       chmod +x $out/bin/aws
     '';
 
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 6e743e2d7138..0eda14f2f4cb 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -1604,7 +1604,7 @@ let
   };
 
   gawkInteractive = appendToName "interactive"
-    (gawk.override { readlineSupport = true; });
+    (gawk.override { interactive = true; });
 
   gawp = goPackages.gawp.bin // { outputs = [ "bin" ]; };
 
@@ -1988,7 +1988,7 @@ let
 
   ised = callPackage ../tools/misc/ised {};
 
-  isl = isl_0_15;
+  isl = isl_0_14;
   isl_0_11 = callPackage ../development/libraries/isl/0.11.1.nix { };
   isl_0_12 = callPackage ../development/libraries/isl/0.12.2.nix { };
   isl_0_14 = callPackage ../development/libraries/isl/0.14.1.nix { };
@@ -3690,7 +3690,7 @@ let
   xflux = callPackage ../tools/misc/xflux { };
 
   xfsprogs = callPackage ../tools/filesystems/xfsprogs { };
-  libxfs = xfsprogs.lib;
+  libxfs = xfsprogs.dev; # outputs TODO
 
   xml2 = callPackage ../tools/text/xml/xml2 { };
 
@@ -6384,8 +6384,8 @@ let
   dbus_python     = pythonPackages.dbus;
 
   # Should we deprecate these? Currently there are many references.
-  dbus_tools = pkgs.dbus.tools;
-  dbus_libs = pkgs.dbus.libs;
+  dbus_tools = pkgs.dbus.out;
+  dbus_libs = pkgs.dbus;
   dbus_daemon = pkgs.dbus.daemon;
 
   dhex = callPackage ../applications/editors/dhex { };
@@ -6669,7 +6669,7 @@ let
   gmp4 = callPackage ../development/libraries/gmp/4.3.2.nix { }; # required by older GHC versions
   gmp5 = callPackage ../development/libraries/gmp/5.1.x.nix { };
   gmp6 = callPackage ../development/libraries/gmp/6.x.nix { };
-  gmp = gmp5;
+  gmp = gmp6;
   gmpxx = appendToName "with-cxx" (gmp.override { cxx = true; });
 
   #GMP ex-satellite, so better keep it near gmp
@@ -6793,6 +6793,7 @@ let
   glib_networking = callPackage ../development/libraries/glib-networking {};
 
   atk = callPackage ../development/libraries/atk { };
+
   atkmm = callPackage ../development/libraries/atkmm { };
 
   pixman = callPackage ../development/libraries/pixman { };
@@ -6801,6 +6802,8 @@ let
     glSupport = config.cairo.gl or (stdenv.isLinux &&
       !stdenv.isArm && !stdenv.isMips);
   };
+
+
   cairomm = callPackage ../development/libraries/cairomm { };
 
   pango = callPackage ../development/libraries/pango { };
@@ -7753,6 +7756,7 @@ let
   });
 
   libva = callPackage ../development/libraries/libva { };
+  libva-full = libva.override { minimal = false; };
 
   libvdpau = callPackage ../development/libraries/libvdpau { };
 
@@ -7805,14 +7809,18 @@ let
 
   libxmi = callPackage ../development/libraries/libxmi { };
 
-  libxml2 = callPackage ../development/libraries/libxml2 {
-    pythonSupport = false;
+  libxml2 = callPackage ../development/libraries/libxml2 { };
+  libxml2Python = pkgs.buildEnv { # slightly hacky
+    name = "libxml2+py-${pkgs.libxml2.version}";
+    paths = with libxml2; [ dev bin py ];
+    inherit (pkgs.libxml2) passthru;
+    # the hook to find catalogs is hidden by buildEnv
+    postBuild = ''
+      mkdir "$out/nix-support"
+      cp '${libxml2.dev}/nix-support/propagated-native-build-inputs' "$out/nix-support/"
+    '';
   };
 
-  libxml2Python = lowPrio (libxml2.override {
-    pythonSupport = true;
-  });
-
   libxmlxx = callPackage ../development/libraries/libxmlxx { };
 
   libxmp = callPackage ../development/libraries/libxmp { };
@@ -7902,7 +7910,7 @@ let
   );
   mesa = mesaDarwinOr (buildEnv {
     name = "mesa-${mesa_noglu.version}";
-    paths = [ mesa_noglu mesa_glu ];
+    paths = [ mesa_noglu.dev mesa_noglu.out mesa_glu ];
   });
 
   meterbridge = callPackage ../applications/audio/meterbridge { };
@@ -8010,13 +8018,10 @@ let
   nspr = callPackage ../development/libraries/nspr { };
 
   nss = lowPrio (callPackage ../development/libraries/nss { });
+  nssTools = nss.tools;
 
   nss_wrapper = callPackage ../development/libraries/nss_wrapper { };
 
-  nssTools = callPackage ../development/libraries/nss {
-    includeTools = true;
-  };
-
   ntk = callPackage ../development/libraries/audio/ntk { };
 
   ntrack = callPackage ../development/libraries/ntrack { };
@@ -8135,9 +8140,7 @@ let
     vtk = vtkWithQt4;
   };
 
-  pcre = callPackage ../development/libraries/pcre {
-    unicodeSupport = config.pcre.unicode or true;
-  };
+  pcre = callPackage ../development/libraries/pcre { };
 
   pcre2 = callPackage ../development/libraries/pcre2 { };
 
@@ -8542,7 +8545,7 @@ let
 
   sqlite-amalgamation = callPackage ../development/libraries/sqlite-amalgamation { };
 
-  sqlite-interactive = appendToName "interactive" (sqlite.override { interactive = true; });
+  sqlite-interactive = appendToName "interactive" (sqlite.override { interactive = true; }).bin;
 
   sqlcipher = lowPrio (callPackage ../development/libraries/sqlcipher {
     readline = null;
@@ -8691,9 +8694,13 @@ let
     inherit (pythonPackages) gyp;
   };
 
-  vaapiIntel = callPackage ../development/libraries/vaapi-intel { };
+  vaapiIntel = callPackage ../development/libraries/vaapi-intel {
+    libva = libva-full; # also wants libva-{x11,drm,wayland}
+  };
 
-  vaapiVdpau = callPackage ../development/libraries/vaapi-vdpau { };
+  vaapiVdpau = callPackage ../development/libraries/vaapi-vdpau {
+    libva = libva-full; # needs libva-{x11,glx}
+  };
 
   vamp = callPackage ../development/libraries/audio/vamp { };
 
@@ -9369,7 +9376,6 @@ let
 
   # Backwards compatibility.
   mod_dnssd = pkgs.apacheHttpdPackages.mod_dnssd;
-  mod_evasive = pkgs.apacheHttpdPackages.mod_evasive;
   mod_fastcgi = pkgs.apacheHttpdPackages.mod_fastcgi;
   mod_python = pkgs.apacheHttpdPackages.mod_python;
   mod_wsgi = pkgs.apacheHttpdPackages.mod_wsgi;
@@ -10623,7 +10629,11 @@ let
 
   systemd = callPackage ../os-specific/linux/systemd {
     linuxHeaders = linuxHeaders_3_18;
-  };
+  }
+    // {
+      udev.bin = systemd;     # ${systemd.udev.bin}/bin/udevadm
+      udev.lib = libudev.out; # ${systemd.udev.lib}/lib/libudev.*
+    };
 
   # In nixos, you can set systemd.package = pkgs.systemd_with_lvm2 to get
   # LVM2 working in systemd.
@@ -10697,7 +10707,11 @@ let
     cross = assert crossSystem != null; crossSystem;
   });
 
-  udev = pkgs.systemd;
+  # This hacky alias covers most use cases without mass-replace (build inputs)
+  # and causes an *evaluation* error if "${udev}" is attempted.
+  udev = [ libudev.dev libudev.out ];
+  libudev = callPackage ../os-specific/linux/systemd/libudev.nix { };
+
   eudev = callPackage ../os-specific/linux/eudev {};
 
   # libudev.so.0
@@ -12057,9 +12071,7 @@ let
 
   inherit (gnome3) gitg;
 
-  giv = callPackage ../applications/graphics/giv {
-    pcre = pcre.override { unicodeSupport = true; };
-  };
+  giv = callPackage ../applications/graphics/giv { };
 
   gmrun = callPackage ../applications/misc/gmrun {};
 
@@ -13675,6 +13687,7 @@ let
 
   vlc = callPackage ../applications/video/vlc {
     ffmpeg = ffmpeg_2;
+    libva = libva-full; # also wants libva-x11
   };
 
   vlc_qt5 = qt5.vlc;
@@ -15233,7 +15246,9 @@ let
 
   why3 = callPackage ../applications/science/logic/why3 {};
 
-  yices = callPackage ../applications/science/logic/yices {};
+  yices = callPackage ../applications/science/logic/yices {
+    gmp-static = gmp.override { withStatic = true; };
+  };
 
   z3 = callPackage ../applications/science/logic/z3 {};
   z3_opt = callPackage ../applications/science/logic/z3_opt {};
diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix
index e58df1f42c33..abd4a8123416 100644
--- a/pkgs/top-level/lua-packages.nix
+++ b/pkgs/top-level/lua-packages.nix
@@ -103,7 +103,7 @@ let
       makeFlagsArray=(
         LUA_LDIR="$out/share/lua/${lua.luaversion}"
         LUA_INC="-I${lua}/include" LUA_CDIR="$out/lib/lua/${lua.luaversion}"
-        EXPAT_INC="-I${expat}/include");
+        EXPAT_INC="-I${expat.dev}/include");
     '';
 
     meta = {
diff --git a/pkgs/top-level/perl-packages.nix b/pkgs/top-level/perl-packages.nix
index 1e8dfa91d2d2..fb8bba33f374 100644
--- a/pkgs/top-level/perl-packages.nix
+++ b/pkgs/top-level/perl-packages.nix
@@ -1940,7 +1940,7 @@ let self = _self // overrides; _self = with self; {
 
     # Don't build a private copy of bzip2.
     BUILD_BZIP2 = false;
-    BZIP2_LIB = "${pkgs.bzip2}/lib";
+    BZIP2_LIB = "${pkgs.bzip2.out}/lib";
     BZIP2_INCLUDE = "${pkgs.bzip2}/include";
 
     meta = {
@@ -2371,8 +2371,8 @@ let self = _self // overrides; _self = with self; {
       sha256 = "0f5gdprcql4kwzgxl2s6ngcfg1jl45lzcqh7dkv5bkwlwmxa9rsi";
     };
     buildInputs = [ DevelChecklib TestRequires pkgs.gmp ];
-    NIX_CFLAGS_COMPILE = "-I${pkgs.gmp}/include";
-    NIX_CFLAGS_LINK = "-L${pkgs.gmp}/lib -lgmp";
+    NIX_CFLAGS_COMPILE = "-I${pkgs.gmp.dev}/include";
+    NIX_CFLAGS_LINK = "-L${pkgs.gmp.out}/lib -lgmp";
   };
 
   CryptEksblowfish = buildPerlPackage rec {
@@ -2491,7 +2491,7 @@ let self = _self // overrides; _self = with self; {
       sha256 = "b66fab514edf97fc32f58da257582704a210c2b35e297d5c31b7fa2ffd08e908";
     };
     NIX_CFLAGS_COMPILE = "-I${pkgs.openssl}/include";
-    NIX_CFLAGS_LINK = "-L${pkgs.openssl}/lib -lcrypto";
+    NIX_CFLAGS_LINK = "-L${pkgs.openssl.out}/lib -lcrypto";
     meta = with stdenv.lib; {
       homepage = https://metacpan.org/release/Crypt-OpenSSL-AES;
       description = "Perl wrapper around OpenSSL's AES library";
@@ -2508,7 +2508,7 @@ let self = _self // overrides; _self = with self; {
       sha256 = "18vg2bqyhc0ahfdh5dkbgph5nh92qcz5vi99jq8aam4h86if78bk";
     };
     NIX_CFLAGS_COMPILE = "-I${pkgs.openssl}/include";
-    NIX_CFLAGS_LINK = "-L${pkgs.openssl}/lib -lcrypto";
+    NIX_CFLAGS_LINK = "-L${pkgs.openssl.out}/lib -lcrypto";
   };
 
   CryptOpenSSLRandom = buildPerlPackage rec {
@@ -2518,7 +2518,7 @@ let self = _self // overrides; _self = with self; {
       sha256 = "12pirh1pj8lpvzcwj2if9i6dbr6a7s9g1zc7gzbd3v87d6mx0rdf";
     };
     NIX_CFLAGS_COMPILE = "-I${pkgs.openssl}/include";
-    NIX_CFLAGS_LINK = "-L${pkgs.openssl}/lib -lcrypto";
+    NIX_CFLAGS_LINK = "-L${pkgs.openssl.out}/lib -lcrypto";
   };
 
   CryptOpenSSLRSA = buildPerlPackage rec {
@@ -2529,7 +2529,7 @@ let self = _self // overrides; _self = with self; {
     };
     propagatedBuildInputs = [ CryptOpenSSLRandom ];
     NIX_CFLAGS_COMPILE = "-I${pkgs.openssl}/include";
-    NIX_CFLAGS_LINK = "-L${pkgs.openssl}/lib -lcrypto";
+    NIX_CFLAGS_LINK = "-L${pkgs.openssl.out}/lib -lcrypto";
   };
 
   CryptSSLeay = buildPerlPackage rec {
@@ -2538,7 +2538,7 @@ let self = _self // overrides; _self = with self; {
       url = "mirror://cpan/authors/id/N/NA/NANIS/${name}.tar.gz";
       sha256 = "1s7zm6ph37kg8jzaxnhi4ff4snxl7mi5h14arxbri0kp6s0lzlzm";
     };
-    makeMakerFlags = "--libpath=${pkgs.openssl}/lib --incpath=${pkgs.openssl}/include";
+    makeMakerFlags = "--libpath=${pkgs.openssl.out}/lib --incpath=${pkgs.openssl}/include";
     buildInputs = [ PathClass TryTiny ];
   };
 
@@ -5147,7 +5147,7 @@ let self = _self // overrides; _self = with self; {
     # tests fail
     doCheck = false;
 
-    makeMakerFlags = "--lib_png_path=${pkgs.libpng} --lib_jpeg_path=${pkgs.libjpeg} --lib_zlib_path=${pkgs.zlib} --lib_ft_path=${pkgs.freetype} --lib_fontconfig_path=${pkgs.fontconfig} --lib_xpm_path=${pkgs.xorg.libXpm}";
+    makeMakerFlags = "--lib_png_path=${pkgs.libpng.out} --lib_jpeg_path=${pkgs.libjpeg.out} --lib_zlib_path=${pkgs.zlib.out} --lib_ft_path=${pkgs.freetype.out} --lib_fontconfig_path=${pkgs.fontconfig.lib} --lib_xpm_path=${pkgs.xorg.libXpm.out}";
   };
 
   GDSecurityImage = buildPerlPackage {
@@ -6421,7 +6421,7 @@ let self = _self // overrides; _self = with self; {
     };
     buildInputs = [ ApacheTest ExtUtilsXSBuilder mod_perl2 pkgs.apacheHttpd pkgs.apr pkgs.aprutil ];
     propagatedBuildInputs = [ mod_perl2 ];
-    makeMakerFlags = "--with-apache2-src=${pkgs.apacheHttpd} --with-apache2-apxs=${pkgs.apacheHttpd}/bin/apxs --with-apache2-httpd=${pkgs.apacheHttpd}/bin/httpd --with-apr-config=${pkgs.apr}/bin/apr-1-config --with-apu-config=${pkgs.aprutil}/bin/apu-1-config";
+    makeMakerFlags = "--with-apache2-src=${pkgs.apacheHttpd} --with-apache2-apxs=${pkgs.apacheHttpd}/bin/apxs --with-apache2-httpd=${pkgs.apacheHttpd.out}/bin/httpd --with-apr-config=${pkgs.apr}/bin/apr-1-config --with-apu-config=${pkgs.aprutil}/bin/apu-1-config";
     preConfigure = ''
       # override broken prereq check
       substituteInPlace configure --replace "prereq_check=\"\$PERL \$PERL_OPTS build/version_check.pl\"" "prereq_check=\"echo\""
@@ -7061,8 +7061,8 @@ let self = _self // overrides; _self = with self; {
     };
     buildInputs = [ pkgs.gmp ];
     doCheck = false;
-    NIX_CFLAGS_COMPILE = "-I${pkgs.gmp}/include";
-    NIX_CFLAGS_LINK = "-L${pkgs.gmp}/lib -lgmp";
+    NIX_CFLAGS_COMPILE = "-I${pkgs.gmp.dev}/include";
+    NIX_CFLAGS_LINK = "-L${pkgs.gmp.out}/lib -lgmp";
   };
 
   MathBigRat = buildPerlPackage rec {
@@ -8833,8 +8833,14 @@ let self = _self // overrides; _self = with self; {
       sha256 = "1x6jjmhvsdq488k6wdg58ajnr4dmbcbk7imyv0aybkhj1ygw7ahv";
     };
     buildInputs = [ pkgs.openssl ];
-    OPENSSL_PREFIX = pkgs.openssl;
     doCheck = false; # Test performs network access.
+    preConfigure = ''
+      mkdir openssl
+      ln -s ${pkgs.openssl.out}/lib openssl
+      ln -s ${pkgs.openssl.bin}/bin openssl
+      ln -s ${pkgs.openssl.dev}/include openssl
+      export OPENSSL_PREFIX=$(realpath openssl)
+    '';
     meta = {
       description = "Perl extension for using OpenSSL";
       license = "SSLeay";
@@ -10241,6 +10247,7 @@ let self = _self // overrides; _self = with self; {
       url = "mirror://cpan/authors/id/U/UM/UMEMOTO/${name}.tar.gz";
       sha256 = "1ads4k4vvq6pnxkdw0s8gaj03w4h9snxyw7zyikfzd20fy76yx6s";
     };
+    setOutputFlags = false;
     buildInputs = [ pkgs.which ];
   };
 
@@ -11187,7 +11194,7 @@ let self = _self // overrides; _self = with self; {
     preConfigure =
       ''
         substituteInPlace Makefile.PL --replace '$Config{libpth}' \
-          "'${pkgs.ncurses}/lib'"
+          "'${pkgs.ncurses.lib}/lib'"
       '';
 
     # Tests don't work because they require /dev/tty.
@@ -12770,7 +12777,7 @@ let self = _self // overrides; _self = with self; {
       url = "http://search.cpan.org/CPAN/authors/id/S/SR/SREZIC/${name}.tar.gz";
       sha256 = "10fsvyr56gm59chc8b70n6bvhd3lh9c05sp8m4arcahid0rpgbwa";
     };
-    makeMakerFlags = "X11LIB=${pkgs.xorg.libX11}/lib";
+    makeMakerFlags = "X11LIB=${pkgs.xorg.libX11.out}/lib";
     buildInputs = with pkgs; [ xorg.libX11 libpng ];
     configurePhase = ''
       perl Makefile.PL PREFIX=$out $makeMakerFlags
@@ -13212,7 +13219,7 @@ let self = _self // overrides; _self = with self; {
     };
     buildInputs = [ pkgs.xorg.libXext pkgs.xorg.libXScrnSaver pkgs.xorg.libX11 ];
     propagatedBuildInputs = [ InlineC ];
-    patchPhase = ''sed -ie 's,-L/usr/X11R6/lib/,-L${pkgs.xorg.libX11}/lib/ -L${pkgs.xorg.libXext}/lib/ -L${pkgs.xorg.libXScrnSaver}/lib/,' IdleTime.pm'';
+    patchPhase = ''sed -ie 's,-L/usr/X11R6/lib/,-L${pkgs.xorg.libX11.out}/lib/ -L${pkgs.xorg.libXext.out}/lib/ -L${pkgs.xorg.libXScrnSaver}/lib/,' IdleTime.pm'';
     meta = {
       description = "Get the idle time of X11";
     };
@@ -13353,7 +13360,7 @@ let self = _self // overrides; _self = with self; {
     patchPhase = if stdenv.isCygwin then ''
       sed -i"" -e "s@my \$compiler = File::Spec->catfile(\$path, \$cc\[0\]) \. \$Config{_exe};@my \$compiler = File::Spec->catfile(\$path, \$cc\[0\]) \. (\$^O eq 'cygwin' ? \"\" : \$Config{_exe});@" inc/Devel/CheckLib.pm
     '' else null;
-    makeMakerFlags = "EXPATLIBPATH=${pkgs.expat}/lib EXPATINCPATH=${pkgs.expat}/include";
+    makeMakerFlags = "EXPATLIBPATH=${pkgs.expat.out}/lib EXPATINCPATH=${pkgs.expat.dev}/include";
   };
 
   XMLXPath = buildPerlPackage {
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index e6b0d1b061f2..21cd971a0413 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -577,7 +577,7 @@ in modules // {
 
     postInstall = ''
       wrapProgram $out/bin/alot \
-        --prefix LD_LIBRARY_PATH : ${pkgs.notmuch}/lib:${pkgs.file}/lib:${pkgs.gpgme}/lib
+        --prefix LD_LIBRARY_PATH : '${pkgs.lib.makeLibraryPath [ pkgs.notmuch pkgs.file pkgs.gpgme ]}'
     '';
 
     meta = {
@@ -2617,7 +2617,7 @@ in modules // {
 
     patchPhase = ''
       # Hardcode cairo library path
-      sed -e 's,ffi\.dlopen(,&"${pkgs.cairo}/lib/" + ,' -i cairocffi/__init__.py
+      sed -e 's,ffi\.dlopen(,&"${pkgs.cairo.out}/lib/" + ,' -i cairocffi/__init__.py
     '';
 
     meta = {
@@ -5667,7 +5667,7 @@ in modules // {
     preFixup = ''
         wrapProgram $out/bin/gtimelog \
           --prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH" \
-          --prefix LD_LIBRARY_PATH ":" "${pkgs.gtk3}/lib" \
+          --prefix LD_LIBRARY_PATH ":" "${pkgs.gtk3.out}/lib" \
 
     '';
 
@@ -5863,7 +5863,7 @@ in modules // {
 
     propagatedBuildInputs = with self; [ keyring colour netifaces praw psutil
       basiciw pkgs.libpulseaudio ];
-    ldWrapperSuffix = "--suffix LD_LIBRARY_PATH : \"${pkgs.libpulseaudio}/lib\"";
+    ldWrapperSuffix = "--suffix LD_LIBRARY_PATH : \"${pkgs.libpulseaudio.out}/lib\"";
     makeWrapperArgs = [ ldWrapperSuffix ]; # libpulseaudio.so is loaded manually
 
     postInstall = ''
@@ -7042,7 +7042,7 @@ in modules // {
     preConfigure = ''
        cat > site.cfg << END
        [samplerate]
-       library_dirs=${pkgs.libsamplerate}/lib
+       library_dirs=${pkgs.libsamplerate.out}/lib
        include_dirs=${pkgs.libsamplerate}/include
        END
     '';
@@ -11780,7 +11780,7 @@ in modules // {
 
     patchPhase = optionalString stdenv.isLinux ''
       substituteInPlace monotonic.py --replace \
-        "ctypes.util.find_library('c')" "'${stdenv.glibc}/lib/libc.so.6'"
+        "ctypes.util.find_library('c')" "'${stdenv.glibc.out}/lib/libc.so.6'"
     '';
   };
 
@@ -14883,7 +14883,7 @@ in modules // {
     };
 
     prePatch = ''
-      substituteInPlace soundfile.py --replace "'sndfile'" "'${pkgs.libsndfile}/lib/libsndfile.so'"
+      substituteInPlace soundfile.py --replace "'sndfile'" "'${pkgs.libsndfile.out}/lib/libsndfile.so'"
     '';
 
     # https://github.com/bastibe/PySoundFile/issues/157
@@ -14943,13 +14943,15 @@ in modules // {
       ++ optionals (isPyPy) [ pkgs.tk pkgs.xorg.libX11 ];
 
     # NOTE: we use LCMS_ROOT as WEBP root since there is not other setting for webp.
-    preConfigure = ''
+    preConfigure = let
+      libinclude = pkg: ''"${pkg.out}/lib", "${pkg.dev}/include"'';
+    in ''
       sed -i "setup.py" \
-          -e 's|^FREETYPE_ROOT =.*$|FREETYPE_ROOT = _lib_include("${pkgs.freetype}")|g ;
-              s|^JPEG_ROOT =.*$|JPEG_ROOT = _lib_include("${pkgs.libjpeg}")|g ;
-              s|^ZLIB_ROOT =.*$|ZLIB_ROOT = _lib_include("${pkgs.zlib}")|g ;
+          -e 's|^FREETYPE_ROOT =.*$|FREETYPE_ROOT = ${libinclude pkgs.freetype}|g ;
+              s|^JPEG_ROOT =.*$|JPEG_ROOT = ${libinclude pkgs.libjpeg}|g ;
+              s|^ZLIB_ROOT =.*$|ZLIB_ROOT = ${libinclude pkgs.zlib}|g ;
               s|^LCMS_ROOT =.*$|LCMS_ROOT = _lib_include("${pkgs.libwebp}")|g ;
-              s|^TIFF_ROOT =.*$|TIFF_ROOT = _lib_include("${pkgs.libtiff}")|g ;
+              s|^TIFF_ROOT =.*$|TIFF_ROOT = ${libinclude pkgs.libtiff}|g ;
               s|^TCL_ROOT=.*$|TCL_ROOT = _lib_include("${pkgs.tcl}")|g ;'
     ''
     # Remove impurities
@@ -15594,7 +15596,7 @@ in modules // {
     preConfigure = ''
       substituteInPlace setup.py \
         --replace '"/usr/include"' '"${pkgs.gdb}/include"' \
-        --replace '"/usr/lib"' '"${pkgs.binutils}/lib"'
+        --replace '"/usr/lib"' '"${pkgs.binutils.out}/lib"'
     '';
 
     meta = {
@@ -15957,11 +15959,11 @@ in modules // {
     doCheck = false;
 
     preConfigure = ''
-      export LDFLAGS="-L${pkgs.fftw}/lib -L${pkgs.fftwFloat}/lib -L${pkgs.fftwLongDouble}/lib"
+      export LDFLAGS="-L${pkgs.fftw.out}/lib -L${pkgs.fftwFloat.out}/lib -L${pkgs.fftwLongDouble.out}/lib"
       export CFLAGS="-I${pkgs.fftw}/include -I${pkgs.fftwFloat}/include -I${pkgs.fftwLongDouble}/include"
     '';
     #+ optionalString isDarwin ''
-    #  export DYLD_LIBRARY_PATH="${pkgs.fftw}/lib"
+    #  export DYLD_LIBRARY_PATH="${pkgs.fftw.out}/lib"
     #'';
 
     meta = {
@@ -16687,7 +16689,7 @@ in modules // {
 
     postPatch = ''
       sed -i -e '/udev_library_name/,/^ *libudev/ {
-        s|CDLL([^,]*|CDLL("${pkgs.udev}/lib/libudev.so.1"|p; d
+        s|CDLL([^,]*|CDLL("${pkgs.libudev.out}/lib/libudev.so.1"|p; d
       }' pyudev/_libudev.py
     '';
 
@@ -17096,8 +17098,8 @@ in modules // {
 
     patchPhase = ''
       substituteInPlace "setup.cfg"                                     \
-              --replace "/usr/local/include" "${pkgs.sqlite}/include"   \
-              --replace "/usr/local/lib" "${pkgs.sqlite}/lib"
+              --replace "/usr/local/include" "${pkgs.sqlite.dev}/include"   \
+              --replace "/usr/local/lib" "${pkgs.sqlite.out}/lib"
     '';
 
     # error: invalid command 'test'
@@ -17153,9 +17155,11 @@ in modules // {
       cd Source
       python setup.py backport
       python setup.py configure \
-        --apr-inc-dir=${pkgs.apr}/include/apr-1 \
-        --apu-inc-dir=${pkgs.aprutil}/include/apr-1 \
-        --apr-lib-dir=${pkgs.apr}/lib \
+        --apr-inc-dir=${pkgs.apr.dev}/include \
+        --apu-inc-dir=${pkgs.aprutil.dev}/include \
+        --apr-lib-dir=${pkgs.apr.out}/lib \
+        --svn-lib-dir=${pkgs.subversion.out}/lib \
+        --svn-bin-dir=${pkgs.subversion.out}/bin \
         --svn-root-dir=${pkgs.subversion}
     '' + (if !stdenv.isDarwin then "" else ''
       sed -i -e 's|libpython2.7.dylib|lib/libpython2.7.dylib|' Makefile
@@ -17446,7 +17450,7 @@ in modules // {
 
 
   reportlab =
-   let freetype = overrideDerivation pkgs.freetype (args: { configureFlags = "--enable-static --enable-shared"; });
+   let freetype = overrideDerivation pkgs.freetype (args: { dontDisableStatic = true; });
    in buildPythonPackage rec {
     name = "reportlab-3.2.0";
 
@@ -18625,7 +18629,7 @@ in modules // {
 
     patchPhase = ''
       cp "${x_ignore_nofocus}/cpp/linux-specific/"* .
-      substituteInPlace x_ignore_nofocus.c --replace "/usr/lib/libX11.so.6" "${pkgs.xorg.libX11}/lib/libX11.so.6"
+      substituteInPlace x_ignore_nofocus.c --replace "/usr/lib/libX11.so.6" "${pkgs.xorg.libX11.out}/lib/libX11.so.6"
       gcc -c -fPIC x_ignore_nofocus.c -o x_ignore_nofocus.o
       gcc -shared \
         -Wl,${if stdenv.isDarwin then "-install_name" else "-soname"},x_ignore_nofocus.so \
@@ -20097,7 +20101,7 @@ in modules // {
     # I don't know why I need to add these libraries. Shouldn't they
     # be part of wxPython?
     postInstall = ''
-      libspaths=${pkgs.xorg.libSM}/lib:${pkgs.xorg.libXScrnSaver}/lib
+      libspaths=${with pkgs.xorg; pkgs.lib.makeLibraryPath [ libSM libXScrnSaver ]}
       wrapProgram $out/bin/taskcoach.py \
         --prefix LD_LIBRARY_PATH : $libspaths
     '';
@@ -22795,7 +22799,7 @@ in modules // {
 
     # Fix the USB backend library lookup
     postPatch = ''
-      libusb=${pkgs.libusb1}/lib/libusb-1.0.so
+      libusb=${pkgs.libusb1.out}/lib/libusb-1.0.so
       test -f $libusb || { echo "ERROR: $libusb doesn't exist, please update/fix this build expression."; exit 1; }
       sed -i -e "s|libname = .*|libname = \"$libusb\"|" usb/backend/libusb1.py
     '';
@@ -22959,7 +22963,7 @@ in modules // {
       mock
     ];
 
-    LD_LIBRARY_PATH = "${pkgs.cairo}/lib";
+    LD_LIBRARY_PATH = "${pkgs.cairo.out}/lib";
 
     meta = {
       description = "Graphite-web, without the interface. Just the rendering HTTP API";
@@ -24536,7 +24540,7 @@ in modules // {
 
     patchPhase = ''
       # Hardcode cairo library path
-      sed -e 's,ffi\.dlopen(,&"${pkgs.xorg.libxcb}/lib/" + ,' -i xcffib/__init__.py
+      sed -e 's,ffi\.dlopen(,&"${pkgs.xorg.libxcb.out}/lib/" + ,' -i xcffib/__init__.py
     '';
 
     propagatedBuildInputs = [ self.cffi self.six ];