diff --git a/pkgs/development/libraries/gdk-pixbuf/default.nix b/pkgs/development/libraries/gdk-pixbuf/default.nix
index a72d7ad5e401..fa1599562ca2 100644
--- a/pkgs/development/libraries/gdk-pixbuf/default.nix
+++ b/pkgs/development/libraries/gdk-pixbuf/default.nix
@@ -32,6 +32,12 @@ stdenv.mkDerivation rec {
 
   doCheck = true;
 
+  # propagate the bin output
+  postPhases = "postPostFixup";
+  postPostFixup = ''
+    echo -n " $bin" >> "$dev"/nix-support/propagated-*build-inputs
+  '';
+
   meta = {
     description = "A library for image loading and manipulation";
     homepage = http://library.gnome.org/devel/gdk-pixbuf/;
diff --git a/pkgs/development/libraries/libav/default.nix b/pkgs/development/libraries/libav/default.nix
index 2f9e1786473e..2268290b9f7c 100644
--- a/pkgs/development/libraries/libav/default.nix
+++ b/pkgs/development/libraries/libav/default.nix
@@ -10,7 +10,7 @@
 , vaapiSupport  ? false,  libva     ? null # ToDo: it has huge closure
 , 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,12 +77,12 @@ let
 
     enableParallelBuilding = true;
 
-    outputs = [ "out" "tools" ];
+    outputs = [ "dev" "out" "bin" ];
 
     postInstall = ''
-      mkdir -p "$tools/bin"
-      mv "$out/bin/avplay" "$tools/bin"
-      cp -s "$out"/bin/* "$tools/bin/"
+      mkdir -p "$bin/bin"
+      mv "$out/bin/avplay" "$bin/bin"
+      cp -s "$out"/bin/* "$bin/bin/"
     '';
 
     doInstallCheck = false; # fails randomly
diff --git a/pkgs/development/libraries/libffi/default.nix b/pkgs/development/libraries/libffi/default.nix
index daff1aa471c7..69c8aab64505 100644
--- a/pkgs/development/libraries/libffi/default.nix
+++ b/pkgs/development/libraries/libffi/default.nix
@@ -24,8 +24,14 @@ stdenv.mkDerivation rec {
   dontStrip = stdenv ? cross; # Don't run the native `strip' when cross-compiling.
 
   postInstall =
-    # Install headers in the right place.
-    '' ln -s${if stdenv.isFreeBSD then "" else "r"}v "$out/lib/"libffi*/include "$out/include"
+    # Install headers and libs in the right places.
+    ''  mv "$out"/lib64/* "$out/lib"
+        rmdir "$out/lib64"
+        ln -s lib "$out/lib64"
+
+        mkdir -p "$dev/"
+        mv "$out/lib/${name}/include" "$dev/include"
+        rmdir "$out/lib/${name}"
     '';
 
   meta = {
diff --git a/pkgs/development/libraries/mesa/default.nix b/pkgs/development/libraries/mesa/default.nix
index 54fd8d3810e3..1458aedc0b13 100644
--- a/pkgs/development/libraries/mesa/default.nix
+++ b/pkgs/development/libraries/mesa/default.nix
@@ -59,7 +59,7 @@ stdenv.mkDerivation {
     patch -R -p1 < ${./rtti.patch}
   '';
 
-  outputs = ["out" "drivers" "osmesa"];
+  outputs = [ "dev" "out" "drivers" "osmesa" ];
 
   configureFlags = [
     "--with-dri-driverdir=$(drivers)/lib/dri"
@@ -113,8 +113,8 @@ stdenv.mkDerivation {
   '' + optionalString enableExtraFeatures ''
       `#$out/lib/libXvMC*` \
       $out/lib/gbm $out/lib/libgbm* \
-      $out/lib/gallium-pipe \
   '' + ''
+      $out/lib/gallium-pipe \
       $out/lib/libdricore* \
       $out/lib/libgallium* \
       $out/lib/vdpau \
@@ -134,8 +134,8 @@ stdenv.mkDerivation {
     sed "/^libdir=/s,$out,$drivers," -i \
   '' + optionalString enableExtraFeatures ''
       `#$drivers/lib/libXvMC*.la` \
-      $drivers/lib/gallium-pipe/*.la \
   '' + ''
+      $drivers/lib/gallium-pipe/*.la \
       $drivers/lib/libgallium.la \
       $drivers/lib/vdpau/*.la \
       $drivers/lib/libdricore*.la
diff --git a/pkgs/development/tools/build-managers/cmake/default.nix b/pkgs/development/tools/build-managers/cmake/default.nix
index a81c3b155343..e6f0e7affe95 100644
--- a/pkgs/development/tools/build-managers/cmake/default.nix
+++ b/pkgs/development/tools/build-managers/cmake/default.nix
@@ -43,10 +43,7 @@ stdenv.mkDerivation rec {
     ++ optional useNcurses ncurses
     ++ optional useQt4 qt4;
 
-  CMAKE_PREFIX_PATH = stdenv.lib.concatStringsSep ":" buildInputs;
-
-  # no idea why the auto-added NIX_LDFLAGS to the same path is not enough
-  NIX_CFLAGS_COMPILE = "-L${zlib.out}/lib";
+  CMAKE_PREFIX_PATH = stdenv.lib.concatStringsSep ":" (buildInputs ++ [zlib.out]);
 
   configureFlags =
     "--docdir=/share/doc/${name} --mandir=/share/man --system-libs"
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index 34fcf4fe595c..1c6a065a9478 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchurl, pkgconfig, intltool, gperf, libcap, dbus, kmod
-, xz, pam, acl, cryptsetup, libuuid, m4, utillinux
+, zlib, xz, pam, acl, cryptsetup, libuuid, m4, utillinux, libffi
 , glib, kbd, libxslt, coreutils, libgcrypt, sysvtools, docbook_xsl
 , kexectools, libmicrohttpd, linuxHeaders
 , pythonPackages ? null, pythonSupport ? false
@@ -30,7 +30,7 @@ stdenv.mkDerivation rec {
   buildInputs =
     [ pkgconfig intltool gperf libcap kmod xz pam acl
       /* cryptsetup */ libuuid m4 glib libxslt libgcrypt docbook_xsl
-      libmicrohttpd linuxHeaders
+      libmicrohttpd linuxHeaders libffi
       autoreconfHook
     ] ++ stdenv.lib.optionals pythonSupport [pythonPackages.python pythonPackages.lxml];
 
@@ -146,10 +146,17 @@ stdenv.mkDerivation rec {
       done
     ''; # */
 
-  postPhases = "postPostFixup";
+  # 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
+    '';
 
+  # propagate the libudev output
+  postPhases = "postPostFixup";
   postPostFixup = ''
-    ls -l "$dev"/nix-support/
     echo -n " $libudev" >> "$dev"/nix-support/propagated-*build-inputs
   '';
 
diff --git a/pkgs/servers/http/apache-httpd/2.2.nix b/pkgs/servers/http/apache-httpd/2.2.nix
index bcbc5baf37b0..70a1b5a17d1d 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
@@ -22,7 +22,7 @@ stdenv.mkDerivation rec {
 
   outputs = [ "dev" "out" "doc" ];
 
-  buildInputs = [perl apr aprutil pcre] ++
+  buildInputs = [ pkgconfig perl apr aprutil pcre zlib ] ++
     stdenv.lib.optional sslSupport openssl;
 
   # An apr-util header file includes an apr header file