What version of gcc does nix use?

Attempting to answer the question here. What version of gcc does nix use by default?

I went poking around searching the code, but nothing jumped out at me…

$ nix eval .#stdenv.cc.cc.name
warning: Git tree '/home/jon/projects/nixpkgs' is dirty

You can use a different stdenv to select a different version:

$ nix eval .#gcc11Stdenv.cc.cc.name
warning: Git tree '/home/jon/projects/nixpkgs' is dirty
1 Like

Awesome, thanks @jonringer !

Just for completeness you can use the nix repl to do it too, i like it better , because i can just keep smashing the complete key, to navigate around.

nix repl '<nixpkgs>'
nix-repl> stdenv.cc.cc.name 

however, @jonringer solution is far superior to mine, as always.


I don’t think nix repl gets enough love :slight_smile:


In case you want to change that it hides in https://raw.githubusercontent.com/NixOS/nixpkgs/master/pkgs/top-level/all-packages.nix

  inherit (let
      num =
        if (with stdenv.targetPlatform; isVc4 || libc == "relibc") then 6
        else if (stdenv.targetPlatform.isAarch64 && stdenv.isDarwin) then 11
        else if stdenv.targetPlatform.isAarch64 then 9
        else 10;
      numS = toString num;
    in {
      gcc = pkgs.${"gcc${numS}"};
      gccFun = callPackage (../development/compilers/gcc + "/${numS}");
    }) gcc gccFun;
  gcc-unwrapped = gcc.cc;

Note that it’s 6, 9, 10 or even 11 depending on target.