feat(cli): nomarchy-pull / nomarchy-rebuild / nomarchy-home
Some checks failed
Check / eval (push) Has been cancelled

Split lifecycle into three clear commands (user pick):
  nomarchy-pull     git pull (if checkout) + flake.lock update
  nomarchy-rebuild  system switch on current lock (snap + nvd)
  nomarchy-home     Home Manager switch

Full upgrade: pull && rebuild && home. Legacy sys-update / sys-rebuild /
home-update remain as wrappers. nixos-rebuild-snap uses NOMARCHY_PATH.

V0: flake check --no-build green.
This commit is contained in:
2026-07-10 13:32:50 +01:00
parent 910f357f08
commit 3d5cb21302
9 changed files with 127 additions and 101 deletions

View File

@@ -54,9 +54,9 @@ in
${distroName} a NixOS desktop, themed from one JSON.
sys-update update inputs + rebuild the system
sys-rebuild rebuild the system, no input update
home-update apply home/theme changes (no sudo)
nomarchy-pull git pull + flake input update (no rebuild)
nomarchy-rebuild rebuild the system (current lock)
nomarchy-home rebuild the desktop / Home Manager
nomarchy-theme-sync apply <theme> switch the whole palette
nomarchy-doctor read-only health check
SUPER+? keybindings cheatsheet
@@ -333,25 +333,63 @@ in
nomarchy-control-center # TUI control center
nomarchy-detect-hw # post-install hardware re-probe (HARDWARE.md §8)
# Friendly wrappers for the two rebuild paths (README §3). Run as
# your user: `nix flake update` must NOT run as root (libgit2
# refuses the user-owned flake repo) — sudo happens inside, only
# for the system switch.
(pkgs.writeShellScriptBin "sys-update" ''
# Day-to-day lifecycle (README §3). Always run as your user —
# `nix flake update` / git must not run as root (libgit2 refuses a
# user-owned flake); sudo is only for the system switch.
#
# nomarchy-pull git pull (if checkout) + flake.lock update
# nomarchy-rebuild system switch against the *current* lock
# nomarchy-home Home Manager switch (desktop layer)
#
# Full distro upgrade: nomarchy-pull && nomarchy-rebuild && nomarchy-home
# Config-only system: nomarchy-rebuild
# Theme/desktop only: nomarchy-home
#
# Legacy names (sys-update / sys-rebuild / home-update) stay as
# thin wrappers so old docs and muscle memory keep working.
(pkgs.writeShellScriptBin "nomarchy-pull" ''
set -euo pipefail
if [ "$(id -u)" -eq 0 ]; then
echo "sys-update: run as your normal user (it sudos the rebuild itself)" >&2
echo "nomarchy-pull: run as your normal user" >&2
exit 1
fi
flake="''${NOMARCHY_PATH:-$HOME/.nomarchy}"
echo "sys-update: updating flake inputs in $flake"
if [ ! -d "$flake" ]; then
echo "nomarchy-pull: flake path not found: $flake" >&2
echo " Set NOMARCHY_PATH or clone/symlink your flake to ~/.nomarchy." >&2
exit 1
fi
# 1) Your checkout (system.nix / home.nix / local edits).
if [ -d "$flake/.git" ]; then
echo "nomarchy-pull: git pull --ff-only in $flake"
git -C "$flake" pull --ff-only
else
echo "nomarchy-pull: $flake is not a git checkout skipping git pull"
fi
# 2) Flake inputs (nixpkgs, nomarchy, home-manager, ).
echo "nomarchy-pull: nix flake update in $flake"
nix flake update --flake "$flake"
echo "nomarchy-pull: done next: nomarchy-rebuild then nomarchy-home"
'')
(pkgs.writeShellScriptBin "nomarchy-rebuild" ''
set -euo pipefail
if [ "$(id -u)" -eq 0 ]; then
echo "nomarchy-rebuild: run as your normal user (it sudos the rebuild itself)" >&2
exit 1
fi
flake="''${NOMARCHY_PATH:-$HOME/.nomarchy}"
if [ ! -d "$flake" ]; then
echo "nomarchy-rebuild: flake path not found: $flake" >&2
exit 1
fi
before=$(readlink -f /run/current-system)
log=$(mktemp)
trap 'rm -f "$log"' EXIT
set +e
# Snapshot-first when snapper is on; pass flake path through sudo
# (nixos-rebuild-snap used to hardcode /etc/nixos).
if command -v nixos-rebuild-snap >/dev/null 2>&1; then
sudo nixos-rebuild-snap "$@" 2>&1 | tee "$log"
sudo env NOMARCHY_PATH="$flake" nixos-rebuild-snap "$@" 2>&1 | tee "$log"
else
sudo nixos-rebuild switch --flake "$flake#default" "$@" 2>&1 | tee "$log"
fi
@@ -359,71 +397,32 @@ in
set -e
if [ "$rc" -ne 0 ]; then
echo
echo "sys-update: rebuild FAILED (exit $rc). Last lines:"
echo "nomarchy-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 +
# rock-stable"); never fails the run.
after=$(readlink -f /run/current-system)
if [ "$before" = "$after" ]; then
echo "sys-update: no changes the system is identical."
echo "nomarchy-rebuild: no changes the system is identical."
else
echo "sys-update: what changed:"
echo "nomarchy-rebuild: what changed:"
${pkgs.nvd}/bin/nvd diff "$before" "$after" || true
fi
'')
# The no-update twin (hardware-QA request): rebuild the system
# against the CURRENT lock — config changes only, no `nix flake
# update` — mirroring how home-update never touches the lock.
# Same snapshot-first path when available.
(pkgs.writeShellScriptBin "sys-rebuild" ''
(pkgs.writeShellScriptBin "nomarchy-home" ''
set -euo pipefail
if [ "$(id -u)" -eq 0 ]; then
echo "sys-rebuild: run as your normal user (it sudos the rebuild itself)" >&2
echo "nomarchy-home: run as your normal user" >&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 "$@" 2>&1 | tee "$log"
else
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)
if [ "$before" = "$after" ]; then
echo "sys-rebuild: no changes the system is identical."
else
echo "sys-rebuild: what changed:"
${pkgs.nvd}/bin/nvd diff "$before" "$after" || true
fi
'')
(pkgs.writeShellScriptBin "home-update" ''
set -euo pipefail
if [ "$(id -u)" -eq 0 ]; then
echo "home-update: run as your normal user" >&2
if [ ! -d "$flake" ]; then
echo "nomarchy-home: flake path not found: $flake" >&2
exit 1
fi
flake="''${NOMARCHY_PATH:-$HOME/.nomarchy}"
log=$(mktemp)
trap 'rm -f "$log"' EXIT
set +e
@@ -432,13 +431,25 @@ in
set -e
if [ "$rc" -ne 0 ]; then
echo
echo "home-update: switch FAILED (exit $rc). Last lines:"
echo "nomarchy-home: 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
echo "nomarchy-home: desktop applied."
'')
# Legacy aliases — same behaviour, old names.
(pkgs.writeShellScriptBin "sys-update" ''
# Was: flake update + system rebuild. Now the two explicit steps.
nomarchy-pull && nomarchy-rebuild "$@"
'')
(pkgs.writeShellScriptBin "sys-rebuild" ''
exec nomarchy-rebuild "$@"
'')
(pkgs.writeShellScriptBin "home-update" ''
exec nomarchy-home "$@"
'')
git
@@ -461,12 +472,15 @@ in
echo "This script must be run as root (use sudo)" >&2
exit 1
fi
# Prefer the path nomarchy-rebuild passes through sudo; fall back
# for hand invocations.
flake="''${NOMARCHY_PATH:-/etc/nixos}"
echo "Creating pre-rebuild snapshot..."
${pkgs.snapper}/bin/snapper -c root create \
-d "Pre-rebuild $(date +'%Y-%m-%d %H:%M:%S')" \
--cleanup-algorithm number
echo "Rebuilding..."
nixos-rebuild switch --flake /etc/nixos#default "$@"
echo "Rebuilding $flake#default ..."
nixos-rebuild switch --flake "$flake#default" "$@"
'')
# The desktop snapshot manager (browse / diff / restore / rollback over
# snapper, elevating via polkit) — the primary `nomarchy-menu snapshot`