Skip to content

Commit

Permalink
uv: Build as a standalone without Python
Browse files Browse the repository at this point in the history
Using `buildPythonPackage` triggers dependency propagation, meaning that using `uv` with `nix-shell` results in a a shell with the `uv` Python input in it.
This is problematic for development usage where you only want the one specified version.

Often this design bug in the Python package builders is worked around by deleting `$out/nix-support/propagated-build-inputs`, but since `uv` is written in Rust and can be built without a Python interpreter so it's better to just build without a Python interpreter.
  • Loading branch information
adisbladis committed Nov 23, 2024
1 parent 4ed371b commit 7b67d15
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
16 changes: 5 additions & 11 deletions pkgs/by-name/uv/uv/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
fetchFromGitHub,
installShellFiles,
pkg-config,
python3Packages,
rustPlatform,
versionCheckHook,
nix-update-script,
}:

python3Packages.buildPythonApplication rec {
rustPlatform.buildRustPackage rec {
pname = "uv";
version = "0.5.4";
pyproject = true;

src = fetchFromGitHub {
owner = "astral-sh";
Expand All @@ -22,17 +20,13 @@ python3Packages.buildPythonApplication rec {
hash = "sha256-Kieh76RUrDEwdL04mvCXOqbXHasMMpXRqp0LwMOIHdM=";
};

cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src;
hash = "sha256-ZhHUKotXVDdwJs2kqIxME5I1FitWetx7FrQtluuIUWo=";
};
useFetchCargoVendor = true;
cargoHash = "sha256-ZhHUKotXVDdwJs2kqIxME5I1FitWetx7FrQtluuIUWo=";

nativeBuildInputs = [
cmake
installShellFiles
pkg-config
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];

dontUseCmakeConfigure = true;
Expand All @@ -42,6 +36,8 @@ python3Packages.buildPythonApplication rec {
"uv"
];

doCheck = false;

postInstall = ''
export HOME=$TMPDIR
installShellCompletion --cmd uv \
Expand All @@ -50,8 +46,6 @@ python3Packages.buildPythonApplication rec {
--zsh <($out/bin/uv --generate-shell-completion zsh)
'';

pythonImportsCheck = [ "uv" ];

nativeCheckInputs = [
versionCheckHook
];
Expand Down
32 changes: 32 additions & 0 deletions pkgs/development/python-modules/uv/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
buildPythonPackage,
installShellFiles,
pkg-config,
rustPlatform,
pkgs,
}:

buildPythonPackage {
inherit (pkgs.uv)
pname
version
src
cargoDeps
dontUseCmakeConfigure
meta
cargoBuildFlags
postInstall
versionCheckProgramArg
;

nativeBuildInputs = [
pkgs.cmake
installShellFiles
pkg-config
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];

pyproject = true;
pythonImportsCheck = [ "uv" ];
}
4 changes: 1 addition & 3 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17395,9 +17395,7 @@ self: super: with self; {

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

uv = toPythonModule (pkgs.uv.override {
python3Packages = self;
});
uv = callPackage ../development/python-modules/uv { };

uvcclient = callPackage ../development/python-modules/uvcclient { };

Expand Down

0 comments on commit 7b67d15

Please sign in to comment.