···
···
gguf-tools = fetchFromGitHub {
19
-
rev = "af7d88d808a7608a33723fba067036202910acb3";
20
-
hash = "sha256-LqNvnUbmq0iziD9VP5OTJCSIy+y/hp5lKCUV7RtKTvM=";
33
+
rev = "8fa6eb65236618e28fd7710a0fba565f7faa1848";
34
+
hash = "sha256-15FvyPOFqTOr5vdWQoPnZz+mYH919++EtghjozDlnSA=";
22
-
nlohmann_json = fetchFromGitHub {
26
-
hash = "sha256-7F0Jon+1oWL7uqet5i1IgHX0fUw/+z0QwEcA3zs5xHg=";
29
-
buildPythonPackage rec {
33
-
src = fetchFromGitHub {
34
-
owner = "ml-explore";
36
-
rev = "refs/tags/v${version}";
37
-
hash = "sha256-wxv9bA9e8VyFv/FMh63sUTTNgkXHGQJNQhLuVynczZA=";
37
+
mlx = buildPythonPackage rec {
42
+
src = fetchFromGitHub {
43
+
owner = "ml-explore";
45
+
tag = "v${version}";
46
+
hash = "sha256-fkf/kKATr384WduFG/X81c5InEAZq5u5+hwrAJIg7MI=";
43
-
# With Darwin SDK 11 we cannot include vecLib/cblas_new.h, this needs to wait for PR #229210
44
-
# In the meantime, pretend Accelerate is not available and use blas/lapack instead.
45
-
./disable-accelerate.patch
50
+
(replaceVars ./darwin-build-fixes.patch {
51
+
sdkVersion = apple-sdk_14.version;
49
-
substituteInPlace CMakeLists.txt \
50
-
--replace "/usr/bin/xcrun" "${xcbuild}/bin/xcrun" \
56
+
substituteInPlace pyproject.toml \
57
+
--replace-fail "nanobind==2.4.0" "nanobind>=2.4.0"
59
+
substituteInPlace mlx/backend/cpu/jit_compiler.cpp \
60
+
--replace-fail "g++" "$CXX"
53
-
dontUseCmakeConfigure = true;
63
+
dontUseCmakeConfigure = true;
55
-
# updates the wrong fetcher rev attribute
56
-
passthru.skipBulkUpdate = true;
65
+
enableParallelBuilding = true;
67
+
# Allows multiple cores to be used in Python builds.
69
+
export MAKEFLAGS+="''${enableParallelBuilding:+-j$NIX_BUILD_CORES}"
59
-
PYPI_RELEASE = version;
60
-
# we can't use Metal compilation with Darwin SDK 11
61
-
CMAKE_ARGS = toString [
62
-
(lib.cmakeBool "MLX_BUILD_METAL" false)
63
-
(lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_GGUFLIB" "${gguf-tools}")
64
-
(lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_JSON" "${nlohmann_json}")
72
+
# updates the wrong fetcher rev attribute
73
+
passthru.skipBulkUpdate = true;
76
+
PYPI_RELEASE = version;
77
+
CMAKE_ARGS = toString [
78
+
# NOTE The `metal` command-line utility used to build the Metal kernels is not open-source.
79
+
# To build mlx with Metal support in Nix, you'd need to use one of the sandbox escape
80
+
# hatches which let you interact with a native install of Xcode, such as `composeXcodeWrapper`
81
+
# or by changing the upstream (e.g., https://github.com/zed-industries/zed/discussions/7016).
82
+
(lib.cmakeBool "MLX_BUILD_METAL" false)
83
+
(lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_GGUFLIB" "${gguf-tools}")
84
+
(lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_JSON" "${nlohmann_json.src}")
85
+
(lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_FMT" "${fmt_10.src}")
68
-
nativeBuildInputs = [
93
+
nativeBuildInputs = [
84
-
homepage = "https://github.com/ml-explore/mlx";
85
-
description = "Array framework for Apple silicon";
86
-
changelog = "https://github.com/ml-explore/mlx/releases/tag/v${version}";
87
-
license = licenses.mit;
88
-
platforms = [ "aarch64-darwin" ];
89
-
maintainers = with maintainers; [
106
+
pythonImportsCheck = [ "mlx" ];
108
+
# Run the mlx Python test suite.
109
+
nativeCheckInputs = [
114
+
pytestFlagsArray = [
118
+
# Additional testing by executing the example Python scripts supplied with mlx
119
+
# using the version of the library we've built.
122
+
runCommand "run-mlx-examples"
124
+
buildInputs = [ mlx ];
125
+
nativeBuildInputs = [ python ];
128
+
cp ${src}/examples/python/logistic_regression.py .
129
+
${python.interpreter} logistic_regression.py
130
+
rm logistic_regression.py
132
+
cp ${src}/examples/python/linear_regression.py .
133
+
${python.interpreter} linear_regression.py
134
+
rm linear_regression.py
141
+
homepage = "https://github.com/ml-explore/mlx";
142
+
description = "Array framework for Apple silicon";
143
+
changelog = "https://github.com/ml-explore/mlx/releases/tag/${src.tag}";
144
+
license = lib.licenses.mit;
145
+
platforms = [ "aarch64-darwin" ];
146
+
maintainers = with lib.maintainers; [