Skip to content

Commit ee67062

Browse files
authored
feat(nix): integrate uv2nix for Python dependency management (#88)
* feat(nix): integrate uv2nix for Python dependency management Replace uv-managed .venv with Nix-managed Python environments using uv2nix. This provides fully reproducible builds with dependencies cached in the Nix store, eliminating the need for uv sync in CI. Key changes: - Add uv2nix, pyproject-nix, and pyproject-build-systems inputs - Create devShells for Python 3.11 and 3.13 (default, python311, python313) - Add build system overrides for pypika (setuptools) and stackone-ai (editables) - Update CI matrix to use nix develop .#pythonXXX instead of uv sync - Simplify setup-nix action with gc-max-store-size for cache management - Add lint-fix alias to justfile The .venv directory is no longer needed as all dependencies are managed by Nix. Both Nix and non-Nix users can still use uv run commands which will work in either environment. * fix(ci): add python-version to cache key for parallel jobs Separate cache keys per Python version to prevent cache overwrites when matrix jobs run in parallel. Default to python311 since it matches the default devShell. * fix(nix): set VIRTUAL_ENV for ty to find site-packages ty needs VIRTUAL_ENV to locate the Python environment's site-packages. Without this, ty looks for .venv which doesn't exist in the Nix environment. Also update justfile to conditionally use 'uv run' prefix only when not in a Nix environment (detected via VIRTUAL_ENV). This makes commands work for both Nix and non-Nix users. * ci: add build-cache job to pre-build Nix environments Add a dedicated build-cache job that runs before other CI jobs to pre-populate the Nix store cache. This ensures that subsequent parallel jobs (gitleaks, ci matrix, coverage) can benefit from the cached derivations instead of each rebuilding from scratch. The build-cache job: - Runs as a matrix for both python311 and python313 - Builds the Nix development environment - Saves the cache via cache-nix-action for downstream jobs gitleaks, ci, and coverage jobs now depend on build-cache to ensure cache is available before they run. * ci: include lockfile hash in cache key for proper invalidation Add flake.lock and uv.lock hash to the cache key so that: - Cache is saved when dependencies change (new hash = new key) - Old cache is still restored via restore-prefixes-first-match - Incremental updates build on previous cache This ensures cache hits do not prevent saving updated derivations while still benefiting from partial cache restoration. * ci: remove build-cache job as lockfile hash handles invalidation Now that cache keys include lockfile hashes, proper invalidation happens automatically. Each job can build and save its own cache, making the dedicated build-cache job unnecessary. * ci: add pyproject.toml and src to cache key hash Include pyproject.toml and src/**/*.py in the cache key hash since source changes affect the editable install derivation.
1 parent daa1a7e commit ee67062

File tree

5 files changed

+268
-84
lines changed

5 files changed

+268
-84
lines changed
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: "Setup Nix"
22
description: "Install Nix and configure cache"
3+
inputs:
4+
python-version:
5+
description: "Python version for cache key (e.g., python311, python313)"
6+
required: false
7+
default: "python311"
38
runs:
49
using: "composite"
510
steps:
@@ -11,8 +16,8 @@ runs:
1116
- name: Cache Nix store
1217
uses: nix-community/cache-nix-action@b426b118b6dc86d6952988d396aa7c6b09776d08 # v7
1318
with:
14-
primary-key: nix-${{ runner.os }}
15-
16-
- name: Load Nix development environment
17-
shell: bash
18-
run: nix develop --command true
19+
primary-key: nix-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('flake.lock', 'uv.lock', 'pyproject.toml', 'src/**/*.py') }}
20+
restore-prefixes-first-match: |
21+
nix-${{ runner.os }}-${{ inputs.python-version }}-
22+
nix-${{ runner.os }}-
23+
gc-max-store-size: 4G

.github/workflows/ci.yaml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ jobs:
3434
runs-on: ubuntu-latest
3535
strategy:
3636
matrix:
37-
python-version: ["3.11", "3.13"]
38-
include:
39-
- python-version: "3.11"
40-
sync-extras: "--all-extras"
41-
- python-version: "3.13"
42-
sync-extras: "--all-extras"
37+
python-version: ["python311", "python313"]
4338
steps:
4439
- name: Checkout repository
4540
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
@@ -48,18 +43,17 @@ jobs:
4843

4944
- name: Setup Nix
5045
uses: ./.github/actions/setup-nix
51-
52-
- name: Install dependencies
53-
run: nix develop --command just install ${{ matrix.sync-extras }}
46+
with:
47+
python-version: ${{ matrix.python-version }}
5448

5549
- name: Run Lint
56-
run: nix develop --command just lint
50+
run: nix develop .#${{ matrix.python-version }} --command just lint
5751

5852
- name: Run Ty
59-
run: nix develop --command just ty
53+
run: nix develop .#${{ matrix.python-version }} --command just ty
6054

6155
- name: Run Tests
62-
run: nix develop --command just test
56+
run: nix develop .#${{ matrix.python-version }} --command just test
6357

6458
coverage:
6559
runs-on: ubuntu-latest
@@ -73,9 +67,6 @@ jobs:
7367
- name: Setup Nix
7468
uses: ./.github/actions/setup-nix
7569

76-
- name: Install dependencies
77-
run: nix develop --command just install --all-extras
78-
7970
- name: Run Tests with Coverage
8071
run: nix develop --command just coverage
8172

flake.lock

Lines changed: 87 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)