qt6.wrapQtAppsHook: add qtwayland to propagatedBuildInputs (#352419)

This commit is contained in:
K900 2024-11-07 23:05:46 +03:00 committed by GitHub
commit 2f696cb1e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 46 additions and 10 deletions

View File

@ -25,12 +25,14 @@ stdenv.mkDerivation {
The same goes for Qt 5 where libraries and tools are under `libsForQt5`. 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} ::: {.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} ## Packages supporting multiple Qt versions {#qt-versions}

View File

@ -2,7 +2,6 @@
, stdenv , stdenv
, fetchFromGitHub , fetchFromGitHub
, qtsvg , qtsvg
, qtwayland
, qttools , qttools
, exiv2 , exiv2
, wrapQtAppsHook , wrapQtAppsHook
@ -28,7 +27,6 @@ stdenv.mkDerivation (finalAttrs: {
buildInputs = [ buildInputs = [
qtsvg qtsvg
qtwayland
exiv2 exiv2
]; ];

View File

@ -22,7 +22,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ nativeBuildInputs = [
cmake cmake
pkg-config pkg-config
qt6Packages.wrapQtAppsHook qt6Packages.wrapQtAppsNoGuiHook
]; ];
buildInputs = [ buildInputs = [

View File

@ -7,6 +7,7 @@
, fetchpatch2 , fetchpatch2
, makeSetupHook , makeSetupHook
, makeWrapper , makeWrapper
, runCommand
, gst_all_1 , gst_all_1
, libglvnd , libglvnd
, darwin , darwin
@ -37,6 +38,15 @@ let
apple-sdk_15 apple-sdk_15
(darwinMinVersionHook "12.0") (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 in
{ {
@ -164,10 +174,27 @@ let
qtwebview = callPackage ./modules/qtwebview.nix { }; qtwebview = callPackage ./modules/qtwebview.nix { };
wrapQtAppsHook = callPackage wrapQtAppsHook = callPackage
({ makeBinaryWrapper }: makeSetupHook ({ makeBinaryWrapper, qtwayland, qtbase }:
makeSetupHook
{ {
name = "wrap-qt6-apps-hook"; name = "wrap-qt6-apps-hook";
propagatedBuildInputs = [ makeBinaryWrapper ]; 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) } ./hooks/wrap-qt-apps-hook.sh)
{ }; { };

View File

@ -75,9 +75,12 @@ else # Only set up Qt once.
fi fi
qtPreHook() { 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 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 exit 1
fi fi
} }

View File

@ -1,4 +1,5 @@
{ qtModule { lib
, qtModule
, qtbase , qtbase
, qtdeclarative , qtdeclarative
, wayland , wayland
@ -22,4 +23,9 @@ qtModule {
postPatch = '' postPatch = ''
cp ${wayland-scanner}/share/wayland/wayland.xml src/3rdparty/protocol/wayland/wayland.xml cp ${wayland-scanner}/share/wayland/wayland.xml src/3rdparty/protocol/wayland/wayland.xml
''; '';
meta = {
platforms = lib.platforms.unix;
badPlatforms = lib.platforms.darwin;
};
} }