Something went wrong. Try again.
What happens if I push all of nixpkgs
Something went wrong. Try again.
3.8 kB · 154 lines
Nix
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155{ buildPythonPackage, fetchFromGitHub, lib, replaceVars, stdenv,
# build-system setuptools,
# nativeBuildInputs cmake,
# buildInputs apple-sdk_14, fmt_10, nanobind, nlohmann_json, pybind11,
# tests numpy, pytestCheckHook, python, runCommand,}:
let # static dependencies included directly during compilation gguf-tools = fetchFromGitHub { owner = "antirez"; repo = "gguf-tools"; rev = "8fa6eb65236618e28fd7710a0fba565f7faa1848"; hash = "sha256-15FvyPOFqTOr5vdWQoPnZz+mYH919++EtghjozDlnSA="; };
mlx = buildPythonPackage rec { pname = "mlx"; version = "0.26.3"; pyproject = true;
src = fetchFromGitHub { owner = "ml-explore"; repo = "mlx"; tag = "v${version}"; hash = "sha256-hbqV/2KYGJ1gyExZd5bgaxTdhl5+Gext+U/+1KAztMU="; };
patches = [ (replaceVars ./darwin-build-fixes.patch { sdkVersion = apple-sdk_14.version; }) ];
postPatch = '' substituteInPlace pyproject.toml \ --replace-fail "nanobind==2.4.0" "nanobind>=2.4.0"
substituteInPlace mlx/backend/cpu/jit_compiler.cpp \ --replace-fail "g++" "$CXX" '';
dontUseCmakeConfigure = true;
enableParallelBuilding = true;
# Allows multiple cores to be used in Python builds. postUnpack = '' export MAKEFLAGS+="''${enableParallelBuilding:+-j$NIX_BUILD_CORES}" '';
# updates the wrong fetcher rev attribute passthru.skipBulkUpdate = true;
env = { PYPI_RELEASE = version; 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.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_GGUFLIB" "${gguf-tools}") (lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_JSON" "${nlohmann_json.src}") (lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_FMT" "${fmt_10.src}") ]; };
build-system = [ setuptools ];
nativeBuildInputs = [ cmake ];
buildInputs = [ apple-sdk_14 fmt_10 gguf-tools nanobind nlohmann_json pybind11 ];
pythonImportsCheck = [ "mlx" ];
# Run the mlx Python test suite. nativeCheckInputs = [ numpy pytestCheckHook ];
enabledTestPaths = [ "python/tests/" ];
# Additional testing by executing the example Python scripts supplied with mlx # using the version of the library we've built. passthru.tests = { mlxTest = runCommand "run-mlx-examples" { buildInputs = [ mlx ]; nativeBuildInputs = [ python ]; } '' cp ${src}/examples/python/logistic_regression.py . ${python.interpreter} logistic_regression.py rm logistic_regression.py
cp ${src}/examples/python/linear_regression.py . ${python.interpreter} linear_regression.py rm linear_regression.py
touch $out ''; };
meta = { homepage = "https://github.com/ml-explore/mlx"; description = "Array framework for Apple silicon"; changelog = "https://github.com/ml-explore/mlx/releases/tag/${src.tag}"; license = lib.licenses.mit; platforms = [ "aarch64-darwin" ]; maintainers = with lib.maintainers; [ viraptor Gabriella439 cameronyule ]; }; };inmlx