diff --git a/doc/languages-frameworks/qt.section.md b/doc/languages-frameworks/qt.section.md index 5dd415852c10..a35dbc56c1c1 100644 --- a/doc/languages-frameworks/qt.section.md +++ b/doc/languages-frameworks/qt.section.md @@ -1,77 +1,78 @@ # Qt {#sec-language-qt} -This section describes the differences between Nix expressions for Qt libraries and applications and Nix expressions for other C++ software. Some knowledge of the latter is assumed. +Writing Nix expressions for Qt libraries and applications is largely similar as for other C++ software. +This section assumes some knowledge of the latter. +There are two problems that the Nixpkgs Qt infrastructure addresses, +which are not shared by other C++ software: -There are primarily two problems which the Qt infrastructure is designed to address: ensuring consistent versioning of all dependencies and finding dependencies at runtime. +1. There are usually multiple supported versions of Qt in Nixpkgs. + All of a package's dependencies must be built with the same version of Qt. + This is similar to the version constraints imposed on interpreted languages like Python. +2. Qt makes extensive use of runtime dependency detection. + Runtime dependencies are made into build dependencies through wrappers. ## Nix expression for a Qt package (default.nix) {#qt-default-nix} ```{=docbook} -{ mkDerivation, qtbase }: +{ stdenv, lib, qtbase }: -mkDerivation { +stdenv.mkDerivation { pname = "myapp"; version = "1.0"; - buildInputs = [ qtbase ]; + buildInputs = [ qtbase ]; } - Import mkDerivation and Qt (such as qtbase modules directly. Do not import Qt package sets; the Qt versions of dependencies may not be coherent, causing build and runtime failures. - - - - - Use mkDerivation instead of stdenv.mkDerivation. mkDerivation is a wrapper around stdenv.mkDerivation which applies some Qt-specific settings. This deriver accepts the same arguments as stdenv.mkDerivation; refer to for details. - - - To use another deriver instead of stdenv.mkDerivation, use mkDerivationWith: - -mkDerivationWith myDeriver { - # ... -} - - If you cannot use mkDerivationWith, please refer to . - - - - - mkDerivation accepts the same arguments as stdenv.mkDerivation, such as buildInputs. + Import Qt modules directly, that is: qtbase, qtdeclarative, etc. + Do not import Qt package sets such as qt5 + because the Qt versions of dependencies may not be coherent, causing build and runtime failures. ``` ## Locating runtime dependencies {#qt-runtime-dependencies} -Qt applications need to be wrapped to find runtime dependencies. If you cannot use `mkDerivation` or `mkDerivationWith` above, include `wrapQtAppsHook` in `nativeBuildInputs`: + +Qt applications must be wrapped to find runtime dependencies. +Include `wrapQtAppsHook` in `nativeBuildInputs`: ```nix +{ stdenv, wrapQtAppsHook }: + stdenv.mkDerivation { # ... - nativeBuildInputs = [ wrapQtAppsHook ]; } ``` -Entries added to `qtWrapperArgs` are used to modify the wrappers created by `wrapQtAppsHook`. The entries are passed as arguments to [wrapProgram executable makeWrapperArgs](#fun-wrapProgram). + +Add entries to `qtWrapperArgs` are to modify the wrappers created by `wrapQtAppsHook`: ```nix -mkDerivation { - # ... +{ stdenv, wrapQtAppsHook }: +stdenv.mkDerivation { + # ... + nativeBuildInputs = [ wrapQtAppsHook ]; qtWrapperArgs = [ ''--prefix PATH : /path/to/bin'' ]; } ``` -Set `dontWrapQtApps` to stop applications from being wrapped automatically. It is required to wrap applications manually with `wrapQtApp`, using the syntax of [wrapProgram executable makeWrapperArgs](#fun-wrapProgram): +The entries are passed as arguments to [wrapProgram](#fun-wrapProgram). + +Set `dontWrapQtApps` to stop applications from being wrapped automatically. +Wrap programs manually with `wrapQtApp`, using the syntax of [wrapProgram](#fun-wrapProgram): ```nix -mkDerivation { - # ... +{ stdenv, lib, wrapQtAppsHook }: +stdenv.mkDerivation { + # ... + nativeBuildInputs = [ wrapQtAppsHook ]; dontWrapQtApps = true; preFixup = '' wrapQtApp "$out/bin/myapp" --prefix PATH : /path/to/bin @@ -79,21 +80,14 @@ mkDerivation { } ``` -> Note: `wrapQtAppsHook` ignores files that are non-ELF executables. This means that scripts won't be automatically wrapped so you'll need to manually wrap them as previously mentioned. An example of when you'd always need to do this is with Python applications that use PyQT. +> Note: `wrapQtAppsHook` ignores files that are non-ELF executables. +> This means that scripts won't be automatically wrapped so you'll need to manually wrap them as previously mentioned. +> An example of when you'd always need to do this is with Python applications that use PyQT. -Libraries are built with every available version of Qt. Use the `meta.broken` attribute to disable the package for unsupported Qt versions: - -```nix -mkDerivation { - # ... - - # Disable this library with Qt < 5.9.0 - meta.broken = builtins.compareVersions qtbase.version "5.9.0" < 0; -} -``` ## Adding a library to Nixpkgs -Qt libraries are added to `qt5-packages.nix` and are made available for every Qt -version supported. +Add Qt libraries to `qt5-packages.nix` to make them available for every +supported Qt version. + ### Example adding a Qt library {#qt-library-all-packages-nix} The following represents the contents of `qt5-packages.nix`. @@ -106,9 +100,23 @@ The following represents the contents of `qt5-packages.nix`. # ... } ``` + +Libraries are built with every available version of Qt. +Use the `meta.broken` attribute to disable the package for unsupported Qt versions: + +```nix +{ stdenv, lib, qtbase }: + +stdenv.mkDerivation { + # ... + # Disable this library with Qt < 5.9.0 + meta.broken = lib.versionOlder qtbase.version "5.9.0"; +} +``` + ## Adding an application to Nixpkgs -Applications that use Qt are also added to `qt5-packages.nix`. An alias is added -in the top-level `all-packages.nix` pointing to the package with the desired Qt5 version. +Add Qt applications to `qt5-packages.nix`. Add an alias to `all-packages.nix` +to select the Qt 5 version used for the application. ### Example adding a Qt application {#qt-application-all-packages-nix}