Shell.nix for KDE Kirigami development

I have been trying to write a shell.nix for developing with Kirigami on NixOS.

I was going through this tutorial trying to figure out all of the dependencies I would need. There are two types of dependencies here:

  1. Checked at compile time.
  2. Checked at runtime.

I managed to get all of compile time dependencies and the app successfully compiles. The problem is that it fails at runtime with this message:

QQmlApplicationEngine failed to load component
qrc:/main.qml:4:1: module "org.kde.kirigami" is not installed

shell.nix contents:

with (import <nixpkgs> {});

mkShell {
  buildInputs = [
    clang-tools
    clang
    cmake
    extra-cmake-modules
    libsForQt5.appstream-qt
    libsForQt5.kcoreaddons
    libsForQt5.kirigami2
    libsForQt5.ki18n
    qt5.full
  ];
}

I have tried both libsForQt512 and libsForQt514 as well as libsForQt5.full but none of that helped.
I even know how this package is called on other distros:
Ubuntu: qml-module-org-kde-kirigami2
Arch: kde-sdk-meta

Does anyone know if this is even packaged on NixOS?
If so, what is the name of the package and how in general should I figure out Qt package names on Nix?

P.S. as I have mentioned above, all of the C++ and QML code is taken from the tutorial.

I believe the org.kde.kirigami qml module is part of libsForQt5.kirigami2 (You should be able to see the qml and related files in /nix/store/<hash>-kirigami2-<version>/lib/qt-5.12.2/qml/org/kde/kirigami.2). However, it seems Qt can’t find it. Is QML2_IMPORT_PATH set in the shell’s environment?

No, QML2_IMPORT_PATH was not set. Setting it fixed the problem.
Not sure if this is an intended behavior or a bug though. :confused:

As a result of @Thra11 suggestion, my current shell.nix looks like this:

with (import <nixpkgs> {});

let
  kirigami = libsForQt5.kirigami2;
  qt = qt5.full;
in

mkShell {
  buildInputs = [
    clang-tools
    clang
    cmake
    extra-cmake-modules
    libsForQt5.appstream-qt
    libsForQt5.kcoreaddons
    kirigami
    libsForQt5.ki18n
    qt
  ];
  shellHook = ''
    export QML2_IMPORT_PATH=${kirigami}/lib/${builtins.replaceStrings ["full-"] [""] qt.name}/qml
  '';
}

I believe you can get the qml prefix more easily by using qt5.qtbase.qtQmlPrefix[1].

In addition to that, I think there should be a way to have nix build a path which combines all the qml modules from all the relevant inputs, not just kirigami. As an example, for the currently running system, there should be a path, /run/current-system/sw/${pkgs.qt5.qtbase.qtQmlPrefix}. Obviously that’s not what we want, as there’s no guarantee that the system has the same Qt packages as the nix shell. I’m not sure what the correct answer is though.

[1] I believe any qt module should have the property and they should all be the same prefix, so you don’t have to use qtbase if it’s not in scope.

Coincidentally, I’m currently running into exactly the same issue with QML2_IMPORT_PATH in mkShell. I don’t think the user should be responsible for constructing and setting it manually. I know that Qt packaging in nixpkgs has its own version of mkDerivation which takes care of the necessary wrapping and environment variables, but it doesn’t appear to have a mkShell replacement.

Perhaps @ttuegel would know what the correct way to do this is.