From ae4fd669e4a5be2038fde3519dce1d79f450be0c Mon Sep 17 00:00:00 2001 From: rewine Date: Mon, 11 Mar 2024 00:34:35 +0800 Subject: [PATCH 1/9] qt6.wrapQtAppsHook: add `qtwayland` to `propagatedBuildInputs` qtwayland client side is the wayland platform plugin, provides a way to run Qt applications as Wayland clients without this, Qt applications only work on x11/xwayland Co-authored-by: Artturin --- pkgs/development/libraries/qt-6/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/qt-6/default.nix b/pkgs/development/libraries/qt-6/default.nix index d306c3e430da..036b4d6eea70 100644 --- a/pkgs/development/libraries/qt-6/default.nix +++ b/pkgs/development/libraries/qt-6/default.nix @@ -164,10 +164,11 @@ let qtwebview = callPackage ./modules/qtwebview.nix { }; wrapQtAppsHook = callPackage - ({ makeBinaryWrapper }: makeSetupHook + ({ makeBinaryWrapper, qtwayland }: makeSetupHook { name = "wrap-qt6-apps-hook"; propagatedBuildInputs = [ makeBinaryWrapper ]; + depsTargetTargetPropagated = lib.optionals stdenv.isLinux [ qtwayland.out ]; } ./hooks/wrap-qt-apps-hook.sh) { }; From b7cd0d3c885afc3e087ea54ed568baaee0bee7ce Mon Sep 17 00:00:00 2001 From: rewine Date: Mon, 11 Mar 2024 00:37:09 +0800 Subject: [PATCH 2/9] qt6.wrapQtAppsNoGuiHook: init Unlike wrapQtAppsHook, wrapQtAppsNoGuiHook does not propagate qtwayland, to reduce closure size for CLI or other non-GUI applications. Co-authored-by: eclairevoyant --- pkgs/development/libraries/qt-6/default.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkgs/development/libraries/qt-6/default.nix b/pkgs/development/libraries/qt-6/default.nix index 036b4d6eea70..34774144f876 100644 --- a/pkgs/development/libraries/qt-6/default.nix +++ b/pkgs/development/libraries/qt-6/default.nix @@ -172,6 +172,14 @@ let } ./hooks/wrap-qt-apps-hook.sh) { }; + wrapQtAppsNoGuiHook = callPackage + ({ makeBinaryWrapper }: makeSetupHook + { + name = "wrap-qt6-apps-no-gui-hook"; + propagatedBuildInputs = [ makeBinaryWrapper ]; + } ./hooks/wrap-qt-apps-hook.sh) + { }; + qmake = callPackage ({ qtbase }: makeSetupHook { From f542c493ada97abfc785a33bf2eb61b7516f2b52 Mon Sep 17 00:00:00 2001 From: rewine Date: Mon, 11 Mar 2024 01:18:59 +0800 Subject: [PATCH 3/9] qt6.qtwayland: set meta.{platforms,badPlatforms} --- pkgs/development/libraries/qt-6/default.nix | 2 +- pkgs/development/libraries/qt-6/modules/qtwayland.nix | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/qt-6/default.nix b/pkgs/development/libraries/qt-6/default.nix index 34774144f876..b9d3c0e56ced 100644 --- a/pkgs/development/libraries/qt-6/default.nix +++ b/pkgs/development/libraries/qt-6/default.nix @@ -168,7 +168,7 @@ let { name = "wrap-qt6-apps-hook"; propagatedBuildInputs = [ makeBinaryWrapper ]; - depsTargetTargetPropagated = lib.optionals stdenv.isLinux [ qtwayland.out ]; + depsTargetTargetPropagated = lib.optionals (lib.meta.availableOn stdenv.targetPlatform qtwayland) [ qtwayland.out ]; } ./hooks/wrap-qt-apps-hook.sh) { }; diff --git a/pkgs/development/libraries/qt-6/modules/qtwayland.nix b/pkgs/development/libraries/qt-6/modules/qtwayland.nix index 54346345e4e3..d3d55685f5fb 100644 --- a/pkgs/development/libraries/qt-6/modules/qtwayland.nix +++ b/pkgs/development/libraries/qt-6/modules/qtwayland.nix @@ -1,4 +1,5 @@ -{ qtModule +{ lib +, qtModule , qtbase , qtdeclarative , wayland @@ -22,4 +23,9 @@ qtModule { postPatch = '' cp ${wayland-scanner}/share/wayland/wayland.xml src/3rdparty/protocol/wayland/wayland.xml ''; + + meta = { + platforms = lib.platforms.unix; + badPlatforms = lib.platforms.darwin; + }; } From ff6a0848ca8066e21fd2a64167cf3a002ea39a13 Mon Sep 17 00:00:00 2001 From: Artturin Date: Tue, 5 Nov 2024 23:20:31 +0200 Subject: [PATCH 4/9] qt6.wrapQtAppsHook: Only propagate plugins,qml of `qtwayland` qt6.{wrapQtAppsHook,wrapQtAppsNoGuiHook}: propagate `qtbase` plugins https://www.github.com/NixOS/nixpkgs/pull/352419#discussion_r1823132984 --- pkgs/development/libraries/qt-6/default.nix | 24 ++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pkgs/development/libraries/qt-6/default.nix b/pkgs/development/libraries/qt-6/default.nix index b9d3c0e56ced..a4aa9124c3b9 100644 --- a/pkgs/development/libraries/qt-6/default.nix +++ b/pkgs/development/libraries/qt-6/default.nix @@ -7,6 +7,7 @@ , fetchpatch2 , makeSetupHook , makeWrapper +, runCommand , gst_all_1 , libglvnd , darwin @@ -37,6 +38,15 @@ let apple-sdk_15 (darwinMinVersionHook "12.0") ]; + + onlyPluginsAndQml = drv: let + drv' = drv.__spliced.targetTarget or drv; + inherit (self.qtbase) qtPluginPrefix qtQmlPrefix; + in (runCommand "${drv'.name}-only-plugins-qml" { } '' + mkdir -p $(dirname "$out/${qtPluginPrefix}") + test -d "${drv'}/${qtPluginPrefix}" && ln -s "${drv'}/${qtPluginPrefix}" "$out/${qtPluginPrefix}" || true + test -d "${drv'}/${qtQmlPrefix}" && ln -s "${drv'}/${qtQmlPrefix}" "$out/${qtQmlPrefix}" || true + ''); in { @@ -164,19 +174,27 @@ let qtwebview = callPackage ./modules/qtwebview.nix { }; wrapQtAppsHook = callPackage - ({ makeBinaryWrapper, qtwayland }: makeSetupHook + ({ makeBinaryWrapper, qtwayland, qtbase }: + makeSetupHook { name = "wrap-qt6-apps-hook"; propagatedBuildInputs = [ makeBinaryWrapper ]; - depsTargetTargetPropagated = lib.optionals (lib.meta.availableOn stdenv.targetPlatform qtwayland) [ qtwayland.out ]; + depsTargetTargetPropagated = [ + (onlyPluginsAndQml qtbase) + ] ++ lib.optionals (lib.meta.availableOn stdenv.targetPlatform qtwayland) [ + (onlyPluginsAndQml qtwayland) + ]; } ./hooks/wrap-qt-apps-hook.sh) { }; wrapQtAppsNoGuiHook = callPackage - ({ makeBinaryWrapper }: makeSetupHook + ({ makeBinaryWrapper, qtbase }: makeSetupHook { name = "wrap-qt6-apps-no-gui-hook"; propagatedBuildInputs = [ makeBinaryWrapper ]; + depsTargetTargetPropagated = [ + (onlyPluginsAndQml qtbase) + ]; } ./hooks/wrap-qt-apps-hook.sh) { }; From 9501a2053937d1783e69d29d968014ceb388df12 Mon Sep 17 00:00:00 2001 From: rewine Date: Wed, 20 Mar 2024 20:03:22 +0800 Subject: [PATCH 5/9] qtbase-setup-hook: add wrapQtAppsNoGuiHook to error message Co-authored-by: eclairevoyant --- pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh b/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh index 1ccfbd0cba38..4057a3c67eed 100644 --- a/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh +++ b/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh @@ -75,9 +75,9 @@ else # Only set up Qt once. fi qtPreHook() { - # Check that wrapQtAppsHook is used, or it is explicitly disabled. + # Check that wrapQtAppsHook/wrapQtAppsNoGuiHook is used, or it is explicitly disabled. if [[ -z "$__nix_wrapQtAppsHook" && -z "$dontWrapQtApps" ]]; then - echo >&2 "Error: wrapQtAppsHook is not used, and dontWrapQtApps is not set." + echo >&2 "Error: neither wrapQtAppsHook nor wrapQtAppsNoGuiHook are used, and dontWrapQtApps is not set either." exit 1 fi } From a2d3be9d042eecca5eb45a40cf148c62613dcee9 Mon Sep 17 00:00:00 2001 From: rewine Date: Wed, 20 Mar 2024 20:20:19 +0800 Subject: [PATCH 6/9] deepin.dde-application-manager: use wrapQtAppsNoGuiHook to avoid propagating qtwayland Co-authored-by: eclairevoyant --- pkgs/desktops/deepin/core/dde-application-manager/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/desktops/deepin/core/dde-application-manager/default.nix b/pkgs/desktops/deepin/core/dde-application-manager/default.nix index 73b412d7e6da..d265cfdc6c06 100644 --- a/pkgs/desktops/deepin/core/dde-application-manager/default.nix +++ b/pkgs/desktops/deepin/core/dde-application-manager/default.nix @@ -22,7 +22,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake pkg-config - qt6Packages.wrapQtAppsHook + qt6Packages.wrapQtAppsNoGuiHook ]; buildInputs = [ From 89fd77165500d7488a89a84a78a1b7b1507d8e3e Mon Sep 17 00:00:00 2001 From: rewine Date: Wed, 20 Mar 2024 20:21:41 +0800 Subject: [PATCH 7/9] pineapple-pictures: let wrapQtAppsHook propagate qtwayland --- pkgs/applications/graphics/pineapple-pictures/default.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/applications/graphics/pineapple-pictures/default.nix b/pkgs/applications/graphics/pineapple-pictures/default.nix index 423ceaadc087..cb03e41704c5 100644 --- a/pkgs/applications/graphics/pineapple-pictures/default.nix +++ b/pkgs/applications/graphics/pineapple-pictures/default.nix @@ -2,7 +2,6 @@ , stdenv , fetchFromGitHub , qtsvg -, qtwayland , qttools , exiv2 , wrapQtAppsHook @@ -28,7 +27,6 @@ stdenv.mkDerivation (finalAttrs: { buildInputs = [ qtsvg - qtwayland exiv2 ]; From 98774a34c85a160386f0b8419364b8eb4867fcba Mon Sep 17 00:00:00 2001 From: rewine Date: Wed, 20 Mar 2024 20:00:13 +0800 Subject: [PATCH 8/9] doc/qt: Mention propagates and wrapQtAppsNoGuiHook Co-authored-by: eclairevoyant Co-authored-by: Artturin --- doc/languages-frameworks/qt.section.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/languages-frameworks/qt.section.md b/doc/languages-frameworks/qt.section.md index dcec4b6fff42..6da0d7b501e9 100644 --- a/doc/languages-frameworks/qt.section.md +++ b/doc/languages-frameworks/qt.section.md @@ -25,12 +25,14 @@ stdenv.mkDerivation { The same goes for Qt 5 where libraries and tools are under `libsForQt5`. -Any Qt package should include `wrapQtAppsHook` in `nativeBuildInputs`, or explicitly set `dontWrapQtApps` to bypass generating the wrappers. +Any Qt package should include `wrapQtAppsHook` or `wrapQtAppsNoGuiHook` in `nativeBuildInputs`, or explicitly set `dontWrapQtApps` to bypass generating the wrappers. ::: {.note} -Qt 6 graphical applications should also include `qtwayland` in `buildInputs` on Linux (but not on platforms e.g. Darwin, where `qtwayland` is not available), to ensure the Wayland platform plugin is available. -This may become default in the future, see [NixOS/nixpkgs#269674](https://github.com/NixOS/nixpkgs/pull/269674). +`wrapQtAppsHook` propagates plugins and QML components from `qtwayland` to ensure the Wayland platform plugin is available, which is required for graphical applications to run under Wayland on non-Qt based desktops. On platforms that do not support `qtwayland` (e.g. Darwin), only plugins `qtbase` will be propagated. + +`wrapQtAppsNoGuiHook` does not propagate `qtwayland` reduce closure size for purely command-line applications. + ::: ## Packages supporting multiple Qt versions {#qt-versions} From c8aec3b28a36121fce3a8ee71c7c64535e7f45e5 Mon Sep 17 00:00:00 2001 From: K900 Date: Thu, 7 Nov 2024 10:52:43 +0300 Subject: [PATCH 9/9] qt: editing pass on docs --- doc/languages-frameworks/qt.section.md | 4 ++-- pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/languages-frameworks/qt.section.md b/doc/languages-frameworks/qt.section.md index 6da0d7b501e9..9b3d1e054a62 100644 --- a/doc/languages-frameworks/qt.section.md +++ b/doc/languages-frameworks/qt.section.md @@ -29,9 +29,9 @@ Any Qt package should include `wrapQtAppsHook` or `wrapQtAppsNoGuiHook` in `nati ::: {.note} -`wrapQtAppsHook` propagates plugins and QML components from `qtwayland` to ensure the Wayland platform plugin is available, which is required for graphical applications to run under Wayland on non-Qt based desktops. On platforms that do not support `qtwayland` (e.g. Darwin), only plugins `qtbase` will be propagated. +`wrapQtAppsHook` propagates plugins and QML components from `qtwayland` on platforms that support it, to allow applications to act as native Wayland clients. It should be used for all graphical applications. -`wrapQtAppsNoGuiHook` does not propagate `qtwayland` reduce closure size for purely command-line applications. +`wrapQtAppsNoGuiHook` does not propagate `qtwayland` to reduce closure size for purely command-line applications. ::: diff --git a/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh b/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh index 4057a3c67eed..48beac0b04fa 100644 --- a/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh +++ b/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh @@ -77,7 +77,10 @@ else # Only set up Qt once. qtPreHook() { # Check that wrapQtAppsHook/wrapQtAppsNoGuiHook is used, or it is explicitly disabled. if [[ -z "$__nix_wrapQtAppsHook" && -z "$dontWrapQtApps" ]]; then - echo >&2 "Error: neither wrapQtAppsHook nor wrapQtAppsNoGuiHook are used, and dontWrapQtApps is not set either." + echo >&2 "Error: this derivation depends on qtbase, but no wrapping behavior was specified." + echo >&2 " - If this is a graphical application, add wrapQtAppsHook to nativeBuildInputs" + echo >&2 " - If this is a CLI application, add wrapQtAppsNoGuiHook to nativeBuildInputs" + echo >&2 " - If this is a library or you need custom wrapping logic, set dontWrapQtApps = true" exit 1 fi }