Skip to content

Cannot find xcrun when building with Nix flakes on Darwin/MacOS #6117

Closed
@josephst

Description

On latest version of llama.cpp, building from flake (ie nix build github:ggerganov/llama.cpp) produces error with latest commit (d01b3c4 at time of writing).

error: builder for '/nix/store/9qrdgaz8s1wfz9fwci01j2vi97y45cfy-llama-cpp-metalkit-0.0.0.drv' failed with exit code 1;
       last 25 log lines:
       > -- Generating done (0.0s)
       > CMake Warning:
       >   Manually-specified variables were not used by the project:
       >
       >     CMAKE_EXPORT_NO_PACKAGE_REGISTRY
       >     CMAKE_POLICY_DEFAULT_CMP0025
       >
       >
       > -- Build files have been written to: /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build
       > cmake: enabled parallel building
       > cmake: enabled parallel installing
       > Running phase: buildPhase
       > build flags: -j8
       > [1/132] Compiling Metal kernels
       > FAILED: bin/default.metallib /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/default.metallib
       > cd /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build && xcrun -sdk macosx metal -O3 -c /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-metal.metal -o /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-metal.air && xcrun -sdk macosx metallib /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-metal.air -o /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/default.metallib && rm -f /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-metal.air && rm -f /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-common.h && rm -f /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-metal.metal
       > /bin/sh: xcrun: command not found
       > [2/132] Building C object CMakeFiles/ggml.dir/ggml-alloc.c.o
       > [3/132] Building C object CMakeFiles/ggml.dir/ggml-backend.c.o
       > [4/132] Building C object CMakeFiles/ggml.dir/ggml-metal.m.o
       > [5/132] Building C object CMakeFiles/ggml.dir/ggml-quants.c.o
       > [6/132] Building C object CMakeFiles/ggml.dir/ggml.c.o
       > [7/132] Building CXX object CMakeFiles/llama.dir/unicode.cpp.o
       > [8/132] Building CXX object CMakeFiles/llama.dir/llama.cpp.o
       > ninja: build stopped: subcommand failed.
       For full logs, run 'nix log /nix/store/9qrdgaz8s1wfz9fwci01j2vi97y45cfy-llama-cpp-metalkit-0.0.0.drv'.

The key error is /bin/sh: xcrun: command not found -- Nix provides a clean $PATH to CMake which does not include /usr/bin and so Cmake is unable to locate or run /usr/bin/xcrun. This behavior is specific to the combination of MacOS and Nix.

This can be fixed by either manually adding /usr/bin to $PATH prior to configuration & build steps, or by using absolute path (/usr/bin/xcrun) and setting dontFixCmake = true; in package.nix.

System details:
Nix 2.21 (sandbox = off), MacOS 14.4 Sonoma

Activity

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions