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.
5 There are two problems that the Nixpkgs Qt infrastructure addresses,
6 which are not shared by other C++ software:
8 1. There are usually multiple supported versions of Qt in Nixpkgs.
9 All of a package's dependencies must be built with the same version of Qt.
10 This is similar to the version constraints imposed on interpreted languages like Python.
11 2. Qt makes extensive use of runtime dependency detection.
12 Runtime dependencies are made into build dependencies through wrappers.
14 ## Nix expression for a Qt package (default.nix) {#qt-default-nix}
18 { stdenv, lib, qtbase, wrapQtAppsHook }: <co xml:id='qt-default-nix-co-1' />
24 buildInputs = [ qtbase ];
25 nativeBuildInputs = [ wrapQtAppsHook ]; <co xml:id='qt-default-nix-co-2' />
30 <callout arearefs='qt-default-nix-co-1'>
32 Import Qt modules directly, that is: <literal>qtbase</literal>, <literal>qtdeclarative</literal>, etc.
33 <emphasis>Do not</emphasis> import Qt package sets such as <literal>qt5</literal>
34 because the Qt versions of dependencies may not be coherent, causing build and runtime failures.
37 <callout arearefs='qt-default-nix-co-2'>
39 All Qt packages must include <literal>wrapQtAppsHook</literal> in
40 <literal>nativeBuildInputs</literal>, or you must explicitly set
41 <literal>dontWrapQtApps</literal>.
47 ## Locating runtime dependencies {#qt-runtime-dependencies}
49 Qt applications must be wrapped to find runtime dependencies.
50 Include `wrapQtAppsHook` in `nativeBuildInputs`:
53 { stdenv, wrapQtAppsHook }:
57 nativeBuildInputs = [ wrapQtAppsHook ];
61 Add entries to `qtWrapperArgs` are to modify the wrappers created by
65 { stdenv, wrapQtAppsHook }:
69 nativeBuildInputs = [ wrapQtAppsHook ];
70 qtWrapperArgs = [ ''--prefix PATH : /path/to/bin'' ];
74 The entries are passed as arguments to [wrapProgram](#fun-wrapProgram).
76 Set `dontWrapQtApps` to stop applications from being wrapped automatically.
77 Wrap programs manually with `wrapQtApp`, using the syntax of
78 [wrapProgram](#fun-wrapProgram):
81 { stdenv, lib, wrapQtAppsHook }:
85 nativeBuildInputs = [ wrapQtAppsHook ];
86 dontWrapQtApps = true;
88 wrapQtApp "$out/bin/myapp" --prefix PATH : /path/to/bin
94 `wrapQtAppsHook` ignores files that are non-ELF executables.
95 This means that scripts won't be automatically wrapped so you'll need to manually wrap them as previously mentioned.
96 An example of when you'd always need to do this is with Python applications that use PyQt.
99 ## Adding a library to Nixpkgs {#adding-a-library-to-nixpkgs}
101 Add Qt libraries to `qt5-packages.nix` to make them available for every
102 supported Qt version.
104 ### Example adding a Qt library {#qt-library-all-packages-nix}
106 The following represents the contents of `qt5-packages.nix`.
112 mylib = callPackage ../path/to/mylib {};
118 Libraries are built with every available version of Qt.
119 Use the `meta.broken` attribute to disable the package for unsupported Qt versions:
122 { stdenv, lib, qtbase }:
124 stdenv.mkDerivation {
126 # Disable this library with Qt < 5.9.0
127 meta.broken = lib.versionOlder qtbase.version "5.9.0";
131 ## Adding an application to Nixpkgs {#adding-an-application-to-nixpkgs}
133 Add Qt applications to `qt5-packages.nix`. Add an alias to `all-packages.nix`
134 to select the Qt 5 version used for the application.
136 ### Example adding a Qt application {#qt-application-all-packages-nix}
138 The following represents the contents of `qt5-packages.nix`.
144 myapp = callPackage ../path/to/myapp {};
150 The following represents the contents of `all-packages.nix`.
156 myapp = libsForQt5.myapp;