`gcc` has wrong version even though it was pinned

Im quite new to nix and have been playing around a bit with shell.nix files to create some simple development environments. I’m having some trouble pinning the correct version of gcc. Consider the following code:

{ nixpkgs ? import <nixpkgs> {} } :
    clang_14 = import (builtins.fetchGit {
        name = "clang_14";
        url = "https://github.com/NixOS/nixpkgs/";
        ref = "refs/heads/nixos-23.11";
        rev = "eb090f7b923b1226e8beb954ce7c8da99030f4a8";
    }) {};
    gcc_11 = import (builtins.fetchGit {
        name = "gcc_11";
        url = "https://github.com/NixOS/nixpkgs/";
        ref = "refs/heads/nixos-23.11";
        rev = "6c9faad8466f17216c0cb6f0bd645f3985046090";
    }) {};
    nixpkgs.mkShell {
        name = "myShell";
        buildInputs = [
            gcc_11.gcc-unwrapped                        # 11.3.0
            clang_14.llvmPackages_14.clang-unwrapped    # 14.0.6
            clang_14.cmake                              # 3.27.7
            clang_14.ninja                              # 1.11.1
            gcc_11.python310Packages.python             # 3.10.9

In principle the script works, all packages have the expected version (indicated in the comment behind the individual packages), but for whatever reason, gcc has the wrong version. The version comes out to 13.0.2.

The hash for gcc comes from here. Even more confusing, if I run

nix-shell -p gcc-unwrapped -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/6c9faad8466f17216c0cb6f0bd645f3985046090.tar.gz

I end up in a shell with gcc-11.3.0, as indented. I use nix (Nix) 2.21.1 on Linux (x86_64).

Can somebody explain this?

have you tried to run the shell with the --pure flag? That would prevent confusion because of already installed versions of gcc.

If this flag is specified, the environment is almost entirely cleared before the interactive shell is
started, so you get an environment that more closely corresponds to the “real” Nix build. A few vari‐
ables, in particular HOME, USER and DISPLAY, are retained.

from the man page of nix-shell

What does type -a gcc say?

mkShell is a wrapper around stdenv.mkDerivation, which means you automatically always get all of stdenv as build inputs — including its default compiler. I recommend running which -a gcc or type -a gcc as @abathur recommended. You almost certainly have both versions of GCC in your PATH.

Try using mkShellNoCC


(also @Qyriad ) I get the following

> type -a gcc
gcc is /nix/store/49nb1m1ysq0vx31qp94alpmi6ccsq9l3-gcc-wrapper-13.2.0/bin/gcc
gcc is /nix/store/8y16aj4mk0rbck2hlg538322d5r1gi7m-gcc-13.2.0/bin/gcc
gcc is /nix/store/vpvk8r47396spnia2zddlz2iab18pcm5-gcc-9.5.0/bin/gcc
gcc is /usr/bin/gcc
gcc is /bin/gcc

/bin/gcc and /usr/bin/gcc both have version 13.2.1. So it seems 11.3.0 is completely missing…

To be fully transparent, I just tested this on a aarch64-linux system (I dont have access to the x86_64-linux-machine until Monday)…

@lovirent The --pure flag did not change anything in respect to the gcc version. But thank you, still useful to know!

@Qyriad Running it with mkShellNoCC I end up with 9.5.0.^^’