diff --git a/pkgs/development/libraries/qt-4/default.nix b/pkgs/development/libraries/qt-4/default.nix
index b4503d40e61c..38b1b2b9da78 100644
--- a/pkgs/development/libraries/qt-4/default.nix
+++ b/pkgs/development/libraries/qt-4/default.nix
@@ -1,62 +1,37 @@
-{ stdenv, fetchurl
-, libXft, pkgconfig, libX11, inputproto
-, xrenderSupport ? true, libXrender ? null
-, xrandrSupport ? true, libXrandr ? null, randrproto ? null
-, xineramaSupport ? true, libXinerama ? null, xineramaproto ? null
-, cursorSupport ? true, libXcursor ? null, libXext ? null
-, mysqlSupport ? true, mysql ? null
-, openglSupport ? false, mesa ? null, libXmu ? null
-, cupsSupport ? true, cups ? null
-, dbusSupport ? true, dbus ? null
-, xfixesSupport ? true, fixesproto ? null, libXfixes ? null
-, smSupport ? true, libICE ? null, libSM ? null
-, freetypeSupport ? true, fontconfig ? null, freetype ? null
-, glibSupport ? true, glib ? null
-, openssl, xextproto, zlib, libjpeg, libpng, which
-}:
-
-assert xrenderSupport -> libXrender != null;
-assert xrandrSupport -> libXrandr != null && randrproto != null;
-assert cursorSupport -> libXcursor != null && libXext != null;
-assert mysqlSupport -> mysql != null;
-assert openglSupport -> mesa != null && libXmu != null;
-assert dbusSupport -> dbus != null;
-assert cupsSupport -> cups != null;
-assert glibSupport -> glib != null;
-assert smSupport -> libICE != null && libSM != null;
-assert freetypeSupport -> fontconfig != null && freetype != null;
-
-stdenv.mkDerivation {
-  name = "qt-4.3.0";
-
-  builder = ./builder.sh;
-  hook = ./setup-hook.sh;  
-  src = fetchurl {
-    url = ftp://ftp.trolltech.com/qt/source/qt-x11-opensource-src-4.3.0.tar.gz;
-    sha256 = "0h0liy7sdp5sarhzdfn7ss61d4ky9h0ky8jysg8v3a97sds7ghxb";
-  };
-
-  buildInputs = [libXft libXrender libXrandr randrproto xextproto libXinerama xineramaproto libXcursor zlib libjpeg mysql libpng which mesa libXmu openssl dbus cups pkgconfig libXext freetype fontconfig inputproto fixesproto libXfixes glib];
-
-  patchPhase = "sed -e 's@/bin/pwd@pwd@' -i configure; sed -e 's@/usr@/FOO@' -i config.tests/*/*.test -i mkspecs/*/*.conf";
-  dontAddPrefix = 1;
-  postConfigure = "export LD_LIBRARY_PATH=$(pwd)/lib";
+args: with args;
+let common =
+rec {
+  setupHook = ./setup-hook.sh;  
+  propagatedBuildInputs = [libXft libXrender libXrandr randrproto xextproto
+  libXinerama xineramaproto libXcursor zlib libjpeg mysql libpng which mesa
+  libXmu openssl dbus cups pkgconfig libXext freetype fontconfig inputproto
+  fixesproto libXfixes glib];
+  prefixKey = "-prefix ";
   configureFlags = "
-    -v -no-separate-debug-info -release
-    -system-zlib -system-libpng -system-libjpeg
+    -v -no-separate-debug-info -release -nomake examples -nomake demos
+    -system-zlib -system-libpng -system-libjpeg -fast
     -qt-gif -confirm-license
-    ${if openglSupport then "-opengl" else "-no-opengl"}
-    ${if xrenderSupport then "-xrender" else "-no-xrender"}
-    ${if xrandrSupport then "-xrandr" else "-no-xrandr"}
-    ${if xineramaSupport then "-xinerama" else "-no-xinerama"}
-    ${if cursorSupport then "-xcursor" else "-no-xcursor"}
-    ${if mysqlSupport then "-qt-sql-mysql -L${mysql}/lib/mysql -I${mysql}/include/mysql" else ""}
-    ${if dbusSupport then "-qdbus" else "-no-qdbus"}
-    ${if cupsSupport then "-cups" else "-no-cups"}
-    ${if glibSupport then "-glib" else "-no-glib"}
-    ${if xfixesSupport then "-xfixes" else "-no-xfixes"}
-    ${if freetypeSupport then "-fontconfig -I${freetype}/include/freetype2" else "-no-fontconfig"}
-  ";
-
-  passthru = {inherit mysqlSupport;};
+    -opengl -xrender -xrandr -xinerama -xcursor -qt-sql-mysql
+    -L${mysql}/lib/mysql -I${mysql}/include/mysql -qdbus -cups -glib -xfixes
+    -fontconfig -I${freetype}/include/freetype2";
+  patchPhase = "sed -e 's@/bin/pwd@pwd@' -i configure; sed -e 's@/usr@/FOO@' -i config.tests/*/*.test -i mkspecs/*/*.conf";
+}; in
+rec {
+	trolltech = stdenv.mkDerivation (common // {
+	  name = "qt-4.3.1";
+	  src = fetchurl {
+		url = ftp://ftp.trolltech.com/qt/source/qt-x11-opensource-src-4.3.1.tar.gz;
+		sha256 = "0qg6apy2r7jbbfinxh0v1jm08yv890r40hhmy5cysn239v3x0nad";
+	  };
+	  patchPhase = common.patchPhase;
+	});
+	kde = stdenv.mkDerivation (common // {
+	  name = "qt-kde-4.3svn";
+	  src = fetchsvn {
+		  url = svn://anonsvn.kde.org/home/kde/trunk/qt-copy;
+		  md5 = "b0588d8ef36642613bdb92930a2330b4";
+	  };
+	  patchPhase = "mkdir .svn; bash apply_patches;patch -R -p0 < patches/0172-prefer-xrandr-over-xinerama.diff;" + common.patchPhase;
+	});
+	default = kde;
 }
