Xcrun missing building node packages on MacOS

Hi y’all! I’m having some trouble getting my home-manager to build itself recently on my mac. Specifically, I’m unable to derive any packages that seem to be node-based? Or maybe whatever node-gyp is? This affects, for me, both bitwarden-cli and bruno.

The error

The result of trying to include either of these looks like:

❯ nix shell "nixpkgs#bitwarden-cli"
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.4.1
npm ERR! gyp info using node@20.12.2 | darwin | arm64
npm ERR! gyp info find Python using Python version 3.11.9 found at "/nix/store/327bf08j5b7l9cnzink3g4vp32y5352j-python3-3.11.9/bin/python3"
npm ERR! gyp WARN read config.gypi ENOENT: no such file or directory, open '/nix/store/185l7cflc6l9ph3dj2kx2r63g7g2cf67-nodejs-20.12.2-source/include/node/config.gypi'
npm ERR! gyp info spawn /nix/store/327bf08j5b7l9cnzink3g4vp32y5352j-python3-3.11.9/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/nice-napi/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/nix/store/185l7cflc6l9ph3dj2kx2r63g7g2cf67-nodejs-20.12.2-source/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/nix/store/185l7cflc6l9ph3dj2kx2r63g7g2cf67-nodejs-20.12.2-source',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/nix/store/185l7cflc6l9ph3dj2kx2r63g7g2cf67-nodejs-20.12.2-source/$(Configuration)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/nice-napi',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! Traceback (most recent call last):
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/gyp_main.py", line 45, in <module>
npm ERR!     sys.exit(gyp.script_main())
npm ERR!              ^^^^^^^^^^^^^^^^^
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 686, in script_main
npm ERR!     return main(sys.argv[1:])
npm ERR!            ^^^^^^^^^^^^^^^^^^
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 678, in main
npm ERR!     return gyp_main(args)
npm ERR!            ^^^^^^^^^^^^^^
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 663, in gyp_main
npm ERR!     generator.GenerateOutput(flat_list, targets, data, params)
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2651, in GenerateOutput
npm ERR!     writer.Write(
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 915, in Write
npm ERR!     self.WriteSources(
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1398, in WriteSources
npm ERR!     cflags = self.xcode_settings.GetCflags(
npm ERR!              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 580, in GetCflags
npm ERR!     sdk_root = self._SdkPath()
npm ERR!                ^^^^^^^^^^^^^^^
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 547, in _SdkPath
npm ERR!     return self._XcodeSdkPath(sdk_root)
npm ERR!            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 551, in _XcodeSdkPath
npm ERR!     sdk_path = self._GetSdkVersionInfoItem(sdk_root, "--show-sdk-path")
npm ERR!                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 525, in _GetSdkVersionInfoItem
npm ERR!     return GetStdoutQuiet(["xcrun", "--sdk", sdk, infoitem])
npm ERR!            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
npm ERR!   File "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1560, in GetStdoutQuiet
npm ERR!     job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
npm ERR!           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
npm ERR!   File "/nix/store/327bf08j5b7l9cnzink3g4vp32y5352j-python3-3.11.9/lib/python3.11/subprocess.py", line 1026, in __init__
npm ERR!     self._execute_child(args, executable, preexec_fn, close_fds,
npm ERR!   File "/nix/store/327bf08j5b7l9cnzink3g4vp32y5352j-python3-3.11.9/lib/python3.11/subprocess.py", line 1955, in _execute_child
npm ERR!     raise child_exception_type(errno_num, err_msg, err_filename)
npm ERR! FileNotFoundError: [Errno 2] No such file or directory: 'xcrun'
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/lib/configure.js:325:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:518:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:294:12)
npm ERR! gyp ERR! System Darwin 23.5.0
npm ERR! gyp ERR! command "/nix/store/ridvrr7dsnxpvh3f1sr41xiwvwk1nnkg-nodejs-20.12.2/bin/node" "/private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /private/tmp/nix-build-bitwarden-cli-2024.6.0.drv-0/source/node_modules/nice-napi
npm ERR! gyp ERR! node -v v20.12.2
npm ERR! gyp ERR! node-gyp -v v9.4.1
npm ERR! gyp ERR! not ok

(full log here)

The trouble is, i have already gotten xcode installed and set up “correctly” from what i can tell. For example:

❯ which xcrun
/usr/bin/xcrun

Attempts to yeet into path

In my futile attempts to get this to find the thing, I’ve been experimenting with the (non-functioning):

{ pkgs, lib, stdenv, ... }: let
  xcrun = pkgs.writeShellScriptBin "xcrun" ''
    exec "/usr/bin/xcrun" "$@"
  '';
  pkgs' = (pkgs.extend (final: prev: {
    bitwarden-cli' = prev.bitwarden-cli.overrideAttrs (prevSet: {
      nativeBuildInputs = prevSet.nativeBuildInputs ++ (
        if stdenv.isDarwin then [xcrun] else []
      );
    });
  }));
in {
  home.packages = [
    pkgs'.bitwarden-cli'
  ];
}

but, it’s non-functioning because of my lack of knowledge of how the overrideAttrs and such work… There’s several layers of … experimentation … with the nix grammar in there so it’s evolved organically a bit. But I keep getting unrelated-to-original-issue errors like

        error: attribute 'stdenv' missing

(yes, this is not enough context for debugging this half of the issue, but not really the goal right now. I don’t think this’ll be the way someone suggests I go? But I could be wrong)

Anyways, anyone have a suggestion on how to get the nix builds to find xcrun? Thanks!

Darwin does not use the system toolchain or Xcode. It builds its own, which does not include xcrun (though that is something I’d like to change). If a package needs xcrun, it needs to include xcbuild.xcrun as a native build input or patch out references to it to use the equivalent paths in the store.

Probably needs to be pkgs.stdenv instead of just stdenv. There’s also no need to extend pkgs just assign the result of overrideAttrs to a name and reference that in home.packages.

1 Like

That looks like it did it! I’ll submit some pull requests today for bruno and bitwarden-cli once i get the chance.

And this solved me being unable to get the package working locally at least to be able to verify the change :slight_smile:. I had a local variable with the package before, actually, but it morphed and evolved into this overlay while i was fighting things :grimacing:.

1 Like