summary refs log tree commit diff
path: root/pkgs/development/libraries/qt-5
diff options
context:
space:
mode:
authorThomas Tuegel <ttuegel@mailbox.org>2017-10-24 06:39:54 -0500
committerThomas Tuegel <ttuegel@mailbox.org>2017-11-07 07:18:46 -0600
commitfe0ab944db2176e6757ae89aeebea16ab8dc69d0 (patch)
tree9a9c8962bc6a3083900770c980a5b87666f89688 /pkgs/development/libraries/qt-5
parent4866f16fbadd2fcc702102944b990ff578379b0a (diff)
downloadnixpkgs-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar
nixpkgs-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar.gz
nixpkgs-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar.bz2
nixpkgs-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar.lz
nixpkgs-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar.xz
nixpkgs-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar.zst
nixpkgs-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.zip
qt5: factor out common definitions and remove symlink farm
The module definitions are factored out and shared between qt56 and qt59. The
symlink farm which was created during builds is no longer needed.
Diffstat (limited to 'pkgs/development/libraries/qt-5')
-rw-r--r--pkgs/development/libraries/qt-5/5.6/default.nix128
-rw-r--r--pkgs/development/libraries/qt-5/5.6/qtbase.patch773
-rw-r--r--pkgs/development/libraries/qt-5/5.6/qtdeclarative.patch (renamed from pkgs/development/libraries/qt-5/5.9/qtdeclarative/import-paths.patch)10
-rw-r--r--pkgs/development/libraries/qt-5/5.6/qtscript.patch (renamed from pkgs/development/libraries/qt-5/5.9/qtscript/0001-glib-2.32.patch)12
-rw-r--r--pkgs/development/libraries/qt-5/5.6/qtserialport.patch (renamed from pkgs/development/libraries/qt-5/5.9/qtserialport/qtserialport-dlopen-udev.patch)10
-rw-r--r--pkgs/development/libraries/qt-5/5.6/qttools.patch64
-rw-r--r--pkgs/development/libraries/qt-5/5.6/qtwebengine-paxmark-mksnapshot.patch (renamed from pkgs/development/libraries/qt-5/5.6/qtwebengine/qtwebengine-paxmark-mksnapshot.patch)0
-rw-r--r--pkgs/development/libraries/qt-5/5.6/qtwebengine.patch (renamed from pkgs/development/libraries/qt-5/5.6/qtwebengine/chromium-clang-update-py.patch)0
-rw-r--r--pkgs/development/libraries/qt-5/5.6/qtwebkit.patch77
-rw-r--r--pkgs/development/libraries/qt-5/5.9/default.nix130
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase.patch1106
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/cmake-paths.patch359
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/compose-search-path.patch18
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/darwin-cf.patch36
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/darwin-series3
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-gl.patch19
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-gtkstyle.patch50
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-libXcursor.patch17
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-resolv.patch26
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/library-paths.patch20
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/libressl.patch33
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/mkspecs-common-mac.patch11
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/mkspecs-features-mac.patch292
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/qgtk-env.patch36
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/qnativesocketengine-type-pun.patch14
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/series9
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase/tzdir.patch39
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtcharts.nix10
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtconnectivity.nix10
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtdeclarative.patch33
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtdeclarative/default.nix20
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtdeclarative/series1
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtlocation.nix13
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtquickcontrols2.nix10
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtscript.patch13
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtscript/default.nix7
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtsensors.nix13
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtserialport.patch22
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtserialport/series1
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtsvg.nix10
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qttools.patch71
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qttools/cmake-paths.patch88
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qttools/default.nix16
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qttools/series1
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtwayland.nix13
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtwebchannel.nix11
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtwebengine-paxmark-mksnapshot.patch (renamed from pkgs/development/libraries/qt-5/5.9/qtwebengine/qtwebengine-paxmark-mksnapshot.patch)0
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtwebkit.patch77
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-dlopen-gtk.patch64
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-dlopen-udev.patch0
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-icucore-darwin.patch13
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtwebkit/series3
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtwebsockets.nix10
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtxmlpatterns.nix6
-rw-r--r--pkgs/development/libraries/qt-5/hooks/fix-qt-builtin-paths.sh64
-rw-r--r--pkgs/development/libraries/qt-5/hooks/fix-qt-module-paths.sh43
-rw-r--r--pkgs/development/libraries/qt-5/hooks/fix-qt-static-libs.sh32
-rw-r--r--pkgs/development/libraries/qt-5/hooks/move-qt-dev-tools.sh34
-rw-r--r--pkgs/development/libraries/qt-5/hooks/qmake-hook.sh18
-rw-r--r--pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh87
-rw-r--r--pkgs/development/libraries/qt-5/hooks/qttools-setup-hook.sh1
-rw-r--r--pkgs/development/libraries/qt-5/mkDerivation.nix29
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtbase.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtbase/default.nix)151
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtcharts.nix7
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtconnectivity.nix8
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtdeclarative.nix25
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtdoc.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtdoc.nix)4
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtgraphicaleffects.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtgraphicaleffects.nix)5
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtimageformats.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtimageformats.nix)4
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtlocation.nix9
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtmacextras.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtmacextras.nix)4
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtmultimedia.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtmultimedia.nix)8
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtquickcontrols.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtquickcontrols.nix)4
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtquickcontrols2.nix7
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtscript.nix6
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtsensors.nix7
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtserialport.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtserialport/default.nix)5
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtsvg.nix7
-rw-r--r--pkgs/development/libraries/qt-5/modules/qttools.nix34
-rw-r--r--pkgs/development/libraries/qt-5/modules/qttranslations.nix (renamed from pkgs/development/libraries/qt-5/5.9/qttranslations.nix)4
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtwayland.nix9
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtwebchannel.nix8
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtwebengine.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtwebengine/default.nix)20
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtwebkit.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtwebkit/default.nix)15
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtwebsockets.nix7
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtx11extras.nix (renamed from pkgs/development/libraries/qt-5/5.9/qtx11extras.nix)4
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtxmlpatterns.nix7
-rw-r--r--pkgs/development/libraries/qt-5/qmake-hook.sh47
-rw-r--r--pkgs/development/libraries/qt-5/qtModule.nix59
-rw-r--r--pkgs/development/libraries/qt-5/qtbase-setup-hook-darwin.sh192
-rw-r--r--pkgs/development/libraries/qt-5/qtbase-setup-hook.sh155
-rw-r--r--pkgs/development/libraries/qt-5/qtsubmodule-setup-hook.sh2
92 files changed, 2989 insertions, 1971 deletions
diff --git a/pkgs/development/libraries/qt-5/5.6/default.nix b/pkgs/development/libraries/qt-5/5.6/default.nix
index b250ae8b952..8b01ce2749c 100644
--- a/pkgs/development/libraries/qt-5/5.6/default.nix
+++ b/pkgs/development/libraries/qt-5/5.6/default.nix
@@ -45,64 +45,39 @@ let
   mirror = "http://download.qt.io";
   srcs = import ./srcs.nix { inherit fetchurl; inherit mirror; };
 
-  mkDerivation = args:
-    stdenv.mkDerivation (args // {
-
-      qmakeFlags =
-        (args.qmakeFlags or [])
-        ++ optional (debug != null)
-           (if debug then "CONFIG+=debug" else "CONFIG+=release");
-
-      cmakeFlags =
-        (args.cmakeFlags or [])
-        ++ [ "-DBUILD_TESTING=OFF" ]
-        ++ optional (debug != null)
-           (if debug then "-DCMAKE_BUILD_TYPE=Debug"
-                     else "-DCMAKE_BUILD_TYPE=Release");
-
-      enableParallelBuilding = args.enableParallelBuilding or true;
-
-    });
-
-  qtSubmodule = args:
-    let
-      inherit (args) name;
-      version = args.version or srcs."${name}".version;
-      src = args.src or srcs."${name}".src;
-    in mkDerivation (args // {
-      name = "${name}-${version}";
-      inherit src;
-
-      propagatedBuildInputs = args.qtInputs ++ (args.propagatedBuildInputs or []);
-      nativeBuildInputs =
-        (args.nativeBuildInputs or [])
-        ++ [ perl self.qmake ];
-
-      NIX_QT_SUBMODULE = args.NIX_QT_SUBMODULE or true;
-
-      outputs = args.outputs or [ "out" "dev" ];
-      setOutputFlags = args.setOutputFlags or false;
-
-      setupHook = ../qtsubmodule-setup-hook.sh;
-
-      meta = {
-        homepage = http://www.qt.io;
-        description = "A cross-platform application framework for C++";
-        license = with licenses; [ fdl13 gpl2 lgpl21 lgpl3 ];
-        maintainers = with maintainers; [ qknight ttuegel periklis ];
-        platforms = platforms.unix;
-      } // (args.meta or {});
-    });
+  patches = {
+    qtbase = [ ./qtbase.patch ];
+    qtdeclarative = [ ./qtdeclarative.patch ];
+    qtscript = [ ./qtscript.patch ];
+    qtserialport = [ ./qtserialport.patch ];
+    qttools = [ ./qttools.patch ];
+    qtwebengine =
+      [ ./qtwebengine.patch ]
+      ++ optional stdenv.needsPax ./qtwebengine-paxmark-mksnapshot.patch;
+    qtwebkit = [ ./qtwebkit.patch ];
+  };
+
+  mkDerivation =
+    import ../mkDerivation.nix
+    { inherit stdenv; inherit (stdenv) lib; }
+    { inherit debug; };
+
+  qtModule =
+    import ../qtModule.nix
+    { inherit mkDerivation perl; inherit (stdenv) lib; }
+    { inherit self srcs patches; };
 
   addPackages = self: with self;
     let
