How to overwrite gcc in `clang*Stdenv`?

I can compile a simple main.cpp with this flake.nix

  description = "Cpp Playground";

  inputs = {
    # Nixpkgs (take the systems nixpkgs version)
    nixpkgs.url = "nixpkgs";

    # You can access packages and modules from different nixpkgs revs
    # at the same time. Here's an working example:
    nixpkgsStable.url = "github:nixos/nixpkgs/nixos-23.11";
    # Also see the 'stable-packages' overlay at 'overlays/default.nix'.

  outputs = {
  } @ inputs: let
    # Supported systems for your flake packages, shell, etc.
    systems = [

    # This is a function that generates an attribute by calling a function you
    # pass to it, with the correct `system` and `pkgs` as arguments.
    forAllSystems = func: nixpkgs.lib.genAttrs systems (system: func system nixpkgs.legacyPackages.${system});
  in {
    devShells =
        system: pkgs: let

          # Toolchain.
          gccVersion = "13";
          gccPkg = pkgs."gcc${gccVersion}";

          llvmVersion = "17";
          llvmPkgs = pkgs."llvmPackages_${llvmVersion}";
          clangStdEnv = pkgs.clang17Stdenv;

          buildInputs = with pkgs; [
            # Dependencies

          nativeBuildInputs = with pkgs; [
        in {
          default = pkgs.mkShell.override {stdenv = clangStdEnv;} rec {
            inherit nativeBuildInputs;
            inherit buildInputs;

            # I use this to simply test the executable in the shell.
            LD_LIBRARY_PATH = nixpkgs.lib.makeLibraryPath [ pkgs.fmt];

This is however not quite right, as I dont know the GCC version (I assumed above 13) for the selected clang 17. Compilations/linking works and execution (luckily) too:

When I now try to override the stdenv like so:

          clangStdEnv = pkgs.stdenvAdapters.overrideCC llvmPkgs.stdenv (llvmPkgs.clang.override {
            gccForLibs = gccPkg;
            bintools = llvmPkgs.bintools;

then the cmake cannot be configured because the compiler does not work:

cmake ..
CMake Warning (dev) at CMakeLists.txt:1 (project):
  cmake_minimum_required() should be called prior to this top-level project()
  call.  Please see the cmake-commands(7) manual for usage documentation of
  both commands.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- The C compiler identification is Clang 17.0.6
-- The CXX compiler identification is Clang 17.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /nix/store/wh36kap4h9d8w5pr46k22aa9nxx0zrh0-clang-wrapper-17.0.6/bin/clang
-- Check for working C compiler: /nix/store/wh36kap4h9d8w5pr46k22aa9nxx0zrh0-clang-wrapper-17.0.6/bin/clang - broken
CMake Error at /nix/store/wn9nlnmyfd1x6ps3zmy04yxjyw3iji86-cmake-3.27.8/share/cmake-3.27/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler


  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/home/nixos/Desktop/Repos/cpp-playground/tests/build/CMakeFiles/CMakeScratch/TryCompile-00M6V0'

    Run Build Command(s): /nix/store/wn9nlnmyfd1x6ps3zmy04yxjyw3iji86-cmake-3.27.8/bin/cmake -E env VERBOSE=1 /nix/store/grll1f1qj7yw6yq42qigkw5fvyjz2rjw-gnumake-4.4.1/bin/make -f Makefile cmTC_bb4f6/fast
    /nix/store/grll1f1qj7yw6yq42qigkw5fvyjz2rjw-gnumake-4.4.1/bin/make  -f CMakeFiles/cmTC_bb4f6.dir/build.make CMakeFiles/cmTC_bb4f6.dir/build
    make[1]: Entering directory '/home/nixos/Desktop/Repos/cpp-playground/tests/build/CMakeFiles/CMakeScratch/TryCompile-00M6V0'
    Building C object CMakeFiles/cmTC_bb4f6.dir/testCCompiler.c.o
    /nix/store/wh36kap4h9d8w5pr46k22aa9nxx0zrh0-clang-wrapper-17.0.6/bin/clang    -MD -MT CMakeFiles/cmTC_bb4f6.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_bb4f6.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_bb4f6.dir/testCCompiler.c.o -c /home/nixos/Desktop/Repos/cpp-playground/tests/build/CMakeFiles/CMakeScratch/TryCompile-00M6V0/testCCompiler.c
    Linking C executable cmTC_bb4f6
    /nix/store/wn9nlnmyfd1x6ps3zmy04yxjyw3iji86-cmake-3.27.8/bin/cmake -E cmake_link_script CMakeFiles/cmTC_bb4f6.dir/link.txt --verbose=1
    /nix/store/wh36kap4h9d8w5pr46k22aa9nxx0zrh0-clang-wrapper-17.0.6/bin/clang -rdynamic CMakeFiles/cmTC_bb4f6.dir/testCCompiler.c.o -o cmTC_bb4f6
    /nix/store/xdqs45iclhp9dz8zz9pvn5zivjbhid1a-binutils-2.40/bin/ld: cannot find crtbeginS.o: No such file or directory
    /nix/store/xdqs45iclhp9dz8zz9pvn5zivjbhid1a-binutils-2.40/bin/ld: cannot find -lgcc: No such file or directory
    /nix/store/xdqs45iclhp9dz8zz9pvn5zivjbhid1a-binutils-2.40/bin/ld: cannot find -lgcc_s: No such file or directory
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[1]: *** [CMakeFiles/cmTC_bb4f6.dir/build.make:100: cmTC_bb4f6] Error 1
    make[1]: Leaving directory '/home/nixos/Desktop/Repos/cpp-playground/tests/build/CMakeFiles/CMakeScratch/TryCompile-00M6V0'
    make: *** [Makefile:127: cmTC_bb4f6/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:1 (project)

CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.27)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!

I dont know how to correct the above error? Does anyone know whats happeningg above?

I think I found the error:
I should not have specified wrapped compiler in gccForLibs = gccPkgs but rather gccForLibs = which is the unwrapped compiler.

Any insight still appreciated…