12

I am requesting GCC 8, but I get GCC 7 instead.

$ nix-shell -p gcc8
[nix-shell:~]$ gcc --version
gcc (GCC) 7.3.0

What is going on?

2 Answers 2

13

You need to base your environment on stdenvNoCC, instead of stdenv

That means, you may create a shell.nix or default.nix file in your current directory, defining the environment, and then run nix-shell.

with import <nixpkgs> {}; {
  qpidEnv = stdenvNoCC.mkDerivation {
    name = "my-gcc8-environment";
    buildInputs = [
        gcc8
        go
        ruby_2_4
        gdb
        swig
        # libev
        #...
    ];
  };
}

Now, it works as expected

$ nix-shell
[nix-shell:~]$ gcc --version
gcc (GCC) 8.1.0

Source: https://groups.google.com/forum/#!topic/nix-devel/of6P-sEtQN0

9
  • 2
    I think you can also mention the wiki's say on this issue: nixos.wiki/wiki/C#Use_a_different_compiler_version Commented Jul 8, 2019 at 19:50
  • What about if in addition, I also want to have a cmake version 2.8.8? And by the way, from the looks of gcc8 or ruby_2_4 it seems that the version has no standard way of format and it is hard-to-get. Is there an index listing of these various versions?
    – daparic
    Commented Sep 30, 2019 at 12:28
  • Probably best to raise separate questions. The only thing I can answer is how to figure what's available. I usually look into pkgs/top-level/all-packages.nix in nixpkgs repository, github.com/NixOS/nixpkgs/blob/…
    – user7610
    Commented Sep 30, 2019 at 12:46
  • Btw, does dropping cmake_2_8 into the package list work? The various ruby etc. packages in the answer are not needed for gcc to work, it is just what environment I needed besides gcc8 at that moments
    – user7610
    Commented Sep 30, 2019 at 12:47
  • 2
    I would like to point out that although this solves the problem, this does not explain why the path to the newly installed gcc did not have a higher priority than that of the existing one. This feels counter intuitive so I presume there is a good reason for this, but it would be nice to hear that reason in the answer. Commented Nov 15, 2022 at 1:49
3

Use nix run instead. It behaves better, and also has nicer progress indicator when downloading packages.

jdanek@nixos ~ % nix run -f channel:nixos-19.03 gcc8
[jdanek@nixos:~]$ gcc --version
gcc (GCC) 8.3.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.