1{
2 buildPythonPackage,
3 hatchling,
4 lib,
5 uv,
6}:
7
8buildPythonPackage {
9 inherit (uv)
10 pname
11 version
12 src
13 meta
14 ;
15 pyproject = true;
16
17 build-system = [ hatchling ];
18
19 postPatch =
20 # Do not rely on path lookup at runtime to find the uv binary.
21 # Use the propagated binary instead.
22 ''
23 substituteInPlace python/uv/_find_uv.py \
24 --replace-fail '"""Return the uv binary path."""' "return '${lib.getExe uv}'"
25 ''
26 # Sidestep the maturin build system in favour of reusing the binary already built by nixpkgs,
27 # to avoid rebuilding the uv binary for every active python package set.
28 + ''
29 substituteInPlace pyproject.toml \
30 --replace-fail 'requires = ["maturin>=1.0,<2.0"]' 'requires = ["hatchling"]' \
31 --replace-fail 'build-backend = "maturin"' 'build-backend = "hatchling.build"'
32
33 cat >> pyproject.toml <<EOF
34 [tool.hatch.build]
35 packages = ['python/uv']
36
37 EOF
38 '';
39
40 postInstall = ''
41 mkdir -p $out/bin && ln -s ${lib.getExe uv} $out/bin/uv
42 '';
43
44 pythonImportsCheck = [ "uv" ];
45}