From 77c5993a69c42a6ebe8d97873bb17eb8aba58dc8 Mon Sep 17 00:00:00 2001 From: Malte Poll <1780588+malt3@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:34:11 +0100 Subject: [PATCH] cc-wrapper: Resolve mktemp and rm path before resetting $PATH Without this, mktemp (and rm) from the host environment is picked up. This may result in mktemp behaving differently (on darwin) or mktemp / rm not being found at all. --- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index b8d170df01b73..cfecb1e446f94 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -236,6 +236,14 @@ if (( "${NIX_DEBUG:-0}" >= 1 )); then printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2 fi +# Resolve mktemp and rm before resetting the PATH. +# If coreutils was added to the PATH above, +# we want to use the configured coreutils versions +# (@coreutils_bin@) of these commands. +# Since rm is used in the trap below, we have no +# choice but to resolve it here. +MKTEMP=$(command -v mktemp) +RM=$(command -v rm) PATH="$path_backup" # Old bash workaround, see above. @@ -246,8 +254,8 @@ if [[ -e @out@/nix-support/cc-wrapper-hook ]]; then fi if (( "${NIX_CC_USE_RESPONSE_FILE:-@use_response_file_by_default@}" >= 1 )); then - responseFile=$(mktemp "${TMPDIR:-/tmp}/cc-params.XXXXXX") - trap 'rm -f -- "$responseFile"' EXIT + responseFile=$("${MKTEMP}" "${TMPDIR:-/tmp}/cc-params.XXXXXX") + trap '"${RM}" -f -- "$responseFile"' EXIT printf "%q\n" \ ${extraBefore+"${extraBefore[@]}"} \ ${params+"${params[@]}"} \