From 0da213b3477cfa186579aa54880231bd2b1073bb Mon Sep 17 00:00:00 2001 From: samuido <176191237+rebuildup@users.noreply.github.com> Date: Sun, 29 Nov 2026 17:12:52 +0900 Subject: [PATCH 1/2] fix: use managed deployment directory for remote bootstrap (#272) --- bootstrap.ps1 | 10 +++++++++- bootstrap.sh | 19 ++++++++++++++++++- docs/adr/ADR-0016.md | 8 ++++++++ platforms/nixos/flake.nix | 9 +++++++-- platforms/nixos/sync-checkout.sh | 13 +++++++++++++ 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/bootstrap.ps1 b/bootstrap.ps1 index f6dd0bc0..cf2af1d5 100644 --- a/bootstrap.ps1 +++ b/bootstrap.ps1 @@ -6,7 +6,11 @@ $ErrorActionPreference = 'Stop' $RepoUrl = if ($env:PC_SETUP_REPO_URL) { $env:PC_SETUP_REPO_URL } else { 'https://github.com/rebuildup/pc-setup.git' } $RepoRef = if ($env:PC_SETUP_REF) { $env:PC_SETUP_REF } else { 'main' } -$TargetDir = if ($env:PC_SETUP_DIR) { $env:PC_SETUP_DIR } else { Join-Path $HOME 'src\pc-setup' } +$DeployDir = if ($env:PC_SETUP_DEPLOY_DIR) { $env:PC_SETUP_DEPLOY_DIR } else { Join-Path $env:LOCALAPPDATA 'pc-setup\deploy' } +$TargetDir = if ($env:PC_SETUP_DIR) { $env:PC_SETUP_DIR } else { $DeployDir } +if ($RepoRef -ne 'main' -and (-not $env:PC_SETUP_DIR -or $TargetDir -eq $DeployDir)) { + throw 'non-main bootstrap requires a separate PC_SETUP_DIR' +} function Write-Step { param([Parameter(Mandatory)][string]$Message) @@ -176,6 +180,9 @@ else { throw "existing checkout has unexpected origin: $currentOrigin" } + $changes = & git -C $TargetDir status --porcelain + if ($LASTEXITCODE -ne 0 -or $changes) { throw "refusing to update dirty or unreadable checkout: $TargetDir" } + if ($TargetDir -eq $DeployDir -and (& git -C $TargetDir branch --show-current) -ne 'main') { throw 'managed deployment must be on main' } Write-Step "Updating existing pc-setup checkout to $RepoRef" $remoteTrackingRef = "refs/remotes/origin/$RepoRef" $fetchRefSpec = "+refs/heads/${RepoRef}:$remoteTrackingRef" @@ -202,6 +209,7 @@ else { & git -C $TargetDir merge --ff-only "origin/$RepoRef" if ($LASTEXITCODE -ne 0) { throw "git fast-forward failed with exit code $LASTEXITCODE" } + if ($TargetDir -eq $DeployDir -and (& git -C $TargetDir rev-parse HEAD) -ne (& git -C $TargetDir rev-parse "origin/$RepoRef")) { throw 'managed deployment contains unpublished commits' } } $applyDir = $TargetDir diff --git a/bootstrap.sh b/bootstrap.sh index cc978b10..c3098c47 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -3,7 +3,12 @@ set -euo pipefail repo_url="${PC_SETUP_REPO_URL:-https://github.com/rebuildup/pc-setup.git}" repo_ref="${PC_SETUP_REF:-main}" -target_dir="${PC_SETUP_DIR:-$HOME/src/pc-setup}" +deploy_dir="${PC_SETUP_DEPLOY_DIR:-$HOME/.local/share/pc-setup/deploy}" +target_dir="${PC_SETUP_DIR:-$deploy_dir}" +if [[ "$repo_ref" != main && ( -z "${PC_SETUP_DIR:-}" || "$target_dir" == "$deploy_dir" ) ]]; then + printf 'non-main bootstrap requires a separate PC_SETUP_DIR\n' >&2 + exit 1 +fi log() { printf '\n==> %s\n' "$*" @@ -158,10 +163,22 @@ else exit 1 fi + if [[ -n "$(git -C "$target_dir" status --porcelain)" ]]; then + printf 'refusing to update dirty checkout: %s\n' "$target_dir" >&2 + exit 1 + fi + if [[ "$target_dir" == "$deploy_dir" && "$(git -C "$target_dir" branch --show-current)" != main ]]; then + printf 'managed deployment must be on main\n' >&2 + exit 1 + fi log "Updating existing pc-setup checkout to $repo_ref" git -C "$target_dir" fetch origin "$repo_ref" git -C "$target_dir" switch "$repo_ref" git -C "$target_dir" merge --ff-only "origin/$repo_ref" + if [[ "$target_dir" == "$deploy_dir" && "$(git -C "$target_dir" rev-parse HEAD)" != "$(git -C "$target_dir" rev-parse "origin/$repo_ref")" ]]; then + printf 'managed deployment contains unpublished commits\n' >&2 + exit 1 + fi fi cd "$target_dir" diff --git a/docs/adr/ADR-0016.md b/docs/adr/ADR-0016.md index 907eb9c9..70575e5f 100644 --- a/docs/adr/ADR-0016.md +++ b/docs/adr/ADR-0016.md @@ -38,6 +38,14 @@ converge は dotfiles の端末定義も毎 tick で各端末へ反映する。I - `~/.local/state/pc-setup` は状態・ログ・ロックの置き場にする。ソースツリーは置かない。 - `apply-global-mise.sh` は自身の位置から repo root を決めるため、converge は必ず `$DEPLOY/scripts/apply-global-mise.sh` を呼ぶ。これで `~/.config/mise/config.toml` と `mise.lock` は配備用チェックアウトを指す。 +### 2a. 初回 bootstrap と既存端末の移行 + +remote bootstrap は通常の定期配備と同じ管理領域を使用する。Unix / NixOS は `~/.local/share/pc-setup/deploy`、Windows は `%LOCALAPPDATA%\pc-setup\deploy`。共通の上書きは `PC_SETUP_DEPLOY_DIR`。汎用開発rootは作成しない。 + +明示的な `PC_SETUP_DIR` または既存 checkout 内からの実行は開発・候補適用の入口として残す。非 main の remote bootstrap は配備先とは別の明示的な checkout を必要とする。定期配備用の checkout を候補ブランチに切り替えてはならない。 + +既存の旧配置は自動移動・削除しない。初回移行では managed deploy を main から準備し、正規 bootstrap/converge で設定を更新する。mise の設定/lock、NixOS wrapper、OS scheduler の参照先と revision を verify/status で確認する。旧 checkout の dirty/untracked/stash/local refs、worktree、他プロセス・設定の参照を確認できるまでは残す。空の旧親 directory も user-owned として扱う。 + ### 3. 安全性 - **dirty は拒否してスキップ**:配備用チェックアウト、または `~/.dotfiles` に未コミットの変更があるとき、reset、checkout、stash はしない。そのステップを skipped として記録し、status の errors に載せる。`~/.dotfiles` については既存の `sync-dotfiles.sh` の拒否をそのまま使う。 diff --git a/platforms/nixos/flake.nix b/platforms/nixos/flake.nix index 8ceb0e6a..1f95b326 100644 --- a/platforms/nixos/flake.nix +++ b/platforms/nixos/flake.nix @@ -193,12 +193,17 @@ name = "pc-setup-bootstrap"; runtimeInputs = bootstrapPackages pkgs; text = '' - pc_setup_dir="''${PC_SETUP_DIR:-$HOME/src/pc-setup}" + deploy_dir="''${PC_SETUP_DEPLOY_DIR:-$HOME/.local/share/pc-setup/deploy}" + pc_setup_dir="''${PC_SETUP_DIR:-$deploy_dir}" pc_setup_ref="''${PC_SETUP_REF:-main}" pc_setup_repo_url="''${PC_SETUP_REPO_URL:-https://github.com/rebuildup/pc-setup.git}" dotfiles_dir="''${DOTFILES_DIR:-$HOME/.dotfiles}" - bash "${./sync-checkout.sh}" "$pc_setup_repo_url" "$pc_setup_ref" "$pc_setup_dir" + if [[ "$pc_setup_ref" != main && ( -z "''${PC_SETUP_DIR:-}" || "$pc_setup_dir" == "$deploy_dir" ) ]]; then + printf 'non-main bootstrap requires a separate PC_SETUP_DIR\n' >&2 + exit 1 + fi + bash "${./sync-checkout.sh}" "$pc_setup_repo_url" "$pc_setup_ref" "$pc_setup_dir" "$deploy_dir" printf 'installing portable global CLI baseline through mise (NixOS FHS compatibility)\n' MISE_ALL_COMPILE=0 \ diff --git a/platforms/nixos/sync-checkout.sh b/platforms/nixos/sync-checkout.sh index 0b85c4e8..37fe259f 100755 --- a/platforms/nixos/sync-checkout.sh +++ b/platforms/nixos/sync-checkout.sh @@ -4,6 +4,7 @@ set -euo pipefail repo_url="${1:?repository URL is required}" repo_ref="${2:?repository ref is required}" target_dir="${3:?target directory is required}" +deploy_dir="${4:-${PC_SETUP_DEPLOY_DIR:-$HOME/.local/share/pc-setup/deploy}}" if [[ ! -e "$target_dir" ]]; then printf 'cloning pc-setup (%s) -> %s\n' "$repo_ref" "$target_dir" @@ -23,6 +24,14 @@ if [[ "$current_origin" != "$repo_url" ]]; then exit 1 fi +if [[ -n "$(git -C "$target_dir" status --porcelain)" ]]; then + printf 'refusing to update dirty checkout: %s\n' "$target_dir" >&2 + exit 1 +fi +if [[ "$target_dir" == "$deploy_dir" && "$(git -C "$target_dir" branch --show-current)" != main ]]; then + printf 'managed deployment must be on main\n' >&2 + exit 1 +fi printf 'updating existing pc-setup checkout to %s\n' "$repo_ref" remote_tracking_ref="refs/remotes/origin/$repo_ref" @@ -41,3 +50,7 @@ else fi git -C "$target_dir" merge --ff-only "origin/$repo_ref" +if [[ "$target_dir" == "$deploy_dir" && "$(git -C "$target_dir" rev-parse HEAD)" != "$(git -C "$target_dir" rev-parse "origin/$repo_ref")" ]]; then + printf 'managed deployment contains unpublished commits\n' >&2 + exit 1 +fi From 7085574d1c09f75abc3895e178f92fe9a4e1beb6 Mon Sep 17 00:00:00 2001 From: samuido <176191237+rebuildup@users.noreply.github.com> Date: Sun, 29 Nov 2026 17:13:28 +0900 Subject: [PATCH 2/2] docs: reconcile workspace guidance and add static regression checks (#272) --- AGENTS.md | 2 +- README.md | 6 +++++- docs/adr/ADR-0002.md | 2 +- platforms/nixos/README.md | 2 +- platforms/ubuntu-wsl/README.md | 15 ++++++--------- scripts/ci.sh | 15 +++++++++++++++ 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 103644da..e50e365c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -61,7 +61,7 @@ Do not pin continuously updated user tools merely to make a snapshot look reprod For `platforms/ubuntu-wsl`: - target WSL2 + Ubuntu -- development repositories live on the Linux filesystem (`~/src` by default), not `/mnt/c` +- development repositories live on the Linux filesystem at explicitly selected project paths, not `/mnt/c`; bootstrap does not establish a general-purpose development root - WSL is treated as its own development machine for tool installation and authentication - GitHub CLI uses the GitHub-maintained Debian/Ubuntu package repository - Rust uses `rustup` diff --git a/README.md b/README.md index 00a8ef54..824ee14f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ remote bootstrap Flake 自体には `flake.lock` を置いていない。GitHub pc-setup の NixOS system profile 適用後は `nix-command` / `flakes` が恒久的に有効になる。ただし remote bootstrap を再実行する場合は `--no-write-lock-file` は引き続き必要。 -Flake / Home Managerがsystem/build packageのcanonical sourceです。portableなユーザーCLIは他OSと同じ `mise.global.toml` を使いますが、NixOS bootstrapでは bare host の dynamic linker に依存しないよう、mise install を一時的な FHS compatibility environment 内で実行します。既存 `~/src/pc-setup` がある場合も `PC_SETUP_REF` へ fast-forward only で同期してから適用します。source compile のNixOS自動fallbackは使わず、bootstrap中だけ `MISE_ALL_COMPILE=0` としてprebuilt artifactを利用します。 +Flake / Home Managerがsystem/build packageのcanonical sourceです。portableなユーザーCLIは他OSと同じ `mise.global.toml` を使いますが、NixOS bootstrapでは bare host の dynamic linker に依存しないよう、mise install を一時的な FHS compatibility environment 内で実行します。既存の配備用 checkout がある場合も `PC_SETUP_REF` へ fast-forward only で同期してから適用します。source compile のNixOS自動fallbackは使わず、bootstrap中だけ `MISE_ALL_COMPILE=0` としてprebuilt artifactを利用します。 NixOS bootstrap は install 済み CLI を bare PATH へ直接出さず、persistent FHS wrapper baseline を `~/.local/state/pc-setup/nix-user-baseline` に構築する。通常 shell の `claude` / `opencode` / `node` 等は、その wrapper から FHS 内の `mise exec` を呼ぶため、system profile 適用前でも generic Linux binary を実行できる。project-local mise config も同じ wrapper から解決する。 @@ -174,6 +174,10 @@ plans/ macos/ ``` +## Managed checkout + +通常の remote bootstrap は Unix / NixOS では `~/.local/share/pc-setup/deploy`、Windows では `%LOCALAPPDATA%\pc-setup\deploy` を使う。定期配備と同じ管理領域で、`PC_SETUP_DEPLOY_DIR` で変更できる。一般の開発領域を自動生成しない。非 main の候補を適用する場合は別の `PC_SETUP_DIR` を明示する。旧 checkout は自動移動・削除しない。移行条件は [ADR-0016](docs/adr/ADR-0016.md) を参照。 + ## Existing checkout repositoryをすでにcloneしている場合はrootから: diff --git a/docs/adr/ADR-0002.md b/docs/adr/ADR-0002.md index 8dfd0156..2583b513 100644 --- a/docs/adr/ADR-0002.md +++ b/docs/adr/ADR-0002.md @@ -22,7 +22,7 @@ fresh distributionで毎回install sourceを探し直すと、Ubuntu archive版 ### 1. Target environment - WSL2上のUbuntuを対象とする。 -- development repositoryはLinux filesystem側の `~/src` を標準workspaceとする。 +- development repositoryはLinux filesystem側の明示的に選択したproject workspaceに置く。汎用開発rootはbootstrapが定義しない(ADR-0016の配置規則)。 - `/mnt/c` 等のWindows-mounted filesystemは、通常のbuild/watch/git workspaceとして使用しない。 - WSL distributionはWindows側とは別のdevelopment machineとしてtool installationとauthenticationを行う。 diff --git a/platforms/nixos/README.md b/platforms/nixos/README.md index bf246490..a8440956 100644 --- a/platforms/nixos/README.md +++ b/platforms/nixos/README.md @@ -205,7 +205,7 @@ nix --extra-experimental-features 'nix-command flakes' \ run --no-write-lock-file 'github:rebuildup/pc-setup?dir=platforms/nixos' ``` -Flake app が必要なbootstrap toolsとFHS compatibility environmentを一時的に用意し、`~/src/pc-setup` のcheckoutを準備します。既存checkoutがある場合はoriginを検証し、`PC_SETUP_REF` をfetchしてtracking branchへ切り替え、fast-forward onlyで同期します。その後 `mise.global.toml` を適用し、`mise install` とdotfiles bootstrapをFHS environment内で実行します。最後に persistent CLI wrapper baseline を構築し、通常 shell 相当の PATH で `verify.sh` を通してから `pc-setup bootstrap complete` とします。 +Flake app が必要なbootstrap toolsとFHS compatibility environmentを一時的に用意し、`${PC_SETUP_DEPLOY_DIR:-$HOME/.local/share/pc-setup/deploy}` のcheckoutを準備します。既存checkoutがある場合はoriginを検証し、`PC_SETUP_REF` をfetchしてtracking branchへ切り替え、fast-forward onlyで同期します。その後 `mise.global.toml` を適用し、`mise install` とdotfiles bootstrapをFHS environment内で実行します。最後に persistent CLI wrapper baseline を構築し、通常 shell 相当の PATH で `verify.sh` を通してから `pc-setup bootstrap complete` とします。 pc-setup の system profile 適用後は `nix-command` / `flakes` が有効になります。remote bootstrap 側は read-only GitHub flake なので、再実行時も `--no-write-lock-file` は維持します。 diff --git a/platforms/ubuntu-wsl/README.md b/platforms/ubuntu-wsl/README.md index d238ea9f..a78369bb 100644 --- a/platforms/ubuntu-wsl/README.md +++ b/platforms/ubuntu-wsl/README.md @@ -106,18 +106,14 @@ Credentials are not stored in pc-setup. ## Workspace -Development repositories belong on the Linux filesystem: - -```text -~/src/ -``` +Development repositories belong on the Linux filesystem at an explicitly selected project path; bootstrap does not create a general-purpose source root. Do not use `/mnt/c` as the normal Git/build/watch/worktree workspace. The root bootstrap checkout itself defaults to: ```text -~/src/pc-setup +~/.local/share/pc-setup/deploy ``` ## Verify @@ -125,7 +121,7 @@ The root bootstrap checkout itself defaults to: After the canonical fresh-setup one-liner above, the current Bash shell is already refreshed. If bootstrap was invoked directly without the trailing `source ~/.bashrc`, either source it manually or open a fresh shell, then run: ```bash -cd ~/src/pc-setup +cd ~/.local/share/pc-setup/deploy ./platforms/ubuntu-wsl/verify.sh ``` @@ -149,8 +145,9 @@ sudo apt-get install -y git curl ca-certificates curl -fsSL https://mise.run/bash | sh export PATH="$HOME/.local/bin:$PATH" -git clone --branch main --single-branch https://github.com/rebuildup/pc-setup.git "$HOME/src/pc-setup" -cd "$HOME/src/pc-setup" +mkdir -p "$HOME/.local/share/pc-setup" +git clone --branch main --single-branch https://github.com/rebuildup/pc-setup.git "$HOME/.local/share/pc-setup/deploy" +cd "$HOME/.local/share/pc-setup/deploy" ./bootstrap.sh source ~/.bashrc ``` diff --git a/scripts/ci.sh b/scripts/ci.sh index 31f0e080..d3b27e7b 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -22,6 +22,21 @@ if [[ "${#shell_scripts[@]}" -eq 0 ]]; then exit 1 fi +printf 'Checking managed bootstrap checkout defaults...\n' +python3 - <<'PY' +from pathlib import Path + +for path in ("bootstrap.sh", "bootstrap.ps1", "platforms/nixos/flake.nix"): + source = Path(path).read_text(encoding="utf-8") + assert "PC_SETUP_DEPLOY_DIR" in source, path + assert "src/pc-setup" not in source and r"src\pc-setup" not in source, path + assert "non-main bootstrap requires a separate PC_SETUP_DIR" in source, path + +assert "$HOME/.local/share/pc-setup/deploy" in Path("bootstrap.sh").read_text() +assert "$HOME/.local/share/pc-setup/deploy" in Path("platforms/nixos/flake.nix").read_text() +assert r"pc-setup\deploy" in Path("bootstrap.ps1").read_text() +PY + printf 'Checking bash syntax...\n' for script in "${shell_scripts[@]}"; do bash -n "$script"