Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated QT doc section to commonmark #105004

Merged
merged 7 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/languages-frameworks/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<xi:include href="perl.xml" />
<xi:include href="php.section.xml" />
<xi:include href="python.section.xml" />
<xi:include href="qt.xml" />
<xi:include href="qt.section.xml" />
<xi:include href="r.section.xml" />
<xi:include href="ruby.xml" />
<xi:include href="rust.section.xml" />
Expand Down
114 changes: 114 additions & 0 deletions doc/languages-frameworks/qt.section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

Qt
=
wiltaylor marked this conversation as resolved.
Show resolved Hide resolved
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.

There are primarily two problems which the Qt infrastructure is designed to address: ensuring consistent versioning of all dependencies and finding dependencies at runtime.


## Nix expression for a Qt package (default.nix) {#qt-default-nix}

```nix
{ mkDerivation, lib, qtbase }: #1
mkDerivation { #2
wiltaylor marked this conversation as resolved.
Show resolved Hide resolved
pname = "myapp";
version = "1.0";

buildInputs = [ qtbase ]; #3
}
```

* **#1:** 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.

* **#2:** 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 [Chapter 6, The Standard Environment](#chap-stdenv), The Standard Environment for details.

> To use another deriver instead of `stdenv.mkDerivation`, use `mkDerivationWith`:

```nix
mkDerivationWith myDeriver {
# ...
}
```

> If you cannot use `mkDerivationWith`, please refer to Locating runtime dependencies below.
wiltaylor marked this conversation as resolved.
Show resolved Hide resolved

* **#3:** `mkDerivation` accepts the same arguments as `stdenv.mkDerivation`, such as `buildInputs`.

---

**Locating runtime dependencies**
Qt applications need to be wrapped to find runtime dependencies. If you cannot use `mkDerivation` or `mkDerivationWith` above, include `wrapQtAppsHook` in `nativeBuildInputs`:

```nix
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).

```nix
mkDerivation {
# ...

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):

```nix
mkDerivation {
# ...

dontWrapQtApps = true;
preFixup = ''
wrapQtApp "$out/bin/myapp" --prefix PATH : /path/to/bin
'';
}
```

> 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 &lt; 5.9.0
meta.broken = builtins.compareVersions qtbase.version "5.9.0" &lt; 0;
}
```
**Adding a library to Nixpkgs**
wiltaylor marked this conversation as resolved.
Show resolved Hide resolved
Add a Qt library to all-packages.nix by adding it to the collection inside `mkLibsForQt5`. This ensures that the library is built with every available version of Qt as needed.

**Example 15.9. Adding a Qt library to all-packages.nix**

```
{
# ...

mkLibsForQt5 = self: with self; {
# ...

mylib = callPackage ../path/to/mylib {};
};

# ...
}
```
**Adding an application to Nixpkgs**
Add a Qt application to *all-packages.nix* using `libsForQt5.callPackage` instead of the usual `callPackage`. The former ensures that all dependencies are built with the same version of Qt.

**Example 15.10 Adding a QT application to all-packages.nix**
```nix
{
# ...

myapp = libsForQt5.callPackage ../path/to/myapp/ {};

# ...
}
```
149 changes: 0 additions & 149 deletions doc/languages-frameworks/qt.xml

This file was deleted.