multiStdenv x86 libgcc linkage issue

Hello there! I’m integrating Nix flake into my C++ project and I’ve encountered linkage issue with gcc-multi. My project targets x86 arch and it is shared library. I’ve set up Nix devshell like this:

devShells.default = pkgs.mkShell.override { stdenv = pkgs.multiStdenv; }
          (with pkgs;
          {
            packages = [
              pkg-config
              cmake
              ninja
            ];
          });

You can notice that I overrided stdenv in mkShell statement with pkgs.multiStdenv.

I have set variables in CMakeLists.txt file to target x86 for compiling:

# build as 32-bit library
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

But when I enter into devshell and try to compile the project, compiling succeeds but linkage does not.

I get following error:

[2/3] Linking CXX shared library libnix-gcc-multi-issue.so.0.1.0
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: skipping incompatible /nix/store/sgznwzgmsn3xxv1jg945d3rsaysjrzqc-gcc-13.2.0-lib/lib64/libstdc++.so when searching for -lstdc++
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: skipping incompatible /nix/store/4zcyrsrdz7xmskwa06fprmyvzl3k8pb6-glibc-multi-2.39-31/lib/libm.so when searching for -lm
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: skipping incompatible /nix/store/sgznwzgmsn3xxv1jg945d3rsaysjrzqc-gcc-13.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: skipping incompatible /nix/store/sgznwzgmsn3xxv1jg945d3rsaysjrzqc-gcc-13.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: skipping incompatible /nix/store/4zcyrsrdz7xmskwa06fprmyvzl3k8pb6-glibc-multi-2.39-31/lib/libc.so when searching for -lc
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: skipping incompatible /nix/store/sgznwzgmsn3xxv1jg945d3rsaysjrzqc-gcc-13.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: skipping incompatible /nix/store/sgznwzgmsn3xxv1jg945d3rsaysjrzqc-gcc-13.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1

I tried to modify NIX_LDFLAGS and LD_LIBRARY_PATH env vars in devshell to ${multiStdenv.cc.cc.lib}/lib, but it didn’t have an effect. I enabled NIX_DEBUG var and got this:

extra flags after to /nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld:
  -dynamic-linker
  /nix/store/4zcyrsrdz7xmskwa06fprmyvzl3k8pb6-glibc-multi-2.39-31/lib/32/ld-linux.so.2
  -rpath
  /nix/store/4zcyrsrdz7xmskwa06fprmyvzl3k8pb6-glibc-multi-2.39-31/lib
  -rpath
  /nix/store/sgznwzgmsn3xxv1jg945d3rsaysjrzqc-gcc-13.2.0-lib/lib64
  -rpath
  /nix/store/sgznwzgmsn3xxv1jg945d3rsaysjrzqc-gcc-13.2.0-lib/lib
  -rpath
  /nix/store/4zcyrsrdz7xmskwa06fprmyvzl3k8pb6-glibc-multi-2.39-31/lib/32

I have no idea where these extra flags are originating from. Seems like they should not have .../lib64 flag.

How can I set correct flags for linker when using multiStdenv?

The sample repo for reproduction of this issue: ChronosXYZ/nix-gcc-multi-issue - nix-gcc-multi-issue - Gitea: Git with a cup of tea