diff --git a/pkgs/development/libraries/qt-4/setup-hook.sh b/pkgs/development/libraries/qt-4/setup-hook.sh
index db1a2529ff54..c999124b8efa 100644
--- a/pkgs/development/libraries/qt-4/setup-hook.sh
+++ b/pkgs/development/libraries/qt-4/setup-hook.sh
@@ -1 +1,6 @@
 export QTDIR=@out@
+if [ -n $qt4BadIncludes ]; then
+	for d in @out@/include/*; do
+		export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I$d";
+	done;
+fi
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 59ae4f42e3c5..588d5a880143 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -1992,12 +1992,17 @@ rec {
     mysqlSupport = false;
   };
 
+  qt4 = getVersion "qt4" qt4_alts;
   # Builds, but not tested yet
-  qt4 = import ../development/libraries/qt-4 {
-    inherit fetchurl stdenv zlib libjpeg libpng which mysql mesa openssl cups dbus fontconfig freetype pkgconfig;
+  # There are two versions: kde and trolltech
+  qt4_alts = import ../development/libraries/qt-4 {
+	inherit fetchurl fetchsvn zlib libjpeg libpng which mysql mesa openssl cups dbus
+	  fontconfig freetype pkgconfig;
     inherit (xlibs) xextproto libXft libXrender libXrandr randrproto
-      libXmu libXinerama xineramaproto libXcursor libICE libSM libX11 libXext inputproto fixesproto libXfixes;
+	  libXmu libXinerama xineramaproto libXcursor libICE libSM libX11 libXext
+	  inputproto fixesproto libXfixes;
     inherit (gnome) glib;
+    stdenv = overrideSetup stdenv ../stdenv/generic/setup-new-2.sh;
     openglSupport = mesaSupported;
     mysqlSupport = true;
   };