Skip to content

Commit 2ce7ae3

Browse files
authored
python3Packages.uv: reuse already built uv binary (#412206)
2 parents 068bc04 + 0b12c69 commit 2ce7ae3

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed
Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
{
22
buildPythonPackage,
3-
installShellFiles,
4-
rustPlatform,
5-
pkgs,
6-
versionCheckHook,
3+
hatchling,
4+
lib,
5+
uv,
76
}:
87

98
buildPythonPackage {
10-
inherit (pkgs.uv)
9+
inherit (uv)
1110
pname
1211
version
1312
src
14-
cargoDeps
1513
meta
16-
cargoBuildFlags
17-
postInstall
18-
versionCheckProgramArg
1914
;
15+
pyproject = true;
2016

21-
postPatch = ''
22-
substituteInPlace python/uv/_find_uv.py \
23-
--replace-fail '"""Return the uv binary path."""' "return '$out/bin/uv'"
24-
'';
17+
build-system = [ hatchling ];
2518

26-
nativeBuildInputs = [
27-
installShellFiles
28-
rustPlatform.cargoSetupHook
29-
rustPlatform.maturinBuildHook
30-
];
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"'
3132
32-
nativeCheckInputs = [ versionCheckHook ];
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+
'';
3343

34-
pyproject = true;
3544
pythonImportsCheck = [ "uv" ];
3645
}

pkgs/top-level/python-packages.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18674,7 +18674,7 @@ self: super: with self; {
1867418674

1867518675
uuid6 = callPackage ../development/python-modules/uuid6 { };
1867618676

18677-
uv = callPackage ../development/python-modules/uv { };
18677+
uv = callPackage ../development/python-modules/uv { inherit (pkgs) uv; };
1867818678

1867918679
uv-build = callPackage ../development/python-modules/uv-build { };
1868018680

0 commit comments

Comments
 (0)