2.2 KiB
uv
uv is an extremely fast Python package installer and resolver, written in Rust.
It manages project dependencies and environments, with support for lockfiles, workspaces, and more.
Due to uv being unaware that it is running on a NixOS system, by default, it will fetch dynamically-linked Python executables that will fail to run, as NixOS cannot run executables intended for generic Linux environments out of the box.
To learn more on this, please visit
https://nix.dev/guides/faq.html#how-to-run-non-nix-executables
There are two ways to mitigate this:
-
Provide
uvwith a statically-linked Python executable (ideally fromnixpkgs) via theUV_PYTHONenvironment variable. Alternatively, the--pythonflag can also be used, but this is easy to forget. It is also helpful to forbiduvfrom downloading any Python binaries via theUV_PYTHON_DOWNLOADSenvironment variable by setting it tonever. These variables can be set inshell.nixand.envfiles, which can be redistributed with the project to ensure other NixOS machines can execute the project. -
Add
programs.nix-ld.enable = trueto your NixOS config. While functional, the previous option is to be preferred, as this is the "works on my machine" option, because redistributing Python projects that useuvto another NixOS machine that does not havenix-ldenabled will cause the same errors to occur.
Additionally, there is the issue of modules from PyPI vendoring dynamically-linked libraries, such as numpy, which will also fail to work.
This topic is not local to uv, but is deserving of documentation nonetheless.
Setting LD_LIBRARY_PATH should be the solution of choice here. Either:
- Use
lib.makeLibraryPathto setLD_LIBRARY_PATHfrom ashell.nix, e.g.LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.openssl pkgs.zlib pkgs.curl ] - (If you have already enabled
nix-ld) setLD_LIBRARY_PATHtoNIX_LD_LIBRARY_PATH. Be aware this is not a silver bullet solution, as this simply provides a list of commonly used libraries, as is shown innixos/modules/programs/nix-ld.nix.