Preserve existing Home Manager backups during recovery switches

This commit is contained in:
Ziad Arafat committed 2026-11-15 12:11:03 -07:00
1 parent 1c4b0657bf
commit 19f9c232e2
3 files changed
+16 -4

No files matched your search

+2
View File
@@ -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.
+6 -3
View File
@@ -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
}
+8 -1
View File
@@ -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'