Skip to content

cc-wrapper mktemp invokation incompatible with MacOS #258607

Closed

Description

@aherrmann

Describe the bug

The cc-wrapper invokes mktemp with the --tmpdir flag, which is not supported on MacOS.

Steps To Reproduce

I do not have a short reproducer. However, the issue was observed on this GitHub actions CI run in a cgo context.

  # runtime/cgo
  mktemp: illegal option -- -
  usage: mktemp [-d] [-q] [-t prefix] [-u] template ...
         mktemp [-d] [-q] [-u] -t prefix 

The issue can be resolved by applying the following change to cc-wrapper.sh:

@@ -246,7 +246,7 @@ 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 cc-params.XXXXXX)
+    responseFile=$(mktemp "${TMPDIR:-/tmp}/cc-params.XXXXXX")
     trap 'rm -f -- "$responseFile"' EXIT
     printf "%q\n" \
        ${extraBefore+"${extraBefore[@]}"} \

Expected behavior

The mktemp error should not have occurred. The code under test used to work, and failed after an update of the nixpkgs revision in use from ea4c80b to 6500b45.

Screenshots

n/a

Additional context

The commit range includes the following two commits that touch on mktemp:

  • 520a544 adds mktemp --tmpdir to the strip setup-hook
  • 6f2b3ba adds mktemp --tmpdir to the cc-wrapper for response file handling
    The latter one seems to be the cause of the issue.

Similar issues were described in #254104 (comment) and numtide/devshell#10 (comment).

Notify maintainers

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"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 21.6.0, macOS 12.6.3`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.13.3`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`

Activity

  1. added
    0.kind: bug
    on Oct 2, 2023
  2. tobim commented on Oct 2, 2023

    @tobim
    Contributor

    So the wrapper picks up the mktemp binary from the system instead of the one from the store because the environment is not pure? This makes the behavior of this and other wrappers unpredictable. Maybe it would be better to make sure that the tools used in the wrapper are actually from its real runtime dependencies in the store?

  3. aherrmann commented on Oct 3, 2023

    @aherrmann
    MemberAuthor

    @tobim Yes, that matches my understanding.

    Maybe it would be better to make sure that the tools used in the wrapper are actually from its real runtime dependencies in the store?

    Yes, that thought crossed my mind, too. However, I saw that there is an explicit import of coreutils, which is then explicitly reverted. And this import is conditional and seems to be disabled on MacOS. I don't know the context or reasoning for all this logic and didn't venture there. But, that may very well also be a good solution.

  4. tobim commented on Oct 3, 2023

    @tobim
    Contributor

    Ah cool! So it basically already works that way. Setting nativeTools = false actually enables the import.

    Your explanation led me to find #11798 where this logic was first introduced. The discussion there is very interesting, afaiu we need to restore PATH to its original value so things like linker scripts will still find the intended executables.

    I think that the commit that introduced the mktemp should have added it before the path gets restored.

  5. aherrmann commented on Oct 3, 2023

    @aherrmann
    MemberAuthor

    Ah cool! So it basically already works that way. Setting nativeTools = false actually enables the import.

    Oh, I see, thanks! I overlooked one negation.

    I think that the commit that introduced the mktemp should have added it before the path gets restored.

    That seems like it could solve the issue, too. Perhaps it's easier to just resolve mktemp before the PATH is reset and then still invoke it later, since there is some more code in-between.

    I had opened #258608 that replaces the mktemp invocation by a portable one. That approach was easier to test in my use-case without rebuilding the world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions