Subject: [bug#57608] Upstreaming KDE Plasma and rest of packages

From: phodina <[email-masked]>
Date: Mon, 31 Oct 2022 07:42:47 +0000

Hi,

> 
> > Another issue is that Dolphin does not create/display thumbnails
> 
> 
> Is that Dolphin opened in GNOME desktop or in Plasma desktop?
> I am asking because Plasma Desktop fails to produce anything more
> than a black screen in the current state of the patches.

Well since Plasma is not yet running it's probably Dolphin in Gnome or other DE. Not sure why thumbnails are missing, but let's note issues about all the KDE programs.
 
> 
> I would also like to take this opportunity to share a couple of
> links related to the process of Plasma Desktop installation, which
> I found this week.
> 
> [Qt/KDE applications segfault on start due to stale qmlcache][1]
> [KDE Community page on kdesrc-build build-system][2]
> [Script to streamline setting up and maintaining KDE software][3]
> 
> I wish I could experiment with the KDESRC system, but I am still
> struggling with packaging a simple GNOME extension, so I am not
> ready for this.
> 
> [1]: https://github.com/NixOS/nixpkgs/issues/177720
> [2]: https://community.kde.org/Get_Involved/development#Building_software_with_kdesrc-build
> [3]: https://invent.kde.org/sdk/kdesrc-build

Thanks for the links. The issue is probably not in the KDESRC itself but in the Qt Framework.

I've been looking into Nix and they have additional patches. I managed to apply some of them.

But then the most needed  could not get to work (marked with ! in the commit).

Would somebody know how to port them into Guix?
It's mostly about CMake and QML. Which is what fails during the `kwin` and `plasma-workspace` build. Therefore they built but are broken when run.

----
Petr

From d35b2ca62f3fc89bf8121e8c1f412b482d90c868 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sun, 30 Oct 2022 14:09:40 +0100
Subject: [PATCH 2/8] gnu: qtbase-5: Apply patch qtbase-assert.patch.

* gnu/packages/qt.scm (qtbase-5)[source]: Apply qtbase-assert.patch.
* gnu/packages/patches/qtbase-assert.patch: New file.
* gnu/local.mk: Add patch.

diff --git a/gnu/local.mk b/gnu/local.mk
index 1d40cecad3..2e2218334a 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1750,6 +1750,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/qpdfview-qt515-compat.patch		\
   %D%/packages/patches/qrcodegen-cpp-make-install.patch		\
   %D%/packages/patches/qtbase-absolute-runpath.patch		\
+  %D%/packages/patches/qtbase-assert.patch		\
   %D%/packages/patches/qtbase-moc-ignore-gcc-macro.patch	\
   %D%/packages/patches/qtbase-use-TZDIR.patch			\
   %D%/packages/patches/qtscript-disable-tests.patch		\
diff --git a/gnu/packages/patches/qtbase-assert.patch b/gnu/packages/patches/qtbase-assert.patch
new file mode 100644
index 0000000000..2215cd8fa0
--- /dev/null
+++ b/gnu/packages/patches/qtbase-assert.patch
@@ -0,0 +1,33 @@
+From 015845b3c320d02691f28373097d1e6dbbac79f7 Mon Sep 17 00:00:00 2001
+From: Thomas Tuegel <[email-masked]>
+Date: Tue, 17 Sep 2019 05:37:04 -0500
+Subject: [PATCH 10/11] qtbase-assert
+
+---
+ src/testlib/qtestassert.h | 7 +++++--
+ 1 file changed, 5 insertions(+), 2 deletions(-)
+
+diff --git a/src/testlib/qtestassert.h b/src/testlib/qtestassert.h
+index 6498ea84ef..d821ced7fc 100644
+--- a/src/testlib/qtestassert.h
++++ b/src/testlib/qtestassert.h
+@@ -44,10 +44,13 @@
+ 
+ QT_BEGIN_NAMESPACE
+ 
+-
++#if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
++#define QTEST_ASSERT(cond) do { } while ((false) && (cond))
++#define QTEST_ASSERT_X(cond, where, what) do { } while ((false) && (cond))
++#else
+ #define QTEST_ASSERT(cond) do { if (!(cond)) qt_assert(#cond,__FILE__,__LINE__); } while (false)
+-
+ #define QTEST_ASSERT_X(cond, where, what) do { if (!(cond)) qt_assert_x(where, what,__FILE__,__LINE__); } while (false)
++#endif
+ 
+ QT_END_NAMESPACE
+ 
+-- 
+2.25.4
+
+
diff --git a/gnu/packages/qt.scm b/gnu/packages/qt.scm
index f46304241c..2a86506579 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -298,6 +298,7 @@ (define-public qtbase-5
                 "1p2fa94m1y8qzhdfi2d7dck93qh1lgsinibwl1wy92bwmacwfhhc"))
               ;; Use TZDIR to avoid depending on package "tzdata".
               (patches (search-patches "qtbase-use-TZDIR.patch"
+                                       "qtbase-assert.patch"
                                        "qtbase-moc-ignore-gcc-macro.patch"
                                        "qtbase-absolute-runpath.patch"))
               (modules '((guix build utils)))
-- 
2.37.2

From 93aab2cdacd879ecb8ae34fa0f6f6793d7c03536 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sun, 30 Oct 2022 14:29:42 +0100
Subject: [PATCH 4/8] gnu: qtbase-5: Apply qtbase-tbd-frameworks.patch.

* gnu/packages/qt.scm (qtbase-5)[source]: Apply qtbase-tbd-frameworks.patch.
* gnu/local.mk: Add patch.
* gnu/packages/patches/qtbase-tbd-frameworks.patch: New file.

diff --git a/gnu/local.mk b/gnu/local.mk
index 9a5b4643a3..9ddf179143 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1752,6 +1752,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/qtbase-absolute-runpath.patch		\
   %D%/packages/patches/qtbase-assert.patch		\
   %D%/packages/patches/qtbase-moc-ignore-gcc-macro.patch	\
+  %D%/packages/patches/qtbase-tbd-frameworks.patch		\
   %D%/packages/patches/qtbase-use-TZDIR.patch			\
   %D%/packages/patches/qtbase-xcursor.patch		\
   %D%/packages/patches/qtscript-disable-tests.patch		\
diff --git a/gnu/packages/patches/qtbase-tbd-frameworks.patch b/gnu/packages/patches/qtbase-tbd-frameworks.patch
new file mode 100644
index 0000000000..ba25d90747
--- /dev/null
+++ b/gnu/packages/patches/qtbase-tbd-frameworks.patch
@@ -0,0 +1,16 @@
+diff --git a/src/gui/Qt5GuiConfigExtras.cmake.in b/src/gui/Qt5GuiConfigExtras.cmake.in
+index 84dbbfebd4..615bfed124 100644
+--- a/src/gui/Qt5GuiConfigExtras.cmake.in
++++ b/src/gui/Qt5GuiConfigExtras.cmake.in
+@@ -119,6 +119,10 @@ macro(_qt5gui_find_extra_libs Name Libs LibDir IncDirs)
+             if (NOT EXISTS "${Qt5Gui_${_cmake_lib_name}_LIBRARY}")
+                 set(Qt5Gui_${_cmake_lib_name}_LIBRARY)
+             endif()
++            set(Qt5Gui_${_cmake_lib_name}_LIBRARY "${Qt5Gui_${_cmake_lib_name}_LIBRARY}/${_lib}.tbd")
++            if (NOT EXISTS "${Qt5Gui_${_cmake_lib_name}_LIBRARY}")
++                set(Qt5Gui_${_cmake_lib_name}_LIBRARY)
++            endif()
+ !!ENDIF
+             if (NOT Qt5Gui_${_cmake_lib_name}_LIBRARY)
+                 # The above find_library call doesn\'t work for finding
+
diff --git a/gnu/packages/qt.scm b/gnu/packages/qt.scm
index e4d8803655..957500aeb2 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -299,6 +299,7 @@ (define-public qtbase-5
               ;; Use TZDIR to avoid depending on package "tzdata".
               (patches (search-patches "qtbase-use-TZDIR.patch"
                                        "qtbase-assert.patch"
+                                       "qtbase-tbd-frameworks.patch"
                                        "qtbase-xcursor.patch"
                                        "qtbase-moc-ignore-gcc-macro.patch"
                                        "qtbase-absolute-runpath.patch"))
-- 
2.37.2

From 65f7ed2fdbd2d83de015d629630e86f7fe6ff3b7 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sun, 30 Oct 2022 14:22:31 +0100
Subject: [PATCH 1/8] gnu: plasma-workspace: Add xorg-server-for-tests in
 native-inputs.

* gnu/packages/kde-plasma.scm (plasma-workspace)[native-inputs]: Add
xorg-server-for-tests.
[arguments]: Launch xorg-server and use dbus to launch tests.

diff --git a/gnu/packages/kde-plasma.scm b/gnu/packages/kde-plasma.scm
index 76d80ba4be..c5d4b16761 100644
--- a/gnu/packages/kde-plasma.scm
+++ b/gnu/packages/kde-plasma.scm
@@ -2490,7 +2490,7 @@ (define-public plasma-workspace
                 "0pxwg3i07sipfchn4qkmlr6kcgqbhj2s10xq69wi32x1fc13jx5x"))))
     (build-system qt-build-system)
     (native-inputs (list extra-cmake-modules kdoctools pkg-config qtsvg-5
-                         qttools-5))
+                         qttools-5 xorg-server-for-tests))
     (inputs (list appmenu-gtk-module
                   appstream-qt
                   baloo
@@ -2610,11 +2610,12 @@ (define-public plasma-workspace
                                       (getcwd))
                               (setenv "QT_QPA_PLATFORM" "offscreen")
                               (setenv "QT_PLUGIN_PATH"
-                                      (string-append #$output
+                                      (string-append #$qtbase-5
                                                      "/lib/qt5/plugins:"
                                                      (getenv "QT_PLUGIN_PATH")))
-                              (invoke "ctest" "-E"
-                               "(appstreamtest|lookandfeel-kcmTest|tst_triangleFilter|systemtraymodeltest|testdesktop| screenpooltest)")))))))
+                              (system "Xvfb :1 -screen 0 640x480x24 &")
+                              (invoke "dbus-launch" "ctest"))))))) ;"-E")
+    ;; "(appstreamtest|lookandfeel-kcmTest|tst_triangleFilter|systemtraymodeltest|testdesktop| screenpooltest)")))))))
     (home-page "https://invent.kde.org/plasma/plasma-workspace")
     (synopsis "Plasma workspace components")
     (description
-- 
2.37.2

From 655d8440e56dfdd03c8b816f8f8446935bcfbc26 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sun, 30 Oct 2022 14:51:07 +0100
Subject: [PATCH 8/8] ! gnu: qtbase-5: Apply qtbase-fix-header_module.patch.

* gnu/packages/qt.scm (qtbase-5)[source]: Apply qtbase-fix-header_module.patch.
* gnu/local.mk: Add patch.
* gnu/packages/patches/qtbase-fix-header_module.patch: New file.

diff --git a/gnu/local.mk b/gnu/local.mk
index 8b6f0913d4..c5ca64e644 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1752,6 +1752,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/qtbase-absolute-runpath.patch		\
   %D%/packages/patches/qtbase-assert.patch		\
   %D%/packages/patches/qtbase-cmake.patch		\
+  %D%/packages/patches/qtbase-fix-header_module.patch	\
   %D%/packages/patches/qtbase-moc-ignore-gcc-macro.patch	\
   %D%/packages/patches/qtbase-qtpluginpath.patch		\
   %D%/packages/patches/qtbase-replace-libdir.patch		\
diff --git a/gnu/packages/patches/qtbase-fix-header_module.patch b/gnu/packages/patches/qtbase-fix-header_module.patch
new file mode 100644
index 0000000000..ed869244dc
--- /dev/null
+++ b/gnu/packages/patches/qtbase-fix-header_module.patch
@@ -0,0 +1,26 @@
+From 2bce8511877db1db532e1437e7140b1d55633f86 Mon Sep 17 00:00:00 2001
+From: Will Dietz <[email-masked]>
+Date: Mon, 30 Sep 2019 20:15:40 -0500
+Subject: [PATCH 11/11] fix header_module
+
+---
+ mkspecs/features/qt_module.prf | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/mkspecs/features/qt_module.prf b/mkspecs/features/qt_module.prf
+index b9e5d35026..9924271042 100644
+--- a/mkspecs/features/qt_module.prf
++++ b/mkspecs/features/qt_module.prf
+@@ -84,7 +84,7 @@ header_module {
+         CONFIG  += qt_no_install_library
+ 
+     # Allow creation of .prl, .la and .pc files.
+-    target.path = $$[QT_INSTALL_LIBS]
++    target.path = $$NIX_OUTPUT_OUT/lib
+     target.CONFIG += dummy_install
+     INSTALLS    += target
+ } else {
+-- 
+2.25.4
+
+
diff --git a/gnu/packages/qt.scm b/gnu/packages/qt.scm
index 47f0db985c..5bf2354f1d 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -300,6 +300,7 @@ (define-public qtbase-5
               (patches (search-patches "qtbase-use-TZDIR.patch"
                                        "qtbase-assert.patch"
                                        "qtbase-cmake.patch"
+                                       "qtbase-fix-header_module.patch"
                                        "qtbase-qtpluginpath.patch"
                                        "qtbase-replace-libdir.patch"
                                        "qtbase-tbd-frameworks.patch"
@@ -437,6 +438,10 @@ (define-public qtbase-5
            (substitute* '("mkspecs/features/qt_common.prf"
             "mkspecs/features/qt_module.prf") (("..NIX_OUTPUT_OUT") #$output))
 
+           ;; qtbase-fix-header_module.patch
+           (substitute* "mkspecs/features/qt_module.prf"
+            (("..NIX_OUTPUT_OUT") #$output))
+
            ;; qtbase-cmake.patch
            (substitute* (list
             "mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in"
-- 
2.37.2

From ac0e8f750999e9da6a52dc9e8ad7734fe3e11b26 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sun, 30 Oct 2022 14:32:41 +0100
Subject: [PATCH 5/8] gnu: qtbase-5: Apply qtbase-qtpluginpath.patch.

* gnu/packages/qt.scm (qtbase-5)[source]: Apply qtbase-qtpluginpath.patch.
* gnu/local.mk: Add patch.
* gnu/packages/patches/qtbase-qtpluginpath.patch: New file.

diff --git a/gnu/local.mk b/gnu/local.mk
index 9ddf179143..115afa6ba5 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1752,6 +1752,8 @@ dist_patch_DATA =						\
   %D%/packages/patches/qtbase-absolute-runpath.patch		\
   %D%/packages/patches/qtbase-assert.patch		\
   %D%/packages/patches/qtbase-moc-ignore-gcc-macro.patch	\
+  %D%/packages/patches/qtbase-qtpluginpath.patch		\
+  %D%/packages/patches/qtbase-replace-libdir.patch		\
   %D%/packages/patches/qtbase-tbd-frameworks.patch		\
   %D%/packages/patches/qtbase-use-TZDIR.patch			\
   %D%/packages/patches/qtbase-xcursor.patch		\
diff --git a/gnu/packages/patches/qtbase-qtpluginpath.patch b/gnu/packages/patches/qtbase-qtpluginpath.patch
new file mode 100644
index 0000000000..8d5f472999
--- /dev/null
+++ b/gnu/packages/patches/qtbase-qtpluginpath.patch
@@ -0,0 +1,34 @@
+From 9fc6efaf774a8716932c98c0b0ea6408ed2614c2 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Milan=20P=C3=A4ssler?= <[email-masked]>
+Date: Sun, 10 May 2020 12:47:28 +0200
+Subject: [PATCH 09/11] qtbase-qtpluginpath
+
+---
+ src/corelib/kernel/qcoreapplication.cpp | 10 ++++++++++
+ 1 file changed, 10 insertions(+)
+
+diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
+index 5fdcc9b914..1a126ef359 100644
+--- a/src/corelib/kernel/qcoreapplication.cpp
++++ b/src/corelib/kernel/qcoreapplication.cpp
+@@ -2691,6 +2691,16 @@ QStringList QCoreApplication::libraryPathsLocked()
+         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));
++            }
++        }
++
++
+         auto setPathsFromEnv = [&](QString libPathEnv) {
+             if (!libPathEnv.isEmpty()) {
+                 QStringList paths = libPathEnv.split(QDir::listSeparator(), Qt::SkipEmptyParts);
+-- 
+2.25.4
+
+
diff --git a/gnu/packages/patches/qtbase-replace-libdir.patch b/gnu/packages/patches/qtbase-replace-libdir.patch
new file mode 100644
index 0000000000..1d07d7d2d6
--- /dev/null
+++ b/gnu/packages/patches/qtbase-replace-libdir.patch
@@ -0,0 +1,69 @@
+From 30d3906ff5e8671e9c97c5336c6c549656c0e293 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Milan=20P=C3=A4ssler?= <[email-masked]>
+Date: Sat, 4 Apr 2020 00:27:41 +0200
+Subject: [PATCH 04/11] qtbase-replace-libdir
+
+---
+ mkspecs/features/qt_common.prf | 20 ++------------------
+ mkspecs/features/qt_module.prf |  5 +----
+ 2 files changed, 3 insertions(+), 22 deletions(-)
+
+diff --git a/mkspecs/features/qt_common.prf b/mkspecs/features/qt_common.prf
+index 8df94aa4ee..414029f31c 100644
+--- a/mkspecs/features/qt_common.prf
++++ b/mkspecs/features/qt_common.prf
+@@ -31,32 +31,16 @@ contains(TEMPLATE, .*lib)|contains(TEMPLATE, aux) {
+         rplbase = $$dirname(_QMAKE_SUPER_CACHE_)/[^/][^/]*
+     else: \
+         rplbase = $$MODULE_BASE_OUTDIR
+-    host_build {
+-        qqt_libdir = \$\$\$\$[QT_HOST_LIBS]
+-        qt_libdir = $$[QT_HOST_LIBS]
+-    } else {
+-        qqt_libdir = \$\$\$\$[QT_INSTALL_LIBS]
+-        qt_libdir = $$[QT_INSTALL_LIBS]
+-    }
++    qt_libdir = $$NIX_OUTPUT_OUT/lib
+     contains(QMAKE_DEFAULT_LIBDIRS, $$qt_libdir) {
+-        lib_replace0.match = $$rplbase/lib/
+-        lib_replace0.replace = $$qqt_libdir/
+-        lib_replace0.CONFIG = path
+-        QMAKE_PRL_INSTALL_REPLACE += lib_replace0
+         lib_replace.match = "[^ ']*$$rplbase/lib"
+         lib_replace.replace =
+     } else {
+         lib_replace.match = $$rplbase/lib
+-        lib_replace.replace = $$qqt_libdir
++        lib_replace.replace = $$qt_libdir
+     }
+     lib_replace.CONFIG = path
+     QMAKE_PRL_INSTALL_REPLACE += lib_replace
+-    !equals(qt_libdir, $$rplbase/lib) {
+-        qtlibdir_replace.match = $$qt_libdir
+-        qtlibdir_replace.replace = $$qqt_libdir
+-        qtlibdir_replace.CONFIG = path
+-        QMAKE_PRL_INSTALL_REPLACE += qtlibdir_replace
+-    }
+ }
+ contains(TEMPLATE, .*lib)|darwin {
+     if(!host_build|!cross_compile):qtConfig(reduce_exports): CONFIG += hide_symbols
+diff --git a/mkspecs/features/qt_module.prf b/mkspecs/features/qt_module.prf
+index 828a9621b9..b9e5d35026 100644
+--- a/mkspecs/features/qt_module.prf
++++ b/mkspecs/features/qt_module.prf
+@@ -305,10 +305,7 @@ load(qt_targets)
+ }
+ !lib_bundle:unix {
+     CONFIG += create_libtool
+-    host_build: \
+-        QMAKE_LIBTOOL_LIBDIR = $$[QT_HOST_LIBS]
+-    else: \
+-        QMAKE_LIBTOOL_LIBDIR = "=$$[QT_INSTALL_LIBS/raw]"
++    QMAKE_LIBTOOL_LIBDIR = $$NIX_OUTPUT_OUT/lib
+     !isEmpty(lib_replace0.match) {
+         ltlib_replace0.match = $$lib_replace0.match
+         ltlib_replace0.replace = $$QMAKE_LIBTOOL_LIBDIR/
+-- 
+2.25.4
+
+
diff --git a/gnu/packages/qt.scm b/gnu/packages/qt.scm
index 957500aeb2..9f2ca2254e 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -299,6 +299,8 @@ (define-public qtbase-5
               ;; Use TZDIR to avoid depending on package "tzdata".
               (patches (search-patches "qtbase-use-TZDIR.patch"
                                        "qtbase-assert.patch"
+                                       "qtbase-qtpluginpath.patch"
+                                       "qtbase-replace-libdir.patch"
                                        "qtbase-tbd-frameworks.patch"
                                        "qtbase-xcursor.patch"
                                        "qtbase-moc-ignore-gcc-macro.patch"
@@ -428,7 +430,15 @@ (define-public qtbase-5
            (lambda _
 		   ;; qtbase-xcursor.patch
 		   (substitute* "src/plugins/platforms/xcb/qxcbcursor.cpp"
-		   (("NIXPKGS_LIBXCURSOR") (string-append "\"" #$libxcursor "/lib\"")))))
+            (("NIXPKGS_LIBXCURSOR") (string-append "\"" #$libxcursor "/lib\"")))
+
+           ;; qtbase-replace-libdir.patch
+           (substitute* '("mkspecs/features/qt_common.prf"
+            "mkspecs/features/qt_module.prf") (("..NIX_OUTPUT_OUT") #$output))
+
+           ;; qtbase-qtpluginpath.patch
+           (substitute* "src/corelib/kernel/qcoreapplication.cpp"
+            (("NIXPKGS_QT_PLUGIN_PREFIX") (string-append "\"" #$output "/lib/qt5/qml\"")))))
          (add-after 'configure 'patch-bin-sh
            (lambda _
              (substitute* '("config.status"
-- 
2.37.2

From 70591a397a4388cec263941b9ec29ca4d4ea3126 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Mon, 31 Oct 2022 08:25:16 +0100
Subject: [PATCH 6/8] ! gnu: qtdeclarative-5: Apply qtdeclarative.patch.

* gnu/packages/qt.scm (qtdeclarative-5)[source]: Apply qtdeclarative.patch.
* gnu/local.mk: Add patch.
* gnu/packages/patches/qtbase-qtdeclarative.patch: New file.

diff --git a/gnu/local.mk b/gnu/local.mk
index 115afa6ba5..7f296ea980 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1757,6 +1757,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/qtbase-tbd-frameworks.patch		\
   %D%/packages/patches/qtbase-use-TZDIR.patch			\
   %D%/packages/patches/qtbase-xcursor.patch		\
+  %D%/packages/patches/qtdeclarative.patch		\
   %D%/packages/patches/qtscript-disable-tests.patch		\
   %D%/packages/patches/quagga-reproducible-build.patch          \
   %D%/packages/patches/quickswitch-fix-dmenu-check.patch	\
diff --git a/gnu/packages/patches/qtdeclarative.patch b/gnu/packages/patches/qtdeclarative.patch
new file mode 100644
index 0000000000..18d30db2b8
--- /dev/null
+++ b/gnu/packages/patches/qtdeclarative.patch
@@ -0,0 +1,115 @@
+diff --git a/src/particles/particles.pro b/src/particles/particles.pro
+index aaaa83419a..58aee00036 100644
+--- a/src/particles/particles.pro
++++ b/src/particles/particles.pro
+@@ -20,6 +20,6 @@ QMLTYPES_FILENAME = plugins.qmltypes
+ QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick/Particles.2
+ QML_IMPORT_NAME = QtQuick.Particles
+ IMPORT_VERSION = 2.$$QT_MINOR_VERSION
+-CONFIG += qmltypes install_qmltypes install_metatypes
++CONFIG += qmltypes install_qmltypes
+ 
+ load(qt_module)
+diff --git a/src/qml/qml.pro b/src/qml/qml.pro
+index e39a8319b6..90c0331278 100644
+--- a/src/qml/qml.pro
++++ b/src/qml/qml.pro
+@@ -72,6 +72,6 @@ QMLTYPES_FILENAME = plugins.qmltypes
+ QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQml
+ QML_IMPORT_NAME = QtQml
+ IMPORT_VERSION = 2.$$QT_MINOR_VERSION
+-CONFIG += qmltypes install_qmltypes install_metatypes
++CONFIG += qmltypes install_qmltypes
+ 
+ load(qt_module)
+diff --git a/src/qmlmodels/qmlmodels.pro b/src/qmlmodels/qmlmodels.pro
+index 4ac093556d..112e2c2be0 100644
+--- a/src/qmlmodels/qmlmodels.pro
++++ b/src/qmlmodels/qmlmodels.pro
+@@ -68,6 +68,6 @@ QMLTYPES_FILENAME = plugins.qmltypes
+ QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQml/Models.2
+ QML_IMPORT_NAME = QtQml.Models
+ IMPORT_VERSION = 2.$$QT_MINOR_VERSION
+-CONFIG += qmltypes install_qmltypes install_metatypes
++CONFIG += qmltypes install_qmltypes
+ 
+ load(qt_module)
+diff --git a/src/qmltest/qmltest.pro b/src/qmltest/qmltest.pro
+index c2e8068fc6..79dba368f7 100644
+--- a/src/qmltest/qmltest.pro
++++ b/src/qmltest/qmltest.pro
+@@ -34,7 +34,7 @@ QMLTYPES_FILENAME = plugins.qmltypes
+ QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/Qt/test/qtestroot
+ QML_IMPORT_NAME = Qt.test.qtestroot
+ QML_IMPORT_VERSION = 1.0
+-CONFIG += qmltypes install_qmltypes install_metatypes
++CONFIG += qmltypes install_qmltypes
+ 
+ # Install qmldir
+ qmldir.files = $$PWD/qmldir
+diff --git a/src/qmlworkerscript/qmlworkerscript.pro b/src/qmlworkerscript/qmlworkerscript.pro
+index 84466062e1..79885455cc 100644
+--- a/src/qmlworkerscript/qmlworkerscript.pro
++++ b/src/qmlworkerscript/qmlworkerscript.pro
+@@ -23,6 +23,6 @@ QMLTYPES_FILENAME = plugins.qmltypes
+ QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQml/WorkerScript.2
+ QML_IMPORT_NAME = QtQml.WorkerScript
+ IMPORT_VERSION = 2.$$QT_MINOR_VERSION
+-CONFIG += qmltypes install_qmltypes install_metatypes
++CONFIG += qmltypes install_qmltypes
+ 
+ load(qt_module)
+diff --git a/src/quick/quick.pro b/src/quick/quick.pro
+index f2d49cf939..c401b04c4e 100644
+--- a/src/quick/quick.pro
++++ b/src/quick/quick.pro
+@@ -52,4 +52,4 @@ QMLTYPES_FILENAME = plugins.qmltypes
+ QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick.2
+ QML_IMPORT_NAME = QtQuick
+ IMPORT_VERSION = 2.$$QT_MINOR_VERSION
+-CONFIG += qmltypes install_qmltypes install_metatypes
++CONFIG += qmltypes install_qmltypes
+diff --git a/src/quickshapes/quickshapes.pro b/src/quickshapes/quickshapes.pro
+index 4dbd3e5e46..0c6b186fc8 100644
+--- a/src/quickshapes/quickshapes.pro
++++ b/src/quickshapes/quickshapes.pro
+@@ -36,4 +36,4 @@ QMLTYPES_FILENAME = plugins.qmltypes
+ QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick/Shapes
+ QML_IMPORT_NAME = QtQuick.Shapes
+ IMPORT_VERSION = 1.$$QT_MINOR_VERSION
+-CONFIG += qmltypes install_qmltypes install_metatypes
++CONFIG += qmltypes install_qmltypes
+diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
+index 005db4248..685c5b1b2 100644
+--- a/src/qml/qml/qqmlimport.cpp
++++ b/src/qml/qml/qqmlimport.cpp
+@@ -1760,6 +1760,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 QString envImportPath = qEnvironmentVariable("QML2_IMPORT_PATH");
+diff --git a/tools/qmlcachegen/qmlcache.prf b/tools/qmlcachegen/qmlcache.prf
+index 537eaf62ea..e21de58f64 100644
+--- a/tools/qmlcachegen/qmlcache.prf
++++ b/tools/qmlcachegen/qmlcache.prf
+@@ -26,7 +26,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/gnu/packages/qt.scm b/gnu/packages/qt.scm
index 9f2ca2254e..1fb3fdae08 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -1112,12 +1112,22 @@ (define-public qtdeclarative-5
              (uri (qt-urls name version))
              (sha256
               (base32
-               "0ji5131g7h2mrgxw1wxc5mcvmsn3fbw64j28gzpa25gv3vcnkhaw"))))
+               "0ji5131g7h2mrgxw1wxc5mcvmsn3fbw64j28gzpa25gv3vcnkhaw"))
+             (patches (search-patches "qtdeclarative.patch"))))
     (arguments
      (substitute-keyword-arguments (package-arguments qtsvg-5)
        ((#:tests? _ #f) #f)             ;TODO: Enable the tests
        ((#:phases phases)
         #~(modify-phases #$phases
+           (add-after 'unpack 'fix-nix-patch
+		    (lambda* _
+                 ;; qtdeclarative.patch
+				 ; TODO: What should be the prefix??
+				 (substitute* "src/qml/qml/qqmlimport.cpp"
+				 (("NIXPKGS_QML2_IMPORT_PREFIX") ""))
+				 (substitute* "tools/qmlcachegen/qmlcache.prf"
+				 (("..NIX_OUTPUT_QML") (string-append #$output
+				 "/lib/qt5/qml/")))))
            (add-after 'build 'fix-qt5core-install-prefix
              (lambda* (#:key outputs #:allow-other-keys)
                  ;; The Qt5Core install prefix is set to qtbase, but qmlcachegen
-- 
2.37.2

From 899e966fad8afa41e9208877b25bbb1284453aa7 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sun, 30 Oct 2022 14:21:33 +0100
Subject: [PATCH 3/8] gnu: qtbase-5: Apply qtbase-xcursor.patch.

* gnu/packages/qt.scm (qtbase-5)[source]: Apply qtbase-xcursor.patch.
* gnu/packages/patches/qtbase-xcursor.patch: New file.
* gnu/local.mk: Add patch.

diff --git a/gnu/local.mk b/gnu/local.mk
index 2e2218334a..9a5b4643a3 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1753,6 +1753,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/qtbase-assert.patch		\
   %D%/packages/patches/qtbase-moc-ignore-gcc-macro.patch	\
   %D%/packages/patches/qtbase-use-TZDIR.patch			\
+  %D%/packages/patches/qtbase-xcursor.patch		\
   %D%/packages/patches/qtscript-disable-tests.patch		\
   %D%/packages/patches/quagga-reproducible-build.patch          \
   %D%/packages/patches/quickswitch-fix-dmenu-check.patch	\
diff --git a/gnu/packages/patches/qtbase-xcursor.patch b/gnu/packages/patches/qtbase-xcursor.patch
new file mode 100644
index 0000000000..42b25661a5
--- /dev/null
+++ b/gnu/packages/patches/qtbase-xcursor.patch
@@ -0,0 +1,30 @@
+From 707098eada20ba074e642a73248de74407bc261c Mon Sep 17 00:00:00 2001
+From: Thomas Tuegel <[email-masked]>
+Date: Tue, 17 Sep 2019 05:35:58 -0500
+Subject: [PATCH 07/11] qtbase-xcursor
+
+---
+ src/plugins/platforms/xcb/qxcbcursor.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/plugins/platforms/xcb/qxcbcursor.cpp b/src/plugins/platforms/xcb/qxcbcursor.cpp
+index 42c7a52bd4..ba670ddb44 100644
+--- a/src/plugins/platforms/xcb/qxcbcursor.cpp
++++ b/src/plugins/platforms/xcb/qxcbcursor.cpp
+@@ -317,10 +317,10 @@ QXcbCursor::QXcbCursor(QXcbConnection *conn, QXcbScreen *screen)
+ #if QT_CONFIG(xcb_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) {
+-- 
+2.25.4
+
+
diff --git a/gnu/packages/qt.scm b/gnu/packages/qt.scm
index 2a86506579..e4d8803655 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -299,6 +299,7 @@ (define-public qtbase-5
               ;; Use TZDIR to avoid depending on package "tzdata".
               (patches (search-patches "qtbase-use-TZDIR.patch"
                                        "qtbase-assert.patch"
+                                       "qtbase-xcursor.patch"
                                        "qtbase-moc-ignore-gcc-macro.patch"
                                        "qtbase-absolute-runpath.patch"))
               (modules '((guix build utils)))
@@ -422,6 +423,11 @@ (define-public qtbase-5
                "-no-mips_dspr2"))
        #:phases
        #~(modify-phases %standard-phases
+         (add-after 'unpack 'nixos-patches
+           (lambda _
+		   ;; qtbase-xcursor.patch
+		   (substitute* "src/plugins/platforms/xcb/qxcbcursor.cpp"
+		   (("NIXPKGS_LIBXCURSOR") (string-append "\"" #$libxcursor "/lib\"")))))
          (add-after 'configure 'patch-bin-sh
            (lambda _
              (substitute* '("config.status"
-- 
2.37.2

From 045e9ce66300d1cb8bc4d58610b4b1f63d859875 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Sun, 30 Oct 2022 14:47:39 +0100
Subject: [PATCH 7/8] ! gnu: qtbase-5: Apply qtbase-cmake.patch.

* gnu/packages/qt.scm (qtbase-5)[source]: Apply qtbase-cmake.patch.
* gnu/local.mk: Add patch.
* gnu/packages/patches/qtbase-cmake.patch: New file.

diff --git a/gnu/local.mk b/gnu/local.mk
index 7f296ea980..8b6f0913d4 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1751,6 +1751,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/qrcodegen-cpp-make-install.patch		\
   %D%/packages/patches/qtbase-absolute-runpath.patch		\
   %D%/packages/patches/qtbase-assert.patch		\
+  %D%/packages/patches/qtbase-cmake.patch		\
   %D%/packages/patches/qtbase-moc-ignore-gcc-macro.patch	\
   %D%/packages/patches/qtbase-qtpluginpath.patch		\
   %D%/packages/patches/qtbase-replace-libdir.patch		\
diff --git a/gnu/packages/patches/qtbase-cmake.patch b/gnu/packages/patches/qtbase-cmake.patch
new file mode 100644
index 0000000000..a83cb4a6cf
--- /dev/null
+++ b/gnu/packages/patches/qtbase-cmake.patch
@@ -0,0 +1,195 @@
+From 7871fbcefc7596a458cec005edafd9d4962baea3 Mon Sep 17 00:00:00 2001
+From: Thomas Tuegel <[email-masked]>
+Date: Tue, 17 Sep 2019 05:34:28 -0500
+Subject: [PATCH 05/11] qtbase-cmake
+
+---
+ mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in  |  2 +-
+ mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in |  4 ++--
+ src/corelib/Qt5CoreConfigExtras.cmake.in             | 10 +++++-----
+ src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in    |  2 +-
+ .../Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in  |  2 +-
+ src/dbus/Qt5DBusConfigExtras.cmake.in                | 12 ++----------
+ src/gui/Qt5GuiConfigExtras.cmake.in                  |  6 +++---
+ src/widgets/Qt5WidgetsConfigExtras.cmake.in          |  2 +-
+ 8 files changed, 16 insertions(+), 24 deletions(-)
+
+diff --git a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
+index b6c3ab8609..edb6a89316 100644
+--- a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
++++ b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
+@@ -574,7 +574,7 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+         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}\")
++        set(imported_location \"$$NIX_OUTPUT_DEV/${PLUGIN_LOCATION}\")
+ !!ELSE
+         set(imported_location \"$${CMAKE_PLUGIN_DIR}${PLUGIN_LOCATION}\")
+ !!ENDIF
+diff --git a/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in b/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
+index b550a52c60..dbd3243885 100644
+--- a/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
++++ b/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
+@@ -53,10 +53,10 @@ set_property(TARGET Qt5::$$CMAKE_PLUGIN_NAME PROPERTY INTERFACE_SOURCES
+ !!ENDIF
+ 
+ !!IF !isEmpty(CMAKE_RELEASE_TYPE)
+-_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME RELEASE \"$${CMAKE_PLUGIN_LOCATION_RELEASE}\" $${CMAKE_DEBUG_AND_RELEASE})
++_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME RELEASE \"$${CMAKE_PLUGIN_DIR}$${CMAKE_PLUGIN_LOCATION_RELEASE}\" $${CMAKE_DEBUG_AND_RELEASE})
+ !!ENDIF
+ !!IF !isEmpty(CMAKE_DEBUG_TYPE)
+-_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME DEBUG \"$${CMAKE_PLUGIN_LOCATION_DEBUG}\" $${CMAKE_DEBUG_AND_RELEASE})
++_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME DEBUG \"$${CMAKE_PLUGIN_DIR}$${CMAKE_PLUGIN_LOCATION_DEBUG}\" $${CMAKE_DEBUG_AND_RELEASE})
+ !!ENDIF
+ 
+ list(APPEND Qt5$${CMAKE_MODULE_NAME}_PLUGINS Qt5::$$CMAKE_PLUGIN_NAME)
+diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in
+index 4c1c3a612b..bb8ab08143 100644
+--- a/src/corelib/Qt5CoreConfigExtras.cmake.in
++++ b/src/corelib/Qt5CoreConfigExtras.cmake.in
+@@ -6,7 +6,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
+@@ -21,7 +21,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
+@@ -38,7 +38,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
+@@ -121,7 +121,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
+@@ -135,7 +135,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/dbus/Qt5DBusConfigExtras.cmake.in b/src/dbus/Qt5DBusConfigExtras.cmake.in
+index a814678f7b..b13b964ec8 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 84dbbfebd4..8ad0720c5c 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_OUT/$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
+ !!ELSE
+     set(imported_implib \"$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
+ !!ENDIF
+diff --git a/src/widgets/Qt5WidgetsConfigExtras.cmake.in b/src/widgets/Qt5WidgetsConfigExtras.cmake.in
+index 83d8004a08..ca0b8e4bfb 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
+-- 
+2.25.4
+
+
diff --git a/gnu/packages/qt.scm b/gnu/packages/qt.scm
index 1fb3fdae08..47f0db985c 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -299,6 +299,7 @@ (define-public qtbase-5
               ;; Use TZDIR to avoid depending on package "tzdata".
               (patches (search-patches "qtbase-use-TZDIR.patch"
                                        "qtbase-assert.patch"
+                                       "qtbase-cmake.patch"
                                        "qtbase-qtpluginpath.patch"
                                        "qtbase-replace-libdir.patch"
                                        "qtbase-tbd-frameworks.patch"
@@ -436,6 +437,19 @@ (define-public qtbase-5
            (substitute* '("mkspecs/features/qt_common.prf"
             "mkspecs/features/qt_module.prf") (("..NIX_OUTPUT_OUT") #$output))
 
+           ;; qtbase-cmake.patch
+           (substitute* (list
+            "mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in"
+            "mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in"
+            "src/corelib/Qt5CoreConfigExtras.cmake.in"
+            "src/corelib/Qt5CoreConfigExtrasMkspecDir.cmake.in"
+            "src/corelib/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in"
+            "src/dbus/Qt5DBusConfigExtras.cmake.in"
+            "src/gui/Qt5GuiConfigExtras.cmake.in"
+            "src/widgets/Qt5WidgetsConfigExtras.cmake.in")
+              (("..NIX_OUTPUT_OUT") #$output)
+              (("..NIX_OUTPUT_DEV") #$output))
+
            ;; qtbase-qtpluginpath.patch
            (substitute* "src/corelib/kernel/qcoreapplication.cpp"
             (("NIXPKGS_QT_PLUGIN_PREFIX") (string-append "\"" #$output "/lib/qt5/qml\"")))))
-- 
2.37.2