-      callPackage = self.newScope { inherit qtCompatVersion qtSubmodule srcs; };
+      callPackage = self.newScope { inherit qtCompatVersion qtModule srcs; };
     in {
 
       inherit mkDerivation;
 
-      qtbase = callPackage ./qtbase {
+      qtbase = callPackage ../modules/qtbase.nix {
         inherit bison cups harfbuzz mesa;
+        inherit (srcs.qtbase) src version;
+        patches = patches.qtbase;
         inherit developerBuild decryptSslTraffic;
       };
 
@@ -110,47 +85,46 @@ let
       /* qtactiveqt = not packaged */
       /* qtandroidextras = not packaged */
       /* qtcanvas3d = not packaged */
-      qtconnectivity = callPackage ./qtconnectivity.nix {};
-      qtdeclarative = callPackage ./qtdeclarative {};
-      qtdoc = callPackage ./qtdoc.nix {};
-      qtenginio = callPackage ./qtenginio.nix {};
-      qtgraphicaleffects = callPackage ./qtgraphicaleffects.nix {};
-      qtimageformats = callPackage ./qtimageformats.nix {};
-      qtlocation = callPackage ./qtlocation.nix {};
+      qtconnectivity = callPackage ../modules/qtconnectivity.nix {};
+      qtdeclarative = callPackage ../modules/qtdeclarative.nix {};
+      qtdoc = callPackage ../modules/qtdoc.nix {};
+      qtgraphicaleffects = callPackage ../modules/qtgraphicaleffects.nix {};
+      qtimageformats = callPackage ../modules/qtimageformats.nix {};
+      qtlocation = callPackage ../modules/qtlocation.nix {};
       /* qtmacextras = not packaged */
-      qtmultimedia = callPackage ./qtmultimedia.nix {
+      qtmultimedia = callPackage ../modules/qtmultimedia.nix {
         inherit gstreamer gst-plugins-base;
       };
       qtquick1 = null;
-      qtquickcontrols = callPackage ./qtquickcontrols.nix {};
-      qtquickcontrols2 = callPackage ./qtquickcontrols2.nix {};
-      qtscript = callPackage ./qtscript {};
-      qtsensors = callPackage ./qtsensors.nix {};
-      qtserialport = callPackage ./qtserialport {};
-      qtsvg = callPackage ./qtsvg.nix {};
-      qttools = callPackage ./qttools {};
-      qttranslations = callPackage ./qttranslations.nix {};
-      qtwayland = callPackage ./qtwayland.nix {};
-      qtwebchannel = callPackage ./qtwebchannel.nix {};
-      qtwebengine = callPackage ./qtwebengine {};
-      qtwebkit = callPackage ./qtwebkit {};
-      qtwebsockets = callPackage ./qtwebsockets.nix {};
+      qtquickcontrols = callPackage ../modules/qtquickcontrols.nix {};
+      qtquickcontrols2 = callPackage ../modules/qtquickcontrols2.nix {};
+      qtscript = callPackage ../modules/qtscript.nix {};
+      qtsensors = callPackage ../modules/qtsensors.nix {};
+      qtserialport = callPackage ../modules/qtserialport.nix {};
+      qtsvg = callPackage ../modules/qtsvg.nix {};
+      qttools = callPackage ../modules/qttools.nix {};
+      qttranslations = callPackage ../modules/qttranslations.nix {};
+      qtwayland = callPackage ../modules/qtwayland.nix {};
+      qtwebchannel = callPackage ../modules/qtwebchannel.nix {};
+      qtwebengine = callPackage ../modules/qtwebengine.nix {};
+      qtwebkit = callPackage ../modules/qtwebkit.nix {};
+      qtwebsockets = callPackage ../modules/qtwebsockets.nix {};
       /* qtwinextras = not packaged */
-      qtx11extras = callPackage ./qtx11extras.nix {};
-      qtxmlpatterns = callPackage ./qtxmlpatterns.nix {};
+      qtx11extras = callPackage ../modules/qtx11extras.nix {};
+      qtxmlpatterns = callPackage ../modules/qtxmlpatterns.nix {};
 
       env = callPackage ../qt-env.nix {};
       full = env "qt-${qtbase.version}" [
-        qtconnectivity qtdeclarative qtdoc qtenginio qtgraphicaleffects
-        qtimageformats qtlocation qtmultimedia qtquickcontrols qtquickcontrols2
-        qtscript qtsensors qtserialport qtsvg qttools qttranslations qtwayland
+        qtconnectivity qtdeclarative qtdoc qtgraphicaleffects qtimageformats
+        qtlocation qtmultimedia qtquickcontrols qtquickcontrols2 qtscript
+        qtsensors qtserialport qtsvg qttools qttranslations qtwayland
         qtwebchannel qtwebengine qtwebkit qtwebsockets qtx11extras qtxmlpatterns
       ];
 
       qmake = makeSetupHook {
         deps = [ self.qtbase.dev ];
         substitutions = { inherit (stdenv) isDarwin; };
-      } ../qmake-hook.sh;
+      } ../hooks/qmake-hook.sh;
     };
 
    self = makeScope newScope addPackages;
diff --git a/pkgs/development/libraries/qt-5/5.6/qtbase.patch b/pkgs/development/libraries/qt-5/5.6/qtbase.patch
new file mode 100644
index 00000000000..0e21a17665b
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/5.6/qtbase.patch
@@ -0,0 +1,773 @@
+diff --git a/mkspecs/features/create_cmake.prf b/mkspecs/features/create_cmake.prf
+index 11fb52a0b1..a4cca1fdcb 100644
+--- a/mkspecs/features/create_cmake.prf
++++ b/mkspecs/features/create_cmake.prf
+@@ -21,7 +21,7 @@ load(cmake_functions)
+ # at cmake time whether package has been found via a symlink, and correct
+ # that to an absolute path. This is only done for installations to
+ # the /usr or / prefix.
+-CMAKE_INSTALL_LIBS_DIR = $$cmakeTargetPath($$[QT_INSTALL_LIBS])
++CMAKE_INSTALL_LIBS_DIR = $$cmakeTargetPath($$NIX_OUTPUT_OUT/lib/)
+ contains(CMAKE_INSTALL_LIBS_DIR, ^(/usr)?/lib(64)?.*): CMAKE_USR_MOVE_WORKAROUND = $$CMAKE_INSTALL_LIBS_DIR
+ 
+ CMAKE_OUT_DIR = $$MODULE_BASE_OUTDIR/lib/cmake
+@@ -47,47 +47,22 @@ split_incpath {
+         $$cmake_extra_source_includes.output
+ }
+ 
+-CMAKE_INCLUDE_DIR = $$cmakeRelativePath($$[QT_INSTALL_HEADERS], $$[QT_INSTALL_PREFIX])
+-contains(CMAKE_INCLUDE_DIR, "^\\.\\./.*") {
+-    CMAKE_INCLUDE_DIR = $$[QT_INSTALL_HEADERS]/
+-    CMAKE_INCLUDE_DIR_IS_ABSOLUTE = True
+-}
++CMAKE_INCLUDE_DIR = $$NIX_OUTPUT_DEV/include/
++CMAKE_INCLUDE_DIR_IS_ABSOLUTE = True
+ 
+ !exists($$first(QT.$${MODULE}_private.includes)): CMAKE_NO_PRIVATE_INCLUDES = true
+ 
+-CMAKE_LIB_DIR = $$cmakeRelativePath($$[QT_INSTALL_LIBS], $$[QT_INSTALL_PREFIX])
+-contains(CMAKE_LIB_DIR,"^\\.\\./.*") {
+-    CMAKE_LIB_DIR = $$[QT_INSTALL_LIBS]/
+-    CMAKE_LIB_DIR_IS_ABSOLUTE = True
+-} else {
+-    CMAKE_RELATIVE_INSTALL_LIBS_DIR = $$cmakeRelativePath($$[QT_INSTALL_PREFIX], $$[QT_INSTALL_LIBS])
+-    # We need to go up another two levels because the CMake files are
+-    # installed in $${CMAKE_LIB_DIR}/cmake/Qt5$${CMAKE_MODULE_NAME}
+-    CMAKE_RELATIVE_INSTALL_DIR = "$${CMAKE_RELATIVE_INSTALL_LIBS_DIR}../../"
+-}
++CMAKE_LIB_DIR = $$NIX_OUTPUT_DEV/lib/
++CMAKE_LIB_DIR_IS_ABSOLUTE = True
+ 
+-CMAKE_BIN_DIR = $$cmakeRelativePath($$[QT_HOST_BINS], $$[QT_INSTALL_PREFIX])
+-contains(CMAKE_BIN_DIR, "^\\.\\./.*") {
+-    CMAKE_BIN_DIR = $$[QT_HOST_BINS]/
+-    CMAKE_BIN_DIR_IS_ABSOLUTE = True
+-}
++CMAKE_BIN_DIR = $$NIX_OUTPUT_BIN/bin/
++CMAKE_BIN_DIR_IS_ABSOLUTE = True
+ 
+-CMAKE_PLUGIN_DIR = $$cmakeRelativePath($$[QT_INSTALL_PLUGINS], $$[QT_INSTALL_PREFIX])
+-contains(CMAKE_PLUGIN_DIR, "^\\.\\./.*") {
+-    CMAKE_PLUGIN_DIR = $$[QT_INSTALL_PLUGINS]/
+-    CMAKE_PLUGIN_DIR_IS_ABSOLUTE = True
+-}
++CMAKE_PLUGIN_DIR = $$NIX_OUTPUT_PLUGIN/
++CMAKE_PLUGIN_DIR_IS_ABSOLUTE = True
+ 
+-win32:!wince:!static:!staticlib {
+-    CMAKE_DLL_DIR = $$cmakeRelativePath($$[QT_INSTALL_BINS], $$[QT_INSTALL_PREFIX])
+-    contains(CMAKE_DLL_DIR, "^\\.\\./.*") {
+-        CMAKE_DLL_DIR = $$[QT_INSTALL_BINS]/
+-        CMAKE_DLL_DIR_IS_ABSOLUTE = True
+-    }
+-} else {
+-    CMAKE_DLL_DIR = $$CMAKE_LIB_DIR
+-    CMAKE_DLL_DIR_IS_ABSOLUTE = $$CMAKE_LIB_DIR_IS_ABSOLUTE
+-}
++CMAKE_DLL_DIR = $$NIX_OUTPUT_DEV/lib/
++CMAKE_DLL_DIR_IS_ABSOLUTE = True
+ 
+ static|staticlib:CMAKE_STATIC_TYPE = true
+ 
+@@ -167,7 +142,7 @@ contains(CONFIG, plugin) {
+       cmake_target_file
+ 
+     cmake_qt5_plugin_file.files = $$cmake_target_file.output
+-    cmake_qt5_plugin_file.path = $$[QT_INSTALL_LIBS]/cmake/Qt5$${CMAKE_MODULE_NAME}
++    cmake_qt5_plugin_file.path = $$NIX_OUTPUT_OUT/lib/cmake/Qt5$${CMAKE_MODULE_NAME}
+     INSTALLS += cmake_qt5_plugin_file
+ 
+     return()
+@@ -314,7 +289,7 @@ exists($$cmake_macros_file.input) {
+     cmake_qt5_module_files.files += $$cmake_macros_file.output
+ }
+ 
+-cmake_qt5_module_files.path = $$[QT_INSTALL_LIBS]/cmake/Qt5$${CMAKE_MODULE_NAME}
++cmake_qt5_module_files.path = $$NIX_OUTPUT_OUT/lib/cmake/Qt5$${CMAKE_MODULE_NAME}
+ 
+ # We are generating cmake files. Most developers of Qt are not aware of cmake,
+ # so we require automatic tests to be available. The only module which should
+diff --git a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
+index d2358cae4b..61d8cc0471 100644
+--- a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
++++ b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
+@@ -9,30 +9,6 @@ if (CMAKE_VERSION VERSION_LESS 3.0.0)
+ endif()
+ !!ENDIF
+ 
+-!!IF !isEmpty(CMAKE_USR_MOVE_WORKAROUND)
+-!!IF !isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-set(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$[QT_INSTALL_PREFIX]\")
+-!!ELSE
+-get_filename_component(_IMPORT_PREFIX \"${CMAKE_CURRENT_LIST_FILE}\" PATH)
+-# Use original install prefix when loaded through a
+-# cross-prefix symbolic link such as /lib -> /usr/lib.
+-get_filename_component(_realCurr \"${_IMPORT_PREFIX}\" REALPATH)
+-get_filename_component(_realOrig \"$$CMAKE_INSTALL_LIBS_DIR/cmake/Qt5$${CMAKE_MODULE_NAME}\" REALPATH)
+-if(_realCurr STREQUAL _realOrig)
+-    get_filename_component(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$CMAKE_INSTALL_LIBS_DIR/$${CMAKE_RELATIVE_INSTALL_LIBS_DIR}\" ABSOLUTE)
+-else()
+-    get_filename_component(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_RELATIVE_INSTALL_DIR}\" ABSOLUTE)
+-endif()
+-unset(_realOrig)
+-unset(_realCurr)
+-unset(_IMPORT_PREFIX)
+-!!ENDIF
+-!!ELIF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-get_filename_component(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_RELATIVE_INSTALL_DIR}\" ABSOLUTE)
+-!!ELSE
+-set(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$[QT_INSTALL_PREFIX]\")
+-!!ENDIF
+-
+ !!IF !equals(TEMPLATE, aux)
+ # For backwards compatibility only. Use Qt5$${CMAKE_MODULE_NAME}_VERSION instead.
+ set(Qt5$${CMAKE_MODULE_NAME}_VERSION_STRING "$$eval(QT.$${MODULE}.MAJOR_VERSION).$$eval(QT.$${MODULE}.MINOR_VERSION).$$eval(QT.$${MODULE}.PATCH_VERSION)")
+@@ -58,11 +34,7 @@ endmacro()
+ macro(_populate_$${CMAKE_MODULE_NAME}_target_properties Configuration LIB_LOCATION IMPLIB_LOCATION)
+     set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
+ 
+-!!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
+-!!ENDIF
+     _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_location})
+     set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+         \"INTERFACE_LINK_LIBRARIES\" \"${_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES}\"
+@@ -75,11 +47,7 @@ macro(_populate_$${CMAKE_MODULE_NAME}_target_properties Configuration LIB_LOCATI
+     )
+ 
+ !!IF !isEmpty(CMAKE_WINDOWS_BUILD)
+-!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    set(imported_implib \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
+-!!ELSE
+     set(imported_implib \"IMPORTED_IMPLIB_${Configuration}\" \"$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
+-!!ENDIF
+     _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_implib})
+     if(NOT \"${IMPLIB_LOCATION}\" STREQUAL \"\")
+         set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+@@ -95,24 +63,13 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+ !!IF !no_module_headers
+ !!IF !isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
+     set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS
+-      \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework\"
+-      \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Headers\"
++      \"$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework\"
++      \"$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Headers\"
+     )
+ !!IF isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
+     set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/\"
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/$${MODULE_INCNAME}\"
+-    )
+-!!ELSE
+-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
+-!!ENDIF
+-!!ELSE
+-!!IF isEmpty(CMAKE_INCLUDE_DIR_IS_ABSOLUTE)
+-    set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$$CMAKE_INCLUDE_DIR\" \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}\")
+-!!IF isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
+-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION\"
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION/$${MODULE_INCNAME}\"
++        \"$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/\"
++        \"$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/$${MODULE_INCNAME}\"
+     )
+ !!ELSE
+     set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
+@@ -128,7 +85,6 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+     set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
+ !!ENDIF
+ !!ENDIF
+-!!ENDIF
+ !!IF !isEmpty(CMAKE_ADD_SOURCE_INCLUDE_DIRS)
+     include(\"${CMAKE_CURRENT_LIST_DIR}/ExtraSourceIncludes.cmake\" OPTIONAL)
+ !!ENDIF
+@@ -254,25 +210,13 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+ !!IF !isEmpty(CMAKE_FIND_OTHER_LIBRARY_BUILD)
+ !!IF isEmpty(CMAKE_DEBUG_TYPE)
+ !!IF !isEmpty(CMAKE_STATIC_WINDOWS_BUILD)
+-!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    if (EXISTS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+-!!ELSE // CMAKE_LIB_DIR_IS_ABSOLUTE
+     if (EXISTS \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+-!!ENDIF // CMAKE_LIB_DIR_IS_ABSOLUTE
+         _populate_$${CMAKE_MODULE_NAME}_target_properties(DEBUG \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" \"\" )
+ !!ELSE // CMAKE_STATIC_WINDOWS_BUILD
+     if (EXISTS
+-!!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}$${CMAKE_LIB_FILE_LOCATION_DEBUG}\"
+-!!ELSE
+         \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\"
+-!!ENDIF
+       AND EXISTS
+-!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+-!!ELSE
+         \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+-!!ENDIF
+         _populate_$${CMAKE_MODULE_NAME}_target_properties(DEBUG \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+ !!ENDIF // CMAKE_STATIC_WINDOWS_BUILD
+     endif()
+@@ -291,25 +235,13 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+ !!IF !isEmpty(CMAKE_FIND_OTHER_LIBRARY_BUILD)
+ !!IF isEmpty(CMAKE_RELEASE_TYPE)
+ !!IF !isEmpty(CMAKE_STATIC_WINDOWS_BUILD)
+-!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    if (EXISTS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+-!!ELSE // CMAKE_LIB_DIR_IS_ABSOLUTE
+     if (EXISTS \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+-!!ENDIF // CMAKE_LIB_DIR_IS_ABSOLUTE
+         _populate_$${CMAKE_MODULE_NAME}_target_properties(RELEASE \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" \"\" )
+ !!ELSE // CMAKE_STATIC_WINDOWS_BUILD
+     if (EXISTS
+-!!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}$${CMAKE_LIB_FILE_LOCATION_RELEASE}\"
+-!!ELSE
+         \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\"
+-!!ENDIF
+       AND EXISTS
+-!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+-!!ELSE
+         \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+-!!ENDIF
+         _populate_$${CMAKE_MODULE_NAME}_target_properties(RELEASE \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+ !!ENDIF // CMAKE_STATIC_WINDOWS_BUILD
+     endif()
+@@ -328,11 +260,7 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+     macro(_populate_$${CMAKE_MODULE_NAME}_plugin_properties Plugin Configuration PLUGIN_LOCATION)
+         set_property(TARGET Qt5::${Plugin} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
+ 
+-!!IF isEmpty(CMAKE_PLUGIN_DIR_IS_ABSOLUTE)
+-        set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_PLUGIN_DIR}${PLUGIN_LOCATION}\")
+-!!ELSE
+         set(imported_location \"$${CMAKE_PLUGIN_DIR}${PLUGIN_LOCATION}\")
+-!!ENDIF
+         _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_location})
+         set_target_properties(Qt5::${Plugin} PROPERTIES
+             \"IMPORTED_LOCATION_${Configuration}\" ${imported_location}
+diff --git a/mkspecs/features/qml_module.prf b/mkspecs/features/qml_module.prf
+index b09d42a0a4..f076265bdd 100644
+--- a/mkspecs/features/qml_module.prf
++++ b/mkspecs/features/qml_module.prf
+@@ -17,10 +17,7 @@ fq_qml_files = $$_PRO_FILE_PWD_/qmldir
+ 
+ for(qmlf, QML_FILES): fq_qml_files += $$absolute_path($$qmlf, $$_PRO_FILE_PWD_)
+ 
+-qml1_target: \
+-    instbase = $$[QT_INSTALL_IMPORTS]
+-else: \
+-    instbase = $$[QT_INSTALL_QML]
++instbase = $$NIX_OUTPUT_QML
+ 
+ # Install rules
+ qmldir.base = $$_PRO_FILE_PWD_
+diff --git a/mkspecs/features/qml_plugin.prf b/mkspecs/features/qml_plugin.prf
+index ebec1db8da..62ace84a6c 100644
+--- a/mkspecs/features/qml_plugin.prf
++++ b/mkspecs/features/qml_plugin.prf
+@@ -46,13 +46,8 @@ exists($$QMLTYPEFILE): QML_FILES += $$QMLTYPEFILE
+ 
+ load(qt_build_paths)
+ 
+-qml1_target {
+-    DESTDIR = $$MODULE_BASE_OUTDIR/imports/$$TARGETPATH
+-    instbase = $$[QT_INSTALL_IMPORTS]
+-} else {
+-    DESTDIR = $$MODULE_BASE_OUTDIR/qml/$$TARGETPATH
+-    instbase = $$[QT_INSTALL_QML]
+-}
++DESTDIR = $$MODULE_BASE_OUTDIR/qml/$$TARGETPATH
++instbase = $$NIX_OUTPUT_QML
+ 
+ target.path = $$instbase/$$TARGETPATH
+ INSTALLS += target
+diff --git a/mkspecs/features/qt_app.prf b/mkspecs/features/qt_app.prf
+index 46aca50cc2..4f4e634724 100644
+--- a/mkspecs/features/qt_app.prf
++++ b/mkspecs/features/qt_app.prf
+@@ -29,7 +29,7 @@ host_build:force_bootstrap {
+     target.path = $$[QT_HOST_BINS]
+ } else {
+     !build_pass:contains(QT_CONFIG, debug_and_release): CONFIG += release
+-    target.path = $$[QT_INSTALL_BINS]
++    target.path = $$NIX_OUTPUT_BIN/bin
+     CONFIG += relative_qt_rpath  # Qt's tools and apps should be relocatable
+ }
+ INSTALLS += target
+diff --git a/mkspecs/features/qt_build_paths.prf b/mkspecs/features/qt_build_paths.prf
+index 1848f00e90..2af93675c5 100644
+--- a/mkspecs/features/qt_build_paths.prf
++++ b/mkspecs/features/qt_build_paths.prf
+@@ -23,6 +23,6 @@ exists($$MODULE_BASE_INDIR/.git): \
+ !force_independent {
+     # If the module is not built independently, everything ends up in qtbase.
+     # This is the case in non-prefix builds, except for selected modules.
+-    MODULE_BASE_OUTDIR = $$[QT_HOST_PREFIX]
+-    MODULE_QMAKE_OUTDIR = $$[QT_HOST_PREFIX]
++    MODULE_BASE_OUTDIR = $$NIX_OUTPUT_OUT
++    MODULE_QMAKE_OUTDIR = $$NIX_OUTPUT_OUT
+ }
+diff --git a/mkspecs/features/qt_common.prf b/mkspecs/features/qt_common.prf
+index c1809468af..0a12ec24db 100644
+--- a/mkspecs/features/qt_common.prf
++++ b/mkspecs/features/qt_common.prf
+@@ -30,8 +30,8 @@ contains(TEMPLATE, .*lib) {
+         qqt_libdir = \$\$\$\$[QT_HOST_LIBS]
+         qt_libdir = $$[QT_HOST_LIBS]
+     } else {
+-        qqt_libdir = \$\$\$\$[QT_INSTALL_LIBS]
+-        qt_libdir = $$[QT_INSTALL_LIBS]
++        qqt_libdir = \$\$\$\$NIX_OUTPUT_OUT/lib
++        qt_libdir = $$NIX_OUTPUT_OUT/lib
+     }
+     contains(QMAKE_DEFAULT_LIBDIRS, $$qt_libdir) {
+         lib_replace.match = "[^ ']*$$rplbase/lib"
+diff --git a/mkspecs/features/qt_docs.prf b/mkspecs/features/qt_docs.prf
+index 183d0c9502..17982b04ec 100644
+--- a/mkspecs/features/qt_docs.prf
++++ b/mkspecs/features/qt_docs.prf
+@@ -41,7 +41,7 @@ QMAKE_DOCS_OUTPUTDIR = $$QMAKE_DOCS_BASE_OUTDIR/$$QMAKE_DOCS_TARGETDIR
+ 
+ QDOC += -outputdir $$shell_quote($$QMAKE_DOCS_OUTPUTDIR)
+ !build_online_docs: \
+-    QDOC += -installdir $$shell_quote($$[QT_INSTALL_DOCS])
++    QDOC += -installdir $$shell_quote($$NIX_OUTPUT_DOC)
+ PREP_DOC_INDEXES =
+ DOC_INDEXES =
+ !isEmpty(QTREPOS) {
+@@ -60,8 +60,8 @@ DOC_INDEXES =
+         DOC_INDEXES += -indexdir $$shell_quote($$qrep/doc)
+ } else {
+     prepare_docs: \
+-        PREP_DOC_INDEXES += -indexdir $$shell_quote($$[QT_INSTALL_DOCS/get])
+-    DOC_INDEXES += -indexdir $$shell_quote($$[QT_INSTALL_DOCS/get])
++        PREP_DOC_INDEXES += -indexdir $$shell_quote($$NIX_OUTPUT_DOC)
++    DOC_INDEXES += -indexdir $$shell_quote($$NIX_OUTPUT_DOC)
+ }
+ doc_command = $$QDOC $$QMAKE_DOCS
+ prepare_docs {
+@@ -75,12 +75,12 @@ prepare_docs {
+     qch_docs.commands = $$QHELPGENERATOR $$shell_quote($$QMAKE_DOCS_OUTPUTDIR/$${QMAKE_DOCS_TARGET}.qhp) -o $$shell_quote($$QMAKE_DOCS_BASE_OUTDIR/$${QMAKE_DOCS_TARGET}.qch)
+ 
+     inst_html_docs.files = $$QMAKE_DOCS_OUTPUTDIR
+-    inst_html_docs.path = $$[QT_INSTALL_DOCS]
++    inst_html_docs.path = $$NIX_OUTPUT_DOC
+     inst_html_docs.CONFIG += no_check_exist directory no_default_install no_build
+     INSTALLS += inst_html_docs
+ 
+     inst_qch_docs.files = $$QMAKE_DOCS_BASE_OUTDIR/$${QMAKE_DOCS_TARGET}.qch
+-    inst_qch_docs.path = $$[QT_INSTALL_DOCS]
++    inst_qch_docs.path = $$NIX_OUTPUT_DOC
+     inst_qch_docs.CONFIG += no_check_exist no_default_install no_build
+     INSTALLS += inst_qch_docs
+ 
+diff --git a/mkspecs/features/qt_example_installs.prf b/mkspecs/features/qt_example_installs.prf
+index 4c68cfd72f..f422f18266 100644
+--- a/mkspecs/features/qt_example_installs.prf
++++ b/mkspecs/features/qt_example_installs.prf
+@@ -70,7 +70,7 @@ probase = $$relative_path($$_PRO_FILE_PWD_, $$dirname(_QMAKE_CONF_)/examples)
+         $$SOURCES $$HEADERS $$FORMS $$RESOURCES $$TRANSLATIONS \
+         $$DBUS_ADAPTORS $$DBUS_INTERFACES
+     addInstallFiles(sources.files, $$sourcefiles)
+-    sources.path = $$[QT_INSTALL_EXAMPLES]/$$probase
++    sources.path = $$NIX_OUTPUT_DEV/share/examples/$$probase
+     INSTALLS += sources
+ 
+     check_examples {
+diff --git a/mkspecs/features/qt_functions.prf b/mkspecs/features/qt_functions.prf
+index 4a1d265a8b..abe0da95f6 100644
+--- a/mkspecs/features/qt_functions.prf
++++ b/mkspecs/features/qt_functions.prf
+@@ -70,7 +70,7 @@ defineTest(qtHaveModule) {
+ defineTest(qtPrepareTool) {
+     cmd = $$eval(QT_TOOL.$${2}.binary)
+     isEmpty(cmd) {
+-        cmd = $$[QT_HOST_BINS]/$$2
++        cmd = $$system("type -p $$2")
+         exists($${cmd}.pl) {
+             cmd = perl -w $$system_path($${cmd}.pl)
+         } else: contains(QMAKE_HOST.os, Windows) {
+diff --git a/mkspecs/features/qt_installs.prf b/mkspecs/features/qt_installs.prf
+index 3a5dbb6274..24f321bd82 100644
+--- a/mkspecs/features/qt_installs.prf
++++ b/mkspecs/features/qt_installs.prf
+@@ -12,16 +12,10 @@
+ #library
+ !qt_no_install_library {
+     win32 {
+-       host_build: \
+-           dlltarget.path = $$[QT_HOST_BINS]
+-       else: \
+-           dlltarget.path = $$[QT_INSTALL_BINS]
++        dlltarget.path = $$NIX_OUTPUT_BIN/bin
+        INSTALLS += dlltarget
+     }
+-    host_build: \
+-        target.path = $$[QT_HOST_LIBS]
+-    else: \
+-        target.path = $$[QT_INSTALL_LIBS]
++    target.path = $$NIX_OUTPUT_OUT/lib
+     !static: target.CONFIG = no_dll
+     INSTALLS += target
+ }
+@@ -29,33 +23,33 @@
+ #headers
+ qt_install_headers {
+     class_headers.files = $$SYNCQT.HEADER_CLASSES
+-    class_headers.path = $$[QT_INSTALL_HEADERS]/$$MODULE_INCNAME
++    class_headers.path = $$NIX_OUTPUT_DEV/include/$$MODULE_INCNAME
+     INSTALLS += class_headers
+ 
+     targ_headers.files = $$SYNCQT.HEADER_FILES
+-    targ_headers.path = $$[QT_INSTALL_HEADERS]/$$MODULE_INCNAME
++    targ_headers.path = $$NIX_OUTPUT_DEV/include/$$MODULE_INCNAME
+     INSTALLS += targ_headers
+ 
+     private_headers.files = $$SYNCQT.PRIVATE_HEADER_FILES
+-    private_headers.path = $$[QT_INSTALL_HEADERS]/$$MODULE_INCNAME/$$VERSION/$$MODULE_INCNAME/private
++    private_headers.path = $$NIX_OUTPUT_DEV/include/$$MODULE_INCNAME/$$VERSION/$$MODULE_INCNAME/private
+     INSTALLS += private_headers
+ 
+     qpa_headers.files = $$SYNCQT.QPA_HEADER_FILES
+-    qpa_headers.path = $$[QT_INSTALL_HEADERS]/$$MODULE_INCNAME/$$VERSION/$$MODULE_INCNAME/qpa
++    qpa_headers.path = $$NIX_OUTPUT_DEV/include/$$MODULE_INCNAME/$$VERSION/$$MODULE_INCNAME/qpa
+     INSTALLS += qpa_headers
+ }
+ 
+ #module
+ qt_install_module {
+     !isEmpty(MODULE_PRI) {
+-        pritarget.path = $$[QT_HOST_DATA]/mkspecs/modules
++        pritarget.path = $$NIX_OUTPUT_DEV/mkspecs/modules
+         pritarget.files = $$MODULE_PRI
+         INSTALLS += pritarget
+     } else: isEmpty(MODULE_PRIVATE_PRI) {
+         warning("Project $$basename(_PRO_FILE_) is a module, but has not defined MODULE_PRI, which is required for Qt to expose the module to other projects.")
+     }
+     !isEmpty(MODULE_PRIVATE_PRI) {
+-        privpritarget.path = $$[QT_HOST_DATA]/mkspecs/modules
++        privpritarget.path = $$NIX_OUTPUT_DEV/mkspecs/modules
+         privpritarget.files = $$MODULE_PRIVATE_PRI
+         INSTALLS += privpritarget
+     }
+diff --git a/mkspecs/features/qt_plugin.prf b/mkspecs/features/qt_plugin.prf
+index 3cf6c7349c..83e68025a5 100644
+--- a/mkspecs/features/qt_plugin.prf
++++ b/mkspecs/features/qt_plugin.prf
+@@ -82,7 +82,7 @@ CONFIG(static, static|shared)|prefix_build {
+     }
+ }
+ 
+-target.path = $$[QT_INSTALL_PLUGINS]/$$PLUGIN_TYPE
++target.path = $$NIX_OUTPUT_PLUGIN/$$PLUGIN_TYPE
+ INSTALLS += target
+ 
+ TARGET = $$qt5LibraryTarget($$TARGET)
+diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in
+index 91a4eb619a..08b533e69c 100644
+--- a/src/corelib/Qt5CoreConfigExtras.cmake.in
++++ b/src/corelib/Qt5CoreConfigExtras.cmake.in
+@@ -3,7 +3,7 @@ if (NOT TARGET Qt5::qmake)
+     add_executable(Qt5::qmake IMPORTED)
+ 
+ !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\")
+ !!ENDIF
+@@ -18,7 +18,7 @@ if (NOT TARGET Qt5::moc)
+     add_executable(Qt5::moc IMPORTED)
+ 
+ !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\")
+ !!ENDIF
+@@ -35,7 +35,7 @@ if (NOT TARGET Qt5::rcc)
+     add_executable(Qt5::rcc IMPORTED)
+ 
+ !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\")
+ !!ENDIF
+@@ -131,7 +131,7 @@ if (NOT TARGET Qt5::WinMain)
+ !!IF !isEmpty(CMAKE_RELEASE_TYPE)
+     set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+ !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\")
+ !!ENDIF
+@@ -145,7 +145,7 @@ if (NOT TARGET Qt5::WinMain)
+     set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+ 
+ !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}\")
+ !!ENDIF
+diff --git a/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in b/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in
+index c357237d0e..6f0c75de3c 100644
+--- a/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in
++++ b/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in
+@@ -1,6 +1,6 @@
+ 
+ !!IF isEmpty(CMAKE_HOST_DATA_DIR_IS_ABSOLUTE)
+-set(_qt5_corelib_extra_includes \"${_qt5Core_install_prefix}/$${CMAKE_HOST_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
++set(_qt5_corelib_extra_includes \"$$NIX_OUTPUT_DEV/$${CMAKE_HOST_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
+ !!ELSE
+ set(_qt5_corelib_extra_includes \"$${CMAKE_HOST_DATA_DIR}mkspecs/$${CMAKE_MKSPEC}\")
+ !!ENDIF
+diff --git a/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in b/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in
+index 706304cf34..546420f6ad 100644
+--- a/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in
++++ b/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in
+@@ -1,6 +1,6 @@
+ 
+ !!IF isEmpty(CMAKE_INSTALL_DATA_DIR_IS_ABSOLUTE)
+-set(_qt5_corelib_extra_includes \"${_qt5Core_install_prefix}/$${CMAKE_INSTALL_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
++set(_qt5_corelib_extra_includes \"$$NIX_OUTPUT_DEV/$${CMAKE_INSTALL_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
+ !!ELSE
+ set(_qt5_corelib_extra_includes \"$${CMAKE_INSTALL_DATA_DIR}mkspecs/$${CMAKE_MKSPEC}\")
+ !!ENDIF
+diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
+index f5b15207cc..f85e0524bb 100644
+--- a/src/corelib/kernel/qcoreapplication.cpp
++++ b/src/corelib/kernel/qcoreapplication.cpp
+@@ -2533,6 +2533,15 @@ QStringList QCoreApplication::libraryPaths()
+         QStringList *app_libpaths = new QStringList;
+         coreappdata()->app_libpaths.reset(app_libpaths);
+ 
++        // Add library paths derived from PATH
++        const QStringList paths = QFile::decodeName(qgetenv("PATH")).split(':');
++        const QString plugindir = QStringLiteral("../" NIXPKGS_QT_PLUGIN_PREFIX);
++        for (const QString &path: paths) {
++            if (!path.isEmpty()) {
++                app_libpaths->append(QDir::cleanPath(path + QDir::separator() + plugindir));
++            }
++        }
++
+         const QByteArray libPathEnv = qgetenv("QT_PLUGIN_PATH");
+         if (!libPathEnv.isEmpty()) {
+             QStringList paths = QFile::decodeName(libPathEnv).split(QDir::listSeparator(), QString::SkipEmptyParts);
+diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp
+index c13c9a5223..6936851511 100644
+--- a/src/corelib/tools/qtimezoneprivate_tz.cpp
++++ b/src/corelib/tools/qtimezoneprivate_tz.cpp
+@@ -64,7 +64,11 @@ typedef QHash<QByteArray, QTzTimeZone> QTzTimeZoneHash;
+ // Parse zone.tab table, assume lists all installed zones, if not will need to read directories
+ static QTzTimeZoneHash loadTzTimeZones()
+ {
+-    QString path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
++    // Try TZDIR first, in case we're running on NixOS.
++    QString path = QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/zone.tab");
++    // Fallback to traditional paths in case we are not on NixOS.
++    if (!QFile::exists(path))
++        path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
+     if (!QFile::exists(path))
+         path = QStringLiteral("/usr/lib/zoneinfo/zone.tab");
+ 
+@@ -636,12 +640,16 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId)
+         if (!tzif.open(QIODevice::ReadOnly))
+             return;
+     } else {
+-        // Open named tz, try modern path first, if fails try legacy path
+-        tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
++        // Try TZDIR first, in case we're running on NixOS
++        tzif.setFileName(QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/") + QString::fromLocal8Bit(ianaId));
+         if (!tzif.open(QIODevice::ReadOnly)) {
+-            tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
+-            if (!tzif.open(QIODevice::ReadOnly))
+-                return;
++            // Open named tz, try modern path first, if fails try legacy path
++            tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
++            if (!tzif.open(QIODevice::ReadOnly)) {
++                tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
++                if (!tzif.open(QIODevice::ReadOnly))
++                    return;
++            }
+         }
+     }
+ 
+diff --git a/src/dbus/Qt5DBusConfigExtras.cmake.in b/src/dbus/Qt5DBusConfigExtras.cmake.in
+index 1d947159e2..b36865fc48 100644
+--- a/src/dbus/Qt5DBusConfigExtras.cmake.in
++++ b/src/dbus/Qt5DBusConfigExtras.cmake.in
+@@ -2,11 +2,7 @@
+ if (NOT TARGET Qt5::qdbuscpp2xml)
+     add_executable(Qt5::qdbuscpp2xml IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5DBus_install_prefix}/$${CMAKE_BIN_DIR}qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+-    set(imported_location \"$${CMAKE_BIN_DIR}qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
++    set(imported_location \"$$NIX_OUTPUT_DEV/bin/qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
+     _qt5_DBus_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::qdbuscpp2xml PROPERTIES
+@@ -17,11 +13,7 @@ endif()
+ if (NOT TARGET Qt5::qdbusxml2cpp)
+     add_executable(Qt5::qdbusxml2cpp IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5DBus_install_prefix}/$${CMAKE_BIN_DIR}qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+-    set(imported_location \"$${CMAKE_BIN_DIR}qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
++    set(imported_location \"$$NIX_OUTPUT_DEV/bin/qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
+     _qt5_DBus_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::qdbusxml2cpp PROPERTIES
+diff --git a/src/gui/Qt5GuiConfigExtras.cmake.in b/src/gui/Qt5GuiConfigExtras.cmake.in
+index 07869efd7d..37b95d1b6b 100644
+--- a/src/gui/Qt5GuiConfigExtras.cmake.in
++++ b/src/gui/Qt5GuiConfigExtras.cmake.in
+@@ -2,7 +2,7 @@
+ !!IF !isEmpty(CMAKE_ANGLE_EGL_DLL_RELEASE)
+ 
+ !!IF isEmpty(CMAKE_INCLUDE_DIR_IS_ABSOLUTE)
+-set(Qt5Gui_EGL_INCLUDE_DIRS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$$CMAKE_INCLUDE_DIR/QtANGLE\")
++set(Qt5Gui_EGL_INCLUDE_DIRS \"$$NIX_OUTPUT_DEV/$$CMAKE_INCLUDE_DIR/QtANGLE\")
+ !!ELSE
+ set(Qt5Gui_EGL_INCLUDE_DIRS \"$$CMAKE_INCLUDE_DIR/QtANGLE\")
+ !!ENDIF
+@@ -17,13 +17,13 @@ macro(_populate_qt5gui_gl_target_properties TargetName Configuration LIB_LOCATIO
+     set_property(TARGET Qt5::${TargetName} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
+ 
+ !!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Gui_install_prefix}/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
++    set(imported_location \"$$NIX_OUTPUT_OUT/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
+ !!ENDIF
+ 
+ !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    set(imported_implib \"${_qt5Gui_install_prefix}/$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
++    set(imported_implib \"$$NIX_OUTPUT_DEV/$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
+ !!ELSE
+     set(imported_implib \"$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
+ !!ENDIF
+diff --git a/src/network/kernel/qdnslookup_unix.cpp b/src/network/kernel/qdnslookup_unix.cpp
+index 584f0b0f0e..24d80063f2 100644
+--- a/src/network/kernel/qdnslookup_unix.cpp
++++ b/src/network/kernel/qdnslookup_unix.cpp
+@@ -83,7 +83,7 @@ static bool resolveLibraryInternal()
+     if (!lib.load())
+ #endif
+     {
+-        lib.setFileName(QLatin1String("resolv"));
++        lib.setFileName(QLatin1String(NIXPKGS_LIBRESOLV));
+         if (!lib.load())
+             return false;
+     }
+diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp
+index dabf1913cc..53bb867e07 100644
+--- a/src/network/kernel/qhostinfo_unix.cpp
++++ b/src/network/kernel/qhostinfo_unix.cpp
+@@ -94,7 +94,7 @@ static bool resolveLibraryInternal()
+     if (!lib.load())
+ #endif
+     {
+-        lib.setFileName(QLatin1String("resolv"));
++        lib.setFileName(QLatin1String(NIXPKGS_LIBRESOLV));
+         if (!lib.load())
+             return false;
+     }
+diff --git a/src/network/ssl/qsslcontext_openssl.cpp b/src/network/ssl/qsslcontext_openssl.cpp
+index 68caaeb6dc..fef4a81474 100644
+--- a/src/network/ssl/qsslcontext_openssl.cpp
++++ b/src/network/ssl/qsslcontext_openssl.cpp
+@@ -340,7 +340,7 @@ init_context:
+ 
+     const QVector<QSslEllipticCurve> qcurves = sslContext->sslConfiguration.ellipticCurves();
+     if (!qcurves.isEmpty()) {
+-#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_EC)
++#if OPENSSL_VERSION_NUMBER >= 0x10002000L && defined(SSL_CTRL_SET_CURVES) && !defined(OPENSSL_NO_EC)
+         // Set the curves to be used
+         if (q_SSLeay() >= 0x10002000L) {
+             // SSL_CTX_ctrl wants a non-const pointer as last argument,
+@@ -354,7 +354,7 @@ init_context:
+                 return sslContext;
+             }
+         } else
+-#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_EC)
++#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L && defined(SSL_CTRL_SET_CURVES) && !defined(OPENSSL_NO_EC)
+         {
+             // specific curves requested, but not possible to set -> error
+             sslContext->errorStr = msgErrorSettingEllipticCurves(QSslSocket::tr("OpenSSL version too old, need at least v1.0.2"));
+diff --git a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
+index 44f1d7e6ba..e24fe54326 100644
+--- a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
++++ b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
+@@ -251,12 +251,9 @@ void TableGenerator::initPossibleLocations()
+     // the QTCOMPOSE environment variable
+     if (qEnvironmentVariableIsSet("QTCOMPOSE"))
+         m_possibleLocations.append(QString::fromLocal8Bit(qgetenv("QTCOMPOSE")));
+-    m_possibleLocations.append(QStringLiteral("/usr/share/X11/locale"));
+-    m_possibleLocations.append(QStringLiteral("/usr/local/share/X11/locale"));
+-    m_possibleLocations.append(QStringLiteral("/usr/lib/X11/locale"));
+-    m_possibleLocations.append(QStringLiteral("/usr/local/lib/X11/locale"));
+     m_possibleLocations.append(QStringLiteral(X11_PREFIX "/share/X11/locale"));
+     m_possibleLocations.append(QStringLiteral(X11_PREFIX "/lib/X11/locale"));
++    m_possibleLocations.append(QLatin1String(NIXPKGS_QTCOMPOSE));
+ }
+ 
+ QString TableGenerator::findComposeFile()
+diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
+index 9bdedcc830..2559b2066b 100644
+--- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
++++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
+@@ -570,7 +570,14 @@ void (*QGLXContext::getProcAddress(const QByteArray &procName)) ()
+ #ifndef QT_NO_LIBRARY
+                 extern const QString qt_gl_library_name();
+ //                QLibrary lib(qt_gl_library_name());
++                // Check system library paths first
+                 QLibrary lib(QLatin1String("GL"));
++#ifdef NIXPKGS_MESA_GL
++                if (!lib.load()) {
++                    // Fallback to Mesa driver
++                    lib.setFileName(QLatin1String(NIXPKGS_MESA_GL));
++                }
++#endif // NIXPKGS_MESA_GL
+                 glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB");
+ #endif
+             }
+diff --git a/src/plugins/platforms/xcb/qxcbcursor.cpp b/src/plugins/platforms/xcb/qxcbcursor.cpp
+index b321ed95dc..9e7a72521c 100644
+--- a/src/plugins/platforms/xcb/qxcbcursor.cpp
++++ b/src/plugins/platforms/xcb/qxcbcursor.cpp
+@@ -303,10 +303,10 @@ QXcbCursor::QXcbCursor(QXcbConnection *conn, QXcbScreen *screen)
+ #if defined(XCB_USE_XLIB) && !defined(QT_NO_LIBRARY)
+     static bool function_ptrs_not_initialized = true;
+     if (function_ptrs_not_initialized) {
+-        QLibrary xcursorLib(QLatin1String("Xcursor"), 1);
++        QLibrary xcursorLib(QLatin1String(NIXPKGS_LIBXCURSOR), 1);
+         bool xcursorFound = xcursorLib.load();
+         if (!xcursorFound) { // try without the version number
+-            xcursorLib.setFileName(QLatin1String("Xcursor"));
++            xcursorLib.setFileName(QLatin1String(NIXPKGS_LIBXCURSOR));
+             xcursorFound = xcursorLib.load();
+         }
+         if (xcursorFound) {
+diff --git a/src/widgets/Qt5WidgetsConfigExtras.cmake.in b/src/widgets/Qt5WidgetsConfigExtras.cmake.in
+index 99d87e2e46..a4eab2aa72 100644
+--- a/src/widgets/Qt5WidgetsConfigExtras.cmake.in
++++ b/src/widgets/Qt5WidgetsConfigExtras.cmake.in
+@@ -3,7 +3,7 @@ if (NOT TARGET Qt5::uic)
+     add_executable(Qt5::uic IMPORTED)
+ 
+ !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Widgets_install_prefix}/$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\")
+ !!ENDIF
diff --git a/pkgs/development/libraries/qt-5/5.9/qtdeclarative/import-paths.patch b/pkgs/development/libraries/qt-5/5.6/qtdeclarative.patch
index d50ee823a78..dbddaa2a1d6 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtdeclarative/import-paths.patch
+++ b/pkgs/development/libraries/qt-5/5.6/qtdeclarative.patch
@@ -1,8 +1,8 @@
-Index: qtdeclarative-opensource-src-5.8.0/src/qml/qml/qqmlimport.cpp
-===================================================================
---- qtdeclarative-opensource-src-5.8.0.orig/src/qml/qml/qqmlimport.cpp
-+++ qtdeclarative-opensource-src-5.8.0/src/qml/qml/qqmlimport.cpp
-@@ -1630,6 +1630,15 @@ QQmlImportDatabase::QQmlImportDatabase(Q
+diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
+index dfdf2edbe..7ee96049d 100644
+--- a/src/qml/qml/qqmlimport.cpp
++++ b/src/qml/qml/qqmlimport.cpp
+@@ -1568,6 +1568,15 @@ QQmlImportDatabase::QQmlImportDatabase(QQmlEngine *e)
      QString installImportsPath =  QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath);
      addImportPath(installImportsPath);
  
diff --git a/pkgs/development/libraries/qt-5/5.9/qtscript/0001-glib-2.32.patch b/pkgs/development/libraries/qt-5/5.6/qtscript.patch
index 887e107b6c1..5508dec1280 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtscript/0001-glib-2.32.patch
+++ b/pkgs/development/libraries/qt-5/5.6/qtscript.patch
@@ -1,12 +1,3 @@
-From abd80356449bb36c8adcc5c9ca1df6b47715d265 Mon Sep 17 00:00:00 2001
-From: Thomas Tuegel <ttuegel@gmail.com>
-Date: Sun, 23 Aug 2015 09:13:34 -0500
-Subject: [PATCH] glib-2.32
-
----
- src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
 diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h b/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h
 index 1f6d25e..087c3fb 100644
 --- a/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h
@@ -20,6 +11,3 @@ index 1f6d25e..087c3fb 100644
  typedef struct _GCond GCond;
  #endif
  
--- 
-2.5.0
-
diff --git a/pkgs/development/libraries/qt-5/5.9/qtserialport/qtserialport-dlopen-udev.patch b/pkgs/development/libraries/qt-5/5.6/qtserialport.patch
index 65bb64710eb..b2cffbe4f39 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtserialport/qtserialport-dlopen-udev.patch
+++ b/pkgs/development/libraries/qt-5/5.6/qtserialport.patch
@@ -1,8 +1,8 @@
-Index: qtserialport-opensource-src-5.8.0/src/serialport/qtudev_p.h
-===================================================================
---- qtserialport-opensource-src-5.8.0.orig/src/serialport/qtudev_p.h
-+++ qtserialport-opensource-src-5.8.0/src/serialport/qtudev_p.h
-@@ -111,9 +111,17 @@ inline QFunctionPointer resolveSymbol(QL
+diff --git a/src/serialport/qtudev_p.h b/src/serialport/qtudev_p.h
+index 6f2cabd..cd3c0ed 100644
+--- a/src/serialport/qtudev_p.h
++++ b/src/serialport/qtudev_p.h
+@@ -105,9 +105,17 @@ inline QFunctionPointer resolveSymbol(QLibrary *udevLibrary, const char *symbolN
  inline bool resolveSymbols(QLibrary *udevLibrary)
  {
      if (!udevLibrary->isLoaded()) {
diff --git a/pkgs/development/libraries/qt-5/5.6/qttools.patch b/pkgs/development/libraries/qt-5/5.6/qttools.patch
new file mode 100644
index 00000000000..dcb15e0e55a
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/5.6/qttools.patch
@@ -0,0 +1,64 @@
+diff --git a/src/assistant/help/Qt5HelpConfigExtras.cmake.in b/src/assistant/help/Qt5HelpConfigExtras.cmake.in
+index 5a5bd5ce..1c6727d4 100644
+--- a/src/assistant/help/Qt5HelpConfigExtras.cmake.in
++++ b/src/assistant/help/Qt5HelpConfigExtras.cmake.in
+@@ -2,14 +2,13 @@
+ if (NOT TARGET Qt5::qcollectiongenerator)
+     add_executable(Qt5::qcollectiongenerator IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Help_install_prefix}/$${CMAKE_BIN_DIR}qcollectiongenerator$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}qcollectiongenerator$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
++    if(NOT EXISTS \"${imported_location}\")
++        set(imported_location \"$${CMAKE_BIN_DIR}qcollectiongenerator$$CMAKE_BIN_SUFFIX\")
++    endif()
+     _qt5_Help_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::qcollectiongenerator PROPERTIES
+         IMPORTED_LOCATION ${imported_location}
+     )
+-endif()
++endif()
+\ No newline at end of file
+diff --git a/src/linguist/Qt5LinguistToolsConfig.cmake.in b/src/linguist/Qt5LinguistToolsConfig.cmake.in
+index 4318b16f..d60db4ff 100644
+--- a/src/linguist/Qt5LinguistToolsConfig.cmake.in
++++ b/src/linguist/Qt5LinguistToolsConfig.cmake.in
+@@ -44,11 +44,7 @@ endmacro()
+ if (NOT TARGET Qt5::lrelease)
+     add_executable(Qt5::lrelease IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5_linguisttools_install_prefix}/$${CMAKE_BIN_DIR}lrelease$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}lrelease$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
+     _qt5_LinguistTools_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::lrelease PROPERTIES
+@@ -59,11 +55,7 @@ endif()
+ if (NOT TARGET Qt5::lupdate)
+     add_executable(Qt5::lupdate IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5_linguisttools_install_prefix}/$${CMAKE_BIN_DIR}lupdate$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}lupdate$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
+     _qt5_LinguistTools_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::lupdate PROPERTIES
+@@ -74,11 +66,7 @@ endif()
+ if (NOT TARGET Qt5::lconvert)
+     add_executable(Qt5::lconvert IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5_linguisttools_install_prefix}/$${CMAKE_BIN_DIR}lconvert$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}lconvert$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
+     _qt5_LinguistTools_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::lconvert PROPERTIES
diff --git a/pkgs/development/libraries/qt-5/5.6/qtwebengine/qtwebengine-paxmark-mksnapshot.patch b/pkgs/development/libraries/qt-5/5.6/qtwebengine-paxmark-mksnapshot.patch
index b3316188f7d..b3316188f7d 100644
--- a/pkgs/development/libraries/qt-5/5.6/qtwebengine/qtwebengine-paxmark-mksnapshot.patch
+++ b/pkgs/development/libraries/qt-5/5.6/qtwebengine-paxmark-mksnapshot.patch
diff --git a/pkgs/development/libraries/qt-5/5.6/qtwebengine/chromium-clang-update-py.patch b/pkgs/development/libraries/qt-5/5.6/qtwebengine.patch
index 65a604d2534..65a604d2534 100644
--- a/pkgs/development/libraries/qt-5/5.6/qtwebengine/chromium-clang-update-py.patch
+++ b/pkgs/development/libraries/qt-5/5.6/qtwebengine.patch
diff --git a/pkgs/development/libraries/qt-5/5.6/qtwebkit.patch b/pkgs/development/libraries/qt-5/5.6/qtwebkit.patch
new file mode 100644
index 00000000000..310d2745825
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/5.6/qtwebkit.patch
@@ -0,0 +1,77 @@
+diff --git a/Source/WTF/WTF.pri b/Source/WTF/WTF.pri
+index 1f4866d66..bb61e4ba3 100644
+--- a/Source/WTF/WTF.pri
++++ b/Source/WTF/WTF.pri
+@@ -12,7 +12,7 @@ mac {
+     # Mac OS does ship libicu but not the associated header files.
+     # Therefore WebKit provides adequate header files.
+     INCLUDEPATH = $${ROOT_WEBKIT_DIR}/Source/WTF/icu $$INCLUDEPATH
+-    LIBS += -licucore
++    LIBS += /usr/lib/libicucore.dylib
+ } else:!use?(wchar_unicode): {
+     win32 {
+         CONFIG(static, static|shared) {
+diff --git a/Source/WebCore/plugins/qt/PluginPackageQt.cpp b/Source/WebCore/plugins/qt/PluginPackageQt.cpp
+index a923d49aa..46772a4bb 100644
+--- a/Source/WebCore/plugins/qt/PluginPackageQt.cpp
++++ b/Source/WebCore/plugins/qt/PluginPackageQt.cpp
+@@ -136,7 +136,11 @@ static void initializeGtk(QLibrary* module = 0)
+         }
+     }
+ 
++#ifdef NIXPKGS_LIBGTK2
++    QLibrary library(QLatin1String(NIXPKGS_LIBGTK2), 0);
++#else
+     QLibrary library(QLatin1String("libgtk-x11-2.0"), 0);
++#endif
+     if (library.load()) {
+         typedef void *(*gtk_init_check_ptr)(int*, char***);
+         gtk_init_check_ptr gtkInitCheck = (gtk_init_check_ptr)library.resolve("gtk_init_check");
+diff --git a/Source/WebCore/plugins/qt/PluginViewQt.cpp b/Source/WebCore/plugins/qt/PluginViewQt.cpp
+index de06a2fea..86fe39ef1 100644
+--- a/Source/WebCore/plugins/qt/PluginViewQt.cpp
++++ b/Source/WebCore/plugins/qt/PluginViewQt.cpp
+@@ -697,7 +697,11 @@ static Display *getPluginDisplay()
+     // support gdk based plugins (like flash) that use a different X connection.
+     // The code below has the same effect as this one:
+     // Display *gdkDisplay = gdk_x11_display_get_xdisplay(gdk_display_get_default());
++#ifdef NIXPKGS_LIBGDK2
++    QLibrary library(QLatin1String(NIXPKGS_LIBGDK2), 0);
++#else
+     QLibrary library(QLatin1String("libgdk-x11-2.0"), 0);
++#endif
+     if (!library.load())
+         return 0;
+ 
+diff --git a/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp b/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp
+index 8de65216b..38f5c05e5 100644
+--- a/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp
++++ b/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp
+@@ -53,7 +53,11 @@ static void messageHandler(QtMsgType type, const QMessageLogContext&, const QStr
+ 
+ static bool initializeGtk()
+ {
++#ifdef NIXPKGS_LIBGTK2
++    QLibrary gtkLibrary(QLatin1String(NIXPKGS_LIBGTK2), 0);
++#else
+     QLibrary gtkLibrary(QLatin1String("libgtk-x11-2.0"), 0);
++#endif
+     if (!gtkLibrary.load())
+         return false;
+     typedef void* (*gtk_init_ptr)(void*, void*);
+diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
+index d734ff684..0f6ff63d1 100644
+--- a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
++++ b/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
+@@ -64,7 +64,11 @@ static Display* getPluginDisplay()
+     // The code below has the same effect as this one:
+     // Display *gdkDisplay = gdk_x11_display_get_xdisplay(gdk_display_get_default());
+ 
++#ifdef NIXPKGS_LIBGDK2
++    QLibrary library(QLatin1String(NIXPKGS_LIBGDK2), 0);
++#else
+     QLibrary library(QLatin1String("libgdk-x11-2.0"), 0);
++#endif
+     if (!library.load())
+         return 0;
+ 
diff --git a/pkgs/development/libraries/qt-5/5.9/default.nix b/pkgs/development/libraries/qt-5/5.9/default.nix
index 8f9be38fc88..879f7f198c9 100644
--- a/pkgs/development/libraries/qt-5/5.9/default.nix
+++ b/pkgs/development/libraries/qt-5/5.9/default.nix
@@ -36,96 +36,68 @@ let
   mirror = "http://download.qt.io";
   srcs = import ./srcs.nix { inherit fetchurl; inherit mirror; };
 
-  mkDerivation = args:
-    stdenv.mkDerivation (args // {
-
-      qmakeFlags =
-        (args.qmakeFlags or [])
-        ++ optional (debug != null)
-           (if debug then "CONFIG+=debug" else "CONFIG+=release");
-
-      cmakeFlags =
-        (args.cmakeFlags or [])
-        ++ [ "-DBUILD_TESTING=OFF" ]
-        ++ optional (debug != null)
-           (if debug then "-DCMAKE_BUILD_TYPE=Debug"
-                     else "-DCMAKE_BUILD_TYPE=Release");
-
-      enableParallelBuilding = args.enableParallelBuilding or true;
-
-    });
-
-  qtSubmodule = args:
-    let
-      inherit (args) name;
-      version = args.version or srcs."${name}".version;
-      src = args.src or srcs."${name}".src;
-    in mkDerivation (args // {
-      name = "${name}-${version}";
-      inherit src;
-
-      propagatedBuildInputs = args.qtInputs ++ (args.propagatedBuildInputs or []);
-      nativeBuildInputs =
-        (args.nativeBuildInputs or [])
-        ++ [ perl self.qmake ];
-
-      NIX_QT_SUBMODULE = args.NIX_QT_SUBMODULE or true;
-
-      outputs = args.outputs or [ "out" "dev" ];
-      setOutputFlags = args.setOutputFlags or false;
-
-      setupHook = ../qtsubmodule-setup-hook.sh;
-
-      meta = {
-        homepage = http://www.qt.io;
-        description = "A cross-platform application framework for C++";
-        license = with licenses; [ fdl13 gpl2 lgpl21 lgpl3 ];
-        maintainers = with maintainers; [ qknight ttuegel periklis ];
-        platforms = platforms.unix;
-      } // (args.meta or {});
-    });
+  patches = {
+    qtbase = [ ./qtbase.patch ];
+    qtdeclarative = [ ./qtdeclarative.patch ];
+    qtscript = [ ./qtscript.patch ];
+    qtserialport = [ ./qtserialport.patch ];
+    qttools = [ ./qttools.patch ];
+    qtwebengine = optional stdenv.needsPax ./qtwebengine-paxmark-mksnapshot.patch;
+    qtwebkit = [ ./qtwebkit.patch ];
+  };
+
+  mkDerivation =
+    import ../mkDerivation.nix
+    { inherit stdenv; inherit (stdenv) lib; }
+    { inherit debug; };
+
+  qtModule =
+    import ../qtModule.nix
+    { inherit mkDerivation perl; inherit (stdenv) lib; }
+    { inherit self srcs patches; };
 
   addPackages = self: with self;
     let
-      callPackage = self.newScope { inherit qtCompatVersion qtSubmodule srcs; };
+      callPackage = self.newScope { inherit qtCompatVersion qtModule srcs; };
     in {
 
       inherit mkDerivation;
 
-      qtbase = callPackage ./qtbase {
+      qtbase = callPackage ../modules/qtbase.nix {
         inherit (srcs.qtbase) src version;
+        patches = patches.qtbase;
         inherit bison cups harfbuzz mesa;
-        inherit dconf gtk3;
+        withGtk3 = true; inherit dconf gtk3;
         inherit developerBuild decryptSslTraffic;
       };
 
-      qtcharts = callPackage ./qtcharts.nix {};
-      qtconnectivity = callPackage ./qtconnectivity.nix {};
-      qtdeclarative = callPackage ./qtdeclarative {};
-      qtdoc = callPackage ./qtdoc.nix {};
-      qtgraphicaleffects = callPackage ./qtgraphicaleffects.nix {};
-      qtimageformats = callPackage ./qtimageformats.nix {};
-      qtlocation = callPackage ./qtlocation.nix {};
-      qtmacextras = callPackage ./qtmacextras.nix {};
-      qtmultimedia = callPackage ./qtmultimedia.nix {
+      qtcharts = callPackage ../modules/qtcharts.nix {};
+      qtconnectivity = callPackage ../modules/qtconnectivity.nix {};
+      qtdeclarative = callPackage ../modules/qtdeclarative.nix {};
+      qtdoc = callPackage ../modules/qtdoc.nix {};
+      qtgraphicaleffects = callPackage ../modules/qtgraphicaleffects.nix {};
+      qtimageformats = callPackage ../modules/qtimageformats.nix {};
+      qtlocation = callPackage ../modules/qtlocation.nix {};
+      qtmacextras = callPackage ../modules/qtmacextras.nix {};
+      qtmultimedia = callPackage ../modules/qtmultimedia.nix {
         inherit gstreamer gst-plugins-base;
       };
       qtquick1 = null;
-      qtquickcontrols = callPackage ./qtquickcontrols.nix {};
-      qtquickcontrols2 = callPackage ./qtquickcontrols2.nix {};
-      qtscript = callPackage ./qtscript {};
-      qtsensors = callPackage ./qtsensors.nix {};
-      qtserialport = callPackage ./qtserialport {};
-      qtsvg = callPackage ./qtsvg.nix {};
-      qttools = callPackage ./qttools {};
-      qttranslations = callPackage ./qttranslations.nix {};
-      qtwayland = callPackage ./qtwayland.nix {};
-      qtwebchannel = callPackage ./qtwebchannel.nix {};
-      qtwebengine = callPackage ./qtwebengine {};
-      qtwebkit = callPackage ./qtwebkit {};
-      qtwebsockets = callPackage ./qtwebsockets.nix {};
-      qtx11extras = callPackage ./qtx11extras.nix {};
-      qtxmlpatterns = callPackage ./qtxmlpatterns.nix {};
+      qtquickcontrols = callPackage ../modules/qtquickcontrols.nix {};
+      qtquickcontrols2 = callPackage ../modules/qtquickcontrols2.nix {};
+      qtscript = callPackage ../modules/qtscript.nix {};
+      qtsensors = callPackage ../modules/qtsensors.nix {};
+      qtserialport = callPackage ../modules/qtserialport.nix {};
+      qtsvg = callPackage ../modules/qtsvg.nix {};
+      qttools = callPackage ../modules/qttools.nix {};
+      qttranslations = callPackage ../modules/qttranslations.nix {};
+      qtwayland = callPackage ../modules/qtwayland.nix {};
+      qtwebchannel = callPackage ../modules/qtwebchannel.nix {};
+      qtwebengine = callPackage ../modules/qtwebengine.nix {};
+      qtwebkit = callPackage ../modules/qtwebkit.nix {};
+      qtwebsockets = callPackage ../modules/qtwebsockets.nix {};
+      qtx11extras = callPackage ../modules/qtx11extras.nix {};
+      qtxmlpatterns = callPackage ../modules/qtxmlpatterns.nix {};
 
       env = callPackage ../qt-env.nix {};
       full = env "qt-${qtbase.version}" ([
@@ -138,8 +110,12 @@ let
 
       qmake = makeSetupHook {
         deps = [ self.qtbase.dev ];
-        substitutions = { inherit (stdenv) isDarwin; };
-      } ../qmake-hook.sh;
+        substitutions = {
+          inherit (stdenv) isDarwin;
+          qtbase_dev = self.qtbase.dev;
+          fix_qt_builtin_paths = ../hooks/fix-qt-builtin-paths.sh;
+        };
+      } ../hooks/qmake-hook.sh;
     };
 
    self = makeScope newScope addPackages;
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase.patch b/pkgs/development/libraries/qt-5/5.9/qtbase.patch
new file mode 100644
index 00000000000..4f6ed98ba29
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/5.9/qtbase.patch
@@ -0,0 +1,1106 @@
+diff --git a/mkspecs/common/mac.conf b/mkspecs/common/mac.conf
+index 5208379f9a..92fe29a0ac 100644
+--- a/mkspecs/common/mac.conf
++++ b/mkspecs/common/mac.conf
+@@ -23,7 +23,7 @@ QMAKE_INCDIR_OPENGL     = \
+ 
+ QMAKE_FIX_RPATH         = install_name_tool -id
+ 
+-QMAKE_LFLAGS_RPATH      = -Wl,-rpath,
++QMAKE_LFLAGS_RPATH      =
+ QMAKE_LFLAGS_GCSECTIONS = -Wl,-dead_strip
+ 
+ QMAKE_LFLAGS_REL_RPATH  =
+diff --git a/mkspecs/features/create_cmake.prf b/mkspecs/features/create_cmake.prf
+index bb5083c925..da8e2cb386 100644
+--- a/mkspecs/features/create_cmake.prf
++++ b/mkspecs/features/create_cmake.prf
+@@ -21,7 +21,7 @@ load(cmake_functions)
+ # at cmake time whether package has been found via a symlink, and correct
+ # that to an absolute path. This is only done for installations to
+ # the /usr or / prefix.
+-CMAKE_INSTALL_LIBS_DIR = $$cmakeTargetPath($$[QT_INSTALL_LIBS])
++CMAKE_INSTALL_LIBS_DIR = $$cmakeTargetPath($$NIX_OUTPUT_OUT/lib/)
+ contains(CMAKE_INSTALL_LIBS_DIR, ^(/usr)?/lib(64)?.*): CMAKE_USR_MOVE_WORKAROUND = $$CMAKE_INSTALL_LIBS_DIR
+ 
+ CMAKE_OUT_DIR = $$MODULE_BASE_OUTDIR/lib/cmake
+@@ -47,47 +47,22 @@ split_incpath {
+         $$cmake_extra_source_includes.output
+ }
+ 
+-CMAKE_INCLUDE_DIR = $$cmakeRelativePath($$[QT_INSTALL_HEADERS], $$[QT_INSTALL_PREFIX])
+-contains(CMAKE_INCLUDE_DIR, "^\\.\\./.*") {
+-    CMAKE_INCLUDE_DIR = $$[QT_INSTALL_HEADERS]/
+-    CMAKE_INCLUDE_DIR_IS_ABSOLUTE = True
+-}
++CMAKE_INCLUDE_DIR = $$NIX_OUTPUT_DEV/include/
++CMAKE_INCLUDE_DIR_IS_ABSOLUTE = True
+ 
+ !exists($$first(QT.$${MODULE}_private.includes)): CMAKE_NO_PRIVATE_INCLUDES = true
+ 
+-CMAKE_LIB_DIR = $$cmakeRelativePath($$[QT_INSTALL_LIBS], $$[QT_INSTALL_PREFIX])
+-contains(CMAKE_LIB_DIR,"^\\.\\./.*") {
+-    CMAKE_LIB_DIR = $$[QT_INSTALL_LIBS]/
+-    CMAKE_LIB_DIR_IS_ABSOLUTE = True
+-} else {
+-    CMAKE_RELATIVE_INSTALL_LIBS_DIR = $$cmakeRelativePath($$[QT_INSTALL_PREFIX], $$[QT_INSTALL_LIBS])
+-    # We need to go up another two levels because the CMake files are
+-    # installed in $${CMAKE_LIB_DIR}/cmake/Qt5$${CMAKE_MODULE_NAME}
+-    CMAKE_RELATIVE_INSTALL_DIR = "$${CMAKE_RELATIVE_INSTALL_LIBS_DIR}../../"
+-}
++CMAKE_LIB_DIR = $$NIX_OUTPUT_DEV/lib/
++CMAKE_LIB_DIR_IS_ABSOLUTE = True
+ 
+-CMAKE_BIN_DIR = $$cmakeRelativePath($$[QT_HOST_BINS], $$[QT_INSTALL_PREFIX])
+-contains(CMAKE_BIN_DIR, "^\\.\\./.*") {
+-    CMAKE_BIN_DIR = $$[QT_HOST_BINS]/
+-    CMAKE_BIN_DIR_IS_ABSOLUTE = True
+-}
++CMAKE_BIN_DIR = $$NIX_OUTPUT_BIN/bin/
++CMAKE_BIN_DIR_IS_ABSOLUTE = True
+ 
+-CMAKE_PLUGIN_DIR = $$cmakeRelativePath($$[QT_INSTALL_PLUGINS], $$[QT_INSTALL_PREFIX])
+-contains(CMAKE_PLUGIN_DIR, "^\\.\\./.*") {
+-    CMAKE_PLUGIN_DIR = $$[QT_INSTALL_PLUGINS]/
+-    CMAKE_PLUGIN_DIR_IS_ABSOLUTE = True
+-}
++CMAKE_PLUGIN_DIR = $$NIX_OUTPUT_PLUGIN/
++CMAKE_PLUGIN_DIR_IS_ABSOLUTE = True
+ 
+-win32:!static:!staticlib {
+-    CMAKE_DLL_DIR = $$cmakeRelativePath($$[QT_INSTALL_BINS], $$[QT_INSTALL_PREFIX])
+-    contains(CMAKE_DLL_DIR, "^\\.\\./.*") {
+-        CMAKE_DLL_DIR = $$[QT_INSTALL_BINS]/
+-        CMAKE_DLL_DIR_IS_ABSOLUTE = True
+-    }
+-} else {
+-    CMAKE_DLL_DIR = $$CMAKE_LIB_DIR
+-    CMAKE_DLL_DIR_IS_ABSOLUTE = $$CMAKE_LIB_DIR_IS_ABSOLUTE
+-}
++CMAKE_DLL_DIR = $$NIX_OUTPUT_DEV/lib/
++CMAKE_DLL_DIR_IS_ABSOLUTE = True
+ 
+ static|staticlib:CMAKE_STATIC_TYPE = true
+ 
+@@ -167,7 +142,7 @@ contains(CONFIG, plugin) {
+       cmake_target_file
+ 
+     cmake_qt5_plugin_file.files = $$cmake_target_file.output
+-    cmake_qt5_plugin_file.path = $$[QT_INSTALL_LIBS]/cmake/Qt5$${CMAKE_MODULE_NAME}
++    cmake_qt5_plugin_file.path = $$NIX_OUTPUT_OUT/lib/cmake/Qt5$${CMAKE_MODULE_NAME}
+     INSTALLS += cmake_qt5_plugin_file
+ 
+     return()
+@@ -314,7 +289,7 @@ exists($$cmake_macros_file.input) {
+     cmake_qt5_module_files.files += $$cmake_macros_file.output
+ }
+ 
+-cmake_qt5_module_files.path = $$[QT_INSTALL_LIBS]/cmake/Qt5$${CMAKE_MODULE_NAME}
++cmake_qt5_module_files.path = $$NIX_OUTPUT_OUT/lib/cmake/Qt5$${CMAKE_MODULE_NAME}
+ 
+ # We are generating cmake files. Most developers of Qt are not aware of cmake,
+ # so we require automatic tests to be available. The only module which should
+diff --git a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
+index 17da8b979e..d648ab4058 100644
+--- a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
++++ b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
+@@ -9,30 +9,6 @@ if (CMAKE_VERSION VERSION_LESS 3.0.0)
+ endif()
+ !!ENDIF
+ 
+-!!IF !isEmpty(CMAKE_USR_MOVE_WORKAROUND)
+-!!IF !isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-set(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$[QT_INSTALL_PREFIX]\")
+-!!ELSE
+-get_filename_component(_IMPORT_PREFIX \"${CMAKE_CURRENT_LIST_FILE}\" PATH)
+-# Use original install prefix when loaded through a
+-# cross-prefix symbolic link such as /lib -> /usr/lib.
+-get_filename_component(_realCurr \"${_IMPORT_PREFIX}\" REALPATH)
+-get_filename_component(_realOrig \"$$CMAKE_INSTALL_LIBS_DIR/cmake/Qt5$${CMAKE_MODULE_NAME}\" REALPATH)
+-if(_realCurr STREQUAL _realOrig)
+-    get_filename_component(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$CMAKE_INSTALL_LIBS_DIR/$${CMAKE_RELATIVE_INSTALL_LIBS_DIR}\" ABSOLUTE)
+-else()
+-    get_filename_component(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_RELATIVE_INSTALL_DIR}\" ABSOLUTE)
+-endif()
+-unset(_realOrig)
+-unset(_realCurr)
+-unset(_IMPORT_PREFIX)
+-!!ENDIF
+-!!ELIF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-get_filename_component(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_RELATIVE_INSTALL_DIR}\" ABSOLUTE)
+-!!ELSE
+-set(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$[QT_INSTALL_PREFIX]\")
+-!!ENDIF
+-
+ !!IF !equals(TEMPLATE, aux)
+ # For backwards compatibility only. Use Qt5$${CMAKE_MODULE_NAME}_VERSION instead.
+ set(Qt5$${CMAKE_MODULE_NAME}_VERSION_STRING "$$eval(QT.$${MODULE}.VERSION)")
+@@ -58,11 +34,7 @@ endmacro()
+ macro(_populate_$${CMAKE_MODULE_NAME}_target_properties Configuration LIB_LOCATION IMPLIB_LOCATION)
+     set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
+ 
+-!!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
+-!!ENDIF
+     _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_location})
+     set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+         \"INTERFACE_LINK_LIBRARIES\" \"${_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES}\"
+@@ -75,11 +47,7 @@ macro(_populate_$${CMAKE_MODULE_NAME}_target_properties Configuration LIB_LOCATI
+     )
+ 
+ !!IF !isEmpty(CMAKE_WINDOWS_BUILD)
+-!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    set(imported_implib \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
+-!!ELSE
+     set(imported_implib \"IMPORTED_IMPLIB_${Configuration}\" \"$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
+-!!ENDIF
+     _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_implib})
+     if(NOT \"${IMPLIB_LOCATION}\" STREQUAL \"\")
+         set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+@@ -95,24 +63,13 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+ !!IF !no_module_headers
+ !!IF !isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
+     set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS
+-      \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework\"
+-      \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Headers\"
++      \"$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework\"
++      \"$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Headers\"
+     )
+ !!IF isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
+     set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/\"
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/$${MODULE_INCNAME}\"
+-    )
+-!!ELSE
+-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
+-!!ENDIF
+-!!ELSE
+-!!IF isEmpty(CMAKE_INCLUDE_DIR_IS_ABSOLUTE)
+-    set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$$CMAKE_INCLUDE_DIR\" \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}\")
+-!!IF isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
+-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION\"
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION/$${MODULE_INCNAME}\"
++        \"$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/\"
++        \"$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/$${MODULE_INCNAME}\"
+     )
+ !!ELSE
+     set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
+@@ -128,7 +85,6 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+     set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
+ !!ENDIF
+ !!ENDIF
+-!!ENDIF
+ !!IF !isEmpty(CMAKE_ADD_SOURCE_INCLUDE_DIRS)
+     include(\"${CMAKE_CURRENT_LIST_DIR}/ExtraSourceIncludes.cmake\" OPTIONAL)
+ !!ENDIF
+@@ -280,25 +236,13 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+ !!IF !isEmpty(CMAKE_FIND_OTHER_LIBRARY_BUILD)
+ !!IF isEmpty(CMAKE_DEBUG_TYPE)
+ !!IF !isEmpty(CMAKE_STATIC_WINDOWS_BUILD)
+-!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    if (EXISTS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+-!!ELSE // CMAKE_LIB_DIR_IS_ABSOLUTE
+     if (EXISTS \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+-!!ENDIF // CMAKE_LIB_DIR_IS_ABSOLUTE
+         _populate_$${CMAKE_MODULE_NAME}_target_properties(DEBUG \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" \"\" )
+ !!ELSE // CMAKE_STATIC_WINDOWS_BUILD
+     if (EXISTS
+-!!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}$${CMAKE_LIB_FILE_LOCATION_DEBUG}\"
+-!!ELSE
+         \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\"
+-!!ENDIF
+       AND EXISTS
+-!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+-!!ELSE
+         \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+-!!ENDIF
+         _populate_$${CMAKE_MODULE_NAME}_target_properties(DEBUG \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+ !!ENDIF // CMAKE_STATIC_WINDOWS_BUILD
+     endif()
+@@ -317,25 +261,13 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+ !!IF !isEmpty(CMAKE_FIND_OTHER_LIBRARY_BUILD)
+ !!IF isEmpty(CMAKE_RELEASE_TYPE)
+ !!IF !isEmpty(CMAKE_STATIC_WINDOWS_BUILD)
+-!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    if (EXISTS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+-!!ELSE // CMAKE_LIB_DIR_IS_ABSOLUTE
+     if (EXISTS \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+-!!ENDIF // CMAKE_LIB_DIR_IS_ABSOLUTE
+         _populate_$${CMAKE_MODULE_NAME}_target_properties(RELEASE \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" \"\" )
+ !!ELSE // CMAKE_STATIC_WINDOWS_BUILD
+     if (EXISTS
+-!!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}$${CMAKE_LIB_FILE_LOCATION_RELEASE}\"
+-!!ELSE
+         \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\"
+-!!ENDIF
+       AND EXISTS
+-!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+-!!ELSE
+         \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+-!!ENDIF
+         _populate_$${CMAKE_MODULE_NAME}_target_properties(RELEASE \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+ !!ENDIF // CMAKE_STATIC_WINDOWS_BUILD
+     endif()
+@@ -354,11 +286,7 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+     macro(_populate_$${CMAKE_MODULE_NAME}_plugin_properties Plugin Configuration PLUGIN_LOCATION)
+         set_property(TARGET Qt5::${Plugin} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
+ 
+-!!IF isEmpty(CMAKE_PLUGIN_DIR_IS_ABSOLUTE)
+-        set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_PLUGIN_DIR}${PLUGIN_LOCATION}\")
+-!!ELSE
+         set(imported_location \"$${CMAKE_PLUGIN_DIR}${PLUGIN_LOCATION}\")
+-!!ENDIF
+         _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_location})
+         set_target_properties(Qt5::${Plugin} PROPERTIES
+             \"IMPORTED_LOCATION_${Configuration}\" ${imported_location}
+diff --git a/mkspecs/features/mac/default_post.prf b/mkspecs/features/mac/default_post.prf
+index 395ac34001..a0e5c68b7e 100644
+--- a/mkspecs/features/mac/default_post.prf
++++ b/mkspecs/features/mac/default_post.prf
+@@ -24,165 +24,3 @@ qt {
+         }
+     }
+ }
+-
+-# Add the same default rpaths as Xcode does for new projects.
+-# This is especially important for iOS/tvOS/watchOS where no other option is possible.
+-!no_default_rpath {
+-    QMAKE_RPATHDIR += @executable_path/Frameworks
+-    equals(TEMPLATE, lib):!plugin:lib_bundle: QMAKE_RPATHDIR += @loader_path/Frameworks
+-}
+-
+-# Don't pass -headerpad_max_install_names when using Bitcode.
+-# In that case the linker emits a warning stating that the flag is ignored when
+-# used with bitcode, for reasons that cannot be determined (rdar://problem/20748962).
+-# Using this flag is also unnecessary in practice on UIKit platforms since they
+-# are sandboxed, and only UIKit platforms support bitcode to begin with.
+-!bitcode: QMAKE_LFLAGS += $$QMAKE_LFLAGS_HEADERPAD
+-
+-app_extension_api_only {
+-    QMAKE_CFLAGS              += $$QMAKE_CFLAGS_APPLICATION_EXTENSION
+-    QMAKE_CXXFLAGS            += $$QMAKE_CFLAGS_APPLICATION_EXTENSION
+-    QMAKE_CXXFLAGS_PRECOMPILE += $$QMAKE_CFLAGS_APPLICATION_EXTENSION
+-    QMAKE_LFLAGS              += $$QMAKE_CFLAGS_APPLICATION_EXTENSION
+-}
+-
+-macx-xcode {
+-    !isEmpty(QMAKE_XCODE_DEBUG_INFORMATION_FORMAT) {
+-        debug_information_format.name = DEBUG_INFORMATION_FORMAT
+-        debug_information_format.value = $$QMAKE_XCODE_DEBUG_INFORMATION_FORMAT
+-        debug_information_format.build = debug
+-        QMAKE_MAC_XCODE_SETTINGS += debug_information_format
+-    }
+-
+-    QMAKE_XCODE_ARCHS =
+-
+-    arch_device.name = "ARCHS[sdk=$${device.sdk}*]"
+-    arch_device.value = $$QMAKE_APPLE_DEVICE_ARCHS
+-    QMAKE_XCODE_ARCHS += $$QMAKE_APPLE_DEVICE_ARCHS
+-    QMAKE_MAC_XCODE_SETTINGS += arch_device
+-
+-    simulator {
+-        arch_simulator.name = "ARCHS[sdk=$${simulator.sdk}*]"
+-        arch_simulator.value = $$QMAKE_APPLE_SIMULATOR_ARCHS
+-        QMAKE_XCODE_ARCHS += $$QMAKE_APPLE_SIMULATOR_ARCHS
+-        QMAKE_MAC_XCODE_SETTINGS += arch_simulator
+-    }
+-
+-    only_active_arch.name = ONLY_ACTIVE_ARCH
+-    only_active_arch.value = YES
+-    only_active_arch.build = debug
+-    QMAKE_MAC_XCODE_SETTINGS += only_active_arch
+-} else {
+-    device|!simulator: VALID_DEVICE_ARCHS = $$QMAKE_APPLE_DEVICE_ARCHS
+-    simulator: VALID_SIMULATOR_ARCHS = $$QMAKE_APPLE_SIMULATOR_ARCHS
+-    VALID_ARCHS = $$VALID_DEVICE_ARCHS $$VALID_SIMULATOR_ARCHS
+-
+-    isEmpty(VALID_ARCHS): \
+-        error("QMAKE_APPLE_DEVICE_ARCHS or QMAKE_APPLE_SIMULATOR_ARCHS must contain at least one architecture")
+-
+-    single_arch: VALID_ARCHS = $$first(VALID_ARCHS)
+-
+-    ACTIVE_ARCHS = $(filter $(EXPORT_VALID_ARCHS), $(ARCHS))
+-    ARCH_ARGS = $(foreach arch, $(if $(EXPORT_ACTIVE_ARCHS), $(EXPORT_ACTIVE_ARCHS), $(EXPORT_VALID_ARCHS)), -arch $(arch))
+-
+-    QMAKE_EXTRA_VARIABLES += VALID_ARCHS ACTIVE_ARCHS ARCH_ARGS
+-
+-    arch_flags = $(EXPORT_ARCH_ARGS)
+-
+-    QMAKE_CFLAGS += $$arch_flags
+-    QMAKE_CXXFLAGS += $$arch_flags
+-    QMAKE_LFLAGS += $$arch_flags
+-
+-    QMAKE_PCH_ARCHS = $$VALID_ARCHS
+-
+-    macos: deployment_target = $$QMAKE_MACOSX_DEPLOYMENT_TARGET
+-    ios: deployment_target = $$QMAKE_IOS_DEPLOYMENT_TARGET
+-    tvos: deployment_target = $$QMAKE_TVOS_DEPLOYMENT_TARGET
+-    watchos: deployment_target = $$QMAKE_WATCHOS_DEPLOYMENT_TARGET
+-
+-    # If we're doing a simulator and device build, device and simulator
+-    # architectures use different paths and flags for the sysroot and
+-    # deployment target switch, so we must multiplex them across multiple
+-    # architectures using -Xarch. Otherwise we fall back to the simple path.
+-    # This is not strictly necessary, but results in cleaner command lines
+-    # and makes it easier for people to override EXPORT_VALID_ARCHS to limit
+-    # individual rules to a different set of architecture(s) from the overall
+-    # build (such as machtest in QtCore).
+-    simulator:device {
+-        QMAKE_XARCH_CFLAGS =
+-        QMAKE_XARCH_LFLAGS =
+-        QMAKE_EXTRA_VARIABLES += QMAKE_XARCH_CFLAGS QMAKE_XARCH_LFLAGS
+-
+-        for (arch, VALID_ARCHS) {
+-            contains(VALID_SIMULATOR_ARCHS, $$arch) {
+-                sdk = $$simulator.sdk
+-                version_identifier = $$simulator.deployment_identifier
+-            } else {
+-                sdk = $$device.sdk
+-                version_identifier = $$device.deployment_identifier
+-            }
+-
+-            version_min_flags = \
+-                -Xarch_$${arch} \
+-                -m$${version_identifier}-version-min=$$deployment_target
+-            QMAKE_XARCH_CFLAGS_$${arch} = $$version_min_flags \
+-                -Xarch_$${arch} \
+-                -isysroot$$xcodeSDKInfo(Path, $$sdk)
+-            QMAKE_XARCH_LFLAGS_$${arch} = $$version_min_flags \
+-                -Xarch_$${arch} \
+-                -Wl,-syslibroot,$$xcodeSDKInfo(Path, $$sdk)
+-
+-            QMAKE_XARCH_CFLAGS += $(EXPORT_QMAKE_XARCH_CFLAGS_$${arch})
+-            QMAKE_XARCH_LFLAGS += $(EXPORT_QMAKE_XARCH_LFLAGS_$${arch})
+-
+-            QMAKE_EXTRA_VARIABLES += \
+-                QMAKE_XARCH_CFLAGS_$${arch} \
+-                QMAKE_XARCH_LFLAGS_$${arch}
+-        }
+-
+-        QMAKE_CFLAGS += $(EXPORT_QMAKE_XARCH_CFLAGS)
+-        QMAKE_CXXFLAGS += $(EXPORT_QMAKE_XARCH_CFLAGS)
+-        QMAKE_LFLAGS += $(EXPORT_QMAKE_XARCH_LFLAGS)
+-    } else {
+-        simulator: \
+-            version_identifier = $$simulator.deployment_identifier
+-        else: \
+-            version_identifier = $$device.deployment_identifier
+-        version_min_flag = -m$${version_identifier}-version-min=$$deployment_target
+-        QMAKE_CFLAGS += -isysroot $$QMAKE_MAC_SDK_PATH $$version_min_flag
+-        QMAKE_CXXFLAGS += -isysroot $$QMAKE_MAC_SDK_PATH $$version_min_flag
+-        QMAKE_LFLAGS += -Wl,-syslibroot,$$QMAKE_MAC_SDK_PATH $$version_min_flag
+-    }
+-
+-    # Enable precompiled headers for multiple architectures
+-    QMAKE_CFLAGS_USE_PRECOMPILE =
+-    for (arch, VALID_ARCHS) {
+-        icc_pch_style: \
+-            use_flag = "-pch-use "
+-        else: \
+-            use_flag = -include
+-
+-        # Only use Xarch with multi-arch, as the option confuses ccache
+-        count(VALID_ARCHS, 1, greaterThan): \
+-            QMAKE_CFLAGS_USE_PRECOMPILE += \
+-                -Xarch_$${arch}
+-
+-        QMAKE_CFLAGS_USE_PRECOMPILE += \
+-            $${use_flag}${QMAKE_PCH_OUTPUT_$${arch}}
+-    }
+-    icc_pch_style {
+-        QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE -include ${QMAKE_PCH_INPUT}
+-        QMAKE_CFLAGS_USE_PRECOMPILE =
+-    } else {
+-        QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
+-        QMAKE_OBJCFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
+-        QMAKE_OBJCXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
+-    }
+-
+-    QMAKE_PCH_OUTPUT_EXT = _${QMAKE_PCH_ARCH}$${QMAKE_PCH_OUTPUT_EXT}
+-}
+-
+-cache(QMAKE_XCODE_DEVELOPER_PATH, stash)
+-cache(QMAKE_XCODE_VERSION, stash)
+-
+-QMAKE_XCODE_LIBRARY_SUFFIX = $$qtPlatformTargetSuffix()
+diff --git a/mkspecs/features/mac/default_pre.prf b/mkspecs/features/mac/default_pre.prf
+index e21e749ee9..3b01424e67 100644
+--- a/mkspecs/features/mac/default_pre.prf
++++ b/mkspecs/features/mac/default_pre.prf
+@@ -1,51 +1,2 @@
+ CONFIG = asset_catalogs rez $$CONFIG
+ load(default_pre)
+-
+-isEmpty(QMAKE_XCODE_DEVELOPER_PATH) {
+-    # Get path of Xcode's Developer directory
+-    QMAKE_XCODE_DEVELOPER_PATH = $$system("/usr/bin/xcode-select --print-path 2>/dev/null")
+-    isEmpty(QMAKE_XCODE_DEVELOPER_PATH): \
+-        error("Xcode path is not set. Please use xcode-select to choose Xcode installation path.")
+-
+-    # Make sure Xcode path is valid
+-    !exists($$QMAKE_XCODE_DEVELOPER_PATH): \
+-        error("Xcode is not installed in $${QMAKE_XCODE_DEVELOPER_PATH}. Please use xcode-select to choose Xcode installation path.")
+-
+-    # Make sure Xcode is set up properly
+-    isEmpty($$list($$system("/usr/bin/xcrun -find xcodebuild 2>/dev/null"))): \
+-        error("Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.")
+-}
+-
+-isEmpty(QMAKE_XCODE_VERSION) {
+-    # Extract Xcode version using xcodebuild
+-    xcode_version = $$system("/usr/bin/xcodebuild -version")
+-    QMAKE_XCODE_VERSION = $$member(xcode_version, 1)
+-    isEmpty(QMAKE_XCODE_VERSION): error("Could not resolve Xcode version.")
+-    unset(xcode_version)
+-}
+-
+-isEmpty(QMAKE_TARGET_BUNDLE_PREFIX) {
+-    QMAKE_XCODE_PREFERENCES_FILE = $$(HOME)/Library/Preferences/com.apple.dt.Xcode.plist
+-    exists($$QMAKE_XCODE_PREFERENCES_FILE): \
+-        QMAKE_TARGET_BUNDLE_PREFIX = $$system("/usr/libexec/PlistBuddy -c 'print IDETemplateOptions:bundleIdentifierPrefix' $$QMAKE_XCODE_PREFERENCES_FILE 2>/dev/null")
+-
+-    !isEmpty(_QMAKE_CACHE_):!isEmpty(QMAKE_TARGET_BUNDLE_PREFIX): \
+-        cache(QMAKE_TARGET_BUNDLE_PREFIX)
+-}
+-
+-QMAKE_ASSET_CATALOGS_APP_ICON = AppIcon
+-
+-# Make the default debug info format for static debug builds
+-# DWARF instead of DWARF with dSYM. This cuts down build times
+-# for application debug builds significantly, as Xcode doesn't
+-# have to pull out all the DWARF info from the Qt static libs
+-# and put it into a dSYM file. We don't need that dSYM file in
+-# the first place, since the information is available in the
+-# object files inside the archives (static libraries).
+-macx-xcode:qtConfig(static): \
+-    QMAKE_XCODE_DEBUG_INFORMATION_FORMAT = dwarf
+-
+-# This variable is used by the xcode_dynamic_library_suffix
+-# feature, which allows Xcode to choose the Qt libraries to link to
+-# at build time, depending on the current Xcode SDK and configuration.
+-QMAKE_XCODE_LIBRARY_SUFFIX_SETTING = QT_LIBRARY_SUFFIX
+diff --git a/mkspecs/features/mac/sdk.prf b/mkspecs/features/mac/sdk.prf
+index 68ab7e4053..e69de29bb2 100644
+--- a/mkspecs/features/mac/sdk.prf
++++ b/mkspecs/features/mac/sdk.prf
+@@ -1,49 +0,0 @@
+-
+-isEmpty(QMAKE_MAC_SDK): \
+-    error("QMAKE_MAC_SDK must be set when using CONFIG += sdk.")
+-
+-contains(QMAKE_MAC_SDK, .*/.*): \
+-    error("QMAKE_MAC_SDK can only contain short-form SDK names (eg. macosx, iphoneos)")
+-
+-defineReplace(xcodeSDKInfo) {
+-    info = $$1
+-    sdk = $$2
+-    isEmpty(sdk): \
+-        sdk = $$QMAKE_MAC_SDK
+-
+-    isEmpty(QMAKE_MAC_SDK.$${sdk}.$${info}) {
+-        QMAKE_MAC_SDK.$${sdk}.$${info} = $$system("/usr/bin/xcodebuild -sdk $$sdk -version $$info 2>/dev/null")
+-        isEmpty(QMAKE_MAC_SDK.$${sdk}.$${info}): error("Could not resolve SDK $$info for \'$$sdk\'")
+-        cache(QMAKE_MAC_SDK.$${sdk}.$${info}, set stash, QMAKE_MAC_SDK.$${sdk}.$${info})
+-    }
+-
+-    return($$eval(QMAKE_MAC_SDK.$${sdk}.$${info}))
+-}
+-
+-QMAKE_MAC_SDK_PATH = $$xcodeSDKInfo(Path)
+-QMAKE_MAC_SDK_PLATFORM_PATH = $$xcodeSDKInfo(PlatformPath)
+-QMAKE_MAC_SDK_VERSION = $$xcodeSDKInfo(SDKVersion)
+-
+-sysrootified =
+-for(val, QMAKE_INCDIR_OPENGL): sysrootified += $${QMAKE_MAC_SDK_PATH}$$val
+-QMAKE_INCDIR_OPENGL = $$sysrootified
+-
+-QMAKESPEC_NAME = $$basename(QMAKESPEC)
+-
+-# Resolve SDK version of various tools
+-for(tool, $$list(QMAKE_CC QMAKE_CXX QMAKE_FIX_RPATH QMAKE_AR QMAKE_RANLIB QMAKE_LINK QMAKE_LINK_SHLIB QMAKE_ACTOOL)) {
+-    tool_variable = QMAKE_MAC_SDK.$${QMAKESPEC_NAME}.$${QMAKE_MAC_SDK}.$${tool}
+-    !isEmpty($$tool_variable) {
+-        $$tool = $$eval($$tool_variable)
+-        next()
+-    }
+-
+-    value = $$eval($$tool)
+-    isEmpty(value): next()
+-
+-    sysrooted = $$system("/usr/bin/xcrun -sdk $$QMAKE_MAC_SDK -find $$first(value) 2>/dev/null")
+-    isEmpty(sysrooted): next()
+-
+-    $$tool = $$sysrooted $$member(value, 1, -1)
+-    cache($$tool_variable, set stash, $$tool)
+-}
+diff --git a/mkspecs/features/qml_module.prf b/mkspecs/features/qml_module.prf
+index 4db0040dc5..65d6da1f4d 100644
+--- a/mkspecs/features/qml_module.prf
++++ b/mkspecs/features/qml_module.prf
+@@ -23,13 +23,8 @@ for(qmlf, AUX_QML_FILES): fq_aux_qml_files += $$absolute_path($$qmlf, $$_PRO_FIL
+ 
+ load(qt_build_paths)
+ 
+-qml1_target {
+-    DESTDIR = $$MODULE_BASE_OUTDIR/imports/$$TARGETPATH
+-    instbase = $$[QT_INSTALL_IMPORTS]
+-} else {
+-    DESTDIR = $$MODULE_BASE_OUTDIR/qml/$$TARGETPATH
+-    instbase = $$[QT_INSTALL_QML]
+-}
++DESTDIR = $$MODULE_BASE_OUTDIR/qml/$$TARGETPATH
++instbase = $$NIX_OUTPUT_QML
+ 
+ !qml1_target:static: CONFIG += builtin_resources
+ 
+diff --git a/mkspecs/features/qml_plugin.prf b/mkspecs/features/qml_plugin.prf
+index d49f4c49c1..097dcd7d39 100644
+--- a/mkspecs/features/qml_plugin.prf
++++ b/mkspecs/features/qml_plugin.prf
+@@ -48,13 +48,8 @@ exists($$QMLTYPEFILE): AUX_QML_FILES += $$QMLTYPEFILE
+ 
+ load(qt_build_paths)
+ 
+-qml1_target {
+-    DESTDIR = $$MODULE_BASE_OUTDIR/imports/$$TARGETPATH
+-    instbase = $$[QT_INSTALL_IMPORTS]
+-} else {
+-    DESTDIR = $$MODULE_BASE_OUTDIR/qml/$$TARGETPATH
+-    instbase = $$[QT_INSTALL_QML]
+-}
++DESTDIR = $$MODULE_BASE_OUTDIR/qml/$$TARGETPATH
++instbase = $$NIX_OUTPUT_QML
+ 
+ target.path = $$instbase/$$TARGETPATH
+ INSTALLS += target
+diff --git a/mkspecs/features/qt_app.prf b/mkspecs/features/qt_app.prf
+index cb84ae0da8..45e16f4302 100644
+--- a/mkspecs/features/qt_app.prf
++++ b/mkspecs/features/qt_app.prf
+@@ -29,7 +29,7 @@ host_build:force_bootstrap {
+     target.path = $$[QT_HOST_BINS]
+ } else {
+     !build_pass:qtConfig(debug_and_release): CONFIG += release
+-    target.path = $$[QT_INSTALL_BINS]
++    target.path = $$NIX_OUTPUT_BIN/bin
+     CONFIG += relative_qt_rpath  # Qt's tools and apps should be relocatable
+ }
+ INSTALLS += target
+diff --git a/mkspecs/features/qt_build_paths.prf b/mkspecs/features/qt_build_paths.prf
+index 1848f00e90..2af93675c5 100644
+--- a/mkspecs/features/qt_build_paths.prf
++++ b/mkspecs/features/qt_build_paths.prf
+@@ -23,6 +23,6 @@ exists($$MODULE_BASE_INDIR/.git): \
+ !force_independent {
+     # If the module is not built independently, everything ends up in qtbase.
+     # This is the case in non-prefix builds, except for selected modules.
+-    MODULE_BASE_OUTDIR = $$[QT_HOST_PREFIX]
+-    MODULE_QMAKE_OUTDIR = $$[QT_HOST_PREFIX]
++    MODULE_BASE_OUTDIR = $$NIX_OUTPUT_OUT
++    MODULE_QMAKE_OUTDIR = $$NIX_OUTPUT_OUT
+ }
+diff --git a/mkspecs/features/qt_common.prf b/mkspecs/features/qt_common.prf
+index 1e138730b3..b7ba74dc3f 100644
+--- a/mkspecs/features/qt_common.prf
++++ b/mkspecs/features/qt_common.prf
+@@ -32,8 +32,8 @@ contains(TEMPLATE, .*lib) {
+         qqt_libdir = \$\$\$\$[QT_HOST_LIBS]
+         qt_libdir = $$[QT_HOST_LIBS]
+     } else {
+-        qqt_libdir = \$\$\$\$[QT_INSTALL_LIBS]
+-        qt_libdir = $$[QT_INSTALL_LIBS]
++        qqt_libdir = \$\$\$\$NIX_OUTPUT_OUT/lib
++        qt_libdir = $$NIX_OUTPUT_OUT/lib
+     }
+     contains(QMAKE_DEFAULT_LIBDIRS, $$qt_libdir) {
+         lib_replace.match = "[^ ']*$$rplbase/lib"
+diff --git a/mkspecs/features/qt_docs.prf b/mkspecs/features/qt_docs.prf
+index 72dde61a40..f891a2baed 100644
+--- a/mkspecs/features/qt_docs.prf
++++ b/mkspecs/features/qt_docs.prf
+@@ -45,7 +45,7 @@ QMAKE_DOCS_OUTPUTDIR = $$QMAKE_DOCS_BASE_OUTDIR/$$QMAKE_DOCS_TARGETDIR
+ 
+ QDOC += -outputdir $$shell_quote($$QMAKE_DOCS_OUTPUTDIR)
+ !build_online_docs: \
+-    QDOC += -installdir $$shell_quote($$[QT_INSTALL_DOCS])
++    QDOC += -installdir $$shell_quote($$NIX_OUTPUT_DOC)
+ PREP_DOC_INDEXES =
+ DOC_INDEXES =
+ !isEmpty(QTREPOS) {
+@@ -64,8 +64,8 @@ DOC_INDEXES =
+         DOC_INDEXES += -indexdir $$shell_quote($$qrep/doc)
+ } else {
+     prepare_docs: \
+-        PREP_DOC_INDEXES += -indexdir $$shell_quote($$[QT_INSTALL_DOCS/get])
+-    DOC_INDEXES += -indexdir $$shell_quote($$[QT_INSTALL_DOCS/get])
++        PREP_DOC_INDEXES += -indexdir $$shell_quote($$NIX_OUTPUT_DOC)
++    DOC_INDEXES += -indexdir $$shell_quote($$NIX_OUTPUT_DOC)
+ }
+ 
+ qtattributionsscanner.target = qtattributionsscanner
+@@ -88,12 +88,12 @@ prepare_docs {
+     qch_docs.commands = $$QHELPGENERATOR $$shell_quote($$QMAKE_DOCS_OUTPUTDIR/$${QMAKE_DOCS_TARGET}.qhp) -o $$shell_quote($$QMAKE_DOCS_BASE_OUTDIR/$${QMAKE_DOCS_TARGET}.qch)
+ 
+     inst_html_docs.files = $$QMAKE_DOCS_OUTPUTDIR
+-    inst_html_docs.path = $$[QT_INSTALL_DOCS]
++    inst_html_docs.path = $$NIX_OUTPUT_DOC
+     inst_html_docs.CONFIG += no_check_exist directory no_default_install no_build
+     INSTALLS += inst_html_docs
+ 
+     inst_qch_docs.files = $$QMAKE_DOCS_BASE_OUTDIR/$${QMAKE_DOCS_TARGET}.qch
+-    inst_qch_docs.path = $$[QT_INSTALL_DOCS]
++    inst_qch_docs.path = $$NIX_OUTPUT_DOC
+     inst_qch_docs.CONFIG += no_check_exist no_default_install no_build
+     INSTALLS += inst_qch_docs
+ 
+diff --git a/mkspecs/features/qt_example_installs.prf b/mkspecs/features/qt_example_installs.prf
+index 0a008374e5..5e7cd92f6f 100644
+--- a/mkspecs/features/qt_example_installs.prf
++++ b/mkspecs/features/qt_example_installs.prf
+@@ -73,7 +73,7 @@ probase = $$relative_path($$_PRO_FILE_PWD_, $$dirname(_QMAKE_CONF_)/examples)
+         $$SOURCES $$HEADERS $$FORMS $$RESOURCES $$TRANSLATIONS \
+         $$DBUS_ADAPTORS $$DBUS_INTERFACES
+     addInstallFiles(sources.files, $$sourcefiles)
+-    sources.path = $$[QT_INSTALL_EXAMPLES]/$$probase
++    sources.path = $$NIX_OUTPUT_DEV/share/examples/$$probase
+     INSTALLS += sources
+ 
+     check_examples {
+diff --git a/mkspecs/features/qt_functions.prf b/mkspecs/features/qt_functions.prf
+index c00fdb73f8..6d8ba132cb 100644
+--- a/mkspecs/features/qt_functions.prf
++++ b/mkspecs/features/qt_functions.prf
+@@ -69,7 +69,7 @@ defineTest(qtHaveModule) {
+ defineTest(qtPrepareTool) {
+     cmd = $$eval(QT_TOOL.$${2}.binary)
+     isEmpty(cmd) {
+-        cmd = $$[QT_HOST_BINS]/$$2
++        cmd = $$system("type -p $$2")
+         exists($${cmd}.pl) {
+             $${1}_EXE = $${cmd}.pl
+             cmd = perl -w $$system_path($${cmd}.pl)
+diff --git a/mkspecs/features/qt_installs.prf b/mkspecs/features/qt_installs.prf
+index 0d3dfb6b93..5f935b4424 100644
+--- a/mkspecs/features/qt_installs.prf
++++ b/mkspecs/features/qt_installs.prf
+@@ -12,16 +12,10 @@
+ #library
+ !qt_no_install_library {
+     win32 {
+-       host_build: \
+-           dlltarget.path = $$[QT_HOST_BINS]
+-       else: \
+-           dlltarget.path = $$[QT_INSTALL_BINS]
++        dlltarget.path = $$NIX_OUTPUT_BIN/bin
+        INSTALLS += dlltarget
+     }
+-    host_build: \
+-        target.path = $$[QT_HOST_LIBS]
+-    else: \
+-        target.path = $$[QT_INSTALL_LIBS]
++    target.path = $$NIX_OUTPUT_OUT/lib
+     !static: target.CONFIG = no_dll
+     INSTALLS += target
+ }
+@@ -29,33 +23,33 @@
+ #headers
+ qt_install_headers {
+     class_headers.files = $$SYNCQT.HEADER_CLASSES
+-    class_headers.path = $$[QT_INSTALL_HEADERS]/$$MODULE_INCNAME
++    class_headers.path = $$NIX_OUTPUT_DEV/include/$$MODULE_INCNAME
+     INSTALLS += class_headers
+ 
+     targ_headers.files = $$SYNCQT.HEADER_FILES
+-    targ_headers.path = $$[QT_INSTALL_HEADERS]/$$MODULE_INCNAME
++    targ_headers.path = $$NIX_OUTPUT_DEV/include/$$MODULE_INCNAME
+     INSTALLS += targ_headers
+ 
+     private_headers.files = $$SYNCQT.PRIVATE_HEADER_FILES $$SYNCQT.INJECTED_PRIVATE_HEADER_FILES
+-    private_headers.path = $$[QT_INSTALL_HEADERS]/$$MODULE_INCNAME/$$VERSION/$$MODULE_INCNAME/private
++    private_headers.path = $$NIX_OUTPUT_DEV/include/$$MODULE_INCNAME/$$VERSION/$$MODULE_INCNAME/private
+     INSTALLS += private_headers
+ 
+     qpa_headers.files = $$SYNCQT.QPA_HEADER_FILES
+-    qpa_headers.path = $$[QT_INSTALL_HEADERS]/$$MODULE_INCNAME/$$VERSION/$$MODULE_INCNAME/qpa
++    qpa_headers.path = $$NIX_OUTPUT_DEV/include/$$MODULE_INCNAME/$$VERSION/$$MODULE_INCNAME/qpa
+     INSTALLS += qpa_headers
+ }
+ 
+ #module
+ qt_install_module {
+     !isEmpty(MODULE_PRI) {
+-        pritarget.path = $$[QT_HOST_DATA]/mkspecs/modules
++        pritarget.path = $$NIX_OUTPUT_DEV/mkspecs/modules
+         pritarget.files = $$MODULE_PRI
+         INSTALLS += pritarget
+     } else: isEmpty(MODULE_PRIVATE_PRI) {
+         warning("Project $$basename(_PRO_FILE_) is a module, but has not defined MODULE_PRI, which is required for Qt to expose the module to other projects.")
+     }
+     !isEmpty(MODULE_PRIVATE_PRI) {
+-        privpritarget.path = $$[QT_HOST_DATA]/mkspecs/modules
++        privpritarget.path = $$NIX_OUTPUT_DEV/mkspecs/modules
+         privpritarget.files = $$MODULE_PRIVATE_PRI
+         INSTALLS += privpritarget
+     }
+diff --git a/mkspecs/features/qt_plugin.prf b/mkspecs/features/qt_plugin.prf
+index 62e1b69fde..abd63123f9 100644
+--- a/mkspecs/features/qt_plugin.prf
++++ b/mkspecs/features/qt_plugin.prf
+@@ -88,7 +88,7 @@ CONFIG(static, static|shared)|prefix_build {
+     }
+ }
+ 
+-target.path = $$[QT_INSTALL_PLUGINS]/$$PLUGIN_TYPE
++target.path = $$NIX_OUTPUT_PLUGIN/$$PLUGIN_TYPE
+ INSTALLS += target
+ 
+ TARGET = $$qt5LibraryTarget($$TARGET)
+diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in
+index 545b9a3d1e..6ac0cdefe4 100644
+--- a/src/corelib/Qt5CoreConfigExtras.cmake.in
++++ b/src/corelib/Qt5CoreConfigExtras.cmake.in
+@@ -3,7 +3,7 @@ if (NOT TARGET Qt5::qmake)
+     add_executable(Qt5::qmake IMPORTED)
+ 
+ !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\")
+ !!ENDIF
+@@ -18,7 +18,7 @@ if (NOT TARGET Qt5::moc)
+     add_executable(Qt5::moc IMPORTED)
+ 
+ !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\")
+ !!ENDIF
+@@ -35,7 +35,7 @@ if (NOT TARGET Qt5::rcc)
+     add_executable(Qt5::rcc IMPORTED)
+ 
+ !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\")
+ !!ENDIF
+@@ -133,7 +133,7 @@ if (NOT TARGET Qt5::WinMain)
+ !!IF !isEmpty(CMAKE_RELEASE_TYPE)
+     set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+ !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\")
+ !!ENDIF
+@@ -147,7 +147,7 @@ if (NOT TARGET Qt5::WinMain)
+     set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+ 
+ !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}\")
+ !!ENDIF
+diff --git a/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in b/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in
+index c357237d0e..6f0c75de3c 100644
+--- a/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in
++++ b/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in
+@@ -1,6 +1,6 @@
+ 
+ !!IF isEmpty(CMAKE_HOST_DATA_DIR_IS_ABSOLUTE)
+-set(_qt5_corelib_extra_includes \"${_qt5Core_install_prefix}/$${CMAKE_HOST_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
++set(_qt5_corelib_extra_includes \"$$NIX_OUTPUT_DEV/$${CMAKE_HOST_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
+ !!ELSE
+ set(_qt5_corelib_extra_includes \"$${CMAKE_HOST_DATA_DIR}mkspecs/$${CMAKE_MKSPEC}\")
+ !!ENDIF
+diff --git a/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in b/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in
+index 706304cf34..546420f6ad 100644
+--- a/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in
++++ b/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in
+@@ -1,6 +1,6 @@
+ 
+ !!IF isEmpty(CMAKE_INSTALL_DATA_DIR_IS_ABSOLUTE)
+-set(_qt5_corelib_extra_includes \"${_qt5Core_install_prefix}/$${CMAKE_INSTALL_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
++set(_qt5_corelib_extra_includes \"$$NIX_OUTPUT_DEV/$${CMAKE_INSTALL_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
+ !!ELSE
+ set(_qt5_corelib_extra_includes \"$${CMAKE_INSTALL_DATA_DIR}mkspecs/$${CMAKE_MKSPEC}\")
+ !!ENDIF
+diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
+index 39e7c71a9c..dced1f2811 100644
+--- a/src/corelib/kernel/qcoreapplication.cpp
++++ b/src/corelib/kernel/qcoreapplication.cpp
+@@ -2533,6 +2533,15 @@ QStringList QCoreApplication::libraryPaths()
+         QStringList *app_libpaths = new QStringList;
+         coreappdata()->app_libpaths.reset(app_libpaths);
+ 
++        // Add library paths derived from PATH
++        const QStringList paths = QFile::decodeName(qgetenv("PATH")).split(':');
++        const QString plugindir = QStringLiteral("../" NIXPKGS_QT_PLUGIN_PREFIX);
++        for (const QString &path: paths) {
++            if (!path.isEmpty()) {
++                app_libpaths->append(QDir::cleanPath(path + QDir::separator() + plugindir));
++            }
++        }
++
+         const QByteArray libPathEnv = qgetenv("QT_PLUGIN_PATH");
+         if (!libPathEnv.isEmpty()) {
+             QStringList paths = QFile::decodeName(libPathEnv).split(QDir::listSeparator(), QString::SkipEmptyParts);
+diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp
+index 1714c9802f..fd2ebb1336 100644
+--- a/src/corelib/tools/qtimezoneprivate_tz.cpp
++++ b/src/corelib/tools/qtimezoneprivate_tz.cpp
+@@ -70,7 +70,11 @@ typedef QHash<QByteArray, QTzTimeZone> QTzTimeZoneHash;
+ // Parse zone.tab table, assume lists all installed zones, if not will need to read directories
+ static QTzTimeZoneHash loadTzTimeZones()
+ {
+-    QString path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
++    // Try TZDIR first, in case we're running on NixOS.
++    QString path = QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/zone.tab");
++    // Fallback to traditional paths in case we are not on NixOS.
++    if (!QFile::exists(path))
++        path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
+     if (!QFile::exists(path))
+         path = QStringLiteral("/usr/lib/zoneinfo/zone.tab");
+ 
+@@ -643,12 +647,16 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId)
+         if (!tzif.open(QIODevice::ReadOnly))
+             return;
+     } else {
+-        // Open named tz, try modern path first, if fails try legacy path
+-        tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
++        // Try TZDIR first, in case we're running on NixOS
++        tzif.setFileName(QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/") + QString::fromLocal8Bit(ianaId));
+         if (!tzif.open(QIODevice::ReadOnly)) {
+-            tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
+-            if (!tzif.open(QIODevice::ReadOnly))
+-                return;
++            // Open named tz, try modern path first, if fails try legacy path
++            tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
++            if (!tzif.open(QIODevice::ReadOnly)) {
++                tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
++                if (!tzif.open(QIODevice::ReadOnly))
++                    return;
++            }
+         }
+     }
+ 
+diff --git a/src/dbus/Qt5DBusConfigExtras.cmake.in b/src/dbus/Qt5DBusConfigExtras.cmake.in
+index 1d947159e2..b36865fc48 100644
+--- a/src/dbus/Qt5DBusConfigExtras.cmake.in
++++ b/src/dbus/Qt5DBusConfigExtras.cmake.in
+@@ -2,11 +2,7 @@
+ if (NOT TARGET Qt5::qdbuscpp2xml)
+     add_executable(Qt5::qdbuscpp2xml IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5DBus_install_prefix}/$${CMAKE_BIN_DIR}qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+-    set(imported_location \"$${CMAKE_BIN_DIR}qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
++    set(imported_location \"$$NIX_OUTPUT_DEV/bin/qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
+     _qt5_DBus_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::qdbuscpp2xml PROPERTIES
+@@ -17,11 +13,7 @@ endif()
+ if (NOT TARGET Qt5::qdbusxml2cpp)
+     add_executable(Qt5::qdbusxml2cpp IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5DBus_install_prefix}/$${CMAKE_BIN_DIR}qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+-    set(imported_location \"$${CMAKE_BIN_DIR}qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
++    set(imported_location \"$$NIX_OUTPUT_DEV/bin/qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
+     _qt5_DBus_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::qdbusxml2cpp PROPERTIES
+diff --git a/src/gui/Qt5GuiConfigExtras.cmake.in b/src/gui/Qt5GuiConfigExtras.cmake.in
+index 07869efd7d..37b95d1b6b 100644
+--- a/src/gui/Qt5GuiConfigExtras.cmake.in
++++ b/src/gui/Qt5GuiConfigExtras.cmake.in
+@@ -2,7 +2,7 @@
+ !!IF !isEmpty(CMAKE_ANGLE_EGL_DLL_RELEASE)
+ 
+ !!IF isEmpty(CMAKE_INCLUDE_DIR_IS_ABSOLUTE)
+-set(Qt5Gui_EGL_INCLUDE_DIRS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$$CMAKE_INCLUDE_DIR/QtANGLE\")
++set(Qt5Gui_EGL_INCLUDE_DIRS \"$$NIX_OUTPUT_DEV/$$CMAKE_INCLUDE_DIR/QtANGLE\")
+ !!ELSE
+ set(Qt5Gui_EGL_INCLUDE_DIRS \"$$CMAKE_INCLUDE_DIR/QtANGLE\")
+ !!ENDIF
+@@ -17,13 +17,13 @@ macro(_populate_qt5gui_gl_target_properties TargetName Configuration LIB_LOCATIO
+     set_property(TARGET Qt5::${TargetName} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
+ 
+ !!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Gui_install_prefix}/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
++    set(imported_location \"$$NIX_OUTPUT_OUT/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
+ !!ENDIF
+ 
+ !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+-    set(imported_implib \"${_qt5Gui_install_prefix}/$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
++    set(imported_implib \"$$NIX_OUTPUT_DEV/$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
+ !!ELSE
+     set(imported_implib \"$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
+ !!ENDIF
+diff --git a/src/network/kernel/qdnslookup_unix.cpp b/src/network/kernel/qdnslookup_unix.cpp
+index 1da00813ce..0bf877afcb 100644
+--- a/src/network/kernel/qdnslookup_unix.cpp
++++ b/src/network/kernel/qdnslookup_unix.cpp
+@@ -92,7 +92,7 @@ static bool resolveLibraryInternal()
+     if (!lib.load())
+ #endif
+     {
+-        lib.setFileName(QLatin1String("resolv"));
++        lib.setFileName(QLatin1String(NIXPKGS_LIBRESOLV));
+         if (!lib.load())
+             return false;
+     }
+diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp
+index cf08a15f96..2310488298 100644
+--- a/src/network/kernel/qhostinfo_unix.cpp
++++ b/src/network/kernel/qhostinfo_unix.cpp
+@@ -102,7 +102,7 @@ static bool resolveLibraryInternal()
+     if (!lib.load())
+ #endif
+     {
+-        lib.setFileName(QLatin1String("resolv"));
++        lib.setFileName(QLatin1String(NIXPKGS_LIBRESOLV));
+         if (!lib.load())
+             return false;
+     }
+diff --git a/src/network/ssl/qsslcontext_openssl.cpp b/src/network/ssl/qsslcontext_openssl.cpp
+index c92d8fc3f8..6008063bcf 100644
+--- a/src/network/ssl/qsslcontext_openssl.cpp
++++ b/src/network/ssl/qsslcontext_openssl.cpp
+@@ -351,7 +351,7 @@ init_context:
+ 
+     const QVector<QSslEllipticCurve> qcurves = sslContext->sslConfiguration.ellipticCurves();
+     if (!qcurves.isEmpty()) {
+-#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_EC)
++#if OPENSSL_VERSION_NUMBER >= 0x10002000L && defined(SSL_CTRL_SET_CURVES) && !defined(OPENSSL_NO_EC)
+         // Set the curves to be used
+         if (q_SSLeay() >= 0x10002000L) {
+             // SSL_CTX_ctrl wants a non-const pointer as last argument,
+@@ -364,7 +364,7 @@ init_context:
+                 sslContext->errorCode = QSslError::UnspecifiedError;
+             }
+         } else
+-#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_EC)
++#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L && defined(SSL_CTRL_SET_CURVES) && !defined(OPENSSL_NO_EC)
+         {
+             // specific curves requested, but not possible to set -> error
+             sslContext->errorStr = msgErrorSettingEllipticCurves(QSslSocket::tr("OpenSSL version too old, need at least v1.0.2"));
+diff --git a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
+index ca9f7af127..a337ad73bf 100644
+--- a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
++++ b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
+@@ -265,12 +265,9 @@ void TableGenerator::initPossibleLocations()
+     m_possibleLocations.reserve(7);
+     if (qEnvironmentVariableIsSet("QTCOMPOSE"))
+         m_possibleLocations.append(QString::fromLocal8Bit(qgetenv("QTCOMPOSE")));
+-    m_possibleLocations.append(QStringLiteral("/usr/share/X11/locale"));
+-    m_possibleLocations.append(QStringLiteral("/usr/local/share/X11/locale"));
+-    m_possibleLocations.append(QStringLiteral("/usr/lib/X11/locale"));
+-    m_possibleLocations.append(QStringLiteral("/usr/local/lib/X11/locale"));
+     m_possibleLocations.append(QStringLiteral(X11_PREFIX "/share/X11/locale"));
+     m_possibleLocations.append(QStringLiteral(X11_PREFIX "/lib/X11/locale"));
++    m_possibleLocations.append(QLatin1String(NIXPKGS_QTCOMPOSE));
+ }
+ 
+ QString TableGenerator::findComposeFile()
+diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
+index 7640a711a9..ef9a14d38b 100644
+--- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
++++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
+@@ -580,7 +580,14 @@ QFunctionPointer QGLXContext::getProcAddress(const char *procName)
+ #if QT_CONFIG(library)
+                 extern const QString qt_gl_library_name();
+ //                QLibrary lib(qt_gl_library_name());
++                // Check system library paths first
+                 QLibrary lib(QLatin1String("GL"));
++#ifdef NIXPKGS_MESA_GL
++                if (!lib.load()) {
++                    // Fallback to Mesa driver
++                    lib.setFileName(QLatin1String(NIXPKGS_MESA_GL));
++                }
++#endif // NIXPKGS_MESA_GL
+                 glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB");
+ #endif
+             }
+diff --git a/src/plugins/platforms/xcb/qxcbcursor.cpp b/src/plugins/platforms/xcb/qxcbcursor.cpp
+index d257ab1242..75853af4e4 100644
+--- a/src/plugins/platforms/xcb/qxcbcursor.cpp
++++ b/src/plugins/platforms/xcb/qxcbcursor.cpp
+@@ -311,10 +311,10 @@ QXcbCursor::QXcbCursor(QXcbConnection *conn, QXcbScreen *screen)
+ #if defined(XCB_USE_XLIB) && QT_CONFIG(library)
+     static bool function_ptrs_not_initialized = true;
+     if (function_ptrs_not_initialized) {
+-        QLibrary xcursorLib(QLatin1String("Xcursor"), 1);
++        QLibrary xcursorLib(QLatin1String(NIXPKGS_LIBXCURSOR), 1);
+         bool xcursorFound = xcursorLib.load();
+         if (!xcursorFound) { // try without the version number
+-            xcursorLib.setFileName(QLatin1String("Xcursor"));
++            xcursorLib.setFileName(QLatin1String(NIXPKGS_LIBXCURSOR));
+             xcursorFound = xcursorLib.load();
+         }
+         if (xcursorFound) {
+diff --git a/src/plugins/platformthemes/gtk3/main.cpp b/src/plugins/platformthemes/gtk3/main.cpp
+index c4cd66c33b..b6f2691587 100644
+--- a/src/plugins/platformthemes/gtk3/main.cpp
++++ b/src/plugins/platformthemes/gtk3/main.cpp
+@@ -39,6 +39,7 @@
+ 
+ #include <qpa/qplatformthemeplugin.h>
+ #include "qgtk3theme.h"
++#include <QFile>
+ 
+ QT_BEGIN_NAMESPACE
+ 
+@@ -54,8 +55,22 @@ public:
+ QPlatformTheme *QGtk3ThemePlugin::create(const QString &key, const QStringList &params)
+ {
+     Q_UNUSED(params);
+-    if (!key.compare(QLatin1String(QGtk3Theme::name), Qt::CaseInsensitive))
++    if (!key.compare(QLatin1String(QGtk3Theme::name), Qt::CaseInsensitive)) {
++
++#ifdef NIXPKGS_QGTK3_XDG_DATA_DIRS
++        QStringList XDG_DATA_DIRS = QFile::decodeName(qgetenv("XDG_DATA_DIRS")).split(':');
++        XDG_DATA_DIRS << QLatin1String(NIXPKGS_QGTK3_XDG_DATA_DIRS);
++        qputenv("XDG_DATA_DIRS", QFile::encodeName(XDG_DATA_DIRS.join(':')));
++#endif
++
++#ifdef NIXPKGS_QGTK3_GIO_EXTRA_MODULES
++        QStringList GIO_EXTRA_MODULES = QFile::decodeName(qgetenv("GIO_EXTRA_MODULES")).split(':');
++        GIO_EXTRA_MODULES << QLatin1String(NIXPKGS_QGTK3_GIO_EXTRA_MODULES);
++        qputenv("GIO_EXTRA_MODULES", QFile::encodeName(GIO_EXTRA_MODULES.join(':')));
++#endif
++
+         return new QGtk3Theme;
++    }
+ 
+     return 0;
+ }
+diff --git a/src/widgets/Qt5WidgetsConfigExtras.cmake.in b/src/widgets/Qt5WidgetsConfigExtras.cmake.in
+index 99d87e2e46..a4eab2aa72 100644
+--- a/src/widgets/Qt5WidgetsConfigExtras.cmake.in
++++ b/src/widgets/Qt5WidgetsConfigExtras.cmake.in
+@@ -3,7 +3,7 @@ if (NOT TARGET Qt5::uic)
+     add_executable(Qt5::uic IMPORTED)
+ 
+ !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Widgets_install_prefix}/$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\")
++    set(imported_location \"$$NIX_OUTPUT_DEV/$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\")
+ !!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\")
+ !!ENDIF
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/cmake-paths.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/cmake-paths.patch
deleted file mode 100644
index 9616f5812cf..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/cmake-paths.patch
+++ /dev/null
@@ -1,359 +0,0 @@
-Index: qtbase-opensource-src-5.9.0/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
-+++ qtbase-opensource-src-5.9.0/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
-@@ -9,30 +9,6 @@ if (CMAKE_VERSION VERSION_LESS 3.0.0)
- endif()
- !!ENDIF
- 
--!!IF !isEmpty(CMAKE_USR_MOVE_WORKAROUND)
--!!IF !isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
--set(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$[QT_INSTALL_PREFIX]\")
--!!ELSE
--get_filename_component(_IMPORT_PREFIX \"${CMAKE_CURRENT_LIST_FILE}\" PATH)
--# Use original install prefix when loaded through a
--# cross-prefix symbolic link such as /lib -> /usr/lib.
--get_filename_component(_realCurr \"${_IMPORT_PREFIX}\" REALPATH)
--get_filename_component(_realOrig \"$$CMAKE_INSTALL_LIBS_DIR/cmake/Qt5$${CMAKE_MODULE_NAME}\" REALPATH)
--if(_realCurr STREQUAL _realOrig)
--    get_filename_component(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$CMAKE_INSTALL_LIBS_DIR/$${CMAKE_RELATIVE_INSTALL_LIBS_DIR}\" ABSOLUTE)
--else()
--    get_filename_component(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_RELATIVE_INSTALL_DIR}\" ABSOLUTE)
--endif()
--unset(_realOrig)
--unset(_realCurr)
--unset(_IMPORT_PREFIX)
--!!ENDIF
--!!ELIF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
--get_filename_component(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_RELATIVE_INSTALL_DIR}\" ABSOLUTE)
--!!ELSE
--set(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$[QT_INSTALL_PREFIX]\")
--!!ENDIF
--
- !!IF !equals(TEMPLATE, aux)
- # For backwards compatibility only. Use Qt5$${CMAKE_MODULE_NAME}_VERSION instead.
- set(Qt5$${CMAKE_MODULE_NAME}_VERSION_STRING "$$eval(QT.$${MODULE}.MAJOR_VERSION).$$eval(QT.$${MODULE}.MINOR_VERSION).$$eval(QT.$${MODULE}.PATCH_VERSION)")
-@@ -59,7 +35,10 @@ macro(_populate_$${CMAKE_MODULE_NAME}_ta
-     set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
- 
- !!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
-+    set(imported_location \"@NIX_OUT@/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
-+    if(NOT EXISTS \"${imported_location}\")
-+        set(imported_location \"@NIX_DEV@/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
-+    endif()
- !!ELSE
-     set(imported_location \"$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
- !!ENDIF
-@@ -74,19 +53,6 @@ macro(_populate_$${CMAKE_MODULE_NAME}_ta
-         \"IMPORTED_LINK_INTERFACE_LIBRARIES_${Configuration}\" \"${_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES}\"
-     )
- 
--!!IF !isEmpty(CMAKE_WINDOWS_BUILD)
--!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
--    set(imported_implib \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
--!!ELSE
--    set(imported_implib \"IMPORTED_IMPLIB_${Configuration}\" \"$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
--!!ENDIF
--    _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_implib})
--    if(NOT \"${IMPLIB_LOCATION}\" STREQUAL \"\")
--        set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
--        \"IMPORTED_IMPLIB_${Configuration}\" ${imported_implib}
--        )
--    endif()
--!!ENDIF
- endmacro()
- !!ENDIF
- 
-@@ -95,24 +61,24 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME
- !!IF !no_module_headers
- !!IF !isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
-     set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS
--      \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework\"
--      \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Headers\"
-+      \"@NIX_OUT@/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework\"
-+      \"@NIX_OUT@/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Headers\"
-     )
- !!IF isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
-     set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
--        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/\"
--        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/$${MODULE_INCNAME}\"
-+        \"@NIX_OUT@/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/\"
-+        \"@NIX_OUT@/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/$${MODULE_INCNAME}\"
-     )
- !!ELSE
-     set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
- !!ENDIF
- !!ELSE
- !!IF isEmpty(CMAKE_INCLUDE_DIR_IS_ABSOLUTE)
--    set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$$CMAKE_INCLUDE_DIR\" \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}\")
-+    set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS \"@NIX_DEV@/$$CMAKE_INCLUDE_DIR\" \"@NIX_DEV@/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}\")
- !!IF isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
-     set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
--        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION\"
--        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION/$${MODULE_INCNAME}\"
-+        \"@NIX_DEV@/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION\"
-+        \"@NIX_DEV@/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION/$${MODULE_INCNAME}\"
-     )
- !!ELSE
-     set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
-@@ -281,7 +247,7 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME
- !!IF isEmpty(CMAKE_DEBUG_TYPE)
- !!IF !isEmpty(CMAKE_STATIC_WINDOWS_BUILD)
- !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
--    if (EXISTS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
-+    if (EXISTS \"@NIX_OUT@/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
- !!ELSE // CMAKE_LIB_DIR_IS_ABSOLUTE
-     if (EXISTS \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
- !!ENDIF // CMAKE_LIB_DIR_IS_ABSOLUTE
-@@ -289,13 +255,13 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME
- !!ELSE // CMAKE_STATIC_WINDOWS_BUILD
-     if (EXISTS
- !!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
--        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}$${CMAKE_LIB_FILE_LOCATION_DEBUG}\"
-+        \"@NIX_OUT@/$${CMAKE_DLL_DIR}$${CMAKE_LIB_FILE_LOCATION_DEBUG}\"
- !!ELSE
-         \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\"
- !!ENDIF
-       AND EXISTS
- !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
--        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
-+        \"@NIX_DEV@/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
- !!ELSE
-         \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
- !!ENDIF
-@@ -318,7 +284,7 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME
- !!IF isEmpty(CMAKE_RELEASE_TYPE)
- !!IF !isEmpty(CMAKE_STATIC_WINDOWS_BUILD)
- !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
--    if (EXISTS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
-+    if (EXISTS \"@NIX_DEV@/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
- !!ELSE // CMAKE_LIB_DIR_IS_ABSOLUTE
-     if (EXISTS \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
- !!ENDIF // CMAKE_LIB_DIR_IS_ABSOLUTE
-@@ -326,13 +292,13 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME
- !!ELSE // CMAKE_STATIC_WINDOWS_BUILD
-     if (EXISTS
- !!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
--        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}$${CMAKE_LIB_FILE_LOCATION_RELEASE}\"
-+        \"@NIX_OUT@/$${CMAKE_DLL_DIR}$${CMAKE_LIB_FILE_LOCATION_RELEASE}\"
- !!ELSE
-         \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\"
- !!ENDIF
-       AND EXISTS
- !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
--        \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
-+        \"@NIX_DEV@/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
- !!ELSE
-         \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
- !!ENDIF
-@@ -354,11 +320,7 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME
-     macro(_populate_$${CMAKE_MODULE_NAME}_plugin_properties Plugin Configuration PLUGIN_LOCATION)
-         set_property(TARGET Qt5::${Plugin} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
- 
--!!IF isEmpty(CMAKE_PLUGIN_DIR_IS_ABSOLUTE)
--        set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_PLUGIN_DIR}${PLUGIN_LOCATION}\")
--!!ELSE
--        set(imported_location \"$${CMAKE_PLUGIN_DIR}${PLUGIN_LOCATION}\")
--!!ENDIF
-+        set(imported_location \"${PLUGIN_LOCATION}\")
-         _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_location})
-         set_target_properties(Qt5::${Plugin} PROPERTIES
-             \"IMPORTED_LOCATION_${Configuration}\" ${imported_location}
-Index: qtbase-opensource-src-5.9.0/src/gui/Qt5GuiConfigExtras.cmake.in
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/gui/Qt5GuiConfigExtras.cmake.in
-+++ qtbase-opensource-src-5.9.0/src/gui/Qt5GuiConfigExtras.cmake.in
-@@ -2,7 +2,7 @@
- !!IF !isEmpty(CMAKE_ANGLE_EGL_DLL_RELEASE)
- 
- !!IF isEmpty(CMAKE_INCLUDE_DIR_IS_ABSOLUTE)
--set(Qt5Gui_EGL_INCLUDE_DIRS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$$CMAKE_INCLUDE_DIR/QtANGLE\")
-+set(Qt5Gui_EGL_INCLUDE_DIRS \"@NIX_DEV@/$$CMAKE_INCLUDE_DIR/QtANGLE\")
- !!ELSE
- set(Qt5Gui_EGL_INCLUDE_DIRS \"$$CMAKE_INCLUDE_DIR/QtANGLE\")
- !!ENDIF
-@@ -17,13 +17,13 @@ macro(_populate_qt5gui_gl_target_propert
-     set_property(TARGET Qt5::${TargetName} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
- 
- !!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5Gui_install_prefix}/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
-+    set(imported_location \"@NIX_OUT@/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
- !!ELSE
-     set(imported_location \"$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
- !!ENDIF
- 
- !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
--    set(imported_implib \"${_qt5Gui_install_prefix}/$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
-+    set(imported_implib \"@NIX_DEV@/$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
- !!ELSE
-     set(imported_implib \"$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
- !!ENDIF
-Index: qtbase-opensource-src-5.9.0/src/widgets/Qt5WidgetsConfigExtras.cmake.in
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/widgets/Qt5WidgetsConfigExtras.cmake.in
-+++ qtbase-opensource-src-5.9.0/src/widgets/Qt5WidgetsConfigExtras.cmake.in
-@@ -3,7 +3,7 @@ if (NOT TARGET Qt5::uic)
-     add_executable(Qt5::uic IMPORTED)
- 
- !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5Widgets_install_prefix}/$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\")
-+    set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\")
- !!ELSE
-     set(imported_location \"$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\")
- !!ENDIF
-Index: qtbase-opensource-src-5.9.0/src/corelib/Qt5CoreConfigExtras.cmake.in
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/corelib/Qt5CoreConfigExtras.cmake.in
-+++ qtbase-opensource-src-5.9.0/src/corelib/Qt5CoreConfigExtras.cmake.in
-@@ -3,7 +3,7 @@ if (NOT TARGET Qt5::qmake)
-     add_executable(Qt5::qmake IMPORTED)
- 
- !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\")
-+    set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\")
- !!ELSE
-     set(imported_location \"$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\")
- !!ENDIF
-@@ -18,7 +18,7 @@ if (NOT TARGET Qt5::moc)
-     add_executable(Qt5::moc IMPORTED)
- 
- !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\")
-+    set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\")
- !!ELSE
-     set(imported_location \"$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\")
- !!ENDIF
-@@ -35,7 +35,7 @@ if (NOT TARGET Qt5::rcc)
-     add_executable(Qt5::rcc IMPORTED)
- 
- !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\")
-+    set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\")
- !!ELSE
-     set(imported_location \"$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\")
- !!ENDIF
-@@ -133,7 +133,7 @@ if (NOT TARGET Qt5::WinMain)
- !!IF !isEmpty(CMAKE_RELEASE_TYPE)
-     set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
- !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\")
-+    set(imported_location \"@NIX_DEV@/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\")
- !!ELSE
-     set(imported_location \"$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\")
- !!ENDIF
-@@ -147,7 +147,7 @@ if (NOT TARGET Qt5::WinMain)
-     set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
- 
- !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5Core_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}\")
-+    set(imported_location \"@NIX_DEV@/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}\")
- !!ELSE
-     set(imported_location \"$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}\")
- !!ENDIF
-Index: qtbase-opensource-src-5.9.0/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in
-+++ qtbase-opensource-src-5.9.0/src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in
-@@ -1,6 +1,6 @@
- 
- !!IF isEmpty(CMAKE_INSTALL_DATA_DIR_IS_ABSOLUTE)
--set(_qt5_corelib_extra_includes \"${_qt5Core_install_prefix}/$${CMAKE_INSTALL_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
-+set(_qt5_corelib_extra_includes \"@NIX_DEV@/$${CMAKE_INSTALL_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
- !!ELSE
- set(_qt5_corelib_extra_includes \"$${CMAKE_INSTALL_DATA_DIR}mkspecs/$${CMAKE_MKSPEC}\")
- !!ENDIF
-Index: qtbase-opensource-src-5.9.0/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in
-+++ qtbase-opensource-src-5.9.0/src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in
-@@ -1,6 +1,6 @@
- 
- !!IF isEmpty(CMAKE_HOST_DATA_DIR_IS_ABSOLUTE)
--set(_qt5_corelib_extra_includes \"${_qt5Core_install_prefix}/$${CMAKE_HOST_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
-+set(_qt5_corelib_extra_includes \"@NIX_DEV@/$${CMAKE_HOST_DATA_DIR}/mkspecs/$${CMAKE_MKSPEC}\")
- !!ELSE
- set(_qt5_corelib_extra_includes \"$${CMAKE_HOST_DATA_DIR}mkspecs/$${CMAKE_MKSPEC}\")
- !!ENDIF
-Index: qtbase-opensource-src-5.9.0/src/dbus/Qt5DBusConfigExtras.cmake.in
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/dbus/Qt5DBusConfigExtras.cmake.in
-+++ qtbase-opensource-src-5.9.0/src/dbus/Qt5DBusConfigExtras.cmake.in
-@@ -3,7 +3,7 @@ if (NOT TARGET Qt5::qdbuscpp2xml)
-     add_executable(Qt5::qdbuscpp2xml IMPORTED)
- 
- !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5DBus_install_prefix}/$${CMAKE_BIN_DIR}qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
-+    set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
- !!ELSE
-     set(imported_location \"$${CMAKE_BIN_DIR}qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
- !!ENDIF
-@@ -18,7 +18,7 @@ if (NOT TARGET Qt5::qdbusxml2cpp)
-     add_executable(Qt5::qdbusxml2cpp IMPORTED)
- 
- !!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5DBus_install_prefix}/$${CMAKE_BIN_DIR}qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
-+    set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
- !!ELSE
-     set(imported_location \"$${CMAKE_BIN_DIR}qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
- !!ENDIF
-Index: qtbase-opensource-src-5.9.0/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
-+++ qtbase-opensource-src-5.9.0/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
-@@ -2,10 +2,10 @@
- add_library(Qt5::$$CMAKE_PLUGIN_NAME MODULE IMPORTED)
- 
- !!IF !isEmpty(CMAKE_RELEASE_TYPE)
--_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME RELEASE \"$${CMAKE_PLUGIN_LOCATION_RELEASE}\")
-+_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME RELEASE \"@NIX_BIN@/$${CMAKE_PLUGIN_LOCATION_RELEASE}\")
- !!ENDIF
- !!IF !isEmpty(CMAKE_DEBUG_TYPE)
--_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME DEBUG \"$${CMAKE_PLUGIN_LOCATION_DEBUG}\")
-+_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME DEBUG \"@NIX_BIN@/$${CMAKE_PLUGIN_LOCATION_DEBUG}\")
- !!ENDIF
- 
- list(APPEND Qt5$${CMAKE_MODULE_NAME}_PLUGINS Qt5::$$CMAKE_PLUGIN_NAME)
-Index: qtbase-opensource-src-5.9.0/mkspecs/features/create_cmake.prf
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/mkspecs/features/create_cmake.prf
-+++ qtbase-opensource-src-5.9.0/mkspecs/features/create_cmake.prf
-@@ -136,28 +136,28 @@ contains(CONFIG, plugin) {
- 
-     win32 {
-         isEmpty(CMAKE_STATIC_TYPE) {
--            CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/$${TARGET}.dll
--            CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/$${TARGET}d.dll
-+            CMAKE_PLUGIN_LOCATION_RELEASE = $${CMAKE_PLUGIN_DIR}$$PLUGIN_TYPE/$${TARGET}.dll
-+            CMAKE_PLUGIN_LOCATION_DEBUG = $${CMAKE_PLUGIN_DIR}$$PLUGIN_TYPE/$${TARGET}d.dll
-         } else:mingw {
--            CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/lib$${TARGET}.a
--            CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/lib$${TARGET}d.a
-+            CMAKE_PLUGIN_LOCATION_RELEASE = $${CMAKE_PLUGIN_DIR}$$PLUGIN_TYPE/lib$${TARGET}.a
-+            CMAKE_PLUGIN_LOCATION_DEBUG = $${CMAKE_PLUGIN_DIR}$$PLUGIN_TYPE/lib$${TARGET}d.a
-         } else {                         # MSVC static
--            CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/$${TARGET}.lib
--            CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/$${TARGET}d.lib
-+            CMAKE_PLUGIN_LOCATION_RELEASE = $${CMAKE_PLUGIN_DIR}$$PLUGIN_TYPE/$${TARGET}.lib
-+            CMAKE_PLUGIN_LOCATION_DEBUG = $${CMAKE_PLUGIN_DIR}$$PLUGIN_TYPE/$${TARGET}d.lib
-         }
-     } else {
-         mac {
-             isEmpty(CMAKE_STATIC_TYPE): CMAKE_PlUGIN_EXT = .dylib
-             else: CMAKE_PlUGIN_EXT = .a
- 
--            CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/lib$${TARGET}$${CMAKE_PlUGIN_EXT}
--            CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/lib$${TARGET}$${CMAKE_PlUGIN_EXT}
-+            CMAKE_PLUGIN_LOCATION_RELEASE = $${CMAKE_PLUGIN_DIR}$$PLUGIN_TYPE/lib$${TARGET}$${CMAKE_PlUGIN_EXT}
-+            CMAKE_PLUGIN_LOCATION_DEBUG = $${CMAKE_PLUGIN_DIR}$$PLUGIN_TYPE/lib$${TARGET}$${CMAKE_PlUGIN_EXT}
-         } else {
-             isEmpty(CMAKE_STATIC_TYPE): CMAKE_PlUGIN_EXT = .so
-             else: CMAKE_PlUGIN_EXT = .a
- 
--            CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/lib$${TARGET}$${CMAKE_PlUGIN_EXT}
--            CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/lib$${TARGET}$${CMAKE_PlUGIN_EXT}
-+            CMAKE_PLUGIN_LOCATION_RELEASE = $${CMAKE_PLUGIN_DIR}$$PLUGIN_TYPE/lib$${TARGET}$${CMAKE_PlUGIN_EXT}
-+            CMAKE_PLUGIN_LOCATION_DEBUG = $${CMAKE_PLUGIN_DIR}$$PLUGIN_TYPE/lib$${TARGET}$${CMAKE_PlUGIN_EXT}
-         }
-     }
-     cmake_target_file.input = $$PWD/data/cmake/Qt5PluginTarget.cmake.in
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/compose-search-path.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/compose-search-path.patch
deleted file mode 100644
index 720e7d81fa2..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/compose-search-path.patch
+++ /dev/null
@@ -1,18 +0,0 @@
-Index: qtbase-opensource-src-5.9.0/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
-+++ qtbase-opensource-src-5.9.0/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
-@@ -265,12 +265,9 @@ void TableGenerator::initPossibleLocatio
-     m_possibleLocations.reserve(7);
-     if (qEnvironmentVariableIsSet("QTCOMPOSE"))
-         m_possibleLocations.append(QString::fromLocal8Bit(qgetenv("QTCOMPOSE")));
--    m_possibleLocations.append(QStringLiteral("/usr/share/X11/locale"));
--    m_possibleLocations.append(QStringLiteral("/usr/local/share/X11/locale"));
--    m_possibleLocations.append(QStringLiteral("/usr/lib/X11/locale"));
--    m_possibleLocations.append(QStringLiteral("/usr/local/lib/X11/locale"));
-     m_possibleLocations.append(QStringLiteral(X11_PREFIX "/share/X11/locale"));
-     m_possibleLocations.append(QStringLiteral(X11_PREFIX "/lib/X11/locale"));
-+    m_possibleLocations.append(QLatin1String(NIXPKGS_QTCOMPOSE));
- }
- 
- QString TableGenerator::findComposeFile()
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/darwin-cf.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/darwin-cf.patch
deleted file mode 100644
index 3e6e0e5101a..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/darwin-cf.patch
+++ /dev/null
@@ -1,36 +0,0 @@
-diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm
-index 341d3bc..3368234 100644
---- a/src/plugins/bearer/corewlan/qcorewlanengine.mm
-+++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm
-@@ -287,7 +287,7 @@ void QScanThread::getUserConfigurations()
-     QMacAutoReleasePool pool;
-     userProfiles.clear();
- 
--    NSArray<NSString *> *wifiInterfaces = [CWWiFiClient interfaceNames];
-+    NSArray *wifiInterfaces = [CWWiFiClient interfaceNames];
-     for (NSString *ifName in wifiInterfaces) {
- 
-         CWInterface *wifiInterface = [[CWWiFiClient sharedWiFiClient] interfaceWithName:ifName];
-@@ -602,7 +602,7 @@ void QCoreWlanEngine::doRequestUpdate()
- 
-     QMacAutoReleasePool pool;
- 
--    NSArray<NSString *> *wifiInterfaces = [CWWiFiClient interfaceNames];
-+    NSArray *wifiInterfaces = [CWWiFiClient interfaceNames];
-     for (NSString *ifName in wifiInterfaces) {
-             scanThread->interfaceName = QString::fromNSString(ifName);
-             scanThread->start();
- QString TableGenerator::findComposeFile()
-diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
-index 59b7637..b91139d 100644
---- a/src/plugins/platforms/cocoa/qcocoawindow.mm
-+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
-@@ -320,7 +320,7 @@ static void qt_closePopups()
- + (void)applicationActivationChanged:(NSNotification*)notification
- {
-     const id sender = self;
--    NSEnumerator<NSWindow*> *windowEnumerator = nullptr;
-+    NSEnumerator *windowEnumerator = nullptr;
-     NSApplication *application = [NSApplication sharedApplication];
- 
- #if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_12)
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/darwin-series b/pkgs/development/libraries/qt-5/5.9/qtbase/darwin-series
deleted file mode 100644
index 1111ff65f44..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/darwin-series
+++ /dev/null
@@ -1,3 +0,0 @@
-mkspecs-common-mac.patch
-mkspecs-features-mac.patch
-darwin-cf.patch
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-gl.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-gl.patch
deleted file mode 100644
index 9385c7f6678..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-gl.patch
+++ /dev/null
@@ -1,19 +0,0 @@
-Index: qtbase-opensource-src-5.9.0/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
-+++ qtbase-opensource-src-5.9.0/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
-@@ -580,7 +580,14 @@ QFunctionPointer QGLXContext::getProcAdd
- #if QT_CONFIG(library)
-                 extern const QString qt_gl_library_name();
- //                QLibrary lib(qt_gl_library_name());
-+                // Check system library paths first
-                 QLibrary lib(QLatin1String("GL"));
-+#ifdef NIXPKGS_MESA_GL
-+                if (!lib.load()) {
-+                    // Fallback to Mesa driver
-+                    lib.setFileName(QLatin1String(NIXPKGS_MESA_GL));
-+                }
-+#endif // NIXPKGS_MESA_GL
-                 glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB");
- #endif
-             }
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-gtkstyle.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-gtkstyle.patch
deleted file mode 100644
index 755b0965cf5..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-gtkstyle.patch
+++ /dev/null
@@ -1,50 +0,0 @@
-Index: qtbase-opensource-src-5.5.1/src/widgets/styles/qgtk2painter.cpp
-===================================================================
---- qtbase-opensource-src-5.5.1.orig/src/widgets/styles/qgtk2painter.cpp
-+++ qtbase-opensource-src-5.5.1/src/widgets/styles/qgtk2painter.cpp
-@@ -96,7 +96,7 @@ static void initGtk()
-     static bool initialized = false;
-     if (!initialized) {
-         // enforce the "0" suffix, so we'll open libgtk-x11-2.0.so.0
--        QLibrary libgtk(QLS("gtk-x11-2.0"), 0, 0);
-+        QLibrary libgtk(QLS("@gtk@/lib/libgtk-x11-2.0"), 0, 0);
- 
-         QGtk2PainterPrivate::gdk_pixmap_new = (Ptr_gdk_pixmap_new)libgtk.resolve("gdk_pixmap_new");
-         QGtk2PainterPrivate::gdk_pixbuf_get_from_drawable = (Ptr_gdk_pixbuf_get_from_drawable)libgtk.resolve("gdk_pixbuf_get_from_drawable");
-Index: qtbase-opensource-src-5.5.1/src/widgets/styles/qgtkstyle_p.cpp
-===================================================================
---- qtbase-opensource-src-5.5.1.orig/src/widgets/styles/qgtkstyle_p.cpp
-+++ qtbase-opensource-src-5.5.1/src/widgets/styles/qgtkstyle_p.cpp
-@@ -327,7 +327,7 @@ void QGtkStylePrivate::gtkWidgetSetFocus
- void QGtkStylePrivate::resolveGtk() const
- {
-     // enforce the "0" suffix, so we'll open libgtk-x11-2.0.so.0
--    QLibrary libgtk(QLS("gtk-x11-2.0"), 0, 0);
-+    QLibrary libgtk(QLS("@gtk@/lib/libgtk-x11-2.0"), 0, 0);
- 
-     gtk_init = (Ptr_gtk_init)libgtk.resolve("gtk_init");
-     gtk_window_new = (Ptr_gtk_window_new)libgtk.resolve("gtk_window_new");
-@@ -425,8 +425,8 @@ void QGtkStylePrivate::resolveGtk() cons
-     pango_font_description_get_family = (Ptr_pango_font_description_get_family)libgtk.resolve("pango_font_description_get_family");
-     pango_font_description_get_style = (Ptr_pango_font_description_get_style)libgtk.resolve("pango_font_description_get_style");
- 
--    gnome_icon_lookup_sync = (Ptr_gnome_icon_lookup_sync)QLibrary::resolve(QLS("gnomeui-2"), 0, "gnome_icon_lookup_sync");
--    gnome_vfs_init= (Ptr_gnome_vfs_init)QLibrary::resolve(QLS("gnomevfs-2"), 0, "gnome_vfs_init");
-+    gnome_icon_lookup_sync = (Ptr_gnome_icon_lookup_sync)QLibrary::resolve(QLS("@libgnomeui@/lib/libgnomeui-2"), 0, "gnome_icon_lookup_sync");
-+    gnome_vfs_init= (Ptr_gnome_vfs_init)QLibrary::resolve(QLS("@gnome_vfs@/lib/libgnomevfs-2"), 0, "gnome_vfs_init");
- }
- 
- /* \internal
-@@ -594,9 +594,9 @@ void QGtkStylePrivate::cleanupGtkWidgets
- static bool resolveGConf()
- {
-     if (!QGtkStylePrivate::gconf_client_get_default) {
--        QGtkStylePrivate::gconf_client_get_default = (Ptr_gconf_client_get_default)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_default");
--        QGtkStylePrivate::gconf_client_get_string =  (Ptr_gconf_client_get_string)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_string");
--        QGtkStylePrivate::gconf_client_get_bool =  (Ptr_gconf_client_get_bool)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_bool");
-+        QGtkStylePrivate::gconf_client_get_default = (Ptr_gconf_client_get_default)QLibrary::resolve(QLS("@gconf@/lib/libgconf-2"), 4, "gconf_client_get_default");
-+        QGtkStylePrivate::gconf_client_get_string =  (Ptr_gconf_client_get_string)QLibrary::resolve(QLS("@gconf@/lib/libgconf-2"), 4, "gconf_client_get_string");
-+        QGtkStylePrivate::gconf_client_get_bool =  (Ptr_gconf_client_get_bool)QLibrary::resolve(QLS("@gconf@/lib/libgconf-2"), 4, "gconf_client_get_bool");
-     }
-     return (QGtkStylePrivate::gconf_client_get_default !=0);
- }
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-libXcursor.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-libXcursor.patch
deleted file mode 100644
index 31339abc785..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-libXcursor.patch
+++ /dev/null
@@ -1,17 +0,0 @@
-Index: qtbase-opensource-src-5.9.0/src/plugins/platforms/xcb/qxcbcursor.cpp
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/plugins/platforms/xcb/qxcbcursor.cpp
-+++ qtbase-opensource-src-5.9.0/src/plugins/platforms/xcb/qxcbcursor.cpp
-@@ -311,10 +311,10 @@ QXcbCursor::QXcbCursor(QXcbConnection *c
- #if defined(XCB_USE_XLIB) && QT_CONFIG(library)
-     static bool function_ptrs_not_initialized = true;
-     if (function_ptrs_not_initialized) {
--        QLibrary xcursorLib(QLatin1String("Xcursor"), 1);
-+        QLibrary xcursorLib(QLatin1String(NIXPKGS_LIBXCURSOR), 1);
-         bool xcursorFound = xcursorLib.load();
-         if (!xcursorFound) { // try without the version number
--            xcursorLib.setFileName(QLatin1String("Xcursor"));
-+            xcursorLib.setFileName(QLatin1String(NIXPKGS_LIBXCURSOR));
-             xcursorFound = xcursorLib.load();
-         }
-         if (xcursorFound) {
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-resolv.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-resolv.patch
deleted file mode 100644
index 598456a49ff..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/dlopen-resolv.patch
+++ /dev/null
@@ -1,26 +0,0 @@
-Index: qtbase-opensource-src-5.9.0/src/network/kernel/qdnslookup_unix.cpp
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/network/kernel/qdnslookup_unix.cpp
-+++ qtbase-opensource-src-5.9.0/src/network/kernel/qdnslookup_unix.cpp
-@@ -92,7 +92,7 @@ static bool resolveLibraryInternal()
-     if (!lib.load())
- #endif
-     {
--        lib.setFileName(QLatin1String("resolv"));
-+        lib.setFileName(QLatin1String(NIXPKGS_LIBRESOLV));
-         if (!lib.load())
-             return false;
-     }
-Index: qtbase-opensource-src-5.9.0/src/network/kernel/qhostinfo_unix.cpp
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/network/kernel/qhostinfo_unix.cpp
-+++ qtbase-opensource-src-5.9.0/src/network/kernel/qhostinfo_unix.cpp
-@@ -102,7 +102,7 @@ static bool resolveLibraryInternal()
-     if (!lib.load())
- #endif
-     {
--        lib.setFileName(QLatin1String("resolv"));
-+        lib.setFileName(QLatin1String(NIXPKGS_LIBRESOLV));
-         if (!lib.load())
-             return false;
-     }
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/library-paths.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/library-paths.patch
deleted file mode 100644
index 4c24d73ed36..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/library-paths.patch
+++ /dev/null
@@ -1,20 +0,0 @@
-Index: qtbase-opensource-src-5.9.0/src/corelib/kernel/qcoreapplication.cpp
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/corelib/kernel/qcoreapplication.cpp
-+++ qtbase-opensource-src-5.9.0/src/corelib/kernel/qcoreapplication.cpp
-@@ -2533,6 +2533,15 @@ QStringList QCoreApplication::libraryPat
-         QStringList *app_libpaths = new QStringList;
-         coreappdata()->app_libpaths.reset(app_libpaths);
- 
-+        // Add library paths derived from PATH
-+        const QStringList paths = QFile::decodeName(qgetenv("PATH")).split(':');
-+        const QString plugindir = QStringLiteral("../" NIXPKGS_QT_PLUGIN_PREFIX);
-+        for (const QString &path: paths) {
-+            if (!path.isEmpty()) {
-+                app_libpaths->append(QDir::cleanPath(path + QDir::separator() + plugindir));
-+            }
-+        }
-+
-         const QByteArray libPathEnv = qgetenv("QT_PLUGIN_PATH");
-         if (!libPathEnv.isEmpty()) {
-             QStringList paths = QFile::decodeName(libPathEnv).split(QDir::listSeparator(), QString::SkipEmptyParts);
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/libressl.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/libressl.patch
deleted file mode 100644
index e9c60e7ab07..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/libressl.patch
+++ /dev/null
@@ -1,33 +0,0 @@
-From 81494e67eccba04fc3fe554d76a9ca6fe7f2250e Mon Sep 17 00:00:00 2001
-From: hasufell <hasufell@gentoo.org>
-Date: Sat, 10 Oct 2015 01:15:01 +0200
-Subject: [PATCH] Fix compilation with libressl
-
-By additionally checking for defined(SSL_CTRL_SET_CURVES), which
-is defined in openssl, but not in libressl.
----
- src/network/ssl/qsslcontext_openssl.cpp | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-Index: qtbase-opensource-src-5.8.0/src/network/ssl/qsslcontext_openssl.cpp
-===================================================================
---- qtbase-opensource-src-5.8.0.orig/src/network/ssl/qsslcontext_openssl.cpp
-+++ qtbase-opensource-src-5.8.0/src/network/ssl/qsslcontext_openssl.cpp
-@@ -351,7 +351,7 @@ init_context:
- 
-     const QVector<QSslEllipticCurve> qcurves = sslContext->sslConfiguration.ellipticCurves();
-     if (!qcurves.isEmpty()) {
--#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_EC)
-+#if OPENSSL_VERSION_NUMBER >= 0x10002000L && defined(SSL_CTRL_SET_CURVES) && !defined(OPENSSL_NO_EC)
-         // Set the curves to be used
-         if (q_SSLeay() >= 0x10002000L) {
-             // SSL_CTX_ctrl wants a non-const pointer as last argument,
-@@ -364,7 +364,7 @@ init_context:
-                 sslContext->errorCode = QSslError::UnspecifiedError;
-             }
-         } else
--#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_EC)
-+#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L && defined(SSL_CTRL_SET_CURVES) && !defined(OPENSSL_NO_EC)
-         {
-             // specific curves requested, but not possible to set -> error
-             sslContext->errorStr = msgErrorSettingEllipticCurves(QSslSocket::tr("OpenSSL version too old, need at least v1.0.2"));
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/mkspecs-common-mac.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/mkspecs-common-mac.patch
deleted file mode 100644
index b77f8778122..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/mkspecs-common-mac.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- qtbase-opensource-src-5.9.1.orig/mkspecs/common/mac.conf	2017-09-16 16:40:30.000000000 +0800
-+++ qtbase-opensource-src-5.9.1/mkspecs/common/mac.conf	2017-09-16 16:41:27.000000000 +0800
-@@ -23,7 +23,7 @@
- 
- QMAKE_FIX_RPATH         = install_name_tool -id
- 
--QMAKE_LFLAGS_RPATH      = -Wl,-rpath,
-+QMAKE_LFLAGS_RPATH      =
- QMAKE_LFLAGS_GCSECTIONS = -Wl,-dead_strip
- 
- QMAKE_LFLAGS_REL_RPATH  =
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/mkspecs-features-mac.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/mkspecs-features-mac.patch
deleted file mode 100644
index 46d950a767b..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/mkspecs-features-mac.patch
+++ /dev/null
@@ -1,292 +0,0 @@
-diff -u -r qtbase-opensource-src-5.9.2.orig/mkspecs/features/mac/default_post.prf qtbase-opensource-src-5.9.2/mkspecs/features/mac/default_post.prf
---- qtbase-opensource-src-5.9.2.orig/mkspecs/features/mac/default_post.prf	2017-10-14 12:31:04.000000000 +0800
-+++ qtbase-opensource-src-5.9.2/mkspecs/features/mac/default_post.prf	2017-10-14 12:42:02.000000000 +0800
-@@ -24,166 +24,3 @@
-         }
-     }
- }
--
--# Add the same default rpaths as Xcode does for new projects.
--# This is especially important for iOS/tvOS/watchOS where no other option is possible.
--!no_default_rpath {
--    QMAKE_RPATHDIR += @executable_path/Frameworks
--    equals(TEMPLATE, lib):!plugin:lib_bundle: QMAKE_RPATHDIR += @loader_path/Frameworks
--}
--
--# Don't pass -headerpad_max_install_names when using Bitcode.
--# In that case the linker emits a warning stating that the flag is ignored when
--# used with bitcode, for reasons that cannot be determined (rdar://problem/20748962).
--# Using this flag is also unnecessary in practice on UIKit platforms since they
--# are sandboxed, and only UIKit platforms support bitcode to begin with.
--!bitcode: QMAKE_LFLAGS += $$QMAKE_LFLAGS_HEADERPAD
--
--app_extension_api_only {
--    QMAKE_CFLAGS              += $$QMAKE_CFLAGS_APPLICATION_EXTENSION
--    QMAKE_CXXFLAGS            += $$QMAKE_CFLAGS_APPLICATION_EXTENSION
--    QMAKE_CXXFLAGS_PRECOMPILE += $$QMAKE_CFLAGS_APPLICATION_EXTENSION
--    QMAKE_LFLAGS              += $$QMAKE_CFLAGS_APPLICATION_EXTENSION
--}
--
--macx-xcode {
--    !isEmpty(QMAKE_XCODE_DEBUG_INFORMATION_FORMAT) {
--        debug_information_format.name = DEBUG_INFORMATION_FORMAT
--        debug_information_format.value = $$QMAKE_XCODE_DEBUG_INFORMATION_FORMAT
--        debug_information_format.build = debug
--        QMAKE_MAC_XCODE_SETTINGS += debug_information_format
--    }
--
--    QMAKE_XCODE_ARCHS =
--
--    arch_device.name = "ARCHS[sdk=$${device.sdk}*]"
--    arch_device.value = $$QMAKE_APPLE_DEVICE_ARCHS
--    QMAKE_XCODE_ARCHS += $$QMAKE_APPLE_DEVICE_ARCHS
--    QMAKE_MAC_XCODE_SETTINGS += arch_device
--
--    simulator {
--        arch_simulator.name = "ARCHS[sdk=$${simulator.sdk}*]"
--        arch_simulator.value = $$QMAKE_APPLE_SIMULATOR_ARCHS
--        QMAKE_XCODE_ARCHS += $$QMAKE_APPLE_SIMULATOR_ARCHS
--        QMAKE_MAC_XCODE_SETTINGS += arch_simulator
--    }
--
--    only_active_arch.name = ONLY_ACTIVE_ARCH
--    only_active_arch.value = YES
--    only_active_arch.build = debug
--    QMAKE_MAC_XCODE_SETTINGS += only_active_arch
--} else {
--    device|!simulator: VALID_DEVICE_ARCHS = $$QMAKE_APPLE_DEVICE_ARCHS
--    simulator: VALID_SIMULATOR_ARCHS = $$QMAKE_APPLE_SIMULATOR_ARCHS
--    VALID_ARCHS = $$VALID_DEVICE_ARCHS $$VALID_SIMULATOR_ARCHS
--
--    isEmpty(VALID_ARCHS): \
--        error("QMAKE_APPLE_DEVICE_ARCHS or QMAKE_APPLE_SIMULATOR_ARCHS must contain at least one architecture")
--
--    single_arch: VALID_ARCHS = $$first(VALID_ARCHS)
--
--    ACTIVE_ARCHS = $(filter $(EXPORT_VALID_ARCHS), $(ARCHS))
--    ARCH_ARGS = $(foreach arch, $(if $(EXPORT_ACTIVE_ARCHS), $(EXPORT_ACTIVE_ARCHS), $(EXPORT_VALID_ARCHS)), -arch $(arch))
--
--    QMAKE_EXTRA_VARIABLES += VALID_ARCHS ACTIVE_ARCHS ARCH_ARGS
--
--    arch_flags = $(EXPORT_ARCH_ARGS)
--
--    QMAKE_CFLAGS += $$arch_flags
--    QMAKE_CXXFLAGS += $$arch_flags
--    QMAKE_LFLAGS += $$arch_flags
--
--    QMAKE_PCH_ARCHS = $$VALID_ARCHS
--
--    macos: deployment_target = $$QMAKE_MACOSX_DEPLOYMENT_TARGET
--    ios: deployment_target = $$QMAKE_IOS_DEPLOYMENT_TARGET
--    tvos: deployment_target = $$QMAKE_TVOS_DEPLOYMENT_TARGET
--    watchos: deployment_target = $$QMAKE_WATCHOS_DEPLOYMENT_TARGET
--
--    # If we're doing a simulator and device build, device and simulator
--    # architectures use different paths and flags for the sysroot and
--    # deployment target switch, so we must multiplex them across multiple
--    # architectures using -Xarch. Otherwise we fall back to the simple path.
--    # This is not strictly necessary, but results in cleaner command lines
--    # and makes it easier for people to override EXPORT_VALID_ARCHS to limit
--    # individual rules to a different set of architecture(s) from the overall
--    # build (such as machtest in QtCore).
--    simulator:device {
--        QMAKE_XARCH_CFLAGS =
--        QMAKE_XARCH_LFLAGS =
--        QMAKE_EXTRA_VARIABLES += QMAKE_XARCH_CFLAGS QMAKE_XARCH_LFLAGS
--
--        for (arch, VALID_ARCHS) {
--            contains(VALID_SIMULATOR_ARCHS, $$arch) {
--                sdk = $$simulator.sdk
--                version_identifier = $$simulator.deployment_identifier
--            } else {
--                sdk = $$device.sdk
--                version_identifier = $$device.deployment_identifier
--            }
--
--            version_min_flags = \
--                -Xarch_$${arch} \
--                -m$${version_identifier}-version-min=$$deployment_target
--            QMAKE_XARCH_CFLAGS_$${arch} = $$version_min_flags \
--                -Xarch_$${arch} \
--                -isysroot$$xcodeSDKInfo(Path, $$sdk)
--            QMAKE_XARCH_LFLAGS_$${arch} = $$version_min_flags \
--                -Xarch_$${arch} \
--                -Wl,-syslibroot,$$xcodeSDKInfo(Path, $$sdk)
--
--            QMAKE_XARCH_CFLAGS += $(EXPORT_QMAKE_XARCH_CFLAGS_$${arch})
--            QMAKE_XARCH_LFLAGS += $(EXPORT_QMAKE_XARCH_LFLAGS_$${arch})
--
--            QMAKE_EXTRA_VARIABLES += \
--                QMAKE_XARCH_CFLAGS_$${arch} \
--                QMAKE_XARCH_LFLAGS_$${arch}
--        }
--
--        QMAKE_CFLAGS += $(EXPORT_QMAKE_XARCH_CFLAGS)
--        QMAKE_CXXFLAGS += $(EXPORT_QMAKE_XARCH_CFLAGS)
--        QMAKE_LFLAGS += $(EXPORT_QMAKE_XARCH_LFLAGS)
--    } else {
--        simulator: \
--            version_identifier = $$simulator.deployment_identifier
--        else: \
--            version_identifier = $$device.deployment_identifier
--        version_min_flag = -m$${version_identifier}-version-min=$$deployment_target
--        QMAKE_CFLAGS += -isysroot $$QMAKE_MAC_SDK_PATH $$version_min_flag
--        QMAKE_CXXFLAGS += -isysroot $$QMAKE_MAC_SDK_PATH $$version_min_flag
--        QMAKE_LFLAGS += -Wl,-syslibroot,$$QMAKE_MAC_SDK_PATH $$version_min_flag
--    }
--
--    # Enable precompiled headers for multiple architectures
--    QMAKE_CFLAGS_USE_PRECOMPILE =
--    for (arch, VALID_ARCHS) {
--        icc_pch_style: \
--            use_flag = "-pch-use "
--        else: \
--            use_flag = -include
--
--        # Only use Xarch with multi-arch, as the option confuses ccache
--        count(VALID_ARCHS, 1, greaterThan): \
--            QMAKE_CFLAGS_USE_PRECOMPILE += \
--                -Xarch_$${arch}
--
--        QMAKE_CFLAGS_USE_PRECOMPILE += \
--            $${use_flag}${QMAKE_PCH_OUTPUT_$${arch}}
--    }
--    icc_pch_style {
--        QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE -include ${QMAKE_PCH_INPUT}
--        QMAKE_CFLAGS_USE_PRECOMPILE =
--    } else {
--        QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
--        QMAKE_OBJCFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
--        QMAKE_OBJCXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
--    }
--
--    QMAKE_PCH_OUTPUT_EXT = _${QMAKE_PCH_ARCH}$${QMAKE_PCH_OUTPUT_EXT}
--}
--
--cache(QMAKE_XCODE_DEVELOPER_PATH, stash)
--!isEmpty(QMAKE_XCODE_VERSION): \
--    cache(QMAKE_XCODE_VERSION, stash)
--
--QMAKE_XCODE_LIBRARY_SUFFIX = $$qtPlatformTargetSuffix()
-diff -u -r qtbase-opensource-src-5.9.2.orig/mkspecs/features/mac/default_pre.prf qtbase-opensource-src-5.9.2/mkspecs/features/mac/default_pre.prf
---- qtbase-opensource-src-5.9.2.orig/mkspecs/features/mac/default_pre.prf	2017-10-14 12:31:04.000000000 +0800
-+++ qtbase-opensource-src-5.9.2/mkspecs/features/mac/default_pre.prf	2017-10-14 12:42:02.000000000 +0800
-@@ -1,56 +1,2 @@
- CONFIG = asset_catalogs rez $$CONFIG
- load(default_pre)
--
--isEmpty(QMAKE_XCODE_DEVELOPER_PATH) {
--    # Get path of Xcode's Developer directory
--    QMAKE_XCODE_DEVELOPER_PATH = $$system("/usr/bin/xcode-select --print-path 2>/dev/null")
--    isEmpty(QMAKE_XCODE_DEVELOPER_PATH): \
--        error("Xcode path is not set. Please use xcode-select to choose Xcode installation path.")
--
--    # Make sure Xcode path is valid
--    !exists($$QMAKE_XCODE_DEVELOPER_PATH): \
--        error("Xcode is not installed in $${QMAKE_XCODE_DEVELOPER_PATH}. Please use xcode-select to choose Xcode installation path.")
--}
--
--isEmpty(QMAKE_XCODEBUILD_PATH): \
--    QMAKE_XCODEBUILD_PATH = $$system("/usr/bin/xcrun -find xcodebuild 2>/dev/null")
--
--!isEmpty(QMAKE_XCODEBUILD_PATH) {
--    # Make sure Xcode is set up properly
--    !system("/usr/bin/xcrun xcodebuild -license check 2>/dev/null"): \
--        error("Xcode not set up properly. You need to confirm the license agreement by running 'sudo xcrun xcodebuild -license accept'.")
--
--    isEmpty(QMAKE_XCODE_VERSION) {
--        # Extract Xcode version using xcodebuild
--        xcode_version = $$system("/usr/bin/xcrun xcodebuild -version")
--        QMAKE_XCODE_VERSION = $$member(xcode_version, 1)
--        isEmpty(QMAKE_XCODE_VERSION): error("Could not resolve Xcode version.")
--        unset(xcode_version)
--    }
--}
--
--isEmpty(QMAKE_TARGET_BUNDLE_PREFIX) {
--    QMAKE_XCODE_PREFERENCES_FILE = $$(HOME)/Library/Preferences/com.apple.dt.Xcode.plist
--    exists($$QMAKE_XCODE_PREFERENCES_FILE): \
--        QMAKE_TARGET_BUNDLE_PREFIX = $$system("/usr/libexec/PlistBuddy -c 'print IDETemplateOptions:bundleIdentifierPrefix' $$QMAKE_XCODE_PREFERENCES_FILE 2>/dev/null")
--
--    !isEmpty(_QMAKE_CACHE_):!isEmpty(QMAKE_TARGET_BUNDLE_PREFIX): \
--        cache(QMAKE_TARGET_BUNDLE_PREFIX)
--}
--
--QMAKE_ASSET_CATALOGS_APP_ICON = AppIcon
--
--# Make the default debug info format for static debug builds
--# DWARF instead of DWARF with dSYM. This cuts down build times
--# for application debug builds significantly, as Xcode doesn't
--# have to pull out all the DWARF info from the Qt static libs
--# and put it into a dSYM file. We don't need that dSYM file in
--# the first place, since the information is available in the
--# object files inside the archives (static libraries).
--macx-xcode:qtConfig(static): \
--    QMAKE_XCODE_DEBUG_INFORMATION_FORMAT = dwarf
--
--# This variable is used by the xcode_dynamic_library_suffix
--# feature, which allows Xcode to choose the Qt libraries to link to
--# at build time, depending on the current Xcode SDK and configuration.
--QMAKE_XCODE_LIBRARY_SUFFIX_SETTING = QT_LIBRARY_SUFFIX
-diff -u -r qtbase-opensource-src-5.9.2.orig/mkspecs/features/mac/sdk.prf qtbase-opensource-src-5.9.2/mkspecs/features/mac/sdk.prf
---- qtbase-opensource-src-5.9.2.orig/mkspecs/features/mac/sdk.prf	2017-10-14 12:31:04.000000000 +0800
-+++ qtbase-opensource-src-5.9.2/mkspecs/features/mac/sdk.prf	2017-10-14 12:42:10.000000000 +0800
-@@ -1,58 +0,0 @@
--
--isEmpty(QMAKE_MAC_SDK): \
--    error("QMAKE_MAC_SDK must be set when using CONFIG += sdk.")
--
--contains(QMAKE_MAC_SDK, .*/.*): \
--    error("QMAKE_MAC_SDK can only contain short-form SDK names (eg. macosx, iphoneos)")
--
--defineReplace(xcodeSDKInfo) {
--    info = $$1
--    equals(info, "Path"): \
--        info = --show-sdk-path
--    equals(info, "PlatformPath"): \
--        info = --show-sdk-platform-path
--    equals(info, "SDKVersion"): \
--        info = --show-sdk-version
--    sdk = $$2
--    isEmpty(sdk): \
--        sdk = $$QMAKE_MAC_SDK
--
--    isEmpty(QMAKE_MAC_SDK.$${sdk}.$${info}) {
--        QMAKE_MAC_SDK.$${sdk}.$${info} = $$system("/usr/bin/xcrun --sdk $$sdk $$info 2>/dev/null")
--        # --show-sdk-platform-path won't work for Command Line Tools; this is fine
--        # only used by the XCTest backend to testlib
--        isEmpty(QMAKE_MAC_SDK.$${sdk}.$${info}):if(!isEmpty(QMAKE_XCODEBUILD_PATH)|!equals(info, "--show-sdk-platform-path")): \
--            error("Could not resolve SDK $$info for \'$$sdk\'")
--        cache(QMAKE_MAC_SDK.$${sdk}.$${info}, set stash, QMAKE_MAC_SDK.$${sdk}.$${info})
--    }
--
--    return($$eval(QMAKE_MAC_SDK.$${sdk}.$${info}))
--}
--
--QMAKE_MAC_SDK_PATH = $$xcodeSDKInfo(Path)
--QMAKE_MAC_SDK_PLATFORM_PATH = $$xcodeSDKInfo(PlatformPath)
--QMAKE_MAC_SDK_VERSION = $$xcodeSDKInfo(SDKVersion)
--
--sysrootified =
--for(val, QMAKE_INCDIR_OPENGL): sysrootified += $${QMAKE_MAC_SDK_PATH}$$val
--QMAKE_INCDIR_OPENGL = $$sysrootified
--
--QMAKESPEC_NAME = $$basename(QMAKESPEC)
--
--# Resolve SDK version of various tools
--for(tool, $$list(QMAKE_CC QMAKE_CXX QMAKE_FIX_RPATH QMAKE_AR QMAKE_RANLIB QMAKE_LINK QMAKE_LINK_SHLIB QMAKE_ACTOOL)) {
--    tool_variable = QMAKE_MAC_SDK.$${QMAKESPEC_NAME}.$${QMAKE_MAC_SDK}.$${tool}
--    !isEmpty($$tool_variable) {
--        $$tool = $$eval($$tool_variable)
--        next()
--    }
--
--    value = $$eval($$tool)
--    isEmpty(value): next()
--
--    sysrooted = $$system("/usr/bin/xcrun -sdk $$QMAKE_MAC_SDK -find $$first(value) 2>/dev/null")
--    isEmpty(sysrooted): next()
--
--    $$tool = $$sysrooted $$member(value, 1, -1)
--    cache($$tool_variable, set stash, $$tool)
--}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/qgtk-env.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/qgtk-env.patch
deleted file mode 100644
index 8e5e2c71828..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/qgtk-env.patch
+++ /dev/null
@@ -1,36 +0,0 @@
-Index: qtbase-opensource-src-5.8.0/src/plugins/platformthemes/gtk3/main.cpp
-===================================================================
---- qtbase-opensource-src-5.8.0.orig/src/plugins/platformthemes/gtk3/main.cpp
-+++ qtbase-opensource-src-5.8.0/src/plugins/platformthemes/gtk3/main.cpp
-@@ -39,6 +39,7 @@
- 
- #include <qpa/qplatformthemeplugin.h>
- #include "qgtk3theme.h"
-+#include <QFile>
- 
- QT_BEGIN_NAMESPACE
- 
-@@ -54,8 +55,22 @@ public:
- QPlatformTheme *QGtk3ThemePlugin::create(const QString &key, const QStringList &params)
- {
-     Q_UNUSED(params);
--    if (!key.compare(QLatin1String(QGtk3Theme::name), Qt::CaseInsensitive))
-+    if (!key.compare(QLatin1String(QGtk3Theme::name), Qt::CaseInsensitive)) {
-+
-+#ifdef NIXPKGS_QGTK3_XDG_DATA_DIRS
-+        QStringList XDG_DATA_DIRS = QFile::decodeName(qgetenv("XDG_DATA_DIRS")).split(':');
-+        XDG_DATA_DIRS << QLatin1String(NIXPKGS_QGTK3_XDG_DATA_DIRS);
-+        qputenv("XDG_DATA_DIRS", QFile::encodeName(XDG_DATA_DIRS.join(':')));
-+#endif
-+
-+#ifdef NIXPKGS_QGTK3_GIO_EXTRA_MODULES
-+        QStringList GIO_EXTRA_MODULES = QFile::decodeName(qgetenv("GIO_EXTRA_MODULES")).split(':');
-+        GIO_EXTRA_MODULES << QLatin1String(NIXPKGS_QGTK3_GIO_EXTRA_MODULES);
-+        qputenv("GIO_EXTRA_MODULES", QFile::encodeName(GIO_EXTRA_MODULES.join(':')));
-+#endif
-+
-         return new QGtk3Theme;
-+    }
- 
-     return 0;
- }
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/qnativesocketengine-type-pun.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/qnativesocketengine-type-pun.patch
deleted file mode 100644
index ad40dfab2f7..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/qnativesocketengine-type-pun.patch
+++ /dev/null
@@ -1,14 +0,0 @@
-Index: qtbase-opensource-src-5.8.0/src/network/socket/qnativesocketengine_unix.cpp
-===================================================================
---- qtbase-opensource-src-5.8.0.orig/src/network/socket/qnativesocketengine_unix.cpp
-+++ qtbase-opensource-src-5.8.0/src/network/socket/qnativesocketengine_unix.cpp
-@@ -979,7 +979,8 @@ qint64 QNativeSocketEnginePrivate::nativ
-             if (cmsgptr->cmsg_len == CMSG_LEN(sizeof(int))
-                     && ((cmsgptr->cmsg_level == IPPROTO_IPV6 && cmsgptr->cmsg_type == IPV6_HOPLIMIT)
-                         || (cmsgptr->cmsg_level == IPPROTO_IP && cmsgptr->cmsg_type == IP_TTL))) {
--                header->hopLimit = *reinterpret_cast<int *>(CMSG_DATA(cmsgptr));
-+                int *ttl = reinterpret_cast<int *>(CMSG_DATA(cmsgptr));
-+                header->hopLimit = *ttl;
-             }
- 
- #ifndef QT_NO_SCTP
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/series b/pkgs/development/libraries/qt-5/5.9/qtbase/series
deleted file mode 100644
index 4f354e87c84..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/series
+++ /dev/null
@@ -1,9 +0,0 @@
-dlopen-resolv.patch
-tzdir.patch
-dlopen-libXcursor.patch
-library-paths.patch
-libressl.patch
-dlopen-gl.patch
-compose-search-path.patch
-cmake-paths.patch
-qgtk-env.patch
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/tzdir.patch b/pkgs/development/libraries/qt-5/5.9/qtbase/tzdir.patch
deleted file mode 100644
index d57f24c3ed0..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/tzdir.patch
+++ /dev/null
@@ -1,39 +0,0 @@
-Index: qtbase-opensource-src-5.9.0/src/corelib/tools/qtimezoneprivate_tz.cpp
-===================================================================
---- qtbase-opensource-src-5.9.0.orig/src/corelib/tools/qtimezoneprivate_tz.cpp
-+++ qtbase-opensource-src-5.9.0/src/corelib/tools/qtimezoneprivate_tz.cpp
-@@ -70,7 +70,11 @@ typedef QHash<QByteArray, QTzTimeZone> Q
- // Parse zone.tab table, assume lists all installed zones, if not will need to read directories
- static QTzTimeZoneHash loadTzTimeZones()
- {
--    QString path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
-+    // Try TZDIR first, in case we're running on NixOS.
-+    QString path = QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/zone.tab");
-+    // Fallback to traditional paths in case we are not on NixOS.
-+    if (!QFile::exists(path))
-+        path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
-     if (!QFile::exists(path))
-         path = QStringLiteral("/usr/lib/zoneinfo/zone.tab");
- 
-@@ -643,12 +647,16 @@ void QTzTimeZonePrivate::init(const QByt
-         if (!tzif.open(QIODevice::ReadOnly))
-             return;
-     } else {
--        // Open named tz, try modern path first, if fails try legacy path
--        tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
-+        // Try TZDIR first, in case we're running on NixOS
-+        tzif.setFileName(QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/") + QString::fromLocal8Bit(ianaId));
-         if (!tzif.open(QIODevice::ReadOnly)) {
--            tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
--            if (!tzif.open(QIODevice::ReadOnly))
--                return;
-+            // Open named tz, try modern path first, if fails try legacy path
-+            tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
-+            if (!tzif.open(QIODevice::ReadOnly)) {
-+                tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
-+                if (!tzif.open(QIODevice::ReadOnly))
-+                    return;
-+            }
-         }
-     }
- 
diff --git a/pkgs/development/libraries/qt-5/5.9/qtcharts.nix b/pkgs/development/libraries/qt-5/5.9/qtcharts.nix
deleted file mode 100644
index afc09e3eeb5..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtcharts.nix
+++ /dev/null
@@ -1,10 +0,0 @@
-{ qtSubmodule, qtbase, qtdeclarative }:
-
-qtSubmodule {
-  name = "qtcharts";
-  qtInputs = [ qtbase qtdeclarative ];
-  outputs = [ "bin" "dev" "out" ];
-  postInstall = ''
-    moveToOutput "$qtQmlPrefix" "$bin"
-  '';
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtconnectivity.nix b/pkgs/development/libraries/qt-5/5.9/qtconnectivity.nix
deleted file mode 100644
index 8153f0d4078..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtconnectivity.nix
+++ /dev/null
@@ -1,10 +0,0 @@
-{ qtSubmodule, qtbase, qtdeclarative }:
-
-qtSubmodule {
-  name = "qtconnectivity";
-  qtInputs = [ qtbase qtdeclarative ];
-  outputs = [ "bin" "dev" "out" ];
-  postInstall = ''
-    moveToOutput "$qtQmlPrefix" "$bin"
-  '';
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtdeclarative.patch b/pkgs/development/libraries/qt-5/5.9/qtdeclarative.patch
new file mode 100644
index 00000000000..bb1bbbeb05e
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/5.9/qtdeclarative.patch
@@ -0,0 +1,33 @@
+diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
+index ee5b38717..bbccef8c4 100644
+--- a/src/qml/qml/qqmlimport.cpp
++++ b/src/qml/qml/qqmlimport.cpp
+@@ -1678,6 +1678,15 @@ QQmlImportDatabase::QQmlImportDatabase(QQmlEngine *e)
+     QString installImportsPath =  QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath);
+     addImportPath(installImportsPath);
+ 
++    // Add import paths derived from PATH
++    const QStringList paths = QFile::decodeName(qgetenv("PATH")).split(':');
++    const QString qmldir = QStringLiteral("../" NIXPKGS_QML2_IMPORT_PREFIX);
++    for (const QString &path: paths) {
++        if (!path.isEmpty()) {
++            addImportPath(QDir::cleanPath(path + QDir::separator() + qmldir));
++        }
++    }
++
+     // env import paths
+     if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QML2_IMPORT_PATH"))) {
+         const QByteArray envImportPath = qgetenv("QML2_IMPORT_PATH");
+diff --git a/tools/qmlcachegen/qmlcache.prf b/tools/qmlcachegen/qmlcache.prf
+index 330da358b..cdf570205 100644
+--- a/tools/qmlcachegen/qmlcache.prf
++++ b/tools/qmlcachegen/qmlcache.prf
+@@ -44,7 +44,7 @@ defineReplace(qmlCacheOutputFileName) {
+ }
+ 
+ qmlcacheinst.base = $$QMLCACHE_DESTDIR
+-qmlcacheinst.path = $$[QT_INSTALL_QML]/$$TARGETPATH
++qmlcacheinst.path = $$NIX_OUTPUT_QML/$$TARGETPATH
+ qmlcacheinst.CONFIG = no_check_exist
+ 
+ qmlcachegen.input = CACHEGEN_FILES
diff --git a/pkgs/development/libraries/qt-5/5.9/qtdeclarative/default.nix b/pkgs/development/libraries/qt-5/5.9/qtdeclarative/default.nix
deleted file mode 100644
index 39b4d35ef36..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtdeclarative/default.nix
+++ /dev/null
@@ -1,20 +0,0 @@
-{ stdenv, qtSubmodule, copyPathsToStore, python2, qtbase, qtsvg, qtxmlpatterns }:
-
-with stdenv.lib;
-
-qtSubmodule {
-  name = "qtdeclarative";
-  patches = copyPathsToStore (readPathsFromFile ./. ./series);
-  qtInputs = [ qtbase qtsvg qtxmlpatterns ];
-  nativeBuildInputs = [ python2 ];
-  outputs = [ "bin" "dev" "out" ];
-
-  preConfigure = ''
-    NIX_CFLAGS_COMPILE+=" -DNIXPKGS_QML2_IMPORT_PREFIX=\"$qtQmlPrefix\""
-  '';
-
-  postInstall = ''
-    moveToOutput "$qtPluginPrefix" "$bin"
-    moveToOutput "$qtQmlPrefix" "$bin"
-  '';
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtdeclarative/series b/pkgs/development/libraries/qt-5/5.9/qtdeclarative/series
deleted file mode 100644
index 38abb916a50..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtdeclarative/series
+++ /dev/null
@@ -1 +0,0 @@
-import-paths.patch
diff --git a/pkgs/development/libraries/qt-5/5.9/qtlocation.nix b/pkgs/development/libraries/qt-5/5.9/qtlocation.nix
deleted file mode 100644
index f883fd4ff40..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtlocation.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ qtSubmodule, qtbase, qtmultimedia }:
-
-qtSubmodule {
-  name = "qtlocation";
-  qtInputs = [ qtbase qtmultimedia ];
-  outputs = [ "bin" "dev" "out" ];
-  postInstall = ''
-    moveToOutput "$qtPluginPrefix" "$bin"
-    moveToOutput "$qtQmlPrefix" "$bin"
-  '';
-  # Linking with -lclipper fails with parallel build enabled
-  enableParallelBuilding = false;
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtquickcontrols2.nix b/pkgs/development/libraries/qt-5/5.9/qtquickcontrols2.nix
deleted file mode 100644
index 37d7d59f815..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtquickcontrols2.nix
+++ /dev/null
@@ -1,10 +0,0 @@
-{ qtSubmodule, qtdeclarative }:
-
-qtSubmodule {
-  name = "qtquickcontrols2";
-  qtInputs = [ qtdeclarative ];
-  outputs = [ "bin" "dev" "out" ];
-  postInstall = ''
-    moveToOutput "$qtQmlPrefix" "$bin"
-  '';
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtscript.patch b/pkgs/development/libraries/qt-5/5.9/qtscript.patch
new file mode 100644
index 00000000000..5508dec1280
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/5.9/qtscript.patch
@@ -0,0 +1,13 @@
+diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h b/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h
+index 1f6d25e..087c3fb 100644
+--- a/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h
++++ b/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h
+@@ -81,7 +81,7 @@
+ #include <pthread.h>
+ #elif PLATFORM(GTK)
+ #include <wtf/gtk/GOwnPtr.h>
+-typedef struct _GMutex GMutex;
++typedef union _GMutex GMutex;
+ typedef struct _GCond GCond;
+ #endif
+ 
diff --git a/pkgs/development/libraries/qt-5/5.9/qtscript/default.nix b/pkgs/development/libraries/qt-5/5.9/qtscript/default.nix
deleted file mode 100644
index 127766e2ebd..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtscript/default.nix
+++ /dev/null
@@ -1,7 +0,0 @@
-{ qtSubmodule, qtbase, qttools }:
-
-qtSubmodule {
-  name = "qtscript";
-  qtInputs = [ qtbase qttools ];
-  patches = [ ./0001-glib-2.32.patch ];
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtsensors.nix b/pkgs/development/libraries/qt-5/5.9/qtsensors.nix
deleted file mode 100644
index 4127d00b769..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtsensors.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ stdenv, qtSubmodule, qtbase, qtdeclarative }:
-
-with stdenv.lib;
-
-qtSubmodule {
-  name = "qtsensors";
-  qtInputs = [ qtbase qtdeclarative ];
-  outputs = [ "bin" "dev" "out" ];
-  postInstall = ''
-    moveToOutput "$qtPluginPrefix" "$bin"
-    moveToOutput "$qtQmlPrefix" "$bin"
-  '';
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtserialport.patch b/pkgs/development/libraries/qt-5/5.9/qtserialport.patch
new file mode 100644
index 00000000000..f25524e80bc
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/5.9/qtserialport.patch
@@ -0,0 +1,22 @@
+diff --git a/src/serialport/qtudev_p.h b/src/serialport/qtudev_p.h
+index af2dab2..8e17f64 100644
+--- a/src/serialport/qtudev_p.h
++++ b/src/serialport/qtudev_p.h
+@@ -111,9 +111,17 @@ inline QFunctionPointer resolveSymbol(QLibrary *udevLibrary, const char *symbolN
+ inline bool resolveSymbols(QLibrary *udevLibrary)
+ {
+     if (!udevLibrary->isLoaded()) {
++#ifdef NIXPKGS_LIBUDEV
++        udevLibrary->setFileNameAndVersion(QLatin1String(NIXPKGS_LIBUDEV), 1);
++#else
+         udevLibrary->setFileNameAndVersion(QStringLiteral("udev"), 1);
++#endif
+         if (!udevLibrary->load()) {
++#ifdef NIXPKGS_LIBUDEV
++            udevLibrary->setFileNameAndVersion(QLatin1String(NIXPKGS_LIBUDEV), 0);
++#else
+             udevLibrary->setFileNameAndVersion(QStringLiteral("udev"), 0);
++#endif
+             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.9/qtserialport/series b/pkgs/development/libraries/qt-5/5.9/qtserialport/series
deleted file mode 100644
index 83f4abf094e..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtserialport/series
+++ /dev/null
@@ -1 +0,0 @@
-qtserialport-dlopen-udev.patch
diff --git a/pkgs/development/libraries/qt-5/5.9/qtsvg.nix b/pkgs/development/libraries/qt-5/5.9/qtsvg.nix
deleted file mode 100644
index ce419731dfa..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtsvg.nix
+++ /dev/null
@@ -1,10 +0,0 @@
-{ qtSubmodule, qtbase }:
-
-qtSubmodule {
-  name = "qtsvg";
-  qtInputs = [ qtbase ];
-  outputs = [ "bin" "dev" "out" ];
-  postInstall = ''
-    moveToOutput "$qtPluginPrefix" "$bin"
-  '';
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qttools.patch b/pkgs/development/libraries/qt-5/5.9/qttools.patch
new file mode 100644
index 00000000000..fbba439ef7a
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/5.9/qttools.patch
@@ -0,0 +1,71 @@
+diff --git a/src/assistant/help/Qt5HelpConfigExtras.cmake.in b/src/assistant/help/Qt5HelpConfigExtras.cmake.in
+index 3b97923a..63336bd5 100644
+--- a/src/assistant/help/Qt5HelpConfigExtras.cmake.in
++++ b/src/assistant/help/Qt5HelpConfigExtras.cmake.in
+@@ -2,11 +2,10 @@
+ if (NOT TARGET Qt5::qcollectiongenerator)
+     add_executable(Qt5::qcollectiongenerator IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Help_install_prefix}/$${CMAKE_BIN_DIR}qcollectiongenerator$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}qcollectiongenerator$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
++    if(NOT EXISTS \"${imported_location}\")
++        set(imported_location \"$${CMAKE_BIN_DIR}qcollectiongenerator$$CMAKE_BIN_SUFFIX\")
++    endif()
+     _qt5_Help_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::qcollectiongenerator PROPERTIES
+@@ -17,11 +16,7 @@ endif()
+ if (NOT TARGET Qt5::qhelpgenerator)
+     add_executable(Qt5::qhelpgenerator IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5Help_install_prefix}/$${CMAKE_BIN_DIR}qhelpgenerator$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}qhelpgenerator$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
+     _qt5_Help_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::qhelpgenerator PROPERTIES
+diff --git a/src/linguist/Qt5LinguistToolsConfig.cmake.in b/src/linguist/Qt5LinguistToolsConfig.cmake.in
+index 4318b16f..d60db4ff 100644
+--- a/src/linguist/Qt5LinguistToolsConfig.cmake.in
++++ b/src/linguist/Qt5LinguistToolsConfig.cmake.in
+@@ -44,11 +44,7 @@ endmacro()
+ if (NOT TARGET Qt5::lrelease)
+     add_executable(Qt5::lrelease IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5_linguisttools_install_prefix}/$${CMAKE_BIN_DIR}lrelease$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}lrelease$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
+     _qt5_LinguistTools_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::lrelease PROPERTIES
+@@ -59,11 +55,7 @@ endif()
+ if (NOT TARGET Qt5::lupdate)
+     add_executable(Qt5::lupdate IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5_linguisttools_install_prefix}/$${CMAKE_BIN_DIR}lupdate$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}lupdate$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
+     _qt5_LinguistTools_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::lupdate PROPERTIES
+@@ -74,11 +66,7 @@ endif()
+ if (NOT TARGET Qt5::lconvert)
+     add_executable(Qt5::lconvert IMPORTED)
+ 
+-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
+-    set(imported_location \"${_qt5_linguisttools_install_prefix}/$${CMAKE_BIN_DIR}lconvert$$CMAKE_BIN_SUFFIX\")
+-!!ELSE
+     set(imported_location \"$${CMAKE_BIN_DIR}lconvert$$CMAKE_BIN_SUFFIX\")
+-!!ENDIF
+     _qt5_LinguistTools_check_file_exists(${imported_location})
+ 
+     set_target_properties(Qt5::lconvert PROPERTIES
diff --git a/pkgs/development/libraries/qt-5/5.9/qttools/cmake-paths.patch b/pkgs/development/libraries/qt-5/5.9/qttools/cmake-paths.patch
deleted file mode 100644
index dfcba9045a7..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qttools/cmake-paths.patch
+++ /dev/null
@@ -1,88 +0,0 @@
-Index: qttools-opensource-src-5.8.0/src/assistant/help/Qt5HelpConfigExtras.cmake.in
-===================================================================
---- qttools-opensource-src-5.8.0.orig/src/assistant/help/Qt5HelpConfigExtras.cmake.in
-+++ qttools-opensource-src-5.8.0/src/assistant/help/Qt5HelpConfigExtras.cmake.in
-@@ -2,11 +2,10 @@
- if (NOT TARGET Qt5::qcollectiongenerator)
-     add_executable(Qt5::qcollectiongenerator IMPORTED)
- 
--!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5Help_install_prefix}/$${CMAKE_BIN_DIR}qcollectiongenerator$$CMAKE_BIN_SUFFIX\")
--!!ELSE
--    set(imported_location \"$${CMAKE_BIN_DIR}qcollectiongenerator$$CMAKE_BIN_SUFFIX\")
--!!ENDIF
-+    set(imported_location \"@NIX_OUT@/$${CMAKE_BIN_DIR}qcollectiongenerator$$CMAKE_BIN_SUFFIX\")
-+    if(NOT EXISTS \"${imported_location}\")
-+        set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}qcollectiongenerator$$CMAKE_BIN_SUFFIX\")
-+    endif()
-     _qt5_Help_check_file_exists(${imported_location})
- 
-     set_target_properties(Qt5::qcollectiongenerator PROPERTIES
-@@ -17,11 +16,10 @@ endif()
- if (NOT TARGET Qt5::qhelpgenerator)
-     add_executable(Qt5::qhelpgenerator IMPORTED)
- 
--!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5Help_install_prefix}/$${CMAKE_BIN_DIR}qhelpgenerator$$CMAKE_BIN_SUFFIX\")
--!!ELSE
--    set(imported_location \"$${CMAKE_BIN_DIR}qhelpgenerator$$CMAKE_BIN_SUFFIX\")
--!!ENDIF
-+    set(imported_location \"@NIX_OUT@/$${CMAKE_BIN_DIR}qhelpgenerator$$CMAKE_BIN_SUFFIX\")
-+    if(NOT EXISTS \"${imported_location}\")
-+        set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}qhelpgenerator$$CMAKE_BIN_SUFFIX\")
-+    endif()
-     _qt5_Help_check_file_exists(${imported_location})
- 
-     set_target_properties(Qt5::qhelpgenerator PROPERTIES
-Index: qttools-opensource-src-5.8.0/src/linguist/Qt5LinguistToolsConfig.cmake.in
-===================================================================
---- qttools-opensource-src-5.8.0.orig/src/linguist/Qt5LinguistToolsConfig.cmake.in
-+++ qttools-opensource-src-5.8.0/src/linguist/Qt5LinguistToolsConfig.cmake.in
-@@ -44,11 +44,10 @@ endmacro()
- if (NOT TARGET Qt5::lrelease)
-     add_executable(Qt5::lrelease IMPORTED)
- 
--!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5_linguisttools_install_prefix}/$${CMAKE_BIN_DIR}lrelease$$CMAKE_BIN_SUFFIX\")
--!!ELSE
--    set(imported_location \"$${CMAKE_BIN_DIR}lrelease$$CMAKE_BIN_SUFFIX\")
--!!ENDIF
-+    set(imported_location \"@NIX_OUT@/$${CMAKE_BIN_DIR}lrelease$$CMAKE_BIN_SUFFIX\")
-+    if(NOT EXISTS \"${imported_location}\")
-+        set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}lrelease$$CMAKE_BIN_SUFFIX\")
-+    endif()
-     _qt5_LinguistTools_check_file_exists(${imported_location})
- 
-     set_target_properties(Qt5::lrelease PROPERTIES
-@@ -59,11 +58,10 @@ endif()
- if (NOT TARGET Qt5::lupdate)
-     add_executable(Qt5::lupdate IMPORTED)
- 
--!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5_linguisttools_install_prefix}/$${CMAKE_BIN_DIR}lupdate$$CMAKE_BIN_SUFFIX\")
--!!ELSE
--    set(imported_location \"$${CMAKE_BIN_DIR}lupdate$$CMAKE_BIN_SUFFIX\")
--!!ENDIF
-+    set(imported_location \"@NIX_OUT@/$${CMAKE_BIN_DIR}lupdate$$CMAKE_BIN_SUFFIX\")
-+    if(NOT EXISTS \"${imported_location}\")
-+        set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}lupdate$$CMAKE_BIN_SUFFIX\")
-+    endif()
-     _qt5_LinguistTools_check_file_exists(${imported_location})
- 
-     set_target_properties(Qt5::lupdate PROPERTIES
-@@ -74,11 +72,10 @@ endif()
- if (NOT TARGET Qt5::lconvert)
-     add_executable(Qt5::lconvert IMPORTED)
- 
--!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
--    set(imported_location \"${_qt5_linguisttools_install_prefix}/$${CMAKE_BIN_DIR}lconvert$$CMAKE_BIN_SUFFIX\")
--!!ELSE
--    set(imported_location \"$${CMAKE_BIN_DIR}lconvert$$CMAKE_BIN_SUFFIX\")
--!!ENDIF
-+    set(imported_location \"@NIX_OUT@/$${CMAKE_BIN_DIR}lconvert$$CMAKE_BIN_SUFFIX\")
-+    if(NOT EXISTS \"${imported_location}\")
-+        set(imported_location \"@NIX_DEV@/$${CMAKE_BIN_DIR}lconvert$$CMAKE_BIN_SUFFIX\")
-+    endif()
-     _qt5_LinguistTools_check_file_exists(${imported_location})
- 
-     set_target_properties(Qt5::lconvert PROPERTIES
diff --git a/pkgs/development/libraries/qt-5/5.9/qttools/default.nix b/pkgs/development/libraries/qt-5/5.9/qttools/default.nix
deleted file mode 100644
index 38d8f1ebe64..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qttools/default.nix
+++ /dev/null
@@ -1,16 +0,0 @@
-{ stdenv, qtSubmodule, copyPathsToStore, qtbase }:
-
-with stdenv.lib;
-
-qtSubmodule {
-  name = "qttools";
-  qtInputs = [ qtbase ];
-  outputs = [ "bin" "dev" "out" ];
-  patches = copyPathsToStore (readPathsFromFile ./. ./series);
-  # qmake moves all binaries to $dev in preFixup
-  postFixup = ''
-    moveToOutput "bin/qdbus" "$bin"
-    moveToOutput "bin/qdbusviewer" "$bin"
-    moveToOutput "bin/qtpaths" "$bin"
-  '';
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qttools/series b/pkgs/development/libraries/qt-5/5.9/qttools/series
deleted file mode 100644
index 6cc1d3b87bc..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qttools/series
+++ /dev/null
@@ -1 +0,0 @@
-cmake-paths.patch
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwayland.nix b/pkgs/development/libraries/qt-5/5.9/qtwayland.nix
deleted file mode 100644
index 8b3072c5534..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtwayland.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ qtSubmodule, qtbase, qtquickcontrols, wayland, pkgconfig }:
-
-qtSubmodule {
-  name = "qtwayland";
-  qtInputs = [ qtbase qtquickcontrols ];
-  buildInputs = [ wayland ];
-  nativeBuildInputs = [ pkgconfig ];
-  outputs = [ "bin" "dev" "out" ];
-  postInstall = ''
-    moveToOutput "$qtPluginPrefix" "$bin"
-    moveToOutput "$qtQmlPrefix" "$bin"
-  '';
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwebchannel.nix b/pkgs/development/libraries/qt-5/5.9/qtwebchannel.nix
deleted file mode 100644
index e6a2d74e714..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtwebchannel.nix
+++ /dev/null
@@ -1,11 +0,0 @@
-{ qtSubmodule, qtbase, qtdeclarative }:
-
-qtSubmodule {
-  name = "qtwebchannel";
-  qtInputs = [ qtbase qtdeclarative ];
-  outputs = [ "bin" "dev" "out" ];
-  postInstall = ''
-    moveToOutput "$qtQmlPrefix" "$bin"
-  '';
-}
-
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwebengine/qtwebengine-paxmark-mksnapshot.patch b/pkgs/development/libraries/qt-5/5.9/qtwebengine-paxmark-mksnapshot.patch
index 5e170567ce5..5e170567ce5 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtwebengine/qtwebengine-paxmark-mksnapshot.patch
+++ b/pkgs/development/libraries/qt-5/5.9/qtwebengine-paxmark-mksnapshot.patch
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwebkit.patch b/pkgs/development/libraries/qt-5/5.9/qtwebkit.patch
new file mode 100644
index 00000000000..c78cb58f564
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/5.9/qtwebkit.patch
@@ -0,0 +1,77 @@
+diff --git a/Source/WTF/WTF.pri b/Source/WTF/WTF.pri
+index 69e4cd1f3..3f729a75e 100644
+--- a/Source/WTF/WTF.pri
++++ b/Source/WTF/WTF.pri
+@@ -12,7 +12,7 @@ mac {
+     # Mac OS does ship libicu but not the associated header files.
+     # Therefore WebKit provides adequate header files.
+     INCLUDEPATH = $${ROOT_WEBKIT_DIR}/Source/WTF/icu $$INCLUDEPATH
+-    LIBS += -licucore
++    LIBS += /usr/lib/libicucore.dylib
+ } else:!use?(wchar_unicode): {
+     win32 {
+         CONFIG(static, static|shared) {
+diff --git a/Source/WebCore/plugins/qt/PluginPackageQt.cpp b/Source/WebCore/plugins/qt/PluginPackageQt.cpp
+index a923d49aa..46772a4bb 100644
+--- a/Source/WebCore/plugins/qt/PluginPackageQt.cpp
++++ b/Source/WebCore/plugins/qt/PluginPackageQt.cpp
+@@ -136,7 +136,11 @@ static void initializeGtk(QLibrary* module = 0)
+         }
+     }
+ 
++#ifdef NIXPKGS_LIBGTK2
++    QLibrary library(QLatin1String(NIXPKGS_LIBGTK2), 0);
++#else
+     QLibrary library(QLatin1String("libgtk-x11-2.0"), 0);
++#endif
+     if (library.load()) {
+         typedef void *(*gtk_init_check_ptr)(int*, char***);
+         gtk_init_check_ptr gtkInitCheck = (gtk_init_check_ptr)library.resolve("gtk_init_check");
+diff --git a/Source/WebCore/plugins/qt/PluginViewQt.cpp b/Source/WebCore/plugins/qt/PluginViewQt.cpp
+index de06a2fea..86fe39ef1 100644
+--- a/Source/WebCore/plugins/qt/PluginViewQt.cpp
++++ b/Source/WebCore/plugins/qt/PluginViewQt.cpp
+@@ -697,7 +697,11 @@ static Display *getPluginDisplay()
+     // support gdk based plugins (like flash) that use a different X connection.
+     // The code below has the same effect as this one:
+     // Display *gdkDisplay = gdk_x11_display_get_xdisplay(gdk_display_get_default());
++#ifdef NIXPKGS_LIBGDK2
++    QLibrary library(QLatin1String(NIXPKGS_LIBGDK2), 0);
++#else
+     QLibrary library(QLatin1String("libgdk-x11-2.0"), 0);
++#endif
+     if (!library.load())
+         return 0;
+ 
+diff --git a/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp b/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp
+index 8de65216b..38f5c05e5 100644
+--- a/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp
++++ b/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp
+@@ -53,7 +53,11 @@ static void messageHandler(QtMsgType type, const QMessageLogContext&, const QStr
+ 
+ static bool initializeGtk()
+ {
++#ifdef NIXPKGS_LIBGTK2
++    QLibrary gtkLibrary(QLatin1String(NIXPKGS_LIBGTK2), 0);
++#else
+     QLibrary gtkLibrary(QLatin1String("libgtk-x11-2.0"), 0);
++#endif
+     if (!gtkLibrary.load())
+         return false;
+     typedef void* (*gtk_init_ptr)(void*, void*);
+diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
+index d734ff684..0f6ff63d1 100644
+--- a/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
++++ b/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
+@@ -64,7 +64,11 @@ static Display* getPluginDisplay()
+     // The code below has the same effect as this one:
+     // Display *gdkDisplay = gdk_x11_display_get_xdisplay(gdk_display_get_default());
+ 
++#ifdef NIXPKGS_LIBGDK2
++    QLibrary library(QLatin1String(NIXPKGS_LIBGDK2), 0);
++#else
+     QLibrary library(QLatin1String("libgdk-x11-2.0"), 0);
++#endif
+     if (!library.load())
+         return 0;
+ 
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-dlopen-gtk.patch b/pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-dlopen-gtk.patch
deleted file mode 100644
index e34eda592af..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-dlopen-gtk.patch
+++ /dev/null
@@ -1,64 +0,0 @@
-Index: qtwebkit-opensource-src-5.8.0/Source/WebCore/plugins/qt/PluginPackageQt.cpp
-===================================================================
---- qtwebkit-opensource-src-5.8.0.orig/Source/WebCore/plugins/qt/PluginPackageQt.cpp
-+++ qtwebkit-opensource-src-5.8.0/Source/WebCore/plugins/qt/PluginPackageQt.cpp
-@@ -136,7 +136,11 @@ static void initializeGtk(QLibrary* modu
-         }
-     }
- 
-+#ifdef NIXPKGS_LIBGTK2
-+    QLibrary library(QLatin1String(NIXPKGS_LIBGTK2), 0);
-+#else
-     QLibrary library(QLatin1String("libgtk-x11-2.0"), 0);
-+#endif
-     if (library.load()) {
-         typedef void *(*gtk_init_check_ptr)(int*, char***);
-         gtk_init_check_ptr gtkInitCheck = (gtk_init_check_ptr)library.resolve("gtk_init_check");
-Index: qtwebkit-opensource-src-5.8.0/Source/WebCore/plugins/qt/PluginViewQt.cpp
-===================================================================
---- qtwebkit-opensource-src-5.8.0.orig/Source/WebCore/plugins/qt/PluginViewQt.cpp
-+++ qtwebkit-opensource-src-5.8.0/Source/WebCore/plugins/qt/PluginViewQt.cpp
-@@ -697,7 +697,11 @@ static Display *getPluginDisplay()
-     // support gdk based plugins (like flash) that use a different X connection.
-     // The code below has the same effect as this one:
-     // Display *gdkDisplay = gdk_x11_display_get_xdisplay(gdk_display_get_default());
-+#ifdef NIXPKGS_LIBGDK2
-+    QLibrary library(QLatin1String(NIXPKGS_LIBGDK2), 0);
-+#else
-     QLibrary library(QLatin1String("libgdk-x11-2.0"), 0);
-+#endif
-     if (!library.load())
-         return 0;
- 
-Index: qtwebkit-opensource-src-5.8.0/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
-===================================================================
---- qtwebkit-opensource-src-5.8.0.orig/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
-+++ qtwebkit-opensource-src-5.8.0/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
-@@ -64,7 +64,11 @@ static Display* getPluginDisplay()
-     // The code below has the same effect as this one:
-     // Display *gdkDisplay = gdk_x11_display_get_xdisplay(gdk_display_get_default());
- 
-+#ifdef NIXPKGS_LIBGDK2
-+    QLibrary library(QLatin1String(NIXPKGS_LIBGDK2), 0);
-+#else
-     QLibrary library(QLatin1String("libgdk-x11-2.0"), 0);
-+#endif
-     if (!library.load())
-         return 0;
- 
-Index: qtwebkit-opensource-src-5.8.0/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp
-===================================================================
---- qtwebkit-opensource-src-5.8.0.orig/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp
-+++ qtwebkit-opensource-src-5.8.0/Source/WebKit2/PluginProcess/qt/PluginProcessMainQt.cpp
-@@ -53,7 +53,11 @@ static void messageHandler(QtMsgType typ
- 
- static bool initializeGtk()
- {
-+#ifdef NIXPKGS_LIBGTK2
-+    QLibrary gtkLibrary(QLatin1String(NIXPKGS_LIBGTK2), 0);
-+#else
-     QLibrary gtkLibrary(QLatin1String("libgtk-x11-2.0"), 0);
-+#endif
-     if (!gtkLibrary.load())
-         return false;
-     typedef void* (*gtk_init_ptr)(void*, void*);
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-dlopen-udev.patch b/pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-dlopen-udev.patch
deleted file mode 100644
index e69de29bb2d..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-dlopen-udev.patch
+++ /dev/null
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-icucore-darwin.patch b/pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-icucore-darwin.patch
deleted file mode 100644
index 63c653da94e..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtwebkit/qtwebkit-icucore-darwin.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-Index: qtwebkit-opensource-src-5.8.0/Source/WTF/WTF.pri
-===================================================================
---- qtwebkit-opensource-src-5.8.0.orig/Source/WTF/WTF.pri
-+++ qtwebkit-opensource-src-5.8.0/Source/WTF/WTF.pri
-@@ -12,7 +12,7 @@ mac {
-     # Mac OS does ship libicu but not the associated header files.
-     # Therefore WebKit provides adequate header files.
-     INCLUDEPATH = $${ROOT_WEBKIT_DIR}/Source/WTF/icu $$INCLUDEPATH
--    LIBS += -licucore
-+    LIBS += /usr/lib/libicucore.dylib
- } else:!use?(wchar_unicode): {
-     win32 {
-         CONFIG(static, static|shared) {
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwebkit/series b/pkgs/development/libraries/qt-5/5.9/qtwebkit/series
deleted file mode 100644
index 140e2a3dd4e..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtwebkit/series
+++ /dev/null
@@ -1,3 +0,0 @@
-qtwebkit-dlopen-gtk.patch
-qtwebkit-dlopen-udev.patch
-qtwebkit-icucore-darwin.patch
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwebsockets.nix b/pkgs/development/libraries/qt-5/5.9/qtwebsockets.nix
deleted file mode 100644
index 888c1fb6534..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtwebsockets.nix
+++ /dev/null
@@ -1,10 +0,0 @@
-{ qtSubmodule, qtbase, qtdeclarative }:
-
-qtSubmodule {
-  name = "qtwebsockets";
-  qtInputs = [ qtbase qtdeclarative ];
-  outputs = [ "bin" "dev" "out" ];
-  postInstall = ''
-    moveToOutput "$qtQmlPrefix" "$bin"
-  '';
-}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtxmlpatterns.nix b/pkgs/development/libraries/qt-5/5.9/qtxmlpatterns.nix
deleted file mode 100644
index 9a8ddbba2bd..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtxmlpatterns.nix
+++ /dev/null
@@ -1,6 +0,0 @@
-{ qtSubmodule, qtbase }:
-
-qtSubmodule {
-  name = "qtxmlpatterns";
-  qtInputs = [ qtbase ];
-}
diff --git a/pkgs/development/libraries/qt-5/hooks/fix-qt-builtin-paths.sh b/pkgs/development/libraries/qt-5/hooks/fix-qt-builtin-paths.sh
new file mode 100644
index 00000000000..4ca11a223de
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/fix-qt-builtin-paths.sh
@@ -0,0 +1,64 @@
+# fixQtBuiltinPaths
+#
+# Usage: fixQtBuiltinPaths _dir_ _pattern_
+#
+# Fix Qt builtin paths in files matching _pattern_ under _dir_.
+#
+fixQtBuiltinPaths() {
+    local dir="$1"
+    local pattern="$2"
+    local bin="${!outputBin}"
+    local dev="${!outputDev}"
+    local doc="${!outputDoc}"
+    local lib="${!outputLib}"
+
+    if [ -d "$dir" ]; then
+        find "$dir" -name "$pattern" | while read pr_; do
+            if grep -q '\$\$\[QT_' "${pr_:?}"; then
+                echo "fixQtBuiltinPaths: Fixing Qt builtin paths in \`${pr_:?}'..."
+                sed -i "${pr_:?}" \
+                    -e "s|\\\$\\\$\\[QT_HOST_BINS[^]]*\\]|$dev/bin|g" \
+                    -e "s|\\\$\\\$\\[QT_HOST_DATA[^]]*\\]/mkspecs|$dev/mkspecs|g" \
+                    -e "s|\\\$\\\$\\[QT_HOST_PREFIX[^]]*\\]|$dev|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_ARCHDATA[^]]*\\]|$lib|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_BINS[^]]*\\]|$bin/bin|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_CONFIGURATION[^]]*\\]|$bin|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_DATA[^]]*\\]|$lib|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_DOCS[^]]*\\]|$doc/share/doc|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_EXAMPLES[^]]*\\]|$doc/examples|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_HEADERS[^]]*\\]|$dev/include|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_LIBS[^]]*\\]|$lib/lib|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_LIBEXECS[^]]*\\]|$lib/libexec|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_PLUGINS[^]]*\\]|$bin/$qtPluginPrefix|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_PREFIX[^]]*\\]|$lib|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_TESTS[^]]*\\]|$dev/tests|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_TRANSLATIONS[^]]*\\]|$lib/translations|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_QML[^]]*\\]|$bin/$qtQmlPrefix|g"
+            fi
+        done
+    elif [ -e "$dir" ]; then
+        if grep -q '\$\$\[QT_' "${dir:?}"; then
+            echo "fixQtBuiltinPaths: Fixing Qt builtin paths in \`${dir:?}'..."
+            sed -i "${dir:?}" \
+                -e "s|\\\$\\\$\\[QT_HOST_BINS[^]]*\\]|$dev/bin|g" \
+                -e "s|\\\$\\\$\\[QT_HOST_DATA[^]]*\\]/mkspecs|$dev/mkspecs|g" \
+                -e "s|\\\$\\\$\\[QT_HOST_PREFIX[^]]*\\]|$dev|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_ARCHDATA[^]]*\\]|$lib|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_BINS[^]]*\\]|$bin/bin|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_CONFIGURATION[^]]*\\]|$bin|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_DATA[^]]*\\]|$lib|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_DOCS[^]]*\\]|$doc/share/doc|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_EXAMPLES[^]]*\\]|$doc/examples|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_HEADERS[^]]*\\]|$dev/include|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_LIBS[^]]*\\]|$lib/lib|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_LIBEXECS[^]]*\\]|$lib/libexec|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_PLUGINS[^]]*\\]|$bin/$qtPluginPrefix|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_PREFIX[^]]*\\]|$lib|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_TESTS[^]]*\\]|$dev/tests|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_TRANSLATIONS[^]]*\\]|$lib/translations|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_QML[^]]*\\]|$bin/$qtQmlPrefix|g"
+        fi
+    else
+        echo "fixQtBuiltinPaths: Warning: \`$dir' does not exist"
+    fi
+}
diff --git a/pkgs/development/libraries/qt-5/hooks/fix-qt-module-paths.sh b/pkgs/development/libraries/qt-5/hooks/fix-qt-module-paths.sh
new file mode 100644
index 00000000000..916981b5299
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/fix-qt-module-paths.sh
@@ -0,0 +1,43 @@
+# fixQtModulePaths
+#
+# Usage: fixQtModulePaths _dir_
+#
+# Find Qt module definitions in directory _dir_ and patch the module paths.
+#
+fixQtModulePaths () {
+    local dir="$1"
+    local bin="${!outputBin}"
+    local dev="${!outputDev}"
+    local lib="${!outputLib}"
+
+    if [ -d "$dir" ]; then
+        find "$dir" -name 'qt_*.pri' | while read pr; do
+            if grep -q '\$\$QT_MODULE_' "${pr:?}"; then
+                echo "fixQtModulePaths: Fixing module paths in \`${pr:?}'..."
+                sed -i "${pr:?}" \
+                    -e "s|\\\$\\\$QT_MODULE_LIB_BASE|$dev/lib|g" \
+                    -e "s|\\\$\\\$QT_MODULE_HOST_LIB_BASE|$dev/lib|g" \
+                    -e "s|\\\$\\\$QT_MODULE_INCLUDE_BASE|$dev/include|g" \
+                    -e "s|\\\$\\\$QT_MODULE_BIN_BASE|$dev/bin|g"
+            fi
+        done
+    elif [ -e "$dir" ]; then
+        echo "fixQtModulePaths: Warning: \`$dir' is not a directory"
+    else
+        echo "fixQtModulePaths: Warning: \`$dir' does not exist"
+    fi
+
+    if [ "z$dev" != "z$lib" ]; then
+        if [ -d "$lib/lib" ]; then
+            mkdir -p "$dev/lib"
+            lndir -silent "$lib/lib" "$dev/lib"
+        fi
+    fi
+
+    if [ "z$bin" != "z$dev" ]; then
+        if [ -d "$bin/bin" ]; then
+            mkdir -p "$dev/bin"
+            lndir -silent "$bin/bin" "$dev/bin"
+        fi
+    fi
+}
diff --git a/pkgs/development/libraries/qt-5/hooks/fix-qt-static-libs.sh b/pkgs/development/libraries/qt-5/hooks/fix-qt-static-libs.sh
new file mode 100644
index 00000000000..2a20e77e7ba
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/fix-qt-static-libs.sh
@@ -0,0 +1,32 @@
+# fixQtStaticLibs
+#
+# Usage: fixQtStaticLibs _lib_ _dev_
+#
+# Find static Qt libraries in output _lib_ and move them to the corresponding
+# path in output _dev_. Any QMake library definitions (*.prl files) are also
+# moved and library paths are patched.
+#
+fixQtStaticLibs() {
+    local lib="$1"
+    local dev="$2"
+
+    pushd "$lib"
+    if [ -d "lib" ]; then
+        find lib \( -name '*.a' -o -name '*.la' -o -name '*.prl' \) -print0 | \
+            while read -r -d $'\0' file; do
+                mkdir -p "$dev/$(dirname "$file")"
+                mv "$lib/$file" "$dev/$file"
+            done
+    fi
+    popd
+
+    if [ -d "$dev" ]; then
+        find "$dev" -name '*.prl' | while read prl; do
+            echo "fixQtStaticLibs: Fixing built-in paths in \`$prl'..."
+            sed -i "$prl" \
+                -e '/^QMAKE_PRL_BUILD_DIR =/d' \
+                -e '/^QMAKE_PRO_INPUT =/d' \
+                -e "s|-L\\\$\\\$NIX_OUTPUT_OUT/lib|-L$lib/lib -L$dev/lib|g"
+        done
+    fi
+}
diff --git a/pkgs/development/libraries/qt-5/hooks/move-qt-dev-tools.sh b/pkgs/development/libraries/qt-5/hooks/move-qt-dev-tools.sh
new file mode 100644
index 00000000000..85489c85105
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/move-qt-dev-tools.sh
@@ -0,0 +1,34 @@
+updateToolPath() {
+    local tool="$1"
+    local target="$2"
+    local original="${!outputBin}/$tool"
+    local actual="${!outputDev}/$tool"
+    if grep -q "$original" "$target"; then
+        echo "updateToolPath: Updating \`$original' in \`$target\'..."
+        sed -i "$target" -e "s|$original|$actual|"
+    fi
+}
+
+moveQtDevTools() {
+    if [ -n "$devTools" ]; then
+        for tool in $devTools; do
+            moveToOutput "$tool" "${!outputDev}"
+        done
+
+        if [ -d "${!outputDev}/mkspecs" ]; then
+            find "${!outputDev}/mkspecs" -name '*.pr?' | while read pr_; do
+                for tool in $devTools; do
+                    updateToolPath "$tool" "$pr_"
+                done
+            done
+        fi
+
+        if [ -d "${!outputDev}/lib/cmake" ]; then
+            find "${!outputDev}/lib/cmake" -name '*.cmake' | while read cmake; do
+                for tool in $devTools; do
+                    updateToolPath "$tool" "$cmake"
+                done
+            done
+        fi
+    fi
+}
diff --git a/pkgs/development/libraries/qt-5/hooks/qmake-hook.sh b/pkgs/development/libraries/qt-5/hooks/qmake-hook.sh
new file mode 100644
index 00000000000..17d3db65849
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/qmake-hook.sh
@@ -0,0 +1,18 @@
+qmakeConfigurePhase() {
+    runHook preConfigure
+
+    qmake PREFIX=$out \
+          NIX_OUTPUT_OUT=$out \
+          NIX_OUTPUT_DEV=${!outputDev} \
+          NIX_OUTPUT_BIN=${!outputBin} \
+          NIX_OUTPUT_DOC=${!outputDev}/${qtDocPrefix:?} \
+          NIX_OUTPUT_QML=${!outputBin}/${qtQmlPrefix:?} \
+          NIX_OUTPUT_PLUGIN=${!outputBin}/${qtPluginPrefix:?} \
+          $qmakeFlags
+
+    runHook postConfigure
+}
+
+if [ -z "$dontUseQmakeConfigure" -a -z "$configurePhase" ]; then
+    configurePhase=qmakeConfigurePhase
+fi
diff --git a/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh b/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh
new file mode 100644
index 00000000000..258b2d09f20
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh
@@ -0,0 +1,87 @@
+qtPluginPrefix=@qtPluginPrefix@
+qtQmlPrefix=@qtQmlPrefix@
+qtDocPrefix=@qtDocPrefix@
+
+. @fix_qt_builtin_paths@
+. @fix_qt_module_paths@
+. @fix_qt_static_libs@
+
+providesQtRuntime() {
+    [ -d "$1/$qtPluginPrefix" ] || [ -d "$1/$qtQmlPrefix" ]
+}
+
+# Build tools are often confused if QMAKE is unset.
+QMAKE=@dev@/bin/qmake
+export QMAKE
+
+QMAKEPATH=
+export QMAKEPATH
+
+QMAKEMODULES=
+export QMAKEMODULES
+
+addToQMAKEPATH() {
+    if [ -d "$1/mkspecs" ]; then
+        QMAKEMODULES="${QMAKEMODULES}${QMAKEMODULES:+:}/mkspecs"
+        QMAKEPATH="${QMAKEPATH}${QMAKEPATH:+:}$1"
+    fi
+}
+
+# Propagate any runtime dependency of the building package.
+# Each dependency is propagated to the user environment and as a build
+# input so that it will be re-propagated to the user environment by any
+# package depending on the building package. (This is necessary in case
+# the building package does not provide runtime dependencies itself and so
+# would not be propagated to the user environment.)
+qtCrossEnvHook() {
+    addToQMAKEPATH "$1"
+    if providesQtRuntime "$1"; then
+        if [ "z${!outputBin}" != "z${!outputDev}" ]; then
+            propagatedBuildInputs+=" $1"
+        fi
+        propagatedUserEnvPkgs+=" $1"
+    fi
+}
+crossEnvHooks+=(qtCrossEnvHook)
+
+qtEnvHook() {
+    addToQMAKEPATH "$1"
+    if providesQtRuntime "$1"; then
+        if [ "z${!outputBin}" != "z${!outputDev}" ]; then
+            propagatedNativeBuildInputs+=" $1"
+        fi
+        if [ -z "$crossConfig" ]; then
+        propagatedUserEnvPkgs+=" $1"
+        fi
+    fi
+}
+envHooks+=(qtEnvHook)
+
+postPatchMkspecs() {
+    local bin="${!outputBin}"
+    local dev="${!outputDev}"
+    local doc="${!outputDoc}"
+    local lib="${!outputLib}"
+
+    moveToOutput "mkspecs" "$dev"
+
+    if [ -d "$dev/mkspecs/modules" ]; then
+        fixQtModulePaths "$dev/mkspecs/modules"
+    fi
+
+    if [ -d "$dev/mkspecs" ]; then
+        fixQtBuiltinPaths "$dev/mkspecs" '*.pr?'
+    fi
+}
+if [ -z "$dontPatchMkspecs" ]; then
+    postPhases="${postPhases}${postPhases:+ }postPatchMkspecs"
+fi
+
+postMoveQtStaticLibs() {
+    if [ "z${!outputLib}" != "z${!outputDev}" ]; then
+        fixQtStaticLibs "${!outputLib}" "${!outputDev}"
+    fi
+}
+if [ -z "$dontMoveQtStaticLibs" ]; then
+    postPhases="${postPhases}${postPhases:+ }postMoveQtStaticLibs"
+fi
diff --git a/pkgs/development/libraries/qt-5/hooks/qttools-setup-hook.sh b/pkgs/development/libraries/qt-5/hooks/qttools-setup-hook.sh
new file mode 100644
index 00000000000..b09cf5f46c9
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/qttools-setup-hook.sh
@@ -0,0 +1 @@
+qmakeFlags="$qmakeFlags${qmakeFlags:+ }QMAKE_LRELEASE=@dev@/bin/lrelease"
diff --git a/pkgs/development/libraries/qt-5/mkDerivation.nix b/pkgs/development/libraries/qt-5/mkDerivation.nix
new file mode 100644
index 00000000000..ef105092fe2
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/mkDerivation.nix
@@ -0,0 +1,29 @@
+{ stdenv, lib }:
+
+let inherit (lib) optional; in
+
+{ debug }:
+
+args:
+
+let
+  args_ = {
+
+    qmakeFlags =
+      (args.qmakeFlags or [])
+      ++ optional (debug != null)
+          (if debug then "CONFIG+=debug" else "CONFIG+=release");
+
+    cmakeFlags =
+      (args.cmakeFlags or [])
+      ++ [ "-DBUILD_TESTING=OFF" ]
+      ++ optional (debug != null)
+          (if debug then "-DCMAKE_BUILD_TYPE=Debug"
+                    else "-DCMAKE_BUILD_TYPE=Release");
+
+    enableParallelBuilding = args.enableParallelBuilding or false;
+
+  };
+in
+
+stdenv.mkDerivation (args // args_)
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase/default.nix b/pkgs/development/libraries/qt-5/modules/qtbase.nix
index eee55dbded3..902d4f01bf8 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtbase/default.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtbase.nix
@@ -1,20 +1,21 @@
 {
-  stdenv, lib, copyPathsToStore,
-  src, version, qtCompatVersion,
+  stdenv, lib,
+  src, patches, version, qtCompatVersion,
 
   coreutils, bison, flex, gdb, gperf, lndir, patchelf, perl, pkgconfig, python2,
   ruby,
   # darwin support
   darwin, libiconv, libcxx,
 
-  dbus, dconf, fontconfig, freetype, glib, gtk3, harfbuzz, icu, libX11, libXcomposite,
+  dbus, fontconfig, freetype, glib, harfbuzz, icu, libX11, libXcomposite,
   libXcursor, libXext, libXi, libXrender, libinput, libjpeg, libpng, libtiff,
-  libxcb, libxkbcommon, libxml2, libxslt, openssl, pcre2, sqlite, udev,
+  libxcb, libxkbcommon, libxml2, libxslt, openssl, pcre16, pcre2, sqlite, udev,
   xcbutil, xcbutilimage, xcbutilkeysyms, xcbutilrenderutil, xcbutilwm, xlibs,
   zlib,
 
   # optional dependencies
   cups ? null, mysql ? null, postgresql ? null,
+  withGtk3 ? false, dconf ? null, gtk3 ? null,
 
   # options
   mesaSupported ? (!stdenv.isDarwin),
@@ -25,6 +26,9 @@
   decryptSslTraffic ? false
 }:
 
+assert withGtk3 -> dconf != null;
+assert withGtk3 -> gtk3 != null;
+
 let
   system-x86_64 = lib.elem stdenv.system lib.platforms.x86_64;
 in
@@ -36,7 +40,7 @@ stdenv.mkDerivation {
 
   propagatedBuildInputs =
     [
-      libxml2 libxslt openssl pcre2 sqlite zlib
+      libxml2 libxslt openssl sqlite zlib
 
       # Text rendering
       harfbuzz icu
@@ -44,6 +48,8 @@ stdenv.mkDerivation {
       # Image formats
       libjpeg libpng libtiff
     ]
+    ++ (if builtins.compareVersions version "5.9.0" >= 0
+           then [ pcre2 ] else [ pcre16 ])
 
     ++ lib.optional (mesaSupported && !stdenv.isDarwin) mesa
 
@@ -66,7 +72,8 @@ stdenv.mkDerivation {
     ]);
 
   buildInputs = [ ]
-    ++ lib.optionals (!stdenv.isDarwin) [ gtk3 libinput ]
+    ++ lib.optional (!stdenv.isDarwin && withGtk3) gtk3
+    ++ lib.optional (!stdenv.isDarwin) libinput
     ++ lib.optional developerBuild gdb
     ++ lib.optional (cups != null) cups
     ++ lib.optional (mysql != null) mysql.lib
@@ -76,14 +83,31 @@ stdenv.mkDerivation {
     [ bison flex gperf lndir perl pkgconfig python2 ]
     ++ lib.optional (!stdenv.isDarwin) patchelf;
 
+  propagatedNativeBuildInputs = [ lndir ];
+
   outputs = [ "bin" "dev" "out" ];
 
-  patches =
-    copyPathsToStore (lib.readPathsFromFile ./. ./series)
-    ++ stdenv.lib.optional stdenv.isDarwin (copyPathsToStore (lib.readPathsFromFile ./. ./darwin-series));
+  inherit patches;
+
+  fix_qt_static_libs = ../hooks/fix-qt-static-libs.sh;
+  fix_qt_builtin_paths = ../hooks/fix-qt-builtin-paths.sh;
+  fix_qt_module_paths = ../hooks/fix-qt-module-paths.sh;
+  preHook = ''
+    . "$fix_qt_static_libs"
+    . "$fix_qt_builtin_paths"
+    . "$fix_qt_module_paths"
+    . ${../hooks/move-qt-dev-tools.sh}
+  '';
 
   postPatch =
     ''
+      for prf in qml_plugin.prf qt_plugin.prf qt_docs.prf qml_module.prf create_cmake.prf; do
+          substituteInPlace "mkspecs/features/$prf" \
+              --subst-var qtPluginPrefix \
+              --subst-var qtQmlPrefix \
+              --subst-var qtDocPrefix
+      done
+
       substituteInPlace configure --replace /bin/pwd pwd
       substituteInPlace src/corelib/global/global.pri --replace /bin/ls ${coreutils}/bin/ls
       sed -e 's@/\(usr\|opt\)/@/var/empty/@g' -i mkspecs/*/*.conf
@@ -126,13 +150,33 @@ stdenv.mkDerivation {
   setOutputFlags = false;
   preConfigure = ''
     export LD_LIBRARY_PATH="$PWD/lib:$PWD/plugins/platforms:$LD_LIBRARY_PATH"
-    export MAKEFLAGS=-j$NIX_BUILD_CORES
+    ${lib.optionalString (builtins.compareVersions version "5.9.0" < 0) ''
+    # We need to set LD to CXX or otherwise we get nasty compile errors
+    export LD=$CXX
+    ''}
 
     configureFlags+="\
         -plugindir $out/$qtPluginPrefix \
         -qmldir $out/$qtQmlPrefix \
         -docdir $out/$qtDocPrefix"
 
+    createQmakeCache() {
+        cat >>"$1" <<EOF
+    NIX_OUTPUT_BIN = $bin
+    NIX_OUTPUT_DEV = $dev
+    NIX_OUTPUT_OUT = $out
+    NIX_OUTPUT_DOC = $dev/$qtDocPrefix
+    NIX_OUTPUT_QML = $bin/$qtQmlPrefix
+    NIX_OUTPUT_PLUGIN = $bin/$qtPluginPrefix
+    EOF
+    }
+
+    find . -name '.qmake.conf' | while read conf; do
+        cache=$(dirname $conf)/.qmake.cache
+        echo "Creating \`$cache'"
+        createQmakeCache "$cache"
+    done
+
     NIX_CFLAGS_COMPILE+=" -DNIXPKGS_QT_PLUGIN_PREFIX=\"$qtPluginPrefix\""
   '';
 
@@ -148,7 +192,7 @@ stdenv.mkDerivation {
     ++ lib.optional (mesaSupported && !stdenv.isDarwin)
        ''-DNIXPKGS_MESA_GL="${mesa.out}/lib/libGL"''
 
-    ++ lib.optionals (!stdenv.isDarwin)
+    ++ lib.optionals (!stdenv.isDarwin && withGtk3)
     [
       ''-DNIXPKGS_QGTK3_XDG_DATA_DIRS="${gtk3}/share/gsettings-schemas/${gtk3.name}"''
       ''-DNIXPKGS_QGTK3_GIO_EXTRA_MODULES="${dconf.lib}/lib/gio/modules"''
@@ -189,6 +233,11 @@ stdenv.mkDerivation {
       "-system-proxies"
       "-pkg-config"
     ]
+    ++ lib.optionals (builtins.compareVersions version "5.9.0" < 0)
+    [
+      "-c++11"
+      "-no-reduce-relocations"
+    ]
     ++ lib.optionals developerBuild [
       "-developer-build"
       "-no-warnings-are-errors"
@@ -202,8 +251,10 @@ stdenv.mkDerivation {
       "-pch"
     ]
 
+    ++ (if builtins.compareVersions version "5.9.0" >= 0
+           then [ (if system-x86_64 then "-sse2" else "-no-sse2") ]
+           else lib.optional (!system-x86_64) "-no-sse2")
     ++ [
-      ''${lib.optionalString (!system-x86_64) "-no"}-sse2''
       "-no-sse3"
       "-no-ssse3"
       "-no-sse4.1"
@@ -232,7 +283,7 @@ stdenv.mkDerivation {
     ]
 
     ++ lib.optionals (!stdenv.isDarwin) [
-      "-rpath"
+      "-${lib.optionalString (builtins.compareVersions version "5.9.0" < 0) "no-"}rpath"
 
       "-system-xcb"
       "-xcb"
@@ -250,14 +301,14 @@ stdenv.mkDerivation {
       ''-${lib.optionalString (cups == null) "no-"}cups''
       "-dbus-linked"
       "-glib"
-      "-gtk"
-      "-inotify"
       "-system-libjpeg"
       "-system-libpng"
       # gold linker of binutils 2.28 generates duplicate symbols
       # TODO: remove for newer version of binutils 
       "-no-use-gold-linker"
     ]
+    ++ lib.optional withGtk3 "-gtk"
+    ++ lib.optional (builtins.compareVersions version "5.9.0" >= 0) "-inotify"
 
     ++ lib.optionals stdenv.isDarwin [
       "-platform macx-clang"
@@ -270,62 +321,43 @@ stdenv.mkDerivation {
   enableParallelBuilding = true;
 
   postInstall =
-    # Hardcode some CMake module paths.
-    ''
-      find "$out" -name "*.cmake" | while read file; do
-          substituteInPlace "$file" \
-              --subst-var-by NIX_OUT "''${!outputLib}" \
-              --subst-var-by NIX_DEV "''${!outputDev}" \
-              --subst-var-by NIX_BIN "''${!outputBin}"
-      done
-    '';
-
-  preFixup =
     # Move selected outputs.
     ''
-      moveToOutput "bin" "$dev"
-      moveToOutput "include" "$dev"
       moveToOutput "mkspecs" "$dev"
-
-      mkdir -p "$dev/share"
-      moveToOutput "share/doc" "$dev"
-
-      moveToOutput "$qtPluginPrefix" "$bin"
     '';
 
+  devTools = [
+    "bin/fixqt4headers.pl"
+    "bin/moc"
+    "bin/qdbuscpp2xml"
+    "bin/qdbusxml2cpp"
+    "bin/qlalr"
+    "bin/qmake"
+    "bin/rcc"
+    "bin/syncqt.pl"
+    "bin/uic"
+  ];
+
   postFixup =
     # Don't retain build-time dependencies like gdb.
     ''
       sed '/QMAKE_DEFAULT_.*DIRS/ d' -i $dev/mkspecs/qconfig.pri
     ''
 
-    # Move libtool archives into $dev
     + ''
-      if [ "z''${!outputLib}" != "z''${!outputDev}" ]; then
-          pushd "''${!outputLib}"
-          find lib -name '*.a' -o -name '*.la' | while read -r file; do
-              mkdir -p "''${!outputDev}/$(dirname "$file")"
-              mv "''${!outputLib}/$file" "''${!outputDev}/$file"
-          done
-          popd
-      fi
+      fixQtModulePaths "''${!outputDev}/mkspecs/modules"
+      fixQtBuiltinPaths "''${!outputDev}" '*.pr?'
     ''
 
-    # Move qmake project files into $dev.
-    # Don't move .prl files on darwin because they end up in
-    # "dev/lib/Foo.framework/Foo.prl" which interferes with subsequent
-    # use of lndir in the qtbase setup-hook. On Linux, the .prl files
-    # are in lib, and so do not cause a subsequent recreation of deep
-    # framework directory trees.
-    + lib.optionalString (!stdenv.isDarwin) ''
-      if [ "z''${!outputLib}" != "z''${!outputDev}" ]; then
-          pushd "''${!outputLib}"
-          find lib -name '*.prl' | while read -r file; do
-              mkdir -p "''${!outputDev}/$(dirname "$file")"
-              mv "''${!outputLib}/$file" "''${!outputDev}/$file"
-          done
-          popd
-      fi
+    # Move static libraries and QMake library definitions into $dev.
+    + ''
+      fixQtStaticLibs "''${!outputLib}" "''${!outputDev}"
+    ''
+
+    # Move development tools to $dev
+    + ''
+      moveQtDevTools
+      moveToOutput bin "$dev"
     ''
 
     # fixup .pc file (where to find 'moc' etc.)
@@ -350,10 +382,7 @@ stdenv.mkDerivation {
       fixDarwinDylibNames_rpath "QtConcurrent" "QtPrintSupport" "QtCore" "QtSql" "QtDBus" "QtTest" "QtGui" "QtWidgets" "QtNetwork" "QtXml" "QtOpenGL"
     '';
 
-  inherit lndir;
-  setupHook = if stdenv.isDarwin
-              then ../../qtbase-setup-hook-darwin.sh
-              else ../../qtbase-setup-hook.sh;
+  setupHook = ../hooks/qtbase-setup-hook.sh;
 
   meta = with lib; {
     homepage = http://www.qt.io;
diff --git a/pkgs/development/libraries/qt-5/modules/qtcharts.nix b/pkgs/development/libraries/qt-5/modules/qtcharts.nix
new file mode 100644
index 00000000000..84d3a17ea8c
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtcharts.nix
@@ -0,0 +1,7 @@
+{ qtModule, qtbase, qtdeclarative }:
+
+qtModule {
+  name = "qtcharts";
+  qtInputs = [ qtbase qtdeclarative ];
+  outputs = [ "out" "dev" "bin" ];
+}
diff --git a/pkgs/development/libraries/qt-5/modules/qtconnectivity.nix b/pkgs/development/libraries/qt-5/modules/qtconnectivity.nix
new file mode 100644
index 00000000000..d866edb052b
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtconnectivity.nix
@@ -0,0 +1,8 @@
+{ qtModule, qtbase, qtdeclarative, bluez }:
+
+qtModule {
+  name = "qtconnectivity";
+  qtInputs = [ qtbase qtdeclarative ];
+  buildInputs = [ bluez ];
+  outputs = [ "out" "dev" "bin" ];
+}
diff --git a/pkgs/development/libraries/qt-5/modules/qtdeclarative.nix b/pkgs/development/libraries/qt-5/modules/qtdeclarative.nix
new file mode 100644
index 00000000000..fc0a751f48a
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtdeclarative.nix
@@ -0,0 +1,25 @@
+{ qtModule, lib, python2, qtbase, qtsvg, qtxmlpatterns }:
+
+with lib;
+
+qtModule {
+  name = "qtdeclarative";
+  qtInputs = [ qtbase qtsvg qtxmlpatterns ];
+  nativeBuildInputs = [ python2 ];
+  outputs = [ "out" "dev" "bin" ];
+  preConfigure = ''
+    NIX_CFLAGS_COMPILE+=" -DNIXPKGS_QML2_IMPORT_PREFIX=\"$qtQmlPrefix\""
+  '';
+  devTools = [
+    "bin/qml"
+    "bin/qmlcachegen"
+    "bin/qmleasing"
+    "bin/qmlimportscanner"
+    "bin/qmllint"
+    "bin/qmlmin"
+    "bin/qmlplugindump"
+    "bin/qmlprofiler"
+    "bin/qmlscene"
+    "bin/qmltestrunner"
+  ];
+}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtdoc.nix b/pkgs/development/libraries/qt-5/modules/qtdoc.nix
index 7f979ee94c0..10623962c43 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtdoc.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtdoc.nix
@@ -1,6 +1,6 @@
-{ qtSubmodule, qtdeclarative }:
+{ qtModule, qtdeclarative }:
 
-qtSubmodule {
+qtModule {
   name = "qtdoc";
   qtInputs = [ qtdeclarative ];
   outputs = [ "out" ];
diff --git a/pkgs/development/libraries/qt-5/5.9/qtgraphicaleffects.nix b/pkgs/development/libraries/qt-5/modules/qtgraphicaleffects.nix
index 3273f12eb83..888f627baab 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtgraphicaleffects.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtgraphicaleffects.nix
@@ -1,6 +1,7 @@
-{ qtSubmodule, qtdeclarative }:
+{ qtModule, qtdeclarative }:
 
-qtSubmodule {
+qtModule {
   name = "qtgraphicaleffects";
   qtInputs = [ qtdeclarative ];
+  outputs = [ "out" ];
 }
diff --git a/pkgs/development/libraries/qt-5/5.9/qtimageformats.nix b/pkgs/development/libraries/qt-5/modules/qtimageformats.nix
index 03d0fffbe80..1a7726070be 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtimageformats.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtimageformats.nix
@@ -1,6 +1,6 @@
-{ qtSubmodule, qtbase }:
+{ qtModule, qtbase }:
 
-qtSubmodule {
+qtModule {
   name = "qtimageformats";
   qtInputs = [ qtbase ];
 }
diff --git a/pkgs/development/libraries/qt-5/modules/qtlocation.nix b/pkgs/development/libraries/qt-5/modules/qtlocation.nix
new file mode 100644
index 00000000000..008583ebaf9
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtlocation.nix
@@ -0,0 +1,9 @@
+{ qtModule, qtbase, qtmultimedia }:
+
+qtModule {
+  name = "qtlocation";
+  qtInputs = [ qtbase qtmultimedia ];
+  outputs = [ "bin" "out" "dev" ];
+  # Linking with -lclipper fails with parallel build enabled
+  enableParallelBuilding = false;
+}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtmacextras.nix b/pkgs/development/libraries/qt-5/modules/qtmacextras.nix
index 582294cc7f7..5a3b1fe35cd 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtmacextras.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtmacextras.nix
@@ -1,6 +1,6 @@
-{ qtSubmodule, qtbase, lib }:
+{ qtModule, qtbase, lib }:
 
-qtSubmodule {
+qtModule {
   name = "qtmacextras";
   qtInputs = [ qtbase ];
   meta = with lib; {
diff --git a/pkgs/development/libraries/qt-5/5.9/qtmultimedia.nix b/pkgs/development/libraries/qt-5/modules/qtmultimedia.nix
index 1c728b036ad..1b7a7c1fcea 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtmultimedia.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtmultimedia.nix
@@ -1,11 +1,11 @@
-{ stdenv, qtSubmodule, qtbase, qtdeclarative, pkgconfig
+{ qtModule, stdenv, qtbase, qtdeclarative, pkgconfig
 , alsaLib, gstreamer, gst-plugins-base, libpulseaudio
 , darwin
 }:
 
 with stdenv.lib;
 
-qtSubmodule {
+qtModule {
   name = "qtmultimedia";
   qtInputs = [ qtbase qtdeclarative ];
   nativeBuildInputs = [ pkgconfig ];
@@ -14,8 +14,4 @@ qtSubmodule {
   outputs = [ "bin" "dev" "out" ];
   qmakeFlags = [ "GST_VERSION=1.0" ];
   NIX_LDFLAGS = optionalString (stdenv.isDarwin) "-lobjc";
-  postInstall = ''
-    moveToOutput "$qtPluginPrefix" "$bin"
-    moveToOutput "$qtQmlPrefix" "$bin"
-  '';
 }
diff --git a/pkgs/development/libraries/qt-5/5.9/qtquickcontrols.nix b/pkgs/development/libraries/qt-5/modules/qtquickcontrols.nix
index 93a864621b8..ba0f20bc0d8 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtquickcontrols.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtquickcontrols.nix
@@ -1,6 +1,6 @@
-{ qtSubmodule, qtdeclarative }:
+{ qtModule, qtdeclarative }:
 
-qtSubmodule {
+qtModule {
   name = "qtquickcontrols";
   qtInputs = [ qtdeclarative ];
 }
diff --git a/pkgs/development/libraries/qt-5/modules/qtquickcontrols2.nix b/pkgs/development/libraries/qt-5/modules/qtquickcontrols2.nix
new file mode 100644
index 00000000000..a9522f4b1f0
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtquickcontrols2.nix
@@ -0,0 +1,7 @@
+{ qtModule, qtdeclarative }:
+
+qtModule {
+  name = "qtquickcontrols2";
+  qtInputs = [ qtdeclarative ];
+  outputs = [ "out" "dev" "bin" ];
+}
diff --git a/pkgs/development/libraries/qt-5/modules/qtscript.nix b/pkgs/development/libraries/qt-5/modules/qtscript.nix
new file mode 100644
index 00000000000..5a1a462a964
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtscript.nix
@@ -0,0 +1,6 @@
+{ qtModule, qtbase, qttools }:
+
+qtModule {
+  name = "qtscript";
+  qtInputs = [ qtbase qttools ];
+}
diff --git a/pkgs/development/libraries/qt-5/modules/qtsensors.nix b/pkgs/development/libraries/qt-5/modules/qtsensors.nix
new file mode 100644
index 00000000000..3b8732b6885
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtsensors.nix
@@ -0,0 +1,7 @@
+{ qtModule, qtbase, qtdeclarative }:
+
+qtModule {
+  name = "qtsensors";
+  qtInputs = [ qtbase qtdeclarative ];
+  outputs = [ "out" "dev" "bin" ];
+}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtserialport/default.nix b/pkgs/development/libraries/qt-5/modules/qtserialport.nix
index 925e8a808f2..2f8c142323d 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtserialport/default.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtserialport.nix
@@ -1,11 +1,10 @@
-{ stdenv, qtSubmodule, lib, copyPathsToStore, qtbase, substituteAll, systemd }:
+{ qtModule, stdenv, lib, qtbase, substituteAll, systemd }:
 
 let inherit (lib) getLib optional; in
 
-qtSubmodule {
+qtModule {
   name = "qtserialport";
   qtInputs = [ qtbase ];
-  patches =  copyPathsToStore (lib.readPathsFromFile ./. ./series);
   NIX_CFLAGS_COMPILE =
     optional stdenv.isLinux
     ''-DNIXPKGS_LIBUDEV="${getLib systemd}/lib/libudev"'';
diff --git a/pkgs/development/libraries/qt-5/modules/qtsvg.nix b/pkgs/development/libraries/qt-5/modules/qtsvg.nix
new file mode 100644
index 00000000000..3ce68e56e41
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtsvg.nix
@@ -0,0 +1,7 @@
+{ qtModule, qtbase }:
+
+qtModule {
+  name = "qtsvg";
+  qtInputs = [ qtbase ];
+  outputs = [ "out" "dev" "bin" ];
+}
diff --git a/pkgs/development/libraries/qt-5/modules/qttools.nix b/pkgs/development/libraries/qt-5/modules/qttools.nix
new file mode 100644
index 00000000000..ae6bd18cb14
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qttools.nix
@@ -0,0 +1,34 @@
+{ qtModule, lib, qtbase }:
+
+with lib;
+
+qtModule {
+  name = "qttools";
+  qtInputs = [ qtbase ];
+  outputs = [ "out" "dev" "bin" ];
+
+  # fixQtBuiltinPaths overwrites a builtin path we should keep
+  postPatch = ''
+    sed -i "src/linguist/linguist.pro" \
+        -e '/^cmake_linguist_config_version_file.input =/ s|$$\[QT_HOST_DATA.*\]|${getDev qtbase}|'
+  '';
+
+  devTools = [
+    "bin/qcollectiongenerator"
+    "bin/linguist"
+    "bin/assistant"
+    "bin/qdoc"
+    "bin/lconvert"
+    "bin/designer"
+    "bin/qtattributesscanner"
+    "bin/lrelease"
+    "bin/pixeltool"
+    "bin/lupdate"
+    "bin/qtdiag"
+    "bin/qhelpgenerator"
+    "bin/qtplugininfo"
+    "bin/qthelpconverter"
+  ];
+
+  setupHook = ../hooks/qttools-setup-hook.sh;
+}
diff --git a/pkgs/development/libraries/qt-5/5.9/qttranslations.nix b/pkgs/development/libraries/qt-5/modules/qttranslations.nix
index 50fc8cf6826..11a6e3fedcb 100644
--- a/pkgs/development/libraries/qt-5/5.9/qttranslations.nix
+++ b/pkgs/development/libraries/qt-5/modules/qttranslations.nix
@@ -1,6 +1,6 @@
-{ qtSubmodule, qttools }:
+{ qtModule, qttools }:
 
-qtSubmodule {
+qtModule {
   name = "qttranslations";
   qtInputs = [ qttools ];
 }
diff --git a/pkgs/development/libraries/qt-5/modules/qtwayland.nix b/pkgs/development/libraries/qt-5/modules/qtwayland.nix
new file mode 100644
index 00000000000..c7a7704f283
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtwayland.nix
@@ -0,0 +1,9 @@
+{ qtModule, qtbase, qtquickcontrols, wayland, pkgconfig }:
+
+qtModule {
+  name = "qtwayland";
+  qtInputs = [ qtbase qtquickcontrols ];
+  buildInputs = [ wayland ];
+  nativeBuildInputs = [ pkgconfig ];
+  outputs = [ "out" "dev" "bin" ];
+}
diff --git a/pkgs/development/libraries/qt-5/modules/qtwebchannel.nix b/pkgs/development/libraries/qt-5/modules/qtwebchannel.nix
new file mode 100644
index 00000000000..84fb88385a3
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtwebchannel.nix
@@ -0,0 +1,8 @@
+{ qtModule, qtbase, qtdeclarative }:
+
+qtModule {
+  name = "qtwebchannel";
+  qtInputs = [ qtbase qtdeclarative ];
+  outputs = [ "out" "dev" "bin" ];
+}
+
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwebengine/default.nix b/pkgs/development/libraries/qt-5/modules/qtwebengine.nix
index 58716f65738..4be72b08784 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtwebengine/default.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtwebengine.nix
@@ -1,4 +1,5 @@
-{ qtSubmodule, qtquickcontrols, qtlocation, qtwebchannel
+{ qtModule, qtCompatVersion,
+  qtdeclarative, qtquickcontrols, qtlocation, qtwebchannel
 
 , bison, coreutils, flex, git, gperf, ninja, pkgconfig, python2, which
 
@@ -18,9 +19,11 @@
 
 with stdenv.lib;
 
-qtSubmodule {
+let qt56 = qtCompatVersion == "5.6"; in
+
+qtModule {
   name = "qtwebengine";
-  qtInputs = [ qtquickcontrols qtlocation qtwebchannel ];
+  qtInputs = [ qtdeclarative qtquickcontrols qtlocation qtwebchannel ];
   nativeBuildInputs = [
     bison coreutils flex git gperf ninja pkgconfig python2 which
   ];
@@ -38,9 +41,9 @@ qtSubmodule {
     + ''
       substituteInPlace ./src/3rdparty/chromium/build/common.gypi \
         --replace /bin/echo ${coreutils}/bin/echo
-      substituteInPlace ./src/3rdparty/chromium/v8/gypfiles/toolchain.gypi \
+      substituteInPlace ./src/3rdparty/chromium/v8/${if qt56 then "build" else "gypfiles"}/toolchain.gypi \
         --replace /bin/echo ${coreutils}/bin/echo
-      substituteInPlace ./src/3rdparty/chromium/v8/gypfiles/standalone.gypi \
+      substituteInPlace ./src/3rdparty/chromium/v8/${if qt56 then "build" else "gypfiles"}/standalone.gypi \
         --replace /bin/echo ${coreutils}/bin/echo
     ''
     # Patch library paths in Qt sources
@@ -62,6 +65,10 @@ qtSubmodule {
 
   preConfigure = ''
     export MAKEFLAGS=-j$NIX_BUILD_CORES
+
+    if [ -d "$PWD/tools/qmake" ]; then
+        QMAKEPATH="$PWD/tools/qmake''${QMAKEPATH:+:}$QMAKEPATH"
+    fi
  '';
 
   qmakeFlags =
@@ -99,7 +106,6 @@ qtSubmodule {
     xlibs.xrandr libXScrnSaver libXcursor libXrandr xlibs.libpciaccess libXtst
     xlibs.libXcomposite
   ];
-  patches = optional stdenv.needsPax ./qtwebengine-paxmark-mksnapshot.patch;
 
   dontUseNinjaBuild = true;
   dontUseNinjaInstall = true;
@@ -111,7 +117,5 @@ qtSubmodule {
     EOF
 
     paxmark m $out/libexec/QtWebEngineProcess
-
-    moveToOutput "$qtQmlPrefix" "$bin"
   '';
 }
diff --git a/pkgs/development/libraries/qt-5/5.9/qtwebkit/default.nix b/pkgs/development/libraries/qt-5/modules/qtwebkit.nix
index 664281aac31..4dce9c4e22e 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtwebkit/default.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtwebkit.nix
@@ -1,5 +1,5 @@
-{ qtSubmodule, stdenv, copyPathsToStore, lib
-, qtdeclarative, qtlocation, qtsensors
+{ qtModule, stdenv, lib
+, qtbase, qtdeclarative, qtlocation, qtsensors
 , fontconfig, gdk_pixbuf, gtk2, libwebp, libxml2, libxslt
 , sqlite, systemd, glib, gst_all_1
 , bison2, flex, gdb, gperf, perl, pkgconfig, python2, ruby
@@ -10,9 +10,9 @@
 
 let inherit (lib) optional optionals getLib; in
 
-qtSubmodule {
+qtModule {
   name = "qtwebkit";
-  qtInputs = [ qtdeclarative qtlocation qtsensors ];
+  qtInputs = [ qtbase qtdeclarative qtlocation qtsensors ];
   buildInputs = [ fontconfig libwebp libxml2 libxslt sqlite glib gst_all_1.gstreamer gst_all_1.gst-plugins-base ]
     ++ optionals (stdenv.isDarwin) (with darwin.apple_sdk.frameworks; [ OpenGL ]);
   nativeBuildInputs = [
@@ -23,7 +23,12 @@ qtSubmodule {
     "/usr/lib/libicucore.dylib"
   ];
 
-  patches =  copyPathsToStore (lib.readPathsFromFile ./. ./series);
+  # QtWebKit overrides qmake's default_pre and default_post features,
+  # so its custom qmake files must be found first at the front of QMAKEPATH.
+  preConfigure = ''
+    QMAKEPATH="$PWD/Tools/qmake''${QMAKEPATH:+:}$QMAKEPATH"
+    fixQtBuiltinPaths . '*.pr?'
+  '';
 
   NIX_CFLAGS_COMPILE =
     optionals flashplayerFix
diff --git a/pkgs/development/libraries/qt-5/modules/qtwebsockets.nix b/pkgs/development/libraries/qt-5/modules/qtwebsockets.nix
new file mode 100644
index 00000000000..ad5e7625f28
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtwebsockets.nix
@@ -0,0 +1,7 @@
+{ qtModule, qtbase, qtdeclarative }:
+
+qtModule {
+  name = "qtwebsockets";
+  qtInputs = [ qtbase qtdeclarative ];
+  outputs = [ "out" "dev" "bin" ];
+}
diff --git a/pkgs/development/libraries/qt-5/5.9/qtx11extras.nix b/pkgs/development/libraries/qt-5/modules/qtx11extras.nix
index a765161e2d7..4d431fee278 100644
--- a/pkgs/development/libraries/qt-5/5.9/qtx11extras.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtx11extras.nix
@@ -1,6 +1,6 @@
-{ qtSubmodule, qtbase }:
+{ qtModule, qtbase }:
 
-qtSubmodule {
+qtModule {
   name = "qtx11extras";
   qtInputs = [ qtbase ];
 }
diff --git a/pkgs/development/libraries/qt-5/modules/qtxmlpatterns.nix b/pkgs/development/libraries/qt-5/modules/qtxmlpatterns.nix
new file mode 100644
index 00000000000..ee8ef617fc8
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/modules/qtxmlpatterns.nix
@@ -0,0 +1,7 @@
+{ qtModule, qtbase }:
+
+qtModule {
+  name = "qtxmlpatterns";
+  qtInputs = [ qtbase ];
+  devTools = [ "bin/xmlpatterns" "bin/xmlpatternsvalidator" ];
+}
diff --git a/pkgs/development/libraries/qt-5/qmake-hook.sh b/pkgs/development/libraries/qt-5/qmake-hook.sh
deleted file mode 100644
index c70410975ec..00000000000
--- a/pkgs/development/libraries/qt-5/qmake-hook.sh
+++ /dev/null
@@ -1,47 +0,0 @@
-qmakeConfigurePhase() {
-    runHook preConfigure
-
-    qmake PREFIX=$out $qmakeFlags
-
-    runHook postConfigure
-}
-
-if [ -z "$dontUseQmakeConfigure" -a -z "$configurePhase" ]; then
-    configurePhase=qmakeConfigurePhase
-fi
-
-_qtModuleMultioutDevsPre() {
-    # We cannot simply set these paths in configureFlags because libQtCore retains
-    # references to the paths it was built with.
-    moveToOutput "bin" "${!outputDev}"
-    moveToOutput "include" "${!outputDev}"
-
-    # The destination directory must exist or moveToOutput will do nothing
-    mkdir -p "${!outputDev}/share"
-    moveToOutput "share/doc" "${!outputDev}"
-}
-
-_qtModuleMultioutDevsPost() {
-    local -a findopts=(-name '*.a' -o -name '*.la')
-    if [ -z "@isDarwin@" ]; then
-        findopts+=(-o -name '*.prl')
-    fi
-
-    # Move libtool archives and qmake project files to $dev/lib
-    if [ "z${!outputLib}" != "z${!outputDev}" ]; then
-        pushd "${!outputLib}"
-        if [ -d "lib" ]; then
-            find lib \( "${findopts[@]}" \) -print0 | \
-                while read -r -d $'\0' file; do
-                    mkdir -p "${!outputDev}/$(dirname "$file")"
-                    mv "${!outputLib}/$file" "${!outputDev}/$file"
-                done
-        fi
-        popd
-    fi
-}
-
-if [ -n "$NIX_QT_SUBMODULE" ]; then
-    preFixupHooks+=(_qtModuleMultioutDevsPre)
-    postFixupHooks+=(_qtModuleMultioutDevsPost)
-fi
diff --git a/pkgs/development/libraries/qt-5/qtModule.nix b/pkgs/development/libraries/qt-5/qtModule.nix
new file mode 100644
index 00000000000..11e4ae1c26c
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/qtModule.nix
@@ -0,0 +1,59 @@
+{ lib, mkDerivation, perl }:
+
+let inherit (lib) licenses maintainers platforms; in
+
+{ self, srcs, patches }:
+
+args:
+
+let
+  inherit (args) name;
+  version = args.version or srcs."${name}".version;
+  src = args.src or srcs."${name}".src;
+in
+
+mkDerivation (args // {
+  name = "${name}-${version}";
+  inherit src;
+  patches = args.patches or patches."${name}" or [];
+
+  nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ perl self.qmake ];
+  propagatedBuildInputs = args.qtInputs ++ (args.propagatedBuildInputs or []);
+
+  outputs = args.outputs or [ "out" "dev" ];
+  setOutputFlags = args.setOutputFlags or false;
+
+  preHook = ''
+    . ${./hooks/move-qt-dev-tools.sh}
+    . ${./hooks/fix-qt-builtin-paths.sh}
+  '';
+
+  preConfigure = ''
+    ${args.preConfigure or ""}
+
+    fixQtBuiltinPaths . '*.pr?'
+  '';
+
+  postFixup = ''
+    if [ -d "''${!outputDev}/lib/pkgconfig" ]; then
+        find "''${!outputDev}/lib/pkgconfig" -name '*.pc' | while read pc; do
+            sed -i "$pc" \
+                -e "/^prefix=/ c prefix=''${!outputLib}" \
+                -e "/^exec_prefix=/ c exec_prefix=''${!outputBin}" \
+                -e "/^includedir=/ c includedir=''${!outputDev}/include"
+        done
+    fi
+
+    moveQtDevTools
+
+    ${args.postFixup or ""}
+  '';
+
+  meta = {
+    homepage = http://www.qt.io;
+    description = "A cross-platform application framework for C++";
+    license = with licenses; [ fdl13 gpl2 lgpl21 lgpl3 ];
+    maintainers = with maintainers; [ qknight ttuegel periklis ];
+    platforms = platforms.unix;
+  } // (args.meta or {});
+})
diff --git a/pkgs/development/libraries/qt-5/qtbase-setup-hook-darwin.sh b/pkgs/development/libraries/qt-5/qtbase-setup-hook-darwin.sh
deleted file mode 100644
index ce1dada0c47..00000000000
--- a/pkgs/development/libraries/qt-5/qtbase-setup-hook-darwin.sh
+++ /dev/null
@@ -1,192 +0,0 @@
-qtPluginPrefix=@qtPluginPrefix@
-qtQmlPrefix=@qtQmlPrefix@
-qtDocPrefix=@qtDocPrefix@
-
-_qtRmCMakeLink() {
-    find "${!outputLib}" -name "*.cmake" -type l | xargs rm
-}
-
-postInstallHooks+=(_qtRmCMakeLink)
-
-addToSearchPathOnceWithCustomDelimiter() {
-    local delim="$1"
-    local search="$2"
-    local target="$3"
-    local dirs
-    local exported
-    IFS="$delim" read -a dirs <<< "${!search}"
-    local canonical
-    if canonical=$(readlink -e "$target"); then
-        for dir in ${dirs[@]}; do
-            if [ "z$dir" == "z$canonical" ]; then exported=1; fi
-        done
-        if [ -z $exported ]; then
-            eval "export ${search}=\"${!search}${!search:+$delim}$canonical\""
-        fi
-    fi
-}
-
-addToSearchPathOnce() {
-    addToSearchPathOnceWithCustomDelimiter ':' "$@"
-}
-
-propagateOnce() {
-    addToSearchPathOnceWithCustomDelimiter ' ' "$@"
-}
-
-_qtPropagate() {
-    for dir in $qtPluginPrefix $qtQmlPrefix; do
-        if [ -d "$1/$dir" ]; then
-            propagateOnce propagatedBuildInputs "$1"
-            break
-        fi
-    done
-    addToSearchPathOnce QT_PLUGIN_PATH "$1/$qtPluginPrefix"
-    addToSearchPathOnce QML2_IMPORT_PATH "$1/$qtQmlPrefix"
-}
-
-crossEnvHooks+=(_qtPropagate)
-
-_qtPropagateNative() {
-    for dir in $qtPluginPrefix $qtQmlPrefix; do
-        if [ -d "$1/$dir" ]; then
-            propagateOnce propagatedNativeBuildInputs "$1"
-            break
-        fi
-    done
-    if [ -z "$crossConfig" ]; then
-    addToSearchPathOnce QT_PLUGIN_PATH "$1/$qtPluginPrefix"
-    addToSearchPathOnce QML2_IMPORT_PATH "$1/$qtQmlPrefix"
-    fi
-}
-
-envHooks+=(_qtPropagateNative)
-
-_qtMultioutDevs() {
-    # This is necessary whether the package is a Qt module or not
-    moveToOutput "mkspecs" "${!outputDev}"
-}
-
-preFixupHooks+=(_qtMultioutDevs)
-
-_qtSetCMakePrefix() {
-    export CMAKE_PREFIX_PATH="$NIX_QT5_TMP${CMAKE_PREFIX_PATH:+:}${CMAKE_PREFIX_PATH}"
-}
-
-_qtRmTmp() {
-    if [ -z "$NIX_QT_SUBMODULE" ]; then
-        rm -fr "$NIX_QT5_TMP"
-    else
-        cat "$NIX_QT5_TMP/nix-support/qt-inputs" | while read file; do
-            if [ ! -d "$NIX_QT5_TMP/$file" ]; then
-                rm -f "$NIX_QT5_TMP/$file"
-            fi
-        done
-
-        cat "$NIX_QT5_TMP/nix-support/qt-inputs" | while read dir; do
-            if [ -d "$NIX_QT5_TMP/$dir" ]; then
-                rmdir --ignore-fail-on-non-empty -p "$NIX_QT5_TMP/$dir"
-            fi
-        done
-
-        rm "$NIX_QT5_TMP/nix-support/qt-inputs"
-    fi
-}
-
-_qtSetQmakePath() {
-    export PATH="$NIX_QT5_TMP/bin${PATH:+:}$PATH"
-}
-
-if [ -z "$NIX_QT5_TMP" ]; then
-    if [ -z "$NIX_QT_SUBMODULE" ]; then
-        NIX_QT5_TMP=$(pwd)/.nix_qt5
-    else
-        NIX_QT5_TMP=$out
-    fi
-    postInstallHooks+=(_qtRmTmp)
-
-    mkdir -p "$NIX_QT5_TMP/nix-support"
-    for subdir in bin include mkspecs share; do
-        mkdir -p "$NIX_QT5_TMP/$subdir"
-        echo "$subdir/" >> "$NIX_QT5_TMP/nix-support/qt-inputs"
-    done
-    mkdir -p "$NIX_QT5_TMP/lib"
-
-    postHooks+=(_qtSetCMakePrefix)
-
-    ln -sf "@dev@/bin/qmake" "$NIX_QT5_TMP/bin"
-    echo "bin/qmake" >> "$NIX_QT5_TMP/nix-support/qt-inputs"
-
-    cat >"$NIX_QT5_TMP/bin/qt.conf" <<EOF
-[Paths]
-Prefix = $NIX_QT5_TMP
-Plugins = $qtPluginPrefix
-Qml2Imports = $qtQmlPrefix
-Documentation = $qtDocPrefix
-EOF
-    echo "bin/qt.conf" >> "$NIX_QT5_TMP/nix-support/qt-inputs"
-
-    export QMAKE="$NIX_QT5_TMP/bin/qmake"
-
-    # Set PATH to find qmake first in a preConfigure hook
-    # It must run after all the envHooks!
-    preConfigureHooks+=(_qtSetQmakePath)
-fi
-
-qt5LinkModuleDir() {
-    if [ -d "$1/$2" ]; then
-        @lndir@/bin/lndir -silent "$1/$2" "$NIX_QT5_TMP/$2"
-        find "$1/$2" -printf "$2/%P\n" >> "$NIX_QT5_TMP/nix-support/qt-inputs"
-    fi
-}
-
-qt5LinkDarwinModuleLibDir() {
-  for fw in $(find "$1"/lib -maxdepth 1 -name '*.framework'); do
-    if [ ! -L "$fw" ]; then
-      ln -s "$fw" "$NIX_QT5_TMP"/lib
-    fi
-  done
-  for file in $(find "$1"/lib -maxdepth 1 -type f); do
-    if [ ! -L "$file" ]; then
-      ln -s "$file" "$NIX_QT5_TMP"/lib
-    fi
-  done
-  for dir in $(find "$1"/lib -maxdepth 1 -mindepth 1 -type d ! -name '*.framework'); do
-      mkdir -p "$NIX_QT5_TMP"/lib/$(basename "$dir")
-      @lndir@/bin/lndir -silent "$dir" "$NIX_QT5_TMP"/lib/$(basename "$dir")
-  done
-}
-
-NIX_QT5_MODULES="${NIX_QT5_MODULES}${NIX_QT5_MODULES:+:}@out@"
-NIX_QT5_MODULES_DEV="${NIX_QT5_MODULES_DEV}${NIX_QT5_MODULES_DEV:+:}@dev@"
-
-_qtLinkAllModules() {
-    IFS=: read -a modules <<< $NIX_QT5_MODULES
-    for module in ${modules[@]}; do
-        qt5LinkDarwinModuleLibDir "$module"
-    done
-
-    IFS=: read -a modules <<< $NIX_QT5_MODULES_DEV
-    for module in ${modules[@]}; do
-        qt5LinkModuleDir "$module" "bin"
-        qt5LinkModuleDir "$module" "include"
-        qt5LinkDarwinModuleLibDir "$module"
-        qt5LinkModuleDir "$module" "mkspecs"
-        qt5LinkModuleDir "$module" "share"
-    done
-}
-
-preConfigureHooks+=(_qtLinkAllModules)
-
-_qtFixCMakePaths() {
-    find "${!outputLib}" -name "*.cmake" | while read file; do
-        substituteInPlace "$file" \
-            --subst-var-by NIX_OUT "${!outputLib}" \
-            --subst-var-by NIX_DEV "${!outputDev}" \
-            --subst-var-by NIX_BIN "${!outputBin}"
-    done
-}
-
-if [ -n "$NIX_QT_SUBMODULE" ]; then
-    postInstallHooks+=(_qtFixCMakePaths)
-fi
diff --git a/pkgs/development/libraries/qt-5/qtbase-setup-hook.sh b/pkgs/development/libraries/qt-5/qtbase-setup-hook.sh
deleted file mode 100644
index e4ef456bf97..00000000000
--- a/pkgs/development/libraries/qt-5/qtbase-setup-hook.sh
+++ /dev/null
@@ -1,155 +0,0 @@
-qtPluginPrefix=@qtPluginPrefix@
-qtQmlPrefix=@qtQmlPrefix@
-qtDocPrefix=@qtDocPrefix@
-
-NIX_QT5_MODULES="${NIX_QT5_MODULES}${NIX_QT5_MODULES:+:}@out@"
-NIX_QT5_MODULES_DEV="${NIX_QT5_MODULES_DEV}${NIX_QT5_MODULES_DEV:+:}@dev@"
-
-providesQtRuntime() {
-    [ -d "$1/$qtPluginPrefix" ] || [ -d "$1/$qtQmlPrefix" ]
-}
-
-# Propagate any runtime dependency of the building package.
-# Each dependency is propagated to the user environment and as a build
-# input so that it will be re-propagated to the user environment by any
-# package depending on the building package. (This is necessary in case
-# the building package does not provide runtime dependencies itself and so
-# would not be propagated to the user environment.)
-_qtCrossEnvHook() {
-    if providesQtRuntime "$1"; then
-        propagatedBuildInputs+=" $1"
-        propagatedUserEnvPkgs+=" $1"
-    fi
-}
-if [ -z "$NIX_QT5_TMP" ]; then
-    crossEnvHooks+=(_qtCrossEnvHook)
-fi
-
-_qtEnvHook() {
-    if providesQtRuntime "$1"; then
-        propagatedNativeBuildInputs+=" $1"
-        if [ -z "$crossConfig" ]; then
-        propagatedUserEnvPkgs+=" $1"
-        fi
-    fi
-}
-if [ -z "$NIX_QT5_TMP" ]; then
-    envHooks+=(_qtEnvHook)
-fi
-
-_qtPreFixupHook() {
-    moveToOutput "mkspecs" "${!outputDev}"
-}
-if [ -z "$NIX_QT5_TMP" ]; then
-    preFixupHooks+=(_qtPreFixupHook)
-fi
-
-_qtPostInstallHook() {
-    # Clean up temporary installation files created by this setup hook.
-    # For building Qt modules, this is necessary to prevent including
-    # dependencies in the output. For all other packages, this is necessary
-    # to induce patchelf to remove the temporary paths from the RPATH of
-    # dynamically-linked objects.
-    if [ -z "$NIX_QT_SUBMODULE" ]; then
-        rm -fr "$NIX_QT5_TMP"
-    else
-        cat "$NIX_QT5_TMP/nix-support/qt-inputs" | while read file; do
-            if [ ! -d "$NIX_QT5_TMP/$file" ]; then
-                rm -f "$NIX_QT5_TMP/$file"
-            fi
-        done
-
-        cat "$NIX_QT5_TMP/nix-support/qt-inputs" | while read dir; do
-            if [ -d "$NIX_QT5_TMP/$dir" ]; then
-                rmdir --ignore-fail-on-non-empty -p "$NIX_QT5_TMP/$dir"
-            fi
-        done
-
-        rm "$NIX_QT5_TMP/nix-support/qt-inputs"
-    fi
-
-    # Patch CMake modules
-    if [ -n "$NIX_QT_SUBMODULE" ]; then
-        find "${!outputLib}" -name "*.cmake" | while read file; do
-            substituteInPlace "$file" \
-                --subst-var-by NIX_OUT "${!outputLib}" \
-                --subst-var-by NIX_DEV "${!outputDev}" \
-                --subst-var-by NIX_BIN "${!outputBin}"
-        done
-    fi
-}
-if [ -z "$NIX_QT5_TMP" ]; then
-    preConfigureHooks+=(_qtPreConfigureHook)
-fi
-
-_qtLinkModuleDir() {
-    if [ -d "$1/$2" ]; then
-        @lndir@/bin/lndir -silent "$1/$2" "$NIX_QT5_TMP/$2"
-        find "$1/$2" -printf "$2/%P\n" >> "$NIX_QT5_TMP/nix-support/qt-inputs"
-    fi
-}
-
-_qtPreConfigureHook() {
-    # Find the temporary qmake executable first.
-    # This must run after all the environment hooks!
-    export PATH="$NIX_QT5_TMP/bin${PATH:+:}$PATH"
-
-    # Link all runtime module dependencies into the temporary directory.
-    IFS=: read -a modules <<< $NIX_QT5_MODULES
-    for module in ${modules[@]}; do
-        _qtLinkModuleDir "$module" "lib"
-    done
-
-    # Link all the build-time module dependencies into the temporary directory.
-    IFS=: read -a modules <<< $NIX_QT5_MODULES_DEV
-    for module in ${modules[@]}; do
-        _qtLinkModuleDir "$module" "bin"
-        _qtLinkModuleDir "$module" "include"
-        _qtLinkModuleDir "$module" "lib"
-        _qtLinkModuleDir "$module" "mkspecs"
-        _qtLinkModuleDir "$module" "share"
-    done
-}
-if [ -z "$NIX_QT5_TMP" ]; then
-    postInstallHooks+=(_qtPostInstallHook)
-fi
-
-if [ -z "$NIX_QT5_TMP" ]; then
-    if [ -z "$NIX_QT_SUBMODULE" ]; then
-        if [ -z "$IN_NIX_SHELL" ]; then
-            NIX_QT5_TMP=$(pwd)/__nix_qt5__
-        else
-            NIX_QT5_TMP=$(mktemp -d)
-        fi
-    else
-        NIX_QT5_TMP=$out
-    fi
-
-    mkdir -p "$NIX_QT5_TMP/nix-support"
-    for subdir in bin include lib mkspecs share; do
-        mkdir -p "$NIX_QT5_TMP/$subdir"
-        echo "$subdir/" >> "$NIX_QT5_TMP/nix-support/qt-inputs"
-    done
-
-    cp "@dev@/bin/qmake" "$NIX_QT5_TMP/bin"
-    echo "bin/qmake" >> "$NIX_QT5_TMP/nix-support/qt-inputs"
-
-    cat >"$NIX_QT5_TMP/bin/qt.conf" <<EOF
-[Paths]
-Prefix = $NIX_QT5_TMP
-Plugins = $qtPluginPrefix
-Qml2Imports = $qtQmlPrefix
-Documentation = $qtDocPrefix
-EOF
-    echo "bin/qt.conf" >> "$NIX_QT5_TMP/nix-support/qt-inputs"
-
-    export QMAKE="$NIX_QT5_TMP/bin/qmake"
-fi
-
-_qtShellCleanupHook () {
-    rm -fr $NIX_QT5_TMP
-}
-
-if [ -n "$IN_NIX_SHELL" ]; then
-    trap _qtShellCleanupHook EXIT
-fi
diff --git a/pkgs/development/libraries/qt-5/qtsubmodule-setup-hook.sh b/pkgs/development/libraries/qt-5/qtsubmodule-setup-hook.sh
deleted file mode 100644
index e41433c1138..00000000000
--- a/pkgs/development/libraries/qt-5/qtsubmodule-setup-hook.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-NIX_QT5_MODULES="${NIX_QT5_MODULES}${NIX_QT5_MODULES:+:}@out@"
-NIX_QT5_MODULES_DEV="${NIX_QT5_MODULES_DEV}${NIX_QT5_MODULES_DEV:+:}@dev@"