In another issue, I wrote about how to patch the ruff binary in a Python virtual environment relying on venv.
This was my devenv.nix:
(...)
languages.python = {
enable = true;
version = "3.12.7";
venv = {
enable = true;
requirements = ./requirements.txt;
};
};
tasks = {
# Patch ruff to make it runnable
"venv:patchelf" = {
exec = "${lib.getExe pkgs.patchelf} --set-interpreter ${pkgs.stdenv.cc.bintools.dynamicLinker} $VIRTUAL_ENV/bin/ruff";
after = [ "devenv:python:virtualenv" ]; # Runs after this
before = [ "devenv:enterShell" ]; # Runs before this
};
};
Since then, I've migrated to uv and I am now unable to patch the ruff binary. devenv.nix is now like this:
(...)
languages.python = {
enable = true;
version = "3.12.7";
# Enable uv, an extremely fast Python package and project manager - https://docs.astral.sh/uv/
uv = {
enable = true;
package = pkgs-unstable.uv;
# Sync the project's dependencies (from `pyproject.toml`) with the virtual environment
sync.enable = true;
};
# Enable Python virtual environment. It's created with `uv venv`.
venv.enable = true;
};
tasks = {
"venv:patchelf-ruff" = {
description = "Patch ruff binary. It is dynamically linked to ld, which will not work with Nix";
exec = "${lib.getExe pkgs.patchelf} --set-interpreter ${pkgs.stdenv.cc.bintools.dynamicLinker} $VIRTUAL_ENV/bin/ruff";
after = [ "devenv:python:uv" ]; # Our task runs after this
before = [ "devenv:enterShell" ]; # Our task runs before this
};
};
I don't know why, but I cannot execute the ruff binary anymore. uv run ruff errors out with cannot execute binary file. Executing ruff directly (it's in the $PATH), results in zsh: exec format error: ruff.
So somehow, setting up the Python virtual environment with uv changes something... but what exactly?
In another issue, I wrote about how to patch the ruff binary in a Python virtual environment relying on
venv
.This was my devenv.nix:
Since then, I've migrated to
uv
and I am now unable to patch the ruff binary. devenv.nix is now like this:I don't know why, but I cannot execute the ruff binary anymore.
uv run ruff
errors out withcannot execute binary file
. Executingruff
directly (it's in the $PATH), results inzsh: exec format error: ruff
.So somehow, setting up the Python virtual environment with
uv
changes something... but what exactly?Thank you for your help!