How to install qmake and Qt libraries into buildFHSUserEnv

How to install qmake and Qt libraries into buildFHSUserEnv? Adding

(with pkgs.libsForQt5; [
  qmake
  qt5.qtbase
  qt5.qtquickcontrols
  qt5.qtquickcontrols2
  qt5.qttools
  qt5.qtgamepad
  qt5.wrapQtAppsHook
])

to targetPkgs does not make qmake available on PATH. If I run it using its full path to nix store it doesn’t see any of those qt libraries I have specified in the targetPkgs.

Using qt5.full does NOT help. It does not contain for example gamepad and probably other libraries and if I specify both qt5.full and qt5.qtgamepad in targetPkgs then magically qmake is on PATH but it does not see qt5.qtgamepad at all.

I’d like to know what is happening why qmake doesn’t get onto PATH when installing just qmake but does with qt5.full… but it does not see the additional libraries etc…

Basically I need

  • A development shell with qmake and certain Qt libraries. I do not want to build a final Nix package (at least not yet).
  • It must be FHS because I’m dependent on some unpatchable precompiled tools with hardcoded paths etc…

I haven’t found any example for doing that. Any help is appreciated.

After a good night’s sleep:

qmake needs PREFIX flag to be set to a path with Qt libs.

  • It can be done either by passing an argument to qmake which is what qmake-hook.sh does when you add qmake to nativeBuildInputs. Using build inputs seems to also automatically use dev outputs of specified input derivations as stated in Section 8.3. of nixpkgs manual. To use this in a development shell it seems one would need to create a qmake wrapper which does the same as qmakeConfigurePhase.
  • Or the PREFIX can be specified on qt.conf which is what qt5.full is seems to be doing by creating a derivation using buildEnv which
    • Explicitely specifies that dev outputs of specified packages should be installed (in mkDerivation this is implicit).
    • Symlinks not just /bin and /share (or whatever the default is) but also /include and /lib to the derivation being created.
    • Copies qmake to $out/bin/.
    • Creates qt.conf (on PATH && near the qmake binary - don’t know which of that is relevant) with PREFIX set to the derivation being created.

So I ended up with something like this in my buildFHSUserEnv

targetPkgs = pkgs: (with pkgs; [
            gcc11
            git
            glib
            gnumake
            libGL
            libglvnd
            pkgconfig
            python3
            udev
            wget
            which
            zlib

            (buildEnv {
              name = "qt-dev-env";
              paths = with libsForQt5; [
                qtbase
                qtconnectivity
                qtdeclarative
                qtgamepad
                qtlocation
                qtquickcontrols2
                qtserialport
                qtsvg
              ];

              # pathsToLink = [ "/bin" "/mkspecs" "/include" "/lib" "/share" ];
              extraOutputsToInstall = [ "out" "dev" ];

              postBuild = with libsForQt5; ''
                rm "$out/bin/qmake"
                cp "${qtbase.dev}/bin/qmake" "$out/bin"
                cat >"$out/bin/qt.conf" <<EOF
                [Paths]
                Prefix = $out
                Plugins = ${qtbase.qtPluginPrefix}
                Qml2Imports = ${qtbase.qtQmlPrefix}
                Documentation = ${qtbase.qtDocPrefix}
                EOF
              '';
            })
          ]);

which works.
I digress.

1 Like