feat: backend Python 環境の Nix フルマネージド化 Phase 1+2(devshell の uv2nix 化と CI 経路一致 / ADR-0021)#500
Conversation
…ase 1) flake.nix に uv2nix / pyproject-nix / pyproject-build-systems を導入し、 backend の Python 依存(uv.lock 準拠)を Nix build の virtualenv (devforge-backend-env)として devshell に提供する。ローカルの backend/.venv を 廃止し、ADR-0021 の発端である VS Code の .venv 絶対パス直書きを解消する。 - flake.nix: uv2nix で uv.lock から pythonSet を構成(wheel 優先)。devshell の python / pytest / ruff / alembic / uvicorn は Nix build 環境から PATH 解決 - flake.lock: 新規 3 input を追加(transitive は全て follows で既存 nixpkgs に集約) - Makefile: .venv/bin/* 参照 10 箇所を PATH 解決へ置換。migrate / migrate-create の nix wrap 漏れも修正。install-backend は devshell ビルド確認のみに変更 - pyright: pyproject / pyrightconfig.json の venv=".venv" 参照を撤廃し、実行側が --pythonpath で明示する方式へ(ローカル = devshell python3、CI = uv sync の .venv) - .vscode/settings.json: python.defaultInterpreterPath の絶対パス直書きを撤廃し direnv(use flake)経由の PATH 解決へ(本 ADR の発端の解消) - docs / rules / skills: .venv/bin/* 前提のコマンド記載を一括更新 CI(test.yml / mutation.yml)の uv sync 経路は Phase 2 で Nix 化予定のため維持。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmQqSTooETKvU1jDM2mCBS
test-backend / codegen-drift / mutation-backend から uv 単体経路 (setup-uv + uv sync --locked + WeasyPrint apt install)を撤去し、 dev と同じ Nix devshell(uv2nix build / flake.nix)経由に置き換える。 - cachix/install-nix-action + nix-community/cache-nix-action を SHA ピンで 導入し、Nix store を flake / uv.lock のハッシュキーでキャッシュする - lint / typecheck / test / codegen はローカルと同一の make ターゲットを 呼ぶ(コマンドの SSoT を Makefile に一本化) - uv sync --locked が担っていた lock drift 検知は uv lock --check として保持 - pip-audit は --no-deps --disable-pip へ変更(export 済み完全固定リストの 照合。Nix の python は ensurepip を持たず一時 venv 作成が SIGABRT するため) - codegen-drift の Node は devshell の nodejs_22 に統一(ローカルと一致) - timeout 10→20 分(Nix キャッシュミス時の devshell 構築を考慮) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughBackend local development and CI execution are migrated from ChangesNix devshell migration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant GitHubActions
participant NixDevshell
participant Makefile
participant BackendTools
GitHubActions->>NixDevshell: install, cache, and build environment
NixDevshell->>Makefile: execute backend targets
Makefile->>BackendTools: run tests, lint, typecheck, mutation tests, or code generation
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.claude/CLAUDE.md:
- Line 102: Update the dependency-definition row in CLAUDE.md to replace the
copy-pasteable `cd backend && uv lock` command with `nix develop --command bash
-c "cd backend && uv lock"`, or explicitly state that the command must run
inside an already-active Nix devshell.
In `@backend/pyproject.toml`:
- Around line 57-58: Update the Phase 1 dependency comments near the CI guidance
to state that CI uses the Nix devshell interpreter via make typecheck-backend,
and remove references to uv sync, .venv creation, or .venv/bin/python. Apply the
same correction to the additional guidance at the referenced location.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ac3cdb31-8b00-4ac6-a3a4-3dedc22de2c3
⛔ Files ignored due to path filters (1)
flake.lockis excluded by!**/*.lock
📒 Files selected for processing (18)
.claude/CLAUDE.md.claude/rules/backend/database.md.claude/rules/backend/python.md.claude/rules/backend/test.md.claude/rules/common/tdd.md.claude/skills/BE_apply/SKILL.md.claude/skills/BE_refacter/SKILL.md.claude/skills/SEC_review/SKILL.md.claude/skills/tdd/SKILL.md.github/workflows/mutation.yml.github/workflows/test.yml.vscode/settings.jsonMakefilebackend/pyproject.tomldocs/development.mdflake.nixpyrightconfig.jsonscripts/gen-third-party-licenses.py
💤 Files with no reviewable changes (1)
- pyrightconfig.json
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
変更概要
ADR-0021 の Phase 1 と Phase 2 の実装(コミットは Phase 単位で分割・独立に revert 可能)。
Phase 1(
e420308): devshell の Python 環境を uv2nix で Nix build 化し、ローカルのbackend/.venvを廃止。ADR-0021 の発端(VS Code の.venv絶対パス直書き)を解消。2e44d21)と同一 + バグ修正 1 件:Makefileのtypecheck-backendで$$(command -v python3)が devshell の外側のシェルで展開され、pyright にホストの python が渡って 325 件の import エラーになる問題を\$$エスケープで修正(元コミットの作業環境が偶然 devshell 内だったため見逃されていた)nix develop実ビルドで問題ないことを確認済みPhase 2(
a65af14): CI のビルド経路を dev と一致させる(uv 単体 → Nix devshell)。test-backend/codegen-drift(test.yml)とmutation-backend(mutation.yml)から setup-uv /uv python install/ WeasyPrint apt install /uv sync --lockedを撤去し、cachix/install-nix-action+nix-community/cache-nix-action(いずれも SHA ピン)で devshell 経由に置換uv lock --checkステップとして保持--no-deps --disable-pipへ変更(export 済み完全固定リストの照合。Nix の python は ensurepip を持たず一時 venv 作成が SIGABRT するため)セルフレビューチェックリスト
必須確認
make ciが pass している(lint + test + build-web)— 旧.venvを撤去した状態の devshell で ruff / pyright 0 errors / pytest 724 passed / vitest 382 passed / build-web pass条件付き確認(該当する場合のみ N/A と記入)
app/schemas//app/routers/の変更なし(make codegen-typesは実行し drift なしを確認済み)web/src/の変更なし破壊的変更
.venv不要、CI は Nix 経由)ADR(設計判断を伴う変更の場合のみ)
レビュー時の注目点
uv lock --checkはローカルの devshell で実走確認済みsmoke-backendは旧経路(pip / Dockerfile)のまま(Phase 3 で Nix 化予定)🤖 Generated with Claude Code
Summary by CodeRabbit