Exclude gcc toolchain for a nix-shell?

I’m a very new nix user, so I’m not even sure what I’m trying to do is a good idea.

We have internal project that is currently very tied to Ubuntu, and I’d like to make it more portable. The core of the project is C++ with some Python tools and shell scripts that depend on some common command line utilities.

I’d love to nix-ify the whole thing, but one step at a time. I thought a good first start would be to create a shell.nix for the project to provide some of the support tools we need, instead relying on sudo apt install ...

However, even the simplest nix shell environments seems to bring in gcc and the rest of the toolchain components automatically. I’d like to keep using the system compiler for the time being.

I know I could remove gcc et al from the PATH, but that seems like a kludge.

Also I thought “nativeBuildInputs” might work, but it didn’t seem to.

Here’s my shell.nix:

{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/65c9cc79f1d179713c227bf447fb0dac384cdcda.tar.gz") {} }:

pkgs.mkShell {
  buildInputs = [
     pkgs.curl
     pkgs.rsync
  ];
}

After I run nix-shell or use direnv

 $ which gcc
/nix/store/azayfhqyg9mjyv6rv9bcypi6ws8aqfmy-gcc-wrapper-9.3.0/bin/gcc

Is there a clean way to set up up a nix shell environment without overriding the gcc toolchain?

1 Like

Have you tried nix-shell --pure?

again, I’m a beginner, but as I understand nix-shell --pure is the opposite of what I want. I want to use the system gcc for now, not nix’s

1 Like

mkShell is just a wrapper around mkDerivation

{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/65c9cc79f1d179713c227bf447fb0dac384cdcda.tar.gz") {} }:

pkgs.stdenvNoCC.mkDerivation {
  name = "shell";
  nativeBuildInputs = [
     pkgs.curl
     pkgs.rsync
  ];
}
[17:56:55] jon@nixos ~/projects/nixpkgs (release-20.09)
$ gcc --help
The program ‘gcc’ is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix-env -iA nixos.ccacheWrapper
  ...
[17:57:07] jon@nixos ~/projects/nixpkgs (release-20.09)
$ nix-shell noccshell.nix

[nix-shell:~/projects/nixpkgs]$ gcc --help
The program ‘gcc’ is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix-env -iA nixos.ccacheWrapper
  ...

[nix-shell:~/projects/nixpkgs]$ curl --help
Usage: curl [options...] <url>
     --abstract-unix-socket <path> Connect via abstract Unix domain socket
    ...
3 Likes

thank, you stdenvNoCC was what I was looking for.

1 Like