From fe3ec7768c405476cc09e4ffa63accbad1db0140 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Sun, 25 Jan 2026 14:37:08 -0500 Subject: [PATCH 1/5] python3Packages.mlx: use nlohmann_json from nixpkgs --- .../python-modules/mlx/default.nix | 5 +++-- .../python-modules/mlx/dont-fetch-json.patch | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/python-modules/mlx/dont-fetch-json.patch diff --git a/pkgs/development/python-modules/mlx/default.nix b/pkgs/development/python-modules/mlx/default.nix index f146911a9974..2cddc0359c93 100644 --- a/pkgs/development/python-modules/mlx/default.nix +++ b/pkgs/development/python-modules/mlx/default.nix @@ -52,8 +52,9 @@ buildPythonPackage (finalAttrs: { }; patches = [ - # Use system nanobind instead of fetching its sources + # Use nix packages instead of fetching their sources ./dont-fetch-nanobind.patch + ./dont-fetch-json.patch ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ (replaceVars ./darwin-build-fixes.patch { @@ -88,7 +89,7 @@ buildPythonPackage (finalAttrs: { (lib.cmakeBool "MLX_BUILD_METAL" false) (lib.cmakeBool "USE_SYSTEM_FMT" true) (lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_GGUFLIB" "${gguf-tools}") - (lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_JSON" "${nlohmann_json.src}") + (lib.cmakeFeature "CMAKE_CXX_FLAGS" "-I${lib.getDev nlohmann_json}/include/nlohmann") # Cmake cannot find nanobind-config.cmake by itself (lib.cmakeFeature "nanobind_DIR" "${nanobind}/${python.sitePackages}/nanobind/cmake") diff --git a/pkgs/development/python-modules/mlx/dont-fetch-json.patch b/pkgs/development/python-modules/mlx/dont-fetch-json.patch new file mode 100644 index 000000000000..e134d25d2cd3 --- /dev/null +++ b/pkgs/development/python-modules/mlx/dont-fetch-json.patch @@ -0,0 +1,20 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 2451aa65..f88d4889 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -241,14 +241,6 @@ else() + set(MLX_BUILD_ACCELERATE OFF) + endif() + +-message(STATUS "Downloading json") +-FetchContent_Declare( +- json +- URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz) +-FetchContent_MakeAvailable(json) +-target_include_directories( +- mlx PRIVATE $) +- + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/mlx) + + target_include_directories( + From 45e266fad1b4eccaca5ac42a90b2d88fdbf041c5 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Sun, 25 Jan 2026 14:47:18 -0500 Subject: [PATCH 2/5] python3Packages.mlx: remove gguf-tools source checkout from buildInputs The `gguf-tools` are defined in `let` section to point to a source checkout, not nixpkgs derivation. Note: regardless, the tools are not used in runtime. Instead, some files from the source checkout are statically compiled during the build. --- pkgs/development/python-modules/mlx/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/development/python-modules/mlx/default.nix b/pkgs/development/python-modules/mlx/default.nix index 2cddc0359c93..c68c8d78bd68 100644 --- a/pkgs/development/python-modules/mlx/default.nix +++ b/pkgs/development/python-modules/mlx/default.nix @@ -104,7 +104,6 @@ buildPythonPackage (finalAttrs: { buildInputs = [ fmt - gguf-tools nlohmann_json pybind11 ] From 1f1f66c30b29510f7e8091b6a59c31f3d56e03ae Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Sun, 25 Jan 2026 14:57:45 -0500 Subject: [PATCH 3/5] python3Packages.mlx: remove pybind11 from buildInputs The package was used to generate bindings before (meaning, it should have probably belonged to nativeBuildInputs). But it's no longer used since https://github.com/ml-explore/mlx/pull/839 (included with v0.8.0). --- pkgs/development/python-modules/mlx/default.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/development/python-modules/mlx/default.nix b/pkgs/development/python-modules/mlx/default.nix index c68c8d78bd68..600d5dd6a5cf 100644 --- a/pkgs/development/python-modules/mlx/default.nix +++ b/pkgs/development/python-modules/mlx/default.nix @@ -15,7 +15,6 @@ apple-sdk, fmt, nlohmann_json, - pybind11, # linux-only openblas, @@ -105,7 +104,6 @@ buildPythonPackage (finalAttrs: { buildInputs = [ fmt nlohmann_json - pybind11 ] ++ lib.optionals stdenv.hostPlatform.isLinux [ openblas From c2facdf896a5e3247ebf9e69f4a5678335f74d33 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Sun, 25 Jan 2026 15:15:31 -0500 Subject: [PATCH 4/5] python3Packages.mlx: enable for x86_64-darwin --- .../python-modules/mlx-lm/default.nix | 4 --- .../python-modules/mlx/default.nix | 33 ++++++++++--------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/pkgs/development/python-modules/mlx-lm/default.nix b/pkgs/development/python-modules/mlx-lm/default.nix index 25809fb16869..e9f388fb1b77 100644 --- a/pkgs/development/python-modules/mlx-lm/default.nix +++ b/pkgs/development/python-modules/mlx-lm/default.nix @@ -84,9 +84,5 @@ buildPythonPackage (finalAttrs: { homepage = "https://github.com/ml-explore/mlx-lm"; changelog = "https://github.com/ml-explore/mlx-lm/releases/tag/${finalAttrs.src.tag}"; license = lib.licenses.mit; - badPlatforms = [ - # Building for x86_64 on macOS is not supported by mlx (dependency) - "x86_64-darwin" - ]; }; }) diff --git a/pkgs/development/python-modules/mlx/default.nix b/pkgs/development/python-modules/mlx/default.nix index 600d5dd6a5cf..13be20543689 100644 --- a/pkgs/development/python-modules/mlx/default.nix +++ b/pkgs/development/python-modules/mlx/default.nix @@ -80,19 +80,24 @@ buildPythonPackage (finalAttrs: { env = { PYPI_RELEASE = 1; - CMAKE_ARGS = toString [ - # NOTE The `metal` command-line utility used to build the Metal kernels is not open-source. - # To build mlx with Metal support in Nix, you'd need to use one of the sandbox escape - # hatches which let you interact with a native install of Xcode, such as `composeXcodeWrapper` - # or by changing the upstream (e.g., https://github.com/zed-industries/zed/discussions/7016). - (lib.cmakeBool "MLX_BUILD_METAL" false) - (lib.cmakeBool "USE_SYSTEM_FMT" true) - (lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_GGUFLIB" "${gguf-tools}") - (lib.cmakeFeature "CMAKE_CXX_FLAGS" "-I${lib.getDev nlohmann_json}/include/nlohmann") + CMAKE_ARGS = toString ( + [ + # NOTE The `metal` command-line utility used to build the Metal kernels is not open-source. + # To build mlx with Metal support in Nix, you'd need to use one of the sandbox escape + # hatches which let you interact with a native install of Xcode, such as `composeXcodeWrapper` + # or by changing the upstream (e.g., https://github.com/zed-industries/zed/discussions/7016). + (lib.cmakeBool "MLX_BUILD_METAL" false) + (lib.cmakeBool "USE_SYSTEM_FMT" true) + (lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_GGUFLIB" "${gguf-tools}") + (lib.cmakeFeature "CMAKE_CXX_FLAGS" "-I${lib.getDev nlohmann_json}/include/nlohmann") - # Cmake cannot find nanobind-config.cmake by itself - (lib.cmakeFeature "nanobind_DIR" "${nanobind}/${python.sitePackages}/nanobind/cmake") - ]; + # Cmake cannot find nanobind-config.cmake by itself + (lib.cmakeFeature "nanobind_DIR" "${nanobind}/${python.sitePackages}/nanobind/cmake") + ] + ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [ + (lib.cmakeBool "MLX_ENABLE_X64_MAC" true) + ] + ); }; build-system = [ @@ -178,9 +183,5 @@ buildPythonPackage (finalAttrs: { cameronyule viraptor ]; - badPlatforms = [ - # Building for x86_64 on macOS is not supported - "x86_64-darwin" - ]; }; }) From 04594bc62c633df93cd342e9d3baf0b1bc3c3a68 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Sun, 25 Jan 2026 15:17:46 -0500 Subject: [PATCH 5/5] ramalama: remove explicit check of mlx-lm availability It's now available on linux and darwin for both cpu architectures ramalama package targets. --- pkgs/by-name/ra/ramalama/package.nix | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pkgs/by-name/ra/ramalama/package.nix b/pkgs/by-name/ra/ramalama/package.nix index 7408bbcce385..2c8199247888 100644 --- a/pkgs/by-name/ra/ramalama/package.nix +++ b/pkgs/by-name/ra/ramalama/package.nix @@ -56,13 +56,10 @@ python3Packages.buildPythonApplication rec { llama-cpp-vulkan podman ] - ++ ( - with python3Packages; - [ - huggingface-hub - ] - ++ lib.optional (lib.meta.availableOn stdenv.hostPlatform mlx-lm) mlx-lm - ) + ++ (with python3Packages; [ + huggingface-hub + mlx-lm + ]) ) } '';