How to override the Qt version inside nix-shell

Hello to everyone,

I’ve been scratching my head for a couple of days about how to create a nix shell with a specific Qt version; I’m not completely new to nix but I cannot figure how to do so:

The current recipe for Qt6 pkgs/development/libraries/qt-6/default.nix uses lib.makeScope to create a scope in a way to build all Qt submodules in a consistent way, I’d like to switch to a different Qt version, and I’ve already generated pkgs/development/libraries/qt-6/srcs.nix with my Qt 6.2.4 sources.

What I’ve come about:

Option 1:

    qt_srcs = import ./scripts/nix/qt/6.2.4/srcs.nix {
           inherit fetchurl;
           mirror = "https://download.qt.io/";
     };
     myqt6 = pkgs.qt6.overrideScope' (final : prev:  { srcs =  qt_srcs ; 
     });

gives no error, but it doesn’t change the version from actual Qt 6.5.4

Option 2:

  myqt6 = pkgs.qt6.overrideScope' (final : prev:  {
       qtbase = prev.qtbase.overrideAttrs ( old : {
          inherit (qt_srcs.qtbase) src version;
       });
       ddqtserialbus = prev.qtserialbus.overrideAttrs ( 
            old : { inherit (qt_srcs.qtserialbus) src version; });
     });

Last one actually detect the change, builds QtBase ok with Qt 6.2.4, but then it tries to build QtSerialBus using QtBase 6.5 headers and 6.2.4 sources and it fails there.

I’ve found some examples about how to use overrideScope but I didn’t manage to make it work for Qt.

Thank you very much

Found the solution,

  qt_srcs = import ./scripts/nix/qt/6.2.4/srcs.nix {
          fetchurl = builtins.fetchurl;
          mirror = "https://download.qt.io/";
   };
   myqt6 = pkgs.qt6.overrideScope' (final : prev:  {
      qtModule = prev.qtModule.override( old : {
        srcs = qt_srcs;
      });
      qtbase = prev.qtbase.overrideAttrs ( old : {
        inherit (qt_srcs.qtbase) src version;
      });
    });

Need to use ovverrideScope' and inside it override qtModule and qtbase attributes. The local file srcs.nix can be generated for any Qt version with ./maintainers/scripts/fetch-kde-qt.sh