Files
home-manager/tests/modules/programs/uv/python.nix
Peter Bittner c51ac59e59 uv: manage Python versions and tools
Add programs.uv.python.{versions,default,prune} and
programs.uv.tool.{packages,prune} to install uv-managed Python versions
and tools during activation.

Install requests are passed verbatim to uv. Unpinned entries track the
latest release on each activation while pinned ones stay put: Python
requests without a patch component are installed with `uv python install
--upgrade` (exact patches, which uv refuses to upgrade, get a plain
install), and tools are refreshed with `uv tool upgrade <packages>`
scoped to the configured list. Both upgrades are scoped to the managed
entries, so installs Home Manager does not own are left untouched. prune
makes a set declarative by running `uv ... uninstall --all` before
reinstalling the listed entries.

The activation blocks run after linkGeneration so uv sees the freshly
linked uv.toml, and a null programs.uv.package is rejected once the
module emits activation commands.
2026-06-17 15:47:24 -05:00

44 lines
1.4 KiB
Nix

{
programs.uv = {
enable = true;
python = {
versions = [
"3.12"
"3.13"
"3.11.9"
"pypy@3.11"
];
# One default per implementation; uv keeps `python` and `pypy` separate.
default = [
"3.13"
"pypy@3.11"
];
};
};
test.stubs.uv.name = "uv";
nmt.script = ''
# Each default is installed first with `--default`, one call per entry, so
# per-implementation executables (python, pypy) are both set. They have no
# patch component, so they also track the latest patch via `--upgrade`.
assertFileContains activate \
'run @uv@/bin/uv python install $VERBOSE_ARG --default --upgrade 3.13'
assertFileContains activate \
'run @uv@/bin/uv python install $VERBOSE_ARG --default --upgrade pypy@3.11'
# Remaining major/minor requests are installed with `--upgrade`, tracking the
# latest patch; default versions are not reinstalled.
assertFileContains activate \
'run @uv@/bin/uv python install $VERBOSE_ARG --upgrade 3.12'
# Exact-patch pins are installed as requested, never upgraded (uv rejects
# upgrading them).
assertFileContains activate \
'run @uv@/bin/uv python install $VERBOSE_ARG 3.11.9'
# Without prune the performant path is used: no uninstall/reinstall churn.
assertFileNotRegex activate 'python uninstall'
'';
}