Flake pulling tools from different revs of nixpkgs

Hi all,
I’m trying to setup a dev environment that would allow me to easily switch between GCC versions and, since I’m using the Qt framework for development, between Qt versions (at least LTS versions).

(I’m doing all this on a RHEL-based machine with nix package manager installed on the side.)

During my testing and soul-searching online, I managed to come up with something like the following

{
  inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
  # Latest nixpkgs rev including Qt v6.5.3
  inputs.nixpkgs-qt6_5_3.url = "nixpkgs/9dbe9b9acc4d002014833bd6af54fbe876742a35";

  outputs = { self, nixpkgs, nixpkgs-qt6_5_3 }: let

    name = "development-environment";
    system = "x86_64-linux";
    pkgs = import nixpkgs { inherit system; };
    pkgs-qt6_5_3 = import nixpkgs-qt6_5_3 { inherit system; };

    # Overriding stdenv. So far I've been able to jump between versions
    # of GCC without issues.
    stdenv = pkgs.gcc12Stdenv;
    mkShell = pkgs.mkShell.override { inherit stdenv; };

  in {

    devShells.${system}.default = mkShell {

      inherit name;

      buildInputs = [
        (with pkgs-qt6_5_3.qt6; env "qt-custom-${qtbase.version}" [ qttools])
        pkgs.bashInteractive
      ];

      shellHook = ''
        export SHELL="${pkgs.bashInteractive}/bin/bash";

        # qtdiag, provided by qt6.qttools, will print Qt version, among other info
        qtdiag
      '';
    };
  };
}

Now running nix develop on this will output

$ nix develop
qtdiag: /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/5mb70vg3kdzkyn0zqdgm4f87mdi0yi4i-libglvnd-1.7.0/lib/libGLX.so.0)
qtdiag: /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/5mb70vg3kdzkyn0zqdgm4f87mdi0yi4i-libglvnd-1.7.0/lib/libEGL.so.1)
qtdiag: /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/5mb70vg3kdzkyn0zqdgm4f87mdi0yi4i-libglvnd-1.7.0/lib/libGLdispatch.so.0)

My understanding is that my stdenv is providing the wrong version of glibc, and qtdiag is trying to dynamically link to a version of the library I don’t have:

  • when inside the flake shell, ${stdenv.cc.libc.version} is 2.40. I suppose this is coming from setting the stdenv to pkgs.gcc12Stdenv;
  • qtdiag is linking to /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libc.so.6 which feels more like GLIBC_2.37,
  • but then complains about glibc version not being GLIBC_2.38.

I also took a detour exploring the effect of

LD_LIBRARY_PATH = "${stdenv.cc.cc.lib}/lib";

in my flake. This doesn’t really do anything since the glibc version qtdiag is linking to is hard-coded (and I feel this is correct for reproducibility reasons).

$ ldd `which qtdiag`
/nix/store/dz0mpd856iz4s7iji667w8fplg2553v0-qt-custom-6.5.3/bin/qtdiag: /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/5mb70vg3kdzkyn0zqdgm4f87mdi0yi4i-libglvnd-1.7.0/lib/libGLX.so.0)
/nix/store/dz0mpd856iz4s7iji667w8fplg2553v0-qt-custom-6.5.3/bin/qtdiag: /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/5mb70vg3kdzkyn0zqdgm4f87mdi0yi4i-libglvnd-1.7.0/lib/libEGL.so.1)
/nix/store/dz0mpd856iz4s7iji667w8fplg2553v0-qt-custom-6.5.3/bin/qtdiag: /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/5mb70vg3kdzkyn0zqdgm4f87mdi0yi4i-libglvnd-1.7.0/lib/libGLdispatch.so.0)
linux-vdso.so.1 (0x00007ffff7fc4000)
libQt6OpenGL.so.6 => /nix/store/dz0mpd856iz4s7iji667w8fplg2553v0-qt-custom-6.5.3/bin/../lib/libQt6OpenGL.so.6 (0x00007ffff7f06000)
...
librt.so.1 => /nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/librt.so.1 (0x00007ffff74c5000)
/nix/store/ld03l52xq2ssn4x0g5asypsxqls40497-glibc-2.37-8/lib/ld-linux-x86-64.so.2 => /nix/store/h7zcxabfxa7v5xdna45y2hplj31ncf8a-glibc-2.40-36/lib64/ld-linux-x86-64.so.2 (0x00007ffff7fc6000)
libbz2.so.1 => /nix/store/6947mfg2jlid97cnvzvc6cvv6wpj2yhg-bzip2-1.0.8/lib/libbz2.so.1 (0x00007ffff6260000)
...

I feel like this is not specifically related to Qt, but I’m lacking some more general understanding on what is the effect of setting a specific stdenv for mkShell. In the end the questions are:

  • when installing a package from a different nixpkgs version, should I also try and install the stdenv, the package was built with?
  • Or maybe this is not the way I’m supposed to mix versions of nixpkgs and there is another, cleaner way?
  • Am I going in the right direction when overriding the mkShell stdenv? Is this the proper way to do it?

Thanks :slight_smile: