# Running locally built Qt apps

**URL:** https://discourse.nixos.org/t/running-locally-built-qt-apps/29984
**Category:** Help
**Created:** [July 4, 2023, 8:03am UTC](https://discourse.nixos.org/t/running-locally-built-qt-apps/29984 "2023-07-04T08:03:33Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![marko](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@marko](https://discourse.nixos.org/u/marko)
#### Post date: [July 4, 2023, 8:03am UTC](https://discourse.nixos.org/t/running-locally-built-qt-apps/29984/1 "2023-07-04T08:03:33Z")

</div>

I am new to Nix and want to use it for reproducible builds. Target is to use Nix for compilation of our own software and run it in the “host” Linux OS (mix of different Linux versions). Following tutorials, I could build now our C++ software as follows:

```auto
nix-shell -p package1 package2 .... 
> cmake ..
> make ...

# in host env, outside of nix-shell
app

```

The `app` would run and use libs in `/nix`. All is nice and as expected.

With Qt apps though, I have added `libsForQt5.qt5.qtbase` as a package for `nix-shell` which was sufficient for compiling and linking `app-qt`. However, running it fails with missing Qt platform message:

```auto
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

```

No platforms are listed either.

In corresponding threads over here and in [Qt Wiki](https://nixos.wiki/wiki/Qt), I can see some wrapper `wrapQtAppsHook`. However, it is not clear how to use it in `nix-shell` when building executable.

Hence the question:

- how could I compile Qt application in a way that would make it possible to use “outside of Nix” - running in Linux PC with Nix installed, but without entering `nix-shell`?

I admit that I haven’t had time to go through full tutorial and later sections on Nix language yet. Which maybe a reason why I struggle with this construction right now. Looking forward to pointers.

---

<div class="post-metadata">

### Author: ![wamserma](https://discourse.nixos.org/user_avatar/discourse.nixos.org/wamserma/32/5353_2.png) [@wamserma](https://discourse.nixos.org/u/wamserma)
#### Post date: [July 4, 2023, 10:08am UTC](https://discourse.nixos.org/t/running-locally-built-qt-apps/29984/2 "2023-07-04T10:08:40Z")

</div>

> [@marko](#):
>
> `Could not find the Qt platform plugin "xcb"`

You also need to wrap the Qt App, see the appropriate section in the Nixpkgs manual: [Nixpkgs Reference Manual](https://nixos.org/manual/nixpkgs/stable/#sec-language-qt)

---

<div class="post-metadata">

### Author: ![marko](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@marko](https://discourse.nixos.org/u/marko)
#### Post date: [July 4, 2023, 10:32am UTC](https://discourse.nixos.org/t/running-locally-built-qt-apps/29984/3 "2023-07-04T10:32:18Z")

</div>

Thank you very much for your help! Is there a way to call that wrapper manually, when compiling an app inside `nix-shell` using `cmake && make` combination?

---

<div class="post-metadata">

### Author: ![wamserma](https://discourse.nixos.org/user_avatar/discourse.nixos.org/wamserma/32/5353_2.png) [@wamserma](https://discourse.nixos.org/u/wamserma)
#### Post date: [July 4, 2023, 11:25am UTC](https://discourse.nixos.org/t/running-locally-built-qt-apps/29984/4 "2023-07-04T11:25:28Z")

</div>

If you put

```auto
nativeBuildInputs = [wrapQtAppsHook];
dontWrapQtApps = true;

```

in your shell.nix, you should be able to call `wrapQtApp "$out/bin/myapp" --prefix PATH : /path/to/bin` manually.

But tbh., at this point it would be better to properly package the app.

---

<div class="post-metadata">

### Author: ![marko](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@marko](https://discourse.nixos.org/u/marko)
#### Post date: [July 4, 2023, 5:54pm UTC](https://discourse.nixos.org/t/running-locally-built-qt-apps/29984/5 "2023-07-04T17:54:06Z")

</div>

I am sure that you are right. I will look into how to package it properly - would have to read up on it. Will mark your reply as a solution while I didn’t make it work properly. But that’s mostly due to lack of time I took to learn Nix bits.

Thank you for your pointers!

---

<div class="post-metadata">

### Author: ![wamserma](https://discourse.nixos.org/user_avatar/discourse.nixos.org/wamserma/32/5353_2.png) [@wamserma](https://discourse.nixos.org/u/wamserma)
#### Post date: [July 4, 2023, 6:49pm UTC](https://discourse.nixos.org/t/running-locally-built-qt-apps/29984/6 "2023-07-04T18:49:25Z")

</div>

As you already got it working in in a nix shell, packaging should be straightforward:

```auto
{ stdenv, lib, qtbase, cmake, wrapQtAppsHook, package1, package2, packageX }: 

    stdenv.mkDerivation {
      pname = "myapp";
      version = "1.0";

      src = ... ; # point this to your source using fetchgit or just "." while you are testing

      buildInputs = [qtbase package1 package2 packageX];
      nativeBuildInputs = [cmake wrapQtAppsHook]; 

      # no need to define the build steps, all done by magic behind the scenes
    }

```

---

<div class="post-metadata">

### Author: ![wamserma](https://discourse.nixos.org/user_avatar/discourse.nixos.org/wamserma/32/5353_2.png) [@wamserma](https://discourse.nixos.org/u/wamserma)
#### Post date: [July 4, 2023, 6:56pm UTC](https://discourse.nixos.org/t/running-locally-built-qt-apps/29984/7 "2023-07-04T18:56:14Z")

</div>

Also have a look at Jacek’s blog where you can find a full example with explanations, including packing things up in a Nix flake:

> **[(Qt)Quick C++ Project Setup with Nix](https://galowicz.de/2023/01/16/cpp-qt-qml-nix-setup/)**
>
> I never install toolchains globally on my systems.Instead, every project comes with its own nix file that describes the completedevelopment toolchain versions and dependencies.This way, fresh checkouts always build the same way on every machine.This...

---

<div class="post-metadata">

### Author: ![marko](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@marko](https://discourse.nixos.org/u/marko)
#### Post date: [July 5, 2023, 10:11am UTC](https://discourse.nixos.org/t/running-locally-built-qt-apps/29984/8 "2023-07-05T10:11:30Z")

</div>

Thanks for the pointers!

---

<div class="post-metadata">

### Author: ![xactyp](https://discourse.nixos.org/user_avatar/discourse.nixos.org/xactyp/32/33080_2.png) [@xactyp](https://discourse.nixos.org/u/xactyp)
#### Post date: [June 30, 2025, 4:01pm UTC](https://discourse.nixos.org/t/running-locally-built-qt-apps/29984/9 "2025-06-30T16:01:11Z")

</div>

try this [How to create a Qt devShell? - #4 by xactyp](https://discourse.nixos.org/t/how-to-create-a-qt-devshell/58529/4)
