feat: installer boots nvim once and restores the lazy-lock pins
A first nvim start cloned the later-round plugins (claudecode, mini.*, nvim-lint, friendly-snippets, ...) at branch tip and rewrote the seeded lazy-lock.json with the tips. The install pipeline now ends with a headless first boot, puts the seeded lockfile back, and runs `Lazy! restore`. It runs only where lazy has never installed a plugin, so a lockfile the user has moved on is never touched, and a second run does nothing.
This commit is contained in:
1 parent
4e2452e994
commit
e0c78a3ffa
5 files changed
+121
No files matched your search
@@ -157,6 +157,22 @@ herdr)
|
|||||||
integration:install) [ "$mode" = install ] && exit 1 ;;
|
integration:install) [ "$mode" = install ] && exit 1 ;;
|
||||||
esac
|
esac
|
||||||
exit 0 ;;
|
exit 0 ;;
|
||||||
|
nvim)
|
||||||
|
# Behaves like lazy.nvim's first start: a plain boot creates the plugin
|
||||||
|
# directory and REWRITES lazy-lock.json with drifted commits, which is the
|
||||||
|
# bug the installer's first-boot step exists to undo. `+Lazy! restore`
|
||||||
|
# records the lockfile it was handed in ~/.nvim-restored-from. Injections:
|
||||||
|
# FAKE_FAIL=nvim:boot and FAKE_FAIL=nvim:restore.
|
||||||
|
_lock=${XDG_CONFIG_HOME:-$HOME/.config}/nvim/lazy-lock.json
|
||||||
|
case "$*" in
|
||||||
|
*'Lazy! restore'*)
|
||||||
|
[ "$mode" = restore ] && exit 1
|
||||||
|
cp "$_lock" "$HOME/.nvim-restored-from"; exit 0 ;;
|
||||||
|
esac
|
||||||
|
mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lazy/lazy.nvim"
|
||||||
|
[ -f "$_lock" ] && printf '{ "drifted": "tip" }\n' > "$_lock"
|
||||||
|
[ "$mode" = boot ] && exit 1
|
||||||
|
exit 0 ;;
|
||||||
fzf)
|
fzf)
|
||||||
# The picker's own fzf, and the only fake here whose ARGV is the thing
|
# The picker's own fzf, and the only fake here whose ARGV is the thing
|
||||||
# under test. `--bind` strings are built across a dozen continued lines, so
|
# under test. `--bind` strings are built across a dozen continued lines, so
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# what: nvim's first boot no longer puts the seeded lazy-lock.json back
|
||||||
|
# why: restore then pins to the tips the boot just wrote, and the pins are lost
|
||||||
|
# kills: …against the SEEDED lockfile, not the one the boot rewrote
|
||||||
|
# run: unit
|
||||||
|
<<<OLD
|
||||||
|
run_sh "cp '$nb_seed' '$nb_lock'" || { warn "could not put the seeded lazy-lock.json back"; return 0; }
|
||||||
|
<<<NEW
|
||||||
|
<<<END
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# what: the nvim first-boot step runs even where lazy already manages plugins
|
||||||
|
# why: it would overwrite a lockfile the user moved on with :Lazy update
|
||||||
|
# kills: …and nvim is not started
|
||||||
|
# run: unit
|
||||||
|
<<<OLD
|
||||||
|
[ ! -e "$nb_lazy" ] || return 0
|
||||||
|
<<<NEW
|
||||||
|
<<<END
|
||||||
@@ -814,6 +814,56 @@ else
|
|||||||
hasnt "with no herdr the step says nothing" "herdr" "$out"
|
hasnt "with no herdr the step says nothing" "herdr" "$out"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
printf '\n\033[1mnvim first boot keeps the lazy-lock.json pins\033[0m\n'
|
||||||
|
# A real first boot clones some plugins at branch tip and rewrites the lockfile
|
||||||
|
# with the tips; the fake nvim does the same rewrite. The step has to undo it:
|
||||||
|
# boot, put the seed back, then restore against the seed. Once only, and never
|
||||||
|
# over a lockfile lazy has already managed.
|
||||||
|
seedlock() {
|
||||||
|
mkdir -p "$SB/.config/nvim"
|
||||||
|
printf '{ "plugin": "pinned" }\n' > "$SB/.config/nvim/lazy-lock.json"
|
||||||
|
}
|
||||||
|
newbox; sh ./seal.sh "$SB/seal" --with nvim >/dev/null; BOXPATH=$SB/seal
|
||||||
|
seedlock; pick core/ripgrep
|
||||||
|
out=$(box install 2>&1 | plain || true)
|
||||||
|
is "a fresh box boots nvim, then restores" "boot restore" \
|
||||||
|
"$(awk '$1=="nvim" {print (/Lazy! restore/ ? "restore" : "boot")}' "$LOG" | tr '\n' ' ' | sed 's/ $//')"
|
||||||
|
is "…against the SEEDED lockfile, not the one the boot rewrote" '{ "plugin": "pinned" }' \
|
||||||
|
"$(cat "$SB/.nvim-restored-from" 2>/dev/null)"
|
||||||
|
is "…and leaves the seed in place" '{ "plugin": "pinned" }' \
|
||||||
|
"$(cat "$SB/.config/nvim/lazy-lock.json")"
|
||||||
|
: > "$LOG"; out=$(box install 2>&1 | plain || true)
|
||||||
|
is "a second run starts no nvim" "0" "$(grep -c '^nvim ' "$LOG" || true)"
|
||||||
|
hasnt "…and prints no nvim section" "pinned to lazy-lock.json" "$out"
|
||||||
|
newbox; sh ./seal.sh "$SB/seal" --with nvim >/dev/null; BOXPATH=$SB/seal
|
||||||
|
printf '{ "plugin": "updated-by-user" }\n' > "$SB/lock.user"
|
||||||
|
seedlock; cp "$SB/lock.user" "$SB/.config/nvim/lazy-lock.json"
|
||||||
|
mkdir -p "$SB/.local/share/nvim/lazy/lazy.nvim"; pick core/ripgrep
|
||||||
|
box install >/dev/null 2>&1 || true
|
||||||
|
is "a lockfile lazy already manages is left alone" "$(cat "$SB/lock.user")" \
|
||||||
|
"$(cat "$SB/.config/nvim/lazy-lock.json")"
|
||||||
|
is "…and nvim is not started" "0" "$(grep -c '^nvim ' "$LOG" || true)"
|
||||||
|
newbox; sh ./seal.sh "$SB/seal" --with nvim >/dev/null; BOXPATH=$SB/seal; pick core/ripgrep
|
||||||
|
box install >/dev/null 2>&1 || true
|
||||||
|
is "with no nvim config there is nothing to pin" "0" "$(grep -c '^nvim ' "$LOG" || true)"
|
||||||
|
newbox; sh ./seal.sh "$SB/seal" --with nvim >/dev/null; BOXPATH=$SB/seal
|
||||||
|
seedlock; pick core/ripgrep; BOXENV='FAKE_FAIL=nvim:restore'
|
||||||
|
rc=0; box install >"$SB/out" 2>&1 || rc=$?; out=$(plain < "$SB/out")
|
||||||
|
has "a failed restore says how to retry" "nvim --headless '+Lazy! restore' +qa" "$out"
|
||||||
|
is "…without failing the install" "0" "$rc"
|
||||||
|
newbox; sh ./seal.sh "$SB/seal" --with nvim >/dev/null; BOXPATH=$SB/seal
|
||||||
|
seedlock; pick core/ripgrep; BOXENV='FAKE_FAIL=nvim:boot'
|
||||||
|
box install >/dev/null 2>&1 || true
|
||||||
|
is "a failed first boot still restores the seed" '{ "plugin": "pinned" }' \
|
||||||
|
"$(cat "$SB/.nvim-restored-from" 2>/dev/null)"
|
||||||
|
newbox
|
||||||
|
if holed nvim; then
|
||||||
|
seedlock; pick core/ripgrep
|
||||||
|
hasnt "with no nvim the step says nothing" "lazy-lock" "$(box install 2>&1 | plain || true)"
|
||||||
|
else
|
||||||
|
printf ' \033[33mskip\033[0m nvim sits at an absolute path find_tool probes\n'
|
||||||
|
fi
|
||||||
|
|
||||||
printf '\n\033[1mclaude desktop trusts only Anthropic'"'"'s key\033[0m\n'
|
printf '\n\033[1mclaude desktop trusts only Anthropic'"'"'s key\033[0m\n'
|
||||||
# A vendor apt repository is a key apt will trust for root-installed packages,
|
# A vendor apt repository is a key apt will trust for root-installed packages,
|
||||||
# so the key is checked against the published fingerprint before it is placed.
|
# so the key is checked against the published fingerprint before it is placed.
|
||||||
|
|||||||
@@ -1219,6 +1219,44 @@ herdr_integrations() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# nvim's first boot, done here so the lazy-lock.json pins survive it.
|
||||||
|
#
|
||||||
|
# The config seeds lazy-lock.json (a create_ file). On a first start lazy.nvim
|
||||||
|
# installs most plugins at their pins, but the ones that join in a later
|
||||||
|
# bootstrap round (claudecode, mini.*, nvim-lint, friendly-snippets, ...) are
|
||||||
|
# cloned at branch tip, and lazy then rewrites the lockfile with the tips. The
|
||||||
|
# pins are gone after the one boot meant to honor them. So the installer does
|
||||||
|
# that boot headless, puts the seeded lockfile back, and `Lazy! restore`s every
|
||||||
|
# plugin to it.
|
||||||
|
#
|
||||||
|
# The gate is "lazy has never installed a plugin here": no plugin directory.
|
||||||
|
# That is also what proves the lockfile on disk is the seed (or one written by
|
||||||
|
# hand), never one lazy rewrote. A lockfile moved on by `:Lazy update` sits
|
||||||
|
# beside a plugin directory and is left alone. The directory this step creates
|
||||||
|
# is its own stamp, so a second run does nothing.
|
||||||
|
nvim_first_boot() {
|
||||||
|
have nvim || return 0
|
||||||
|
nb_lock=${XDG_CONFIG_HOME:-$HOME/.config}/nvim/lazy-lock.json
|
||||||
|
nb_lazy=${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lazy
|
||||||
|
[ -f "$nb_lock" ] || return 0
|
||||||
|
[ ! -e "$nb_lazy" ] || return 0
|
||||||
|
NVIM=$(find_tool nvim)
|
||||||
|
workdir || return 0
|
||||||
|
nb_seed=$WORKDIR/lazy-lock.seed.json nb_log=$WORKDIR/nvim-first-boot.log
|
||||||
|
head_ "nvim plugins, pinned to lazy-lock.json"
|
||||||
|
run_sh "cp '$nb_lock' '$nb_seed'" || { warn "could not save the seeded lazy-lock.json"; return 0; }
|
||||||
|
if ! run_sh "'$NVIM' --headless +qa </dev/null >'$nb_log' 2>&1"; then
|
||||||
|
warn "nvim's first boot failed -- restoring the pins anyway"
|
||||||
|
[ -r "$nb_log" ] && tail -n 20 "$nb_log" >&2
|
||||||
|
fi
|
||||||
|
run_sh "cp '$nb_seed' '$nb_lock'" || { warn "could not put the seeded lazy-lock.json back"; return 0; }
|
||||||
|
run_sh "'$NVIM' --headless '+Lazy! restore' +qa </dev/null >'$nb_log' 2>&1" && return 0
|
||||||
|
warn "Lazy! restore failed -- plugins may not match lazy-lock.json. Retry with:"
|
||||||
|
warn " nvim --headless '+Lazy! restore' +qa"
|
||||||
|
[ -r "$nb_log" ] && tail -n 20 "$nb_log" >&2
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
cmd_install() {
|
cmd_install() {
|
||||||
# A cron job re-running `--unattended install` gets its SAVED selection --
|
# A cron job re-running `--unattended install` gets its SAVED selection --
|
||||||
# that contract stands. But on a box where nothing was ever chosen,
|
# that contract stands. But on a box where nothing was ever chosen,
|
||||||
@@ -1279,6 +1317,7 @@ cmd_install() {
|
|||||||
install_npm "$(col npm)"
|
install_npm "$(col npm)"
|
||||||
install_uv "$(col uv)"
|
install_uv "$(col uv)"
|
||||||
herdr_integrations
|
herdr_integrations
|
||||||
|
nvim_first_boot
|
||||||
|
|
||||||
rm -f "$tbl"
|
rm -f "$tbl"
|
||||||
if [ -s "$FAILED" ]; then
|
if [ -s "$FAILED" ]; then
|
||||||
|
|||||||
Reference in new issue
Block a user