From 13766d9c3ddbe68495e5b5e4c32c8b14ba4e67ff Mon Sep 17 00:00:00 2001 From: gotomts Date: Wed, 13 May 2026 11:30:29 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix(nix):=20Determinate=20Nix=20=E3=81=A8?= =?UTF-8?q?=20nix-darwin=20=E3=81=AE=E7=AB=B6=E5=90=88=E3=82=92=E8=A7=A3?= =?UTF-8?q?=E6=B6=88=20(nix.enable=20=3D=20false)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nix-darwin 側で Nix 管理を無効化し、Determinate Nix の daemon に委ねる。 nix-command / flakes は Determinate がデフォルト有効なため、旧来の `nix.settings.experimental-features` 宣言は削除する。 S14 (CI 検証) の試運転で `darwin-rebuild switch` が以下のエラーで 失敗していたため発見した本番ブロッカー: error: Determinate detected, aborting activation Determinate uses its own daemon to manage the Nix installation that conflicts with nix-darwin's native Nix management. To turn off nix-darwin's management of the Nix installation, set: nix.enable = false; ローカル PC にも Determinate Nix が入っているため、本修正なしでは m5mbp で `darwin-rebuild switch` を実行できない状態だった。CI で 事前検出できた本番投入ブロッカー。 --- nix/hosts/m5mbp/darwin.nix | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/nix/hosts/m5mbp/darwin.nix b/nix/hosts/m5mbp/darwin.nix index a629bd9..28ee7c2 100644 --- a/nix/hosts/m5mbp/darwin.nix +++ b/nix/hosts/m5mbp/darwin.nix @@ -27,10 +27,17 @@ # ユーザースコープオプションは system.primaryUser で対象を明示する必要がある。 system.primaryUser = username; - nix.settings.experimental-features = [ - "nix-command" - "flakes" - ]; + # Determinate Nix (公式インストーラの最新版) と nix-darwin の native Nix 管理は + # 同時稼働できないため、nix-darwin 側の管理を無効化する。 + # Determinate Nix は nix-command / flakes をデフォルトで有効化済みなので、 + # 旧来の `nix.settings.experimental-features` 宣言は不要。 + # + # 本修正は CI 検証 (S14) で `darwin-rebuild switch` が以下のエラーで失敗した + # ことから発見した本番ブロッカー: + # error: Determinate detected, aborting activation + # Determinate uses its own daemon to manage the Nix installation that + # conflicts with nix-darwin's native Nix management. + nix.enable = false; # ユーザー宣言(home-manager から参照される) users.users.${username} = { From af4fb2c2d05fd0cbdd655202687b99aaacb9da73 Mon Sep 17 00:00:00 2001 From: gotomts Date: Wed, 13 May 2026 11:30:50 +0900 Subject: [PATCH 2/3] =?UTF-8?q?ci(nix):=20nix=20flake=20check=20+=20m5mbp?= =?UTF-8?q?=20closure=20build=20=E3=82=92=20GitHub=20Actions=20=E3=81=A7?= =?UTF-8?q?=E5=AE=9F=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR で nix/ が変更されるたびに以下を実行する flake-check ジョブを追加: - nix flake check (構文 / 型 / 依存解決の壊れ検知) - nix build .#darwinConfigurations.m5mbp.system --no-link (closure 構築) 並行 Claude セッションへの影響なく drift を継続検知できる。Brewfile を 更新したのに homebrew.nix を直し忘れた、といったケースを物理防止する。 スコープ縮小の経緯: - 当初は ci 専用 host (username=runner) で `darwin-rebuild switch` まで CI で走らせる構成を試した - しかし本番 (m5mbp) と CI 環境 (runner / TCC / GUI / hardware) の差分を 埋める作業が膨らみ、本番投入の安全性向上に対して費用対効果が悪かった - 1 度の試運転で Determinate Nix と nix-darwin の競合 (前コミット `nix.enable = false`) を発見したことで CI の主目的は達成 - それ以降の iteration は CI 環境固有の問題に終始したため、ci-switch ジョブと ci host 定義は採用見送り - activation の検証は実機での `darwin-rebuild build` → `switch` で行う 設計: - runs-on: macos-latest (最新 macOS runner に自動追従) - DeterminateSystems/nix-installer-action でローカルと同じ Determinate Nix - run: で untrusted input (github.event.*) を一切評価しない (injection 対策) - concurrency で同一 ref の重複 run をキャンセルし課金を抑制 --- .github/workflows/nix-check.yml | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/nix-check.yml diff --git a/.github/workflows/nix-check.yml b/.github/workflows/nix-check.yml new file mode 100644 index 0000000..158b20f --- /dev/null +++ b/.github/workflows/nix-check.yml @@ -0,0 +1,63 @@ +# Nix flake / nix-darwin 構成の CI 検証 +# +# 目的: +# PR で nix/ が変更されるたびに `nix flake check` と m5mbp の system closure +# ビルドを走らせ、構文・型・依存解決の壊れを検知する。これにより main 更新 +# による drift (Brewfile ↔ homebrew.nix 等) を継続検知できる。 +# +# 設計判断: +# - `darwin-rebuild switch` 自体は CI で実行しない: +# ci 用に専用 host (username=runner 等) を作って switch する案を試したが、 +# 本番 (m5mbp) と CI 環境 (runner / TCC / GUI / hardware) の差分を埋める +# 作業が膨らみ、本番投入の安全性向上に対して費用対効果が悪かった。 +# activation の検証は実機での `darwin-rebuild build` → `switch` で行う方針。 +# - runs-on: macos-latest を採用 (最新 macOS runner に自動追従) +# - DeterminateSystems/nix-installer-action: ローカル開発と同じ Determinate Nix +# +# セキュリティ: +# - run: で github.event.* の自由文 (PR title / body / commit message 等) を +# 一切評価しない (injection 対策) +name: nix-check + +on: + pull_request: + paths: + - 'nix/**' + - '.github/workflows/nix-check.yml' + push: + branches: + - main + - 'feature/nix-migration-**' + paths: + - 'nix/**' + - '.github/workflows/nix-check.yml' + +# 同一ブランチで複数 push があった場合、進行中のジョブをキャンセルして最新だけ走らせる +concurrency: + group: nix-check-${{ github.ref }} + cancel-in-progress: true + +jobs: + flake-check: + name: nix flake check + build closure + runs-on: macos-latest + timeout-minutes: 20 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Nix (Determinate Systems) + uses: DeterminateSystems/nix-installer-action@main + with: + # diagnostic 送信を無効化 (Determinate 公式推奨の opt-out) + diagnostic-endpoint: '' + + - name: nix flake check + working-directory: nix + run: nix flake check --print-build-logs + + - name: Build m5mbp system closure + working-directory: nix + run: | + nix build .#darwinConfigurations.m5mbp.system \ + --no-link --print-build-logs From 33e46b0776d082cc481c02a3b580fe3900b7e667 Mon Sep 17 00:00:00 2001 From: gotomts Date: Wed, 13 May 2026 11:47:38 +0900 Subject: [PATCH 3/3] =?UTF-8?q?ci(nix):=20push=20trigger=20=E3=82=92=20mai?= =?UTF-8?q?n=20=E9=99=90=E5=AE=9A=E3=81=AB=E7=B5=9E=E3=82=8A=20feature=20b?= =?UTF-8?q?ranch=20=E3=81=AE=E9=87=8D=E8=A4=87=E8=B5=B7=E5=8B=95=E3=82=92?= =?UTF-8?q?=E8=A7=A3=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit これまで feature/nix-migration-** への push でも push イベントが起動し、 同 SHA に対して pull_request イベントと二重に nix-check が走っていた。 concurrency group が github.ref ベース (push と pull_request で値が違う) なので互いに cancel されず、毎回手動で push 重複 run をキャンセルする 運用になっていた。 feature branch は PR 経由で常に pull_request イベントを発火させるため、 push トリガーは main の直接 push (hotfix 等) のみに絞る。 --- .github/workflows/nix-check.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nix-check.yml b/.github/workflows/nix-check.yml index 158b20f..aee2fcb 100644 --- a/.github/workflows/nix-check.yml +++ b/.github/workflows/nix-check.yml @@ -25,9 +25,11 @@ on: - 'nix/**' - '.github/workflows/nix-check.yml' push: + # feature branch への push は pull_request イベントだけで検証する + # (push と pull_request の重複起動を避ける)。main の直接 push (hotfix 等) + # のみここで拾う。 branches: - main - - 'feature/nix-migration-**' paths: - 'nix/**' - '.github/workflows/nix-check.yml'