NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.07k stars 14.05k forks source link

nodejs: node-gyp fails to build due to hardcoded Xcode SDK paths in patch #239371

Open yakimant opened 1 year ago

yakimant commented 1 year ago

Describe the bug

After nixpkgs upgrade we started to have a build issue with node-gyp for dtrace-provider:

gcc -O2 -Wall -arch i386   -c -o usdt.o usdt.c
gcc: error: Failed to determine realpath of '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk' (errno=No such file or directory)
gcc: error: sh -c '/Applications/Xcode-14.3.1.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -find gcc 2> /dev/null' failed with exit code 16384: (null) (errno=No such file or directory)
xcode-select: Failed to locate 'gcc', requesting installation of command line developer tools.

Removing this patch solves the issue: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/web/nodejs/bypass-darwin-xcrun-node16.patch (see https://github.com/NixOS/nixpkgs/pull/193759) Maybe it is introducing new issues though.

On my machine I have the following in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ folder:

MacOSX.sdk
MacOSX13.3.sdk -> MacOSX.sdk
MacOSX13.sdk -> MacOSX.sdk

Steps To Reproduce

We run yarn install and packages/lock contain dtrace-provider. But I can come back with proper reproducing steps if needed.

Notify maintainers

@marsam, @lilyinstarlight

Metadata

❯ nix-shell -p nix-info --run "nix-info -m"

 - system: `"aarch64-darwin"`
 - host os: `Darwin 22.5.0, macOS 13.4`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.13.4`
 - channels(status): `""`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
lilyinstarlight commented 1 year ago

Maybe it is introducing new issues though.

Can confirm it does introduce new issues (unfortunately) where you are now impurely using your host system xcode tools (which don't always exist) instead of the nixpkgs ones

I'll see if I can root this out. Can you give me an exact derivation/command to reproduce so I don't have to make my own?

lilyinstarlight commented 1 year ago

Also to clarify, the paths are hardcoded in that patch because what they are should not matter iirc. It basically pretends xcode is available so node-gyp is happy and thinks it has SDK and CLT available, but it should not actually be using those values anywhere when you try to build for real

But clearly that assumption is wrong then if it's somehow leaking in for you and your build

yakimant commented 1 year ago

I think smth like this should help to reproduce:

  1. Create package.json:
    {
    "dependencies": {
    "dtrace-provider": "^0.8.8"
    }
    }
  2. nix-shell --packages nodejs yarn
  3. NODE_DTRACE_PROVIDER_REQUIRE=hard yarn install --verbose

Thanks for confirming the issue!

lilyinstarlight commented 1 year ago

Oh, you're experiencing this when just running npm/yarn plain rather than in a Nix derivation

Yeah we should probably make this patch dependent on whether or not we're in a Nix build I suppose

samrose commented 5 months ago

You could just use /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk this case, as that symlink points to whateer sdk is installed no matter the version

samrose commented 5 months ago

Yeah we should probably make this patch dependent on whether or not we're in a Nix build I suppose

How would you go about doing that?