1 # Qt {#sec-language-qt}
3 Writing Nix expressions for Qt libraries and applications is largely similar as for other C++ software.
4 This section assumes some knowledge of the latter.
6 The major caveat with Qt applications is that Qt uses a plugin system to load additional modules at runtime.
7 In Nixpkgs, we wrap Qt applications to inject environment variables telling Qt where to discover the required plugins and QML modules.
9 This effectively makes the runtime dependencies pure and explicit at build-time, at the cost of introducing
12 ## Nix expression for a Qt package (default.nix) {#qt-default-nix}
21 buildInputs = [ qt6.qtbase ];
22 nativeBuildInputs = [ qt6.wrapQtAppsHook ];
26 The same goes for Qt 5 where libraries and tools are under `libsForQt5`.
28 Any Qt package should include `wrapQtAppsHook` or `wrapQtAppsNoGuiHook` in `nativeBuildInputs`, or explicitly set `dontWrapQtApps` to bypass generating the wrappers.
32 `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.
34 `wrapQtAppsNoGuiHook` does not propagate `qtwayland` to reduce closure size for purely command-line applications.
38 ## Packages supporting multiple Qt versions {#qt-versions}
40 If your package is a library that can be built with multiple Qt versions, you may want to take Qt modules as separate arguments (`qtbase`, `qtdeclarative` etc.), and invoke the package from `pkgs/top-level/qt5-packages.nix` or `pkgs/top-level/qt6-packages.nix` using the respective `callPackage` functions.
42 Applications should generally be built with upstream's preferred Qt version.
44 ## Locating additional runtime dependencies {#qt-runtime-dependencies}
46 Add entries to `qtWrapperArgs` are to modify the wrappers created by
54 nativeBuildInputs = [ qt6.wrapQtAppsHook ];
55 qtWrapperArgs = [ ''--prefix PATH : /path/to/bin'' ];
59 The entries are passed as arguments to [wrapProgram](#fun-wrapProgram).
61 If you need more control over the wrapping process, set `dontWrapQtApps` to disable automatic wrapper generation,
62 and then create wrappers manually in `fixupPhase`, using `wrapQtApp`, which itself is a small wrapper over [wrapProgram](#fun-wrapProgram):
64 The `makeWrapper` arguments required for Qt are also exposed in the environment as `$qtWrapperArgs`.
67 { stdenv, lib, wrapQtAppsHook }:
71 nativeBuildInputs = [ wrapQtAppsHook ];
72 dontWrapQtApps = true;
74 wrapQtApp "$out/bin/myapp" --prefix PATH : /path/to/bin
80 `wrapQtAppsHook` ignores files that are non-ELF executables.
81 This means that scripts won't be automatically wrapped so you'll need to manually wrap them as previously mentioned.
82 An example of when you'd always need to do this is with Python applications that use PyQt.