diff --git a/doc/languages-frameworks/qt.section.md b/doc/languages-frameworks/qt.section.md index dcec4b6fff42..9b3d1e054a62 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` 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` to reduce closure size for purely command-line applications. + ::: ## Packages supporting multiple Qt versions {#qt-versions} 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 ]; 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 = [ diff --git a/pkgs/development/libraries/qt-6/default.nix b/pkgs/development/libraries/qt-6/default.nix index d306c3e430da..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,10 +174,27 @@ let qtwebview = callPackage ./modules/qtwebview.nix { }; wrapQtAppsHook = callPackage - ({ makeBinaryWrapper }: makeSetupHook + ({ makeBinaryWrapper, qtwayland, qtbase }: + makeSetupHook { name = "wrap-qt6-apps-hook"; propagatedBuildInputs = [ makeBinaryWrapper ]; + depsTargetTargetPropagated = [ + (onlyPluginsAndQml qtbase) + ] ++ lib.optionals (lib.meta.availableOn stdenv.targetPlatform qtwayland) [ + (onlyPluginsAndQml qtwayland) + ]; + } ./hooks/wrap-qt-apps-hook.sh) + { }; + + wrapQtAppsNoGuiHook = callPackage + ({ makeBinaryWrapper, qtbase }: makeSetupHook + { + name = "wrap-qt6-apps-no-gui-hook"; + propagatedBuildInputs = [ makeBinaryWrapper ]; + depsTargetTargetPropagated = [ + (onlyPluginsAndQml qtbase) + ]; } ./hooks/wrap-qt-apps-hook.sh) { }; 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..48beac0b04fa 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,12 @@ 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: 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 } 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; + }; }