Skip to content

Commit 0ed3c16

Browse files
committed
Add impure flake.nix dev-shell using uv
- Based on `pyproject.nix`'s impure template, overlays a major-version-pinned `cpython` (`python313`) so nix(os) devs can drop into a `nix develop` shell w/ `uv` mgring the py env. - Pkgs installed in the dev-shell: - `bashInteractive` + `bash-completion` to ensure sh completions activate. - `uv` for py-deps/venv mgmt, `setuptools` for build. - `tox` for the test matrix (not declared in any `-requirements.txt`). - `ruff` + `pyright` from nixpkgs to avoid sys-sh integration issues on nix(os). - `shellHook` sets `UV_PROJECT_ENVIRONMENT=py313` so the venv lands in `./py313/` instead of the version-ambig `.venv` default, then `uv add`s the test-requirements and `tox` group, and `uv lock`s. Other, TODOs left in-file as ctx for follow-up: - translate `[docs|test]-requirements.txt` deps into nixpkgs equivs (prolly via `pyproject.nix`/`uv2nix`). - decide if core-devs prefer plain `pip install -e .` over `uv` to avoid the extra tooling layer. - tip for `xonsh` users: `nix develop -c uv run xonsh`. (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code
1 parent 73cc29e commit 0ed3c16

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

flake.nix

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# An "impure" template thx to `pyproject.nix`,
2+
# https://pyproject-nix.github.io/pyproject.nix/templates.html#impure
3+
# https://github.com/pyproject-nix/pyproject.nix/blob/master/templates/impure/flake.nix
4+
{
5+
description = "An impure dev-shell (overlay) using `uv`";
6+
7+
inputs = {
8+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small";
9+
};
10+
11+
outputs =
12+
{ nixpkgs, ... }:
13+
let
14+
inherit (nixpkgs) lib;
15+
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
16+
in
17+
{
18+
devShells = forAllSystems (
19+
system:
20+
let
21+
pkgs = nixpkgs.legacyPackages.${system};
22+
23+
# XXX NOTE XXX, for now we overlay specific pkgs via
24+
# a major-version-pinned-`cpython`
25+
cpython = "python313";
26+
venv_dir = "py313";
27+
pypkgs = pkgs."${cpython}Packages";
28+
in
29+
{
30+
default = pkgs.mkShell {
31+
32+
packages = [
33+
# XXX, ensure sh completions activate!
34+
pkgs.bashInteractive
35+
pkgs.bash-completion
36+
37+
# pkgs.xonsh
38+
pkgs.uv
39+
pkgs.${cpython} # ?TODO^ how to set from `cpython` above?
40+
pkgs."${cpython}Packages".setuptools
41+
42+
# testing-n-tooling
43+
# ?TODO, if we want to pull `xxx-requirements.txt` from
44+
# nixpkgs directly?
45+
# - [ ] extract-n-translate all `[docs|test]-requirements.txt` deps
46+
# into their equiv nxpkgs equivalents.
47+
#
48+
# For ex. we can explicitily add them like the below,
49+
# but ideally we use a translator lib (like
50+
# `pyproject.nix` and/or `uv2nix`).
51+
#
52+
# pkgs."${cpython}Packages".black
53+
# pkgs."${cpython}Packages".coverage
54+
# pkgs."${cpython}Packages".hypothesis
55+
# pkgs."${cpython}Packages".mypy
56+
# pkgs."${cpython}Packages".pytest
57+
# pkgs."${cpython}Packages".towncrier
58+
59+
# XXX, pkgs not listed in `-requirements.txt` files.
60+
pkgs."${cpython}Packages".tox
61+
62+
# XXX, on nix(os), use pkgs version to avoid
63+
# build/sys-sh-integration issues
64+
pkgs.ruff
65+
pkgs.pyright
66+
67+
];
68+
69+
shellHook = ''
70+
# unmask to debug **this** dev-shell-hook
71+
# set -e
72+
73+
# RUNTIME-SETTINGS
74+
# ------ uv ------
75+
# - always use and explicit py-version abbreviated
76+
# `${venv_dir}` (like `./py313/`) venv-subdir instead
77+
# the default (and version ambiguous) `.venv` used by
78+
# `uv`.
79+
export UV_PROJECT_ENVIRONMENT=${venv_dir}
80+
81+
# - sync the `uv` env with all extras, namely the test
82+
# and docs deps as required by the full CI/CD
83+
# pipeline used on Github.
84+
uv add -r test-requirements.in -c test-requirements.txt --group test
85+
86+
# ?TODO? next line is unneeded since
87+
# `test-requirements.[in|txt]` already is super set of
88+
# `docs-requirements.[in|txt]`?
89+
# uv add -r docs-requirements.in -c docs-requirements.txt --group docs
90+
91+
# NOTE, a `tox.ini` is included in repo even though no
92+
# explicit dependency is declared elsewhere.
93+
uv add --group test tox
94+
95+
# generate a `uv.lock`
96+
uv lock
97+
98+
# ?TODO, this would update to latest deps versions right?
99+
# - [ ] a dev can invoke this explicitly if wanted?
100+
# uv sync
101+
102+
# ?TODO? if core-devs would prefer not (encouraging us)
103+
# to use `uv` we can instead use `pip` directly, but it
104+
# seems a bit pedantic and less convenient when devving
105+
# on nix(os).
106+
# pip install -e .
107+
108+
# ------ HOT-TIPS ------
109+
# - to launch the py-venv installed `xonsh` (like your
110+
# fave collab @goodboy) run the `nix develop` cmd with,
111+
# >> nix develop -c uv run xonsh
112+
'';
113+
};
114+
}
115+
);
116+
};
117+
}

0 commit comments

Comments
 (0)