NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.58k stars 13.73k forks source link

cc-wrapper.sh: `mktemp: command not found` #316674

Open cormacrelf opened 3 months ago

cormacrelf commented 3 months ago

Describe the bug

cc-wrapper.sh is not using Nix mktemp, it's expecting one to be in the environment. So it fails when you run it with an empty PATH.

This is happening because it's:

  1. Saving a PATH backup
  2. Setting PATH to nix's coreutils/bin:gnugrep:bin
  3. Using it for grep & cat etc
  4. Restoring the PATH backup
  5. Attempting to use mktemp

https://github.com/NixOS/nixpkgs/blob/0e9703512aaa0dfa34f15e4931a2f7d58a47bcb1/pkgs/build-support/cc-wrapper/cc-wrapper.sh#L239-L249

Steps To Reproduce

  1. On pretty much any system:

    $ env - $(which nix) run nixpkgs#clang
    /nix/store/c1ib07kj7baid3s3wf5m98hcpbvgs8mk-clang-wrapper-16.0.6/bin/clang: line 249: mktemp: command not found

There is no step 2. You might encounter a situation like this when running Clang with a heavily stripped environment in a Remote Build Execution context.

Expected behavior

cc-wrapper should not error if the PATH is empty

Additional context

It looks to me like this is the root cause of #258608. Probably same with https://github.com/tweag/rules_nixpkgs/issues/439.

Notify maintainers

No maintainers seem to be listed in cc-wrapper's metadata. But maybe @Artturin?

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
almost any system imaginable

Add a :+1: reaction to issues you find important.

Artturin commented 3 months ago

https://github.com/NixOS/nixpkgs/pull/316700