feat(rebuild): #56 human rebuild errors point at doctor
Some checks failed
Check / eval (push) Has been cancelled

sys-update / sys-rebuild / home-update tee output and on failure print
the last 40 log lines plus nomarchy-doctor + RECOVERY.md. theme-sync HM
switch failure notify/die text matches. Close #56.

Verified: V1 (HM rebuild; failure-footer shell smoke).
This commit is contained in:
Bernardo Magri
2026-07-10 08:45:33 +01:00
parent e81529c1bb
commit a102dff508
4 changed files with 81 additions and 25 deletions

View File

@@ -329,7 +329,7 @@ in
# refuses the user-owned flake repo) — sudo happens inside, only
# for the system switch.
(pkgs.writeShellScriptBin "sys-update" ''
set -e
set -euo pipefail
if [ "$(id -u)" -eq 0 ]; then
echo "sys-update: run as your normal user (it sudos the rebuild itself)" >&2
exit 1
@@ -338,10 +338,24 @@ in
echo "sys-update: updating flake inputs in $flake"
nix flake update --flake "$flake"
before=$(readlink -f /run/current-system)
log=$(mktemp)
trap 'rm -f "$log"' EXIT
set +e
if command -v nixos-rebuild-snap >/dev/null 2>&1; then
sudo nixos-rebuild-snap "$@" # BTRFS snapshot first
sudo nixos-rebuild-snap "$@" 2>&1 | tee "$log"
else
sudo nixos-rebuild switch --flake "$flake#default" "$@"
sudo nixos-rebuild switch --flake "$flake#default" "$@" 2>&1 | tee "$log"
fi
rc=''${PIPESTATUS[0]}
set -e
if [ "$rc" -ne 0 ]; then
echo
echo "sys-update: rebuild FAILED (exit $rc). Last lines:"
tail -n 40 "$log" || true
echo
echo "Diagnose: nomarchy-doctor"
echo "Recovery: docs/RECOVERY.md (boot menu generations / snapper)"
exit "$rc"
fi
# What did that update actually change? Package-level diff of the
# old vs new generation (the informative half of "informative +
@@ -359,17 +373,31 @@ in
# update` — mirroring how home-update never touches the lock.
# Same snapshot-first path when available.
(pkgs.writeShellScriptBin "sys-rebuild" ''
set -e
set -euo pipefail
if [ "$(id -u)" -eq 0 ]; then
echo "sys-rebuild: run as your normal user (it sudos the rebuild itself)" >&2
exit 1
fi
flake="''${NOMARCHY_PATH:-$HOME/.nomarchy}"
before=$(readlink -f /run/current-system)
log=$(mktemp)
trap 'rm -f "$log"' EXIT
set +e
if command -v nixos-rebuild-snap >/dev/null 2>&1; then
sudo nixos-rebuild-snap "$@" # BTRFS snapshot first
sudo nixos-rebuild-snap "$@" 2>&1 | tee "$log"
else
sudo nixos-rebuild switch --flake "$flake#default" "$@"
sudo nixos-rebuild switch --flake "$flake#default" "$@" 2>&1 | tee "$log"
fi
rc=''${PIPESTATUS[0]}
set -e
if [ "$rc" -ne 0 ]; then
echo
echo "sys-rebuild: rebuild FAILED (exit $rc). Last lines:"
tail -n 40 "$log" || true
echo
echo "Diagnose: nomarchy-doctor"
echo "Recovery: docs/RECOVERY.md (boot menu generations / snapper)"
exit "$rc"
fi
# Same what-changed diff as sys-update (the twins stay twins).
after=$(readlink -f /run/current-system)
@@ -381,8 +409,27 @@ in
fi
'')
(pkgs.writeShellScriptBin "home-update" ''
set -euo pipefail
if [ "$(id -u)" -eq 0 ]; then
echo "home-update: run as your normal user" >&2
exit 1
fi
flake="''${NOMARCHY_PATH:-$HOME/.nomarchy}"
log=$(mktemp)
trap 'rm -f "$log"' EXIT
set +e
home-manager switch --flake "$flake" "$@" 2>&1 | tee "$log"
rc=''${PIPESTATUS[0]}
set -e
exec home-manager switch --flake "''${NOMARCHY_PATH:-$HOME/.nomarchy}" "$@"
if [ "$rc" -ne 0 ]; then
echo
echo "home-update: switch FAILED (exit $rc). Last lines:"
tail -n 40 "$log" || true
echo
echo "Diagnose: nomarchy-doctor"
echo "Recovery: home-manager generations (or docs/RECOVERY.md)"
exit "$rc"
fi
'')
git