From a223473fc2d75e4d959e4ac674320985c1e96a66 Mon Sep 17 00:00:00 2001 From: rain Date: Wed, 19 Aug 2026 08:16:41 -0400 Subject: [PATCH] Scope update-neovim.sh to debian: arch gets neovim from pacman; guard no-ops elsewhere --- dot_config/topgrade/topgrade.toml | 5 ++ dot_local/bin/update-neovim.sh | 68 +++++++++++++++++++++++ run_once_20-install-user-packages.sh.tmpl | 50 ++++++++++++++++- 3 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 dot_local/bin/update-neovim.sh diff --git a/dot_config/topgrade/topgrade.toml b/dot_config/topgrade/topgrade.toml index 9e88ba1..11419a8 100644 --- a/dot_config/topgrade/topgrade.toml +++ b/dot_config/topgrade/topgrade.toml @@ -31,3 +31,8 @@ repos = [ "~/Documents/Git/*" ] +[commands] +# Debian-only (script no-ops elsewhere): apt neovim is stale, so debian +# machines install from the pinned binary tarball. Arch uses pacman. +"~/.local/bin/update-neovim.sh" = "neovim" + diff --git a/dot_local/bin/update-neovim.sh b/dot_local/bin/update-neovim.sh new file mode 100644 index 0000000..a605111 --- /dev/null +++ b/dot_local/bin/update-neovim.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# ============================================================================= +# update-neovim.sh — chezmoi-managed, deployed to ~/.local/bin/update-neovim.sh +# +# Installs or upgrades neovim from the official binary tarball. +# Bump NVIM_TARGET_VERSION to upgrade. Topgrade calls this via +# ~/.config/topgrade/topgrade.toml. +# +# Debian-only: arch gets neovim from pacman (see PACMAN_PKGS in +# run_once_20-install-user-packages.sh.tmpl), so this is a no-op +# on non-debian machines. +# +# Idempotent: no-op if installed version matches target. +# ============================================================================= +set -euo pipefail + +OS_ID="$(. /etc/os-release 2>/dev/null && echo "$ID" || true)" +if [[ "$OS_ID" != "debian" ]]; then + echo "neovim: not debian ($OS_ID) — no action" + exit 0 +fi + +NVIM_TARGET_VERSION="v0.11.4" + +ARCH="$(uname -m)" +case "$ARCH" in + x86_64) + NVIM_TARBALL="nvim-linux64.tar.gz" + NVIM_EXTRACT_DIR="nvim-linux64" + ;; + aarch64|arm64) + NVIM_TARBALL="nvim-linux-arm64.tar.gz" + NVIM_EXTRACT_DIR="nvim-linux-arm64" + ;; + *) + echo "unsupported arch: $ARCH" >&2 + exit 1 + ;; +esac + +if command -v nvim >/dev/null 2>&1; then + INSTALLED_VER="$(nvim --version 2>/dev/null | head -1 | awk '{print $2}')" + if [[ "$INSTALLED_VER" == "$NVIM_TARGET_VERSION" ]]; then + echo "neovim $INSTALLED_VER matches target — no action" + exit 0 + fi + echo "neovim $INSTALLED_VER -> $NVIM_TARGET_VERSION" +else + echo "installing neovim $NVIM_TARGET_VERSION" +fi + +cd /tmp +TMP_TARBALL="$(mktemp /tmp/nvim-update.XXXXXX.tar.gz)" +trap 'rm -f "$TMP_TARBALL"' EXIT + +if ! curl -fL --retry 3 \ + "https://github.com/neovim/neovim/releases/download/${NVIM_TARGET_VERSION}/${NVIM_TARBALL}" \ + -o "$TMP_TARBALL"; then + echo "failed to download $NVIM_TARBALL" >&2 + exit 1 +fi + +sudo rm -rf /opt/nvim-linux* /usr/local/bin/nvim +sudo tar -xzf "$TMP_TARBALL" -C /opt/ +sudo ln -sf "/opt/${NVIM_EXTRACT_DIR}/bin/nvim" /usr/local/bin/nvim + +echo "neovim $NVIM_TARGET_VERSION installed" +nvim --version | head -1 \ No newline at end of file diff --git a/run_once_20-install-user-packages.sh.tmpl b/run_once_20-install-user-packages.sh.tmpl index b665d42..6da568f 100755 --- a/run_once_20-install-user-packages.sh.tmpl +++ b/run_once_20-install-user-packages.sh.tmpl @@ -200,8 +200,54 @@ if command -v bun >/dev/null 2>&1; then fi fi -# Neovim comes from the system package (pacman list above); topgrade keeps -# it current. No manual tarball install. +# Neovim — debian apt ships a stale version, so install the official +# binary tarball, pinned to a known-good version. Bump +# NVIM_TARGET_VERSION here and in ~/.local/bin/update-neovim.sh to +# upgrade (topgrade runs the script on debian machines). +NVIM_TARGET_VERSION="v0.11.4" +ARCH="$(uname -m)" +case "$ARCH" in + x86_64) + NVIM_TARBALL="nvim-linux64.tar.gz" + NVIM_EXTRACT_DIR="nvim-linux64" + ;; + aarch64|arm64) + NVIM_TARBALL="nvim-linux-arm64.tar.gz" + NVIM_EXTRACT_DIR="nvim-linux-arm64" + ;; + *) + die "unsupported arch for neovim tarball: $ARCH" + ;; +esac + +if command -v nvim >/dev/null 2>&1; then + INSTALLED_VER="$(nvim --version 2>/dev/null | head -1 | awk '{print $2}')" + if [[ "$INSTALLED_VER" == "$NVIM_TARGET_VERSION" ]]; then + log "neovim $INSTALLED_VER matches target — skipping" + NVIM_TARBALL="" + else + log "neovim $INSTALLED_VER != target $NVIM_TARGET_VERSION — upgrading" + fi +fi + +if [[ -n "$NVIM_TARBALL" ]]; then + log "downloading neovim $NVIM_TARGET_VERSION ($NVIM_TARBALL)" + cd /tmp + if ! curl -fL --retry 3 \ + "https://github.com/neovim/neovim/releases/download/${NVIM_TARGET_VERSION}/${NVIM_TARBALL}" \ + -o nvim.tar.gz; then + die "failed to download neovim tarball" + fi + sudo rm -rf /opt/nvim-linux* /usr/local/bin/nvim + sudo tar -xzf nvim.tar.gz -C /opt/ + sudo ln -sf "/opt/${NVIM_EXTRACT_DIR}/bin/nvim" /usr/local/bin/nvim + rm -f nvim.tar.gz +fi + +# Verify neovim is reachable (PATH may need /usr/local/bin explicitly for this run) +if ! command -v nvim >/dev/null 2>&1 && [[ -x /usr/local/bin/nvim ]]; then + export PATH="/usr/local/bin:$PATH" +fi {{ else -}} die "unsupported os_family: {{ .os_family }}"