NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.74k stars 1.52k forks source link

gcc always present in nix-shell and overrides clang #5117

Open babbaj opened 3 years ago

babbaj commented 3 years ago

Is your feature request related to a problem? Please describe. When creating a nix-shell with -p, even with --pure, gcc will be included in the $PATH and it will take precedence over any explicitly listed package. This makes it very annoying to try to build a program with clang instead of gcc and requires creating a shell.nix or setting cmake variables to work around.

Describe the solution you'd like nix-shell is currently created with pkgs.runCommandCC, use pkgs.runCommand instead to just remove gcc

Describe alternatives you've considered Getting the package arguments to be in the $PATH before the default packages would also work without being a potentially breaking change

trofi commented 3 years ago

I also noticed that pointing cc to clang is not very easy via nix-shell -p clang due to always-present gcc:

$ nix-shell -p gcc -p clang --command 'cc --version'
gcc (GCC) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ nix-shell -p clang -p gcc --command 'cc --version'
gcc (GCC) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

nixos-discourse commented 1 month ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/using-gcc-14-with-nix/52001/2

szmarczak commented 1 month ago

ref: https://github.com/NixOS/nix/pull/9836

szmarczak commented 1 month ago

ref: https://stackoverflow.com/questions/50277775/how-do-i-select-gcc-version-in-nix-shell

szmarczak commented 1 month ago

ref: https://www.reddit.com/r/NixOS/comments/1cqeuhx/why_does_nixshell_p_suddenly_allow_me_to_compile_c/

szmarczak commented 1 month ago

ref: https://github.com/NixOS/nixpkgs/issues/283248