From 7b67d15f0eed6551490afbdf80a37a0034d8fb1b Mon Sep 17 00:00:00 2001 From: adisbladis Date: Mon, 18 Nov 2024 22:42:33 +0000 Subject: [PATCH] uv: Build as a standalone without Python 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. --- pkgs/by-name/uv/uv/package.nix | 16 +++------- .../development/python-modules/uv/default.nix | 32 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 4 +-- 3 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 pkgs/development/python-modules/uv/default.nix diff --git a/pkgs/by-name/uv/uv/package.nix b/pkgs/by-name/uv/uv/package.nix index d8e53eb32fba..027dc511fb9b 100644 --- a/pkgs/by-name/uv/uv/package.nix +++ b/pkgs/by-name/uv/uv/package.nix @@ -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"; @@ -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; @@ -42,6 +36,8 @@ python3Packages.buildPythonApplication rec { "uv" ]; + doCheck = false; + postInstall = '' export HOME=$TMPDIR installShellCompletion --cmd uv \ @@ -50,8 +46,6 @@ python3Packages.buildPythonApplication rec { --zsh <($out/bin/uv --generate-shell-completion zsh) ''; - pythonImportsCheck = [ "uv" ]; - nativeCheckInputs = [ versionCheckHook ]; diff --git a/pkgs/development/python-modules/uv/default.nix b/pkgs/development/python-modules/uv/default.nix new file mode 100644 index 000000000000..529b3b782bc9 --- /dev/null +++ b/pkgs/development/python-modules/uv/default.nix @@ -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" ]; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 86f156f8cffb..679f9e689e6b 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -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 { };