Skip to content

feat: backend Python 環境の Nix フルマネージド化 Phase 1+2(devshell の uv2nix 化と CI 経路一致 / ADR-0021)#500

Merged
yusuke0610 merged 4 commits into
mainfrom
feat/adr-0021-phase1-nix-devshell
Jul 15, 2026
Merged

feat: backend Python 環境の Nix フルマネージド化 Phase 1+2(devshell の uv2nix 化と CI 経路一致 / ADR-0021)#500
yusuke0610 merged 4 commits into
mainfrom
feat/adr-0021-phase1-nix-devshell

Conversation

@yusuke0610

@yusuke0610 yusuke0610 commented Jul 15, 2026

Copy link
Copy Markdown
Owner

変更概要

ADR-0021 の Phase 1 と Phase 2 の実装(コミットは Phase 単位で分割・独立に revert 可能)。

経緯: Phase 1 は PR #499 で実装済みでしたが、コミットがマージ(13:27)の 17 分後に push されたため main に取り込まれていませんでした。本 PR はそのコミットを最新 main へ cherry-pick し(+ 下記バグ修正を amend)、Phase 2 を追加したものです。

Phase 1(e420308: devshell の Python 環境を uv2nix で Nix build 化し、ローカルの backend/.venv を廃止。ADR-0021 の発端(VS Code の .venv 絶対パス直書き)を解消。

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 経由に置換
  • lint / typecheck / test / codegen はローカルと同一の make ターゲットを呼ぶ(コマンドの SSoT を Makefile に一本化)
  • lock drift 検知は uv lock --check ステップとして保持
  • pip-audit は --no-deps --disable-pip へ変更(export 済み完全固定リストの照合。Nix の python は ensurepip を持たず一時 venv 作成が SIGABRT するため)
  • codegen-drift の Node は devshell の nodejs_22 に統一(ローカルと一致)

セルフレビューチェックリスト

必須確認

  • make ci が pass している(lint + test + build-web)— 旧 .venv を撤去した状態の devshell で ruff / pyright 0 errors / pytest 724 passed / vitest 382 passed / build-web pass
  • コメント・ドキュメント・エラーメッセージは日本語で記述した

条件付き確認(該当する場合のみ N/A と記入)

  • N/A — app/schemas/ / app/routers/ の変更なし(make codegen-types は実行し drift なしを確認済み)
  • N/A — ページ・認証・ナビゲーション・レイアウトの変更なし(E2E 不要)
  • N/A — 新規環境変数なし
  • N/A — web/src/ の変更なし

破壊的変更

  • 破壊的変更なし(API 契約・DB スキーマ・既存の公開インターフェースに変更なし。開発フロー変更のみ: ローカルは .venv 不要、CI は Nix 経由)

ADR(設計判断を伴う変更の場合のみ)

  • 既存 ADR が対応している(ADR-0021 Phase 1+2 の実装。ステータスは Proposed のまま — Accepted 昇格は Phase 3 完了後、その際に ADR-0017 / 0014 の記述追従も実施)

レビュー時の注目点

  • 初回 CI は Nix store キャッシュが無いため遅い(devshell 構築数分。timeout は 10→20 分に拡大済み)。2 回目以降は cache-nix-action の restore で短縮される想定
  • pip-audit / codegen(Node 22 化)/ uv lock --check はローカルの devshell で実走確認済み
  • actionlint は追加分クリーン(test.yml:315 の SC2034 は既存警告)
  • smoke-backend は旧経路(pip / Dockerfile)のまま(Phase 3 で Nix 化予定)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 改善
    • バックエンドの開発・テスト・Lint・型チェック・移行などを Nix devshell 経由で統一する手順に更新しました。
    • ローカル実行時の環境差分や依存/ネイティブ解決の問題を軽減します。
    • VS Code の Python 設定を簡素化しました。
  • CI
    • バックエンド検証とコード生成ドリフト/ミューテーションテストを Nix devshell ベースに移行しました。
    • Nix ストアキャッシュに対応し、実行効率を改善しました。
  • ドキュメント
    • 実行コマンド例(ruff/pytest/ alembic/ mutmut など)と運用ルールを更新しました。

claude and others added 2 commits July 15, 2026 23:09
…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>
@github-actions github-actions Bot added the feature 新機能 label Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b10da675-5b35-4131-b2bf-92f28b4dff21

📥 Commits

Reviewing files that changed from the base of the PR and between 6d25015 and 710dadf.

📒 Files selected for processing (1)
  • backend/pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/pyproject.toml

📝 Walkthrough

Walkthrough

Backend local development and CI execution are migrated from .venv commands to a uv2nix-based Nix devshell. Make targets, workflows, editor settings, Pyright configuration, and development guidance are updated accordingly.

Changes

Nix devshell migration

Layer / File(s) Summary
Build the backend environment
flake.nix, backend/pyproject.toml, pyrightconfig.json, .vscode/settings.json
The backend environment is built with uv2nix, and Python tooling receives its interpreter from the devshell at execution time.
Route local tooling through the devshell
Makefile, scripts/gen-third-party-licenses.py
Backend tests, mutation testing, linting, typechecking, code generation, licensing, and migrations use the Nix devshell.
Migrate backend CI and code generation
.github/workflows/test.yml, .github/workflows/mutation.yml
CI installs and caches Nix, runs backend checks through Make targets, and performs mutation testing and code generation inside the devshell.
Update development procedures
.claude/..., docs/development.md
Development commands for Python tooling, Alembic, uvicorn, Ruff, pytest, and mutmut now use nix develop.

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
Loading

Possibly related PRs

  • yusuke0610/devforge#418: Changes the backend CI and code-generation workflow areas migrated here to Nix devshell execution.
  • yusuke0610/devforge#446: Adds the Pyright hard gate and backend typecheck workflow integrated here through Make targets.
  • yusuke0610/devforge#499: Updates the same backend dependency and lock-check workflow areas migrated here.

Suggested labels: test

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: migrating backend Python to a Nix-managed uv2nix devshell and aligning CI under ADR-0021.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/adr-0021-phase1-nix-devshell

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added documentation Improvements or additions to documentation backend バックエンド ci CI / ワークフロー labels Jul 15, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5e4215f and a65af14.

⛔ Files ignored due to path filters (1)
  • flake.lock is 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.json
  • Makefile
  • backend/pyproject.toml
  • docs/development.md
  • flake.nix
  • pyrightconfig.json
  • scripts/gen-third-party-licenses.py
💤 Files with no reviewable changes (1)
  • pyrightconfig.json

Comment thread .claude/CLAUDE.md Outdated
Comment thread backend/pyproject.toml Outdated
@yusuke0610
yusuke0610 merged commit 973d8f6 into main Jul 15, 2026
23 checks passed
@yusuke0610
yusuke0610 deleted the feat/adr-0021-phase1-nix-devshell branch July 20, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend バックエンド ci CI / ワークフロー documentation Improvements or additions to documentation feature 新機能

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants