feat(lifecycle): auto-commit sweep of the machine flake before pull/rebuild/home
Some checks failed
Check / eval (push) Failing after 3m11s

With settings.autoCommit on, only menu/theme mutations were committed
(theme-sync pathspec-limits to theme-state.json by design), so hand
edits to system.nix/home.nix and lock bumps stayed forever-dirty.

New internal nomarchy-autocommit (nomarchy-lifecycle): live-reads the
same flag, commits everything dirty as "nomarchy: auto-commit before
<pull|rebuild|home switch>" with the swept file list in the body,
fallback identity, never fatal (|| true at call sites). Called at the
top of all three lifecycle commands; before the ff-only pull it also
un-dirties the tree. Exposed via passthru.autocommit + package export;
guarded by checks.lifecycle-autocommit (sandbox repos: sweep, no-op on
clean/off/non-repo). Sync sweep: README, RECOVERY, ROADMAP, rofi
toggle, control-center prompt, theme-sync docstring, JOURNAL.

Verified: V1+ — flake check --no-build green; the new check builds;
end-to-end run of the built nomarchy-rebuild (stubbed sudo/rebuild)
against a copy of a real dirty ~/.nomarchy: 4 files → one commit,
clean tree. No VM boot — no session-visible surface.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-12 12:52:05 +01:00
parent cc9caf802e
commit 9e37e11915
9 changed files with 146 additions and 7 deletions

View File

@@ -15,6 +15,41 @@ let
flake="''${NOMARCHY_PATH:-$HOME/.nomarchy}"
'';
# Opt-in sweep (settings.autoCommit — the same flag theme-sync honours):
# commit EVERYTHING dirty in the machine flake before a pull/rebuild/
# home switch, so hand edits to system.nix/home.nix and lock bumps land
# in history at the moment they become live — `git log` mirrors the
# generation list. Complements nomarchy-theme-sync's auto_commit, which
# is pathspec-limited to theme-state.json on menu writes precisely so
# half-finished hand edits never ride a settings-named commit; here the
# sweep is the point, and the commit body lists what was swept. Never
# fatal — callers `|| true` so a git hiccup can't block a rebuild. Not
# in the symlinkJoin paths (internal; callers use the store path) but
# exposed as passthru.autocommit for checks.lifecycle-autocommit.
nomarchy-autocommit = writeShellScriptBin "nomarchy-autocommit" ''
${preamble "nomarchy-autocommit"}
label="''${1:-rebuild}"
[ -d "$flake/.git" ] || exit 0
command -v git >/dev/null 2>&1 || exit 0
flag=$(${jq}/bin/jq -r '.settings.autoCommit // false' \
"$flake/theme-state.json" 2>/dev/null || true)
[ "$flag" = "true" ] || exit 0
dirty=$(git -C "$flake" status --porcelain || true)
[ -n "$dirty" ] || exit 0
g=(git -C "$flake")
if [ -z "$("''${g[@]}" config user.email 2>/dev/null || true)" ]; then
g+=(-c user.name=Nomarchy -c user.email=nomarchy@localhost)
fi
"''${g[@]}" add -A
if "''${g[@]}" commit --quiet -m "nomarchy: auto-commit before $label" \
-m "$dirty"; then
echo "nomarchy-autocommit: committed pending flake changes before $label:"
echo "$dirty" | sed 's/^/ /'
else
echo "nomarchy-autocommit: commit failed continuing without it" >&2
fi
'';
nomarchy-pull = writeShellScriptBin "nomarchy-pull" ''
${preamble "nomarchy-pull"}
if [ ! -e "$flake/flake.nix" ]; then
@@ -22,6 +57,9 @@ let
echo " Set NOMARCHY_PATH or put your machine flake in ~/.nomarchy." >&2
exit 1
fi
# With settings.autoCommit on, sweep pending hand edits into a commit
# first also keeps the ff-only pull below safe on a dirty tree.
${nomarchy-autocommit}/bin/nomarchy-autocommit pull || true
# Optional: pull *your* machine config only if this checkout tracks a
# remote. Distro updates come from the nomarchy flake *input* below
# many installs have no upstream on ~/.nomarchy (local auto-commits).
@@ -52,6 +90,9 @@ let
echo "nomarchy-rebuild: no flake.nix at $flake" >&2
exit 1
fi
# With settings.autoCommit on, sweep pending hand edits (system.nix,
# lock bumps, ) into a commit so `git log` mirrors the generations.
${nomarchy-autocommit}/bin/nomarchy-autocommit rebuild || true
before=$(readlink -f /run/current-system)
log=$(mktemp)
trap 'rm -f "$log"' EXIT
@@ -94,6 +135,9 @@ let
echo "nomarchy-home: no flake.nix at $flake" >&2
exit 1
fi
# With settings.autoCommit on, sweep pending hand edits (home.nix, )
# into a commit so `git log` mirrors the generations.
${nomarchy-autocommit}/bin/nomarchy-autocommit "home switch" || true
# Snapshot the active HM generation before the switch so we can nvd it.
hm_before=""
for d in \
@@ -164,6 +208,7 @@ symlinkJoin {
home-update
nomarchy-what-changed
];
passthru.autocommit = nomarchy-autocommit;
meta = {
description = "Nomarchy machine-flake lifecycle: pull, rebuild, home";
mainProgram = "nomarchy-pull";