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 20, 2024
1 parent f959feb commit 09d02b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
11 changes: 5 additions & 6 deletions pkgs/by-name/uv/uv/package.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
stdenv,
lib,
cmake,
fetchFromGitHub,
installShellFiles,
pkg-config,
python3Packages,
rustPlatform,
versionCheckHook,
nix-update-script,
}:

python3Packages.buildPythonApplication rec {
stdenv.mkDerivation rec {
pname = "uv";
version = "0.4.30";
pyproject = true;

src = fetchFromGitHub {
owner = "astral-sh";
Expand All @@ -37,11 +36,13 @@ python3Packages.buildPythonApplication rec {
installShellFiles
pkg-config
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
rustPlatform.cargoBuildHook
rustPlatform.cargoInstallHook
];

dontUseCmakeConfigure = true;

cargoBuildType = "release";
cargoBuildFlags = [
"--package"
"uv"
Expand All @@ -55,8 +56,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 @@ -17380,9 +17380,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 09d02b9

Please sign in to comment.