Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 から解決する。

Expand Down Expand Up @@ -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から:
Expand Down
10 changes: 9 additions & 1 deletion bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
19 changes: 18 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' "$*"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/ADR-0002.md
Original file line number Diff line number Diff line change
Expand Up @@ -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を行う。

Expand Down
8 changes: 8 additions & 0 deletions docs/adr/ADR-0016.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` の拒否をそのまま使う。
Expand Down
2 changes: 1 addition & 1 deletion platforms/nixos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` は維持します。

Expand Down
9 changes: 7 additions & 2 deletions platforms/nixos/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
13 changes: 13 additions & 0 deletions platforms/nixos/sync-checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
15 changes: 6 additions & 9 deletions platforms/ubuntu-wsl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,22 @@ 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

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
```

Expand All @@ -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
```
Expand Down
15 changes: 15 additions & 0 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading