From 0b12c690c53b5d98d8fc75e2469eff1c4f08a7e3 Mon Sep 17 00:00:00 2001 From: Benjamin Sparks Date: Fri, 30 May 2025 02:21:26 +0200 Subject: [PATCH] python3Packages.uv: reuse already built uv binary master: `nix-build -A python3Packages.uv` - `0.59s user 0.19s system 0% cpu 12:01.12 total` branch: `nix-build -A python3Packages.uv` - `1.55s user 0.15s system 7% cpu 9.331 total` --- .../development/python-modules/uv/default.nix | 51 +++++++++++-------- pkgs/top-level/python-packages.nix | 2 +- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/pkgs/development/python-modules/uv/default.nix b/pkgs/development/python-modules/uv/default.nix index 726a861372db..2ab81cf60602 100644 --- a/pkgs/development/python-modules/uv/default.nix +++ b/pkgs/development/python-modules/uv/default.nix @@ -1,36 +1,45 @@ { buildPythonPackage, - installShellFiles, - rustPlatform, - pkgs, - versionCheckHook, + hatchling, + lib, + uv, }: buildPythonPackage { - inherit (pkgs.uv) + inherit (uv) pname version src - cargoDeps meta - cargoBuildFlags - postInstall - versionCheckProgramArg ; + pyproject = true; - postPatch = '' - substituteInPlace python/uv/_find_uv.py \ - --replace-fail '"""Return the uv binary path."""' "return '$out/bin/uv'" + build-system = [ hatchling ]; + + postPatch = + # Do not rely on path lookup at runtime to find the uv binary. + # Use the propagated binary instead. + '' + substituteInPlace python/uv/_find_uv.py \ + --replace-fail '"""Return the uv binary path."""' "return '${lib.getExe uv}'" + '' + # Sidestep the maturin build system in favour of reusing the binary already built by nixpkgs, + # to avoid rebuilding the uv binary for every active python package set. + + '' + substituteInPlace pyproject.toml \ + --replace-fail 'requires = ["maturin>=1.0,<2.0"]' 'requires = ["hatchling"]' \ + --replace-fail 'build-backend = "maturin"' 'build-backend = "hatchling.build"' + + cat >> pyproject.toml <