diff --git a/README.md b/README.md index 9d2c3a2..99b1ad7 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,8 @@ features; healthy managed configurations remain linked. You can recover with `dot` also replaces an absent/unreadable inherited Nix CA-bundle path with a readable local system bundle (including Fedora/AlmaLinux's `/etc/pki` path), while preserving valid custom bundles and keeping TLS verification enabled. +Switches use timestamped `hm-bak.*` backup suffixes so an older `hm-bak` cannot +block recovery or be overwritten. Apps that write their own settings (Claude Code, pi, Vesktop, Konsole profiles, VSCodium, Zed, `~/.ssh/config`) are linked **out of the Nix store** into this checkout. Changes made in the app show up in `git diff`, so commit them. diff --git a/bin/dot b/bin/dot index 24d114f..057ff7e 100755 --- a/bin/dot +++ b/bin/dot @@ -153,13 +153,16 @@ cmd_switch() { [ -n "${1:-}" ] && cmd_profile "$1" source_nix || die "nix missing: run dot nix" ensure_nix_features - local attr; attr="$(flake_attr)" + local attr backup_ext; attr="$(flake_attr)" + # Shared homes can already have an hm-bak from a previous host/container. + # Preserve old backups instead of making the recovery switch clobber one. + backup_ext="hm-bak.$(date -u +%Y%m%dT%H%M%SZ).$$" step "home-manager switch → $attr" export DOTFILES_DIR if have home-manager; then - home-manager switch --flake "$DOTFILES_DIR#$attr" --impure -b hm-bak + home-manager switch --flake "$DOTFILES_DIR#$attr" --impure -b "$backup_ext" else - nix run --inputs-from "$DOTFILES_DIR" home-manager -- switch --flake "$DOTFILES_DIR#$attr" --impure -b hm-bak + nix run --inputs-from "$DOTFILES_DIR" home-manager -- switch --flake "$DOTFILES_DIR#$attr" --impure -b "$backup_ext" fi } diff --git a/tests/nix-bootstrap.sh b/tests/nix-bootstrap.sh index 9af7b84..e8b1fc2 100644 --- a/tests/nix-bootstrap.sh +++ b/tests/nix-bootstrap.sh @@ -55,6 +55,13 @@ mv "$conf" "$fixture/healthy-link" ln -s "$fixture/missing-again" "$conf" flake_attr() { echo headless; } have() { [ "$1" = home-manager ]; } -home-manager() { grep -qx 'extra-experimental-features = nix-command flakes' "$conf"; } +printf 'existing backup\n' >"$conf.hm-bak" +home-manager() { + grep -qx 'extra-experimental-features = nix-command flakes' "$conf" + # The fixed hm-bak suffix would collide with this existing backup. + [[ " $* " == *' -b hm-bak.'* ]] + [ ! -e "$conf.${*: -1}" ] +} cmd_switch +grep -qx 'existing backup' "$conf.hm-bak" echo 'Nix bootstrap recovery checks passed'