Make the committed Nix test environment usable by others and by CI. - .github/workflows/nix-parity.yml installs Nix from the official release installer, pinned by version and SHA-256 (recorded in ci/digests.txt; the installer verifies the tarball hashes it embeds), checks the flake outputs and runs a parity smoke set on Python 3.12 and 3.13. Release-gate tests run only on 3.12, the release interpreter. It triggers on changes to the flake, lock, pyproject, .envrc or the workflow, and on dispatch; it is not a required check. - .envrc (`use flake`) loads the 3.12 shell for direnv users. - tests/test_nix_parity_policy.py keeps the flake's uv pin, CI extras, non-editable install and marker filter in step with ci.yml, and the workflow's action and installer pins in step with ci/digests.txt. - A nix-test-environment contract surface maps the flake, lock, .envrc, workflow and doc to that test. - docs/NIX_TEST_ENVIRONMENT.md gains direnv and CI sections; CONTRIBUTING and README point to the flake, and CONTRIBUTING's supported-interpreter line now matches pyproject (3.11+, CI and release on 3.11 and 3.12). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4.0 KiB
Nix test environments
flake.nix provides local test environments that match the CPU pull-request
CI. Nix supplies the interpreter, the pinned uv and the native runtime
libraries that prebuilt wheels need; uv.lock stays the single source of truth
for Python dependencies, so a local run resolves exactly what CI resolves.
Use it when the host interpreter differs from CI. Release-gate checks accept only Python 3.11 and 3.12, and newer interpreters surface warnings that CI does not, so results from an arbitrary system Python are not comparable with CI.
Requirements
Nix with flakes enabled. Dependency installation needs network access to PyPI and the PyTorch CPU index, as in CI; the tests themselves run offline.
Running tests
nix run .#test -- tests/test_cli.py # Python 3.12, CI marker filter
nix run .#test-py311 -- tests # Python 3.11 (release matrix)
nix run .#test-py313 -- tests # Python 3.13 (forward compatibility)
nix develop # shell with python, git and the runner
Each run installs uv at the version pinned in .github/workflows/ci.yml,
syncs the locked environment with the CI extras (dev, recovery, mcp)
as a non-editable install, and runs pytest with the CI options
(--strict-config --strict-markers) and marker filter. The CI environment
variables (CUDA_VISIBLE_DEVICES=, Hugging Face offline settings,
TOKENIZERS_PARALLELISM=false) are set. With no arguments the whole tests
directory runs.
Environments are kept per interpreter under .nix-test/<python>/ (ignored by
git) and reused when the lock is unchanged. Overrides:
| Variable | Effect |
|---|---|
OBLITERATUS_NIX_STATE |
Directory for the per-interpreter tool and test environments |
OBLITERATUS_TEST_EXTRAS |
Replaces the extras passed to uv sync |
OBLITERATUS_TEST_MARKERS |
Replaces the pytest marker expression |
The operator-UI gate, which needs the reviewed Gradio build from the spaces
extra, runs with:
OBLITERATUS_NIX_STATE=.nix-test-ui \
OBLITERATUS_TEST_EXTRAS="--extra dev --extra spaces" \
OBLITERATUS_TEST_MARKERS="operator_ui" \
nix run .#test -- tests/conditional/test_gradio_pillow_backport.py
direnv
The repository ships an .envrc containing use flake. With
direnv and nix-direnv installed, run direnv allow once
in the checkout and the Python 3.12 shell loads whenever you enter the
directory.
Continuous integration
.github/workflows/nix-parity.yml exercises the same flake on GitHub-hosted
runners for Python 3.12 and 3.13. It runs when flake.nix, flake.lock,
uv.lock, pyproject.toml, .envrc or the workflow itself changes, and on
manual dispatch. It installs Nix from the official release installer, pinned by
version and SHA-256 in ci/digests.txt (the installer in turn verifies the Nix
tarball hashes it embeds), checks the flake outputs, and runs a parity smoke set
through nix run .#test-py<version>. Release-gate tests run only in the 3.12
job, because those gates accept only the release interpreters (3.11 and 3.12).
The workflow is not part of the required pull-request check. Other CI systems
can use the flake the same way: install Nix with flakes enabled, then run
nix run .#test -- <tests> from a checkout. No credentials or private caches
are needed; packages come from the public NixOS cache, PyPI and the PyTorch CPU
index.
tests/test_nix_parity_policy.py keeps the flake in step with
.github/workflows/ci.yml: the uv pin, the CI extras, the non-editable install
and the marker filter must match, and the workflow's action and installer pins
must match ci/digests.txt.
Scope
These environments reproduce the CPU pull-request job locally. They are not a
substitute for CI: selection by the test-risk map, coverage gates, sharding and
the conditional GPU, MPS, MLX and remote lanes still run where the workflow
defines them. When .github/workflows/ci.yml changes its uv pin, extras or
marker filter, update flake.nix in the same change; the policy test fails
otherwise.