user7610
user7610

Reputation: 28811

How do I select GCC version in nix-shell?

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?

Upvotes: 12

Views: 9286

Answers (2)

user7610
user7610

Reputation: 28811

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

Upvotes: 3

user7610
user7610

Reputation: 28811

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

Upvotes: 13

Related Questions