1

Based on How can I create a development shell for qt 5.5 with debug symbols in the qt libraries, and looking at qtbase.nix, I tried this in default.nix:

with import <nixpkgs> {};
stdenv.mkDerivation {
    name = "myapp";
    buildInputs = [ 
        (qt5.qtbase.override { debug = true; }) 
        qt5.qtdeclarative 
        qt5.qtgraphicaleffects 
        qt5.qtimageformats 
        qt5.qtquickcontrols2 
        qt5.qttools 
        ...unrelated deps... 
    ];
}

This seemed to build Qt successfully, but then when invoking nix-shell, I get the error:

Error: detected mismatched Qt dependencies:
    /nix/store/2w9sd3z24hhxvllk47xwflwcsh318k1q-qtbase-5.15.3-dev
    /nix/store/74ly900da8fi9b5vvmyqzi4yqa84p0sz-qtbase-5.15.3-dev

The very few hits that google finds for this error message do not seem to be relevant to the situation.

After looking at strace output and drv files, I intuited that maybe qtdeclarative is still using the non-overridden version of qtbase, so then I tried:

with import <nixpkgs> {};

let myqtbase = qt5.qtbase.override { debug = true; }; in
let myqtdecl = qt5.qtdeclarative.override { qtbase = myqtbase; }; in

stdenv.mkDerivation {
    name = "myapp";
    buildInputs = [
        myqtbase
        myqtdecl
        (qt5.qtgraphicaleffects.override { qtdeclarative = myqtdecl; })
        (qt5.qtimageformats.override { qtbase = myqtbase; })
        (qt5.qtquickcontrols2.override { qtdeclarative = myqtdecl; })
        (qt5.qttools.override { qtbase = myqtbase; qtdeclarative = myqtdecl; })
        ...unrelated deps...
    ];
}

This time, it fails earlier with basically the same issue:

these 5 derivations will be built:
  /nix/store/khxivycbzgvjcxypa1im98grvpnjp2rd-qtdeclarative-5.15.3.drv
  /nix/store/bax6i6afc6bgc6qjgbrps8l5q3r3fbis-qttools-5.15.3.drv
  /nix/store/hhcnis5nh4raixqajj67zvak7xx44q3y-qtimageformats-5.15.3.drv
  /nix/store/jl43kcgfm9svrnddja9bi0kwhqxrcs27-qtgraphicaleffects-5.15.3.drv
  /nix/store/wjhaakqxzdk5x5j315mx16rdqagrnavl-qtquickcontrols2-5.15.3.drv
building '/nix/store/khxivycbzgvjcxypa1im98grvpnjp2rd-qtdeclarative-5.15.3.drv'...
Error: detected mismatched Qt dependencies:
    /nix/store/74ly900da8fi9b5vvmyqzi4yqa84p0sz-qtbase-5.15.3-dev
    /nix/store/2w9sd3z24hhxvllk47xwflwcsh318k1q-qtbase-5.15.3-dev
error: builder for '/nix/store/khxivycbzgvjcxypa1im98grvpnjp2rd-qtdeclarative-5.15.3.drv' failed with exit code 1;
       last 3 log lines:
       > Error: detected mismatched Qt dependencies:
       >     /nix/store/74ly900da8fi9b5vvmyqzi4yqa84p0sz-qtbase-5.15.3-dev
       >     /nix/store/2w9sd3z24hhxvllk47xwflwcsh318k1q-qtbase-5.15.3-dev
       For full logs, run 'nix log /nix/store/khxivycbzgvjcxypa1im98grvpnjp2rd-qtdeclarative-5.15.3.drv'.
error: build of '/nix/store/bax6i6afc6bgc6qjgbrps8l5q3r3fbis-qttools-5.15.3.drv', '/nix/store/hhcnis5nh4raixqajj67zvak7xx44q3y-qtimageformats-5.15.3.drv', '/nix/store/jl43kcgfm9svrnddja9bi0kwhqxrcs27-qtgraphicaleffects-5.15.3.drv', '/nix/store/khxivycbzgvjcxypa1im98grvpnjp2rd-qtdeclarative-5.15.3.drv', '/nix/store/wjhaakqxzdk5x5j315mx16rdqagrnavl-qtquickcontrols2-5.15.3.drv' failed

At this point, I don't have a single clue what or where is trying to pull in different versions of qtbase (both -dev!) or why and I'm out of ideas.

I also looked at https://nixos.org/manual/nixpkgs/stable/#sec-pkg-override which is linked from the previous Q&A, but my familiarity with Nix is insufficiently deep to truly comprehend what's written there.

Halp?

glaebhoerl
  • 7,695
  • 3
  • 30
  • 41

1 Answers1

2

Well, in your default.nix you've overriden the wrong attribute. The correct way is:

with import <nixpkgs> {};
let
  qt5-debug = pkgs.qt5.override {
    developerBuild = true;
    debug = true;
  };
in stdenv.mkDerivation {
    name = "myapp";
    buildInputs = [ 
        qt5-debug.qtbase 
        qt5-debug.qtdeclarative 
        qt5-debug.qtgraphicaleffects 
        qt5-debug.qtimageformats 
        qt5-debug.qtquickcontrols2 
        qt5-debug.qttools 
    ];
}

Result:

file  /nix/store/xd3..-qtbase-5.15.3/lib/libQt5Gui.so.5.15.3
/nix/store/xd3..-qtbase-5.15.3/lib/libQt5Gui.so.5.15.3: 
ELF shared object, 64-bit LSB x86-64, not stripped

Unfortunately (or fortunately) nix is a full-blown programming language with unbounded recursion and other high-level functional utility. Which means great flexibility, which is great. But sometimes, one just have to look into the source code in the nixpkgs. The correct parameters are defined in the qt 5's default.nix and from there it's pretty easy to figure out why overriding just the submodule fails.

vitalii
  • 3,335
  • 14
  • 18
  • How is recursion related to the problem? How would you structure a package set so that it doesn't need recursion, and would that structure be easier to use? – Robert Hensing Sep 04 '22 at 11:55
  • @vitalii Thank you so much! It hadn't occurred to me that `qt5` would be its own thing, rather than merely in there for cleaner namespacing. (So I *was* looking at the source, fwiw, just not of the right thing.) And it seems that `developerBuild` *is* necessary, despite the appearance that it's for developers *of* Qt, rather than developers *using* Qt. Without it, it even silently inserted `-DQT_NO_DEBUG` into my ambient compile flags. I felt like I was losing my goddang mind. – glaebhoerl Sep 04 '22 at 12:59
  • @RobertHensing Recursion has everything to do with this problem. Suppose you want to make a module overridable. Now you need to return a function `makeOverridable` to override a module multiple times. What would be the __type__ of a module? It would be a huge thingy the size of the module itself. At this points type errors are useless. To validate program you have to execute it. My point here is not that the QT module is badly written, but that's unavoidable that once in a while users will have to check module code to see what gone wrong with their configurations. – vitalii Sep 04 '22 at 13:47
  • It's not the recursion that makes a hypothetical type system hard, but rather the dynamic and structural typing. Please don't make unsubstantiated claims if you don't need to. – Robert Hensing Sep 04 '22 at 22:55