Skip to content

Commit

Permalink
qt6.wrapQtAppsHook: add qtwayland to propagatedBuildInputs (#352419)
Browse files Browse the repository at this point in the history
  • Loading branch information
K900 authored Nov 7, 2024
2 parents b2a0e31 + c8aec3b commit 2f696cb
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
8 changes: 5 additions & 3 deletions doc/languages-frameworks/qt.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 0 additions & 2 deletions pkgs/applications/graphics/pineapple-pictures/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
, stdenv
, fetchFromGitHub
, qtsvg
, qtwayland
, qttools
, exiv2
, wrapQtAppsHook
Expand All @@ -28,7 +27,6 @@ stdenv.mkDerivation (finalAttrs: {

buildInputs = [
qtsvg
qtwayland
exiv2
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [
cmake
pkg-config
qt6Packages.wrapQtAppsHook
qt6Packages.wrapQtAppsNoGuiHook
];

buildInputs = [
Expand Down
29 changes: 28 additions & 1 deletion pkgs/development/libraries/qt-6/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
, fetchpatch2
, makeSetupHook
, makeWrapper
, runCommand
, gst_all_1
, libglvnd
, darwin
Expand Down Expand Up @@ -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
{

Expand Down Expand Up @@ -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)
{ };

Expand Down
7 changes: 5 additions & 2 deletions pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 7 additions & 1 deletion pkgs/development/libraries/qt-6/modules/qtwayland.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ qtModule
{ lib
, qtModule
, qtbase
, qtdeclarative
, wayland
Expand All @@ -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;
};
}

0 comments on commit 2f696cb

Please sign in to comment.