|
| 1 | +--- |
| 2 | +name: windows-internals |
| 3 | +description: Windows-operational internals for this chezmoi repo: WSL cloud-init provisioning, Rancher Desktop/Docker, ssh-tpm-agent commit signing, the dual gpg.exe split, WezTerm, and the Windows bootstrap/elevation block. Triggers: Windows internals, WSL, cloud-init, rsync --delete, Rancher Desktop, moby, rdctl, Docker daemon pipe, ssh-tpm-agent, TPM, two gpg.exe, WezTerm, Windows bootstrap, elevation, YASB. Load before changing Windows-operational scripts/data. |
| 4 | +--- |
| 5 | + |
| 6 | +# Windows internals |
| 7 | + |
| 8 | +**Scope:** `home/.chezmoiscripts/*windows*.ps1.tmpl` (except the mise-shim scripts; see the `mise-on-windows` skill), `home/.chezmoiscripts/run_onchange_after_bootstrap_windows.ps1.tmpl` (shared with `mise-on-windows`), `home/.chezmoiscripts/run_after_96_rancher_desktop_windows.ps1.tmpl`, `home/.chezmoidata/wsl/`, `home/.chezmoidata/ssh-tpm-agent.yaml`, `home/.chezmoidata/ssh-signing.yaml`, `home/private_dot_ssh/allowed_signers.tmpl`, `home/.chezmoitemplates/wsl-*.tmpl`, `home/dot_config/wezterm/`. |
| 9 | + |
| 10 | +## Windows bootstrap / elevation |
| 11 | + |
| 12 | +- **Windows bootstrap** — `home/.chezmoiscripts/run_onchange_after_bootstrap_windows.ps1.tmpl` installs packages via Chocolatey (`choco install -y`) and Winget, runs `mise install`, syncs Neovim plugins, and configures/starts YASB autostart via `HKCU\Software\Microsoft\Windows\CurrentVersion\Run`. `home/.chezmoiscripts/run_onchange_after_choco_review_windows.ps1.tmpl` runs interactive Chocolatey drift review after overlay changes when `bash` is available. Runs only on Windows. The elevated block does **not** skip Chocolatey/WSL when `CI` is set (same code path as interactive runs; `windows-elevation.ps1.tmpl` still avoids UAC in CI by running the block in-process). The same bootstrap script also places `mise-shim.exe` — that part is owned by the `mise-on-windows` skill. |
| 13 | + |
| 14 | + |
| 15 | +## WezTerm, ssh-tpm-agent, gpg, WSL |
| 16 | + |
| 17 | +- **WezTerm** — `home/dot_config/wezterm/wezterm.lua` (→ `~/.config/wezterm/wezterm.lua`). Windows terminal emulator with kitty graphics protocol support. Ignored on non-Windows via `.chezmoiignore`. |
| 18 | +- **ssh-tpm-agent (Windows commit signing):** TPM-sealed SSH signing key for git on Windows. Version pinned in `home/.chezmoidata/ssh-tpm-agent.yaml`; installed by `home/.chezmoiscripts/run_onchange_after_98_ssh_tpm_agent_windows.ps1.tmpl` into `%LOCALAPPDATA%\Programs\ssh-tpm-agent\`; autostart via HKCU Run key. Windows `ssh-agent` service is disabled by `home/.chezmoiscripts/run_once_after_91_disable_windows_ssh_agent_windows.ps1.tmpl` so ssh-tpm-agent can bind the openssh named pipe. Per-machine signing keys listed in `home/.chezmoidata/ssh-signing.yaml`, rendered to `~/.ssh/allowed_signers` via `home/private_dot_ssh/allowed_signers.tmpl`. Gated everywhere on `sshSigning.enabled`. See `docs/ssh-signing.md` for the per-machine setup flow. |
| 19 | +- **Two `gpg.exe` on Windows.** Git-for-Windows ships an MSYS2 `gpg` at `/usr/bin/gpg` (`C:\Program Files\Git\usr\bin\gpg.exe`) with a TTY-only pinentry that hangs from non-TTY shells, and homedir `~/.gnupg`. Chocolatey's `gnupg` package installs upstream GnuPG at `C:\Program Files\GnuPG\bin\gpg.exe` with `pinentry-basic.exe` and homedir `%APPDATA%\gnupg` (`~/AppData/Roaming/gnupg`). The two share nothing: different keyrings, agents, and sockets. For signing, smartcard, or TPM work always invoke the Chocolatey gpg by full path or set `gpg.program = "C:/Program Files/GnuPG/bin/gpg.exe"` in `~/.gitconfig.overrides`. Switch agent state with `"/c/Program Files/GnuPG/bin/gpgconf.exe" --kill all` before retrying after a hung run. For unattended signing add `pinentry-mode loopback` to `%APPDATA%\gnupg\gpg.conf` and `allow-loopback-pinentry` to `%APPDATA%\gnupg\gpg-agent.conf`. |
| 20 | +- **WSL** — The Windows bootstrap script provisions WSL Ubuntu non-interactively via cloud-init. The cloud-init YAML lives in `home/.chezmoidata/wsl/00-ubuntu-user-data.yaml` as `windowsWsl.ubuntuCloudInitUserData` (static data; `.chezmoi.toml` `[data] wsl` remains the boolean “running inside WSL”). On **first** WSL setup, `~/.local/share/chezmoi` is created with **`cp -a` from the Windows chezmoi source** on `/mnt/<drive>/...` (see `home/.chezmoitemplates/wsl-windows-chezmoi-source-mount-path.tmpl`: maps `.chezmoi.sourceDir`). On **subsequent** runs the WSL source is **refreshed with `rsync -a --delete` from the Windows source** (`home/.chezmoitemplates/wsl-update-dotfiles-bash.sh.tmpl`) so renames and deletions on the Windows side are mirrored in WSL — without `--delete`, stale files plus `.chezmoiremove` tombstones produce `inconsistent state` errors that abort apply. **Treat the Windows chezmoi source as the authoritative tree:** any WSL-only edits to files under `~/.local/share/chezmoi/` on the WSL side are overwritten on the next Windows apply. Make source edits on Windows, run `chezmoi apply` there, and WSL will be reconciled. Shared Windows WSL script inputs (`profile.windows.wslUser` + mount path) are built in `home/.chezmoitemplates/wsl-windows-script-context.json.tmpl` (`toJson` / `fromJson`) for `run_onchange_after_bootstrap_windows.ps1.tmpl` and `run_after_95_wsl_ensure_windows.ps1.tmpl`. Set `profile.windows.wslUser` in `home/.chezmoidata/profile.yaml` (required on Windows; empty fails apply for WSL/bootstrap scripts). Scripts substitute `__WSL_CHEZMOI_SOURCE__` and `__WSL_USER__` into that blob at apply time, write `~/.cloud-init/Ubuntu.user-data`, install Ubuntu with `--no-launch`, and wait for cloud-init. Inside WSL, `chezmoi.os` is `"linux"` so the full Unix config stack (zsh, brew, tmux, etc.) applies without modification. |
| 21 | + |
| 22 | +## Rancher Desktop / Docker (Windows) |
| 23 | + |
| 24 | +- Rancher Desktop provides the Docker daemon on Windows via a WSL2 backend (`rancher-desktop` distro). |
| 25 | +- Container engine must be **`moby`** (not containerd) for the `docker` CLI to work. |
| 26 | +- Docker CLI and `rdctl` live at `C:\Program Files\Rancher Desktop\resources\resources\win32\bin\`. |
| 27 | +- Settings file: `%LOCALAPPDATA%\rancher-desktop\settings.json` (schema version in `version` field). |
| 28 | +- `rdctl set` covers engine and Kubernetes flags; WSL integration (`WSL.integrations.<distro>`) must use `rdctl api -X PUT --input <file> /v1/settings` with a `version` field. |
| 29 | +- `home/.chezmoiscripts/run_after_96_rancher_desktop_windows.ps1.tmpl` starts RD, waits for the Docker daemon pipe (`\\.\pipe\docker_engine`), and enables WSL integration for Ubuntu. |
| 30 | +- The script runs after WSL ensure (95) so Ubuntu is available for integration. |
| 31 | +- If the backend crashes (WSL distros show Stopped while UI shows online), fix with: `rdctl shutdown --wait && wsl --shutdown && rdctl start --container-engine.name moby`. |
0 commit comments