How to install qmake and Qt libraries into buildFHSUserEnv

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