From a9ba9af8db5d72adfc9372d27abd9c813a8febce Mon Sep 17 00:00:00 2001 From: rain Date: Mon, 22 Jun 2026 14:47:43 -0400 Subject: [PATCH] Convert sway from hostname-allowlist to bootstrap prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces the implicit hostname-based enable (miche/byte/kaiser got sway automatically) with an explicit promptBool asked at first init. New flow: 1. `chezmoi init` asks: "sway_setup? [y/N]" 2. User says y or N (default N) 3. Answer is captured in data.sway_setup 4. run_once_40-install-sway.sh.tmpl gates on .sway_setup 5. Per-box override via marker files (preserved): - ~/.config/chezmoi/features/sway → force ON - ~/.config/chezmoi/features/no-sway → force OFF Migration for existing boxes: - Miche/byte/kaiser already have ~/.config/chezmoi/features/sway marker (from previous hostname-allowlist install) → sway_setup=true - Rye/crouton have no marker → sway_setup=false (default) - Both groups pick up the new template on next chezmoi apply --- .chezmoi.yaml.tmpl | 37 +++++++++++--------------------- run_once_40-install-sway.sh.tmpl | 4 ++-- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/.chezmoi.yaml.tmpl b/.chezmoi.yaml.tmpl index b840cc1..94ae392 100644 --- a/.chezmoi.yaml.tmpl +++ b/.chezmoi.yaml.tmpl @@ -62,29 +62,16 @@ data: os_family: {{ $osFamily | quote }} os_id: {{ .chezmoi.osRelease.id | quote }} - # Sway/Wayland desktop stack — enabled per host. Pis don't need it - # (headless); x86_64 desktops do. Override at runtime by creating - # `~/.config/chezmoi/features/sway` (force ON) or - # `~/.config/chezmoi/features/no-sway` (force OFF). + # Sway/Wayland desktop stack — opt-in at bootstrap time. When you + # run `chezmoi init` for the first time, you'll be asked: + # "Install the sway + wofi + foot Wayland desktop stack? [y/N]" + # Answering `y` installs the packages and writes the configs. + # Answering `N` (or pressing enter for default) skips both. # - # To toggle for a new box: `touch ~/.config/chezmoi/features/sway` - # then `chezmoi apply`. - {{- $swayOverrideOn := stat (joinPath .chezmoi.homeDir ".config/chezmoi/features/sway") }} - {{- $swayOverrideOff := stat (joinPath .chezmoi.homeDir ".config/chezmoi/features/no-sway") }} - {{- if $swayOverrideOn }} - sway: true - {{- else if $swayOverrideOff }} - sway: false - {{- else }} - {{- /* Hostname allowlist for the desktop stack. Match if hostname - equals or starts with any of the listed prefixes (e.g. "byte" - matches both "byte" and "byte-arch"). */}} - {{- $swayHosts := list "miche" "byte" "kaiser" }} - {{- $swayMatch := false }} - {{- range $swayHosts }} - {{- if or (eq . $.chezmoi.hostname) (hasPrefix (printf "%s-" .) $.chezmoi.hostname) (hasPrefix (printf "%s." .) $.chezmoi.hostname) }} - {{- $swayMatch = true }} - {{- end }} - {{- end }} - sway: {{ $swayMatch }} - {{- end }} \ No newline at end of file + # To flip later: `touch ~/.config/chezmoi/features/sway` to enable, + # or `touch ~/.config/chezmoi/features/no-sway` to disable, then + # `chezmoi apply`. The marker files override the bootstrap answer. + {{- $swayMarker := not (not (stat (joinPath .chezmoi.homeDir ".config/chezmoi/features/sway"))) }} + {{- $noSwayMarker := not (not (stat (joinPath .chezmoi.homeDir ".config/chezmoi/features/no-sway"))) }} + {{- $swayPrompt := promptBool "sway_setup" false }} + sway_setup: {{ or $swayMarker (and $swayPrompt (not $noSwayMarker)) }} \ No newline at end of file diff --git a/run_once_40-install-sway.sh.tmpl b/run_once_40-install-sway.sh.tmpl index e3000e4..0ab0ada 100644 --- a/run_once_40-install-sway.sh.tmpl +++ b/run_once_40-install-sway.sh.tmpl @@ -16,8 +16,8 @@ set -euo pipefail log() { printf '\033[1;34m[sway]\033[0m %s\n' "$*"; } # --- 0. Gate on the .sway flag --- -{{ if not .sway -}} -log "sway not enabled for this host (.sway=false). Skipping." +{{ if not .sway_setup -}} +log "sway_setup not enabled for this host (.sway_setup=false). Skipping." log "To enable: touch ~/.config/chezmoi/features/sway && chezmoi apply" exit 0 {{ end -}}