Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agents/skills/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ New migration format:
- Use `$OMARCHY_PATH` to reference the Omarchy directory.
- Be idempotent. Check existing state before changing it.
- Migrations are strictly ordered and synchronous. A migration that cannot finish must exit non-zero, remain pending, and stop the queue; never mark later migrations complete against state an earlier migration has not established.
- The one exception is a deferral: a migration that changed nothing, cannot finish yet, and that no later migration depends on may exit `75` (EX_TEMPFAIL). `omarchy-migrate` then leaves it pending, keeps the login notification, runs the migrations after it and exits 0, so `omarchy update` carries on; the next update or login retries it. Any other non-zero status still stops the queue and fails the update.
- Use helper commands such as `omarchy-cmd-present`, `omarchy-cmd-missing`,
`omarchy-pkg-add`, `omarchy-pkg-drop`, `omarchy-pkg-present`, and
`omarchy-pkg-missing` when appropriate.
Expand Down
21 changes: 20 additions & 1 deletion bin/omarchy-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,36 @@ wait_for_pacman_transaction
mkdir -p "$STATE_DIR"
[[ -d $MIGRATIONS_DIR ]] || exit 0

# A migration that exits 75 (EX_TEMPFAIL) is deferred: it left nothing half
# done, stays pending with its login notification, and nothing later depends on
# it, so the rest of the migrations and of the update go ahead. Any other
# failure stops here, as before.
deferred=()

while IFS=$'\t' read -r name file marker <&3; do
[[ -n $name ]] || continue

if [[ ! -f $marker ]]; then
echo -e "\e[32m\nRunning migration (${name%.sh})\e[0m"
OMARCHY_PATH="$OMARCHY_PATH" bash -euo pipefail "$file" 3<&-
status=0
OMARCHY_PATH="$OMARCHY_PATH" bash -euo pipefail "$file" 3<&- || status=$?
if (( status == 75 )); then
deferred+=("${name%.sh}")
echo -e "\e[33mMigration ${name%.sh} deferred; it stays pending and runs again with the next update or omarchy-migrate\e[0m"
continue
elif (( status != 0 )); then
exit "$status"
fi
mkdir -p "$(dirname "$marker")"
touch "$marker"
fi
done 3< <(migration_entries)

if (( ${#deferred[@]} > 0 )); then
echo -e "\e[33m\nDeferred migrations still pending: ${deferred[*]}\e[0m"
exit 0
fi

# Clear a login-time notification the user left sitting there and then resolved
# by running migrations some other way. The substring matches both the current
# and legacy notification titles.
Expand Down
4 changes: 3 additions & 1 deletion docs/file-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ was already applying in the visible update terminal.

`omarchy-migrate` waits for any active pacman transaction to finish, then runs
pending migrations. It does not need `--force`; migrations happen when state
files are missing. `omarchy update` runs `omarchy-migrate` after the package
files are missing. A migration that exits 75 is deferred: it stays pending with
its login notification while the later migrations and the rest of the update
run; any other failure stops the queue. `omarchy update` runs `omarchy-migrate` after the package
transaction in the already-visible update terminal, then runs
`omarchy-hook post-update`.

Expand Down
3 changes: 2 additions & 1 deletion docs/lifecycle-dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The set is fixed in the dispatcher; adding one is an upstream change. The `provi
| `update-verify` | Update, after the last package step: the transaction, migrations, the post-update hook, AUR, mise and orphans | Read-only. Verifies the boot chain boots the updated system, whose new kernel may still wait for its reboot. A failure leaves the update unfinished: it exits non-zero and offers no reboot. | required | `omarchy-update-boot verify` (`omarchy update`) |
| `boot-rebuild` | Owner provisioning, when a factory reset left boot entries for another machine identity | Rebuilds the platform's boot files, after upstream has started the Limine menu over where there is one | optional | `omarchy-provision-owner` |
| `luks-slots` | Owner provisioning, once the re-key keeps only the owner's slot and the acknowledged recovery slot, before it destroys the staged key; the disk password change, once the owner's new key is confirmed; the password reset with the recovery key, once the owner's new password and the recovery key are the disk's only keys and the accounts follow | `luks-slots owner=<slot> [recovery=<slot>]` records the root volume's kept slots wherever the platform's boot checks look for them. Without `recovery=` the recorded recovery slot stays; an empty one records none. Idempotent. It fails when a slot is not in the LUKS header, and the caller then retries. A platform that implements it also has owner provisioning create a recovery passphrase (see [Recovery passphrase](#recovery-passphrase)). | required | `omarchy-provision-owner`, `omarchy-drive-password`, `omarchy-drive-recover` |
| `migrate` | The platform migration (`migrations/1790347292.sh`), on every update until it has run | Moves the machine onto the platform's official package set in place, or does nothing when the platform has no target set yet. Idempotent and resumable: a machine already on the target, or one whose migration waits for a reboot, exits 0. A refusal or failure exits non-zero and leaves the migration pending. | optional | the migration; ticket 42 |
| `migrate` | The platform migration (`migrations/1790347292.sh`), on every update until it has run | Moves the machine onto the platform's official package set in place, or does nothing when the platform has no target set yet. Idempotent and resumable: a machine already on the target, or one whose migration waits for a reboot, exits 0. A refusal that changed nothing exits 75, which leaves the migration pending without stopping later migrations or the update; a failure exits with any other non-zero status and stops them. | optional | the migration; ticket 42 |

## Platform registration

Expand Down Expand Up @@ -164,5 +164,6 @@ Snapdragon laptops boot Limine with unified kernel images, like x86, and `qualco
- `test/shell.d/provision-owner-luks-test.sh` runs owner provisioning through the dispatcher into `omarchy-mac-boot`'s staged entrypoints, and `packages/omarchy-mac/boot/test/mac-provision-test.sh` covers those entrypoints on their own (ticket 32) and `luks-slots` (ticket 33).
- `test/shell.d/factory-reset-luks-test.sh` runs `stage_full_reset` through the real dispatcher: on x86 with Mac entrypoints on disk that must not run (generic path unchanged), and on Apple into `omarchy-mac-boot`'s staged reset entrypoints, covering a finished reset, with the Mac's first boot re-armed and `@factory` scrubbed, and a failed verification that rolls back to the previous root. `test/shell.d/factory-reset-dispatch-test.sh` and `factory-reset-accounts-test.sh` are upstream's. `packages/omarchy-mac/boot/test/mac-reset-test.sh` covers the reset entrypoints on their own (tickets 34 and 81).
- `test/shell.d/luks-rekey-journal-test.sh` also runs the Apple setup attempt, recovery step included, killed after every durable step on the slot-table fake and on file-backed LUKS2 and LUKS1 volumes (ticket 33).
- `test/shell.d/migrate-deferred-test.sh` covers the runner: a deferred migration stays pending with its notification while later ones run, is retried on every run, and any other failure still stops the queue.
- `test/shell.d/drive-password-test.sh` checks that an Apple password change records the owner's new slot through `luks-slots`, including after an interruption, and that x86 never calls it.
- `test/shell.d/drive-recover-test.sh` runs the password reset with the recovery key from a boot's cached unlock, killed after every step and rerun on the slot-table fake and on file-backed LUKS2 and LUKS1 volumes, on x86 and on Apple (where it records both slots through `luks-slots`), and the mac-image harness's `recovery-reset` case runs it on an image with a power loss part way (ticket 70).
78 changes: 78 additions & 0 deletions test/shell.d/migrate-deferred-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

set -euo pipefail

source "$(dirname "$0")/base-test.sh"

test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT

test_root="$test_tmp/omarchy"
test_home="$test_tmp/home"
stub_bin="$test_tmp/bin"
state="$test_home/.local/state/omarchy/migrations"
mkdir -p "$test_root/migrations" "$test_home" "$stub_bin"

cat >"$stub_bin/omarchy-notification-dismiss" <<'SH'
#!/bin/bash
printf '%s\n' "$1" >>"$TEST_DISMISSALS"
SH
chmod +x "$stub_bin/omarchy-notification-dismiss"

# Each migration records its run and exits with the status its fixture file holds.
for name in 100 200 300; do
cat >"$test_root/migrations/$name.sh" <<SH
echo $name >>"\$TEST_CALLS"
exit "\$(cat "\$TEST_STATUS/$name")"
SH
done
mkdir -p "$test_tmp/status"

run_migrate() {
: >"$test_tmp/calls"
: >"$test_tmp/dismissals"
HOME="$test_home" \
OMARCHY_PATH="$test_root" \
PATH="$stub_bin:$ROOT/bin:$PATH" \
TEST_CALLS="$test_tmp/calls" \
TEST_STATUS="$test_tmp/status" \
TEST_DISMISSALS="$test_tmp/dismissals" \
"$ROOT/bin/omarchy-migrate" "$@"
}

set_status() {
echo "$2" >"$test_tmp/status/$1"
}

set_status 100 75
set_status 200 0
set_status 300 0
run_migrate >"$test_tmp/out" || fail "a deferred migration does not fail omarchy-migrate" "$(cat "$test_tmp/out")"
[[ $(cat "$test_tmp/calls") == $'100\n200\n300' ]] || fail "later migrations run after a deferred one" "$(cat "$test_tmp/calls")"
[[ ! -e $state/100.sh && -e $state/200.sh && -e $state/300.sh ]] || fail "only the deferred migration stays pending"
[[ $(run_migrate --pending) == "100.sh" ]] || fail "omarchy-migrate --pending lists the deferred migration"
[[ ! -s $test_tmp/dismissals ]] || fail "a deferred migration keeps the pending-migrations notification"
grep -q 'Deferred migrations still pending: 100' "$test_tmp/out" || fail "omarchy-migrate names the deferred migration" "$(cat "$test_tmp/out")"
pass "a migration exiting 75 stays pending with its notification while later migrations run"

run_migrate >"$test_tmp/out" || fail "a still-deferred migration does not fail omarchy-migrate"
[[ $(cat "$test_tmp/calls") == "100" ]] || fail "a rerun retries only the deferred migration" "$(cat "$test_tmp/calls")"
set_status 100 0
run_migrate >"$test_tmp/out" || fail "a deferred migration completes on a later run"
[[ -e $state/100.sh ]] || fail "a deferred migration is marked done once it succeeds"
grep -Fx 'Omarchy Migrations' "$test_tmp/dismissals" >/dev/null || fail "the notification clears once nothing is deferred"
pass "a deferred migration is retried on every run and marked done once it succeeds"

rm -rf "$state"
set_status 100 75
set_status 200 3
if run_migrate >"$test_tmp/out" 2>&1; then
fail "a failing migration still fails omarchy-migrate after a deferred one"
else
status=$?
fi
(( status == 3 )) || fail "omarchy-migrate exits with the failing migration's status" "status $status"
[[ $(cat "$test_tmp/calls") == $'100\n200' ]] || fail "a failing migration stops the queue" "$(cat "$test_tmp/calls")"
[[ ! -e $state/100.sh && ! -e $state/200.sh && ! -e $state/300.sh ]] || fail "nothing is marked done past a failure"
[[ ! -s $test_tmp/dismissals ]] || fail "a failure keeps the notification"
pass "any status other than 0 and 75 still stops the queue with that status"
6 changes: 5 additions & 1 deletion test/shell.d/platform-migration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ run_migration >/dev/null || fail "an entrypoint: the migration completes"
[[ $(cat "$tmp/ran") == $'sudo omarchy-lifecycle-dispatch migrate\ndispatch migrate' ]] || fail "an entrypoint: dispatched as root" "$(cat "$tmp/ran")"
echo 2 >"$tmp/status"
if run_migration >/dev/null 2>&1; then fail "a refused platform migration leaves the migration pending"; fi
echo 75 >"$tmp/status"
status=0
run_migration >/dev/null 2>&1 || status=$?
[[ $status == 75 ]] || fail "a deferred platform migration exits 75 for omarchy-migrate" "status $status"
echo 0 >"$tmp/status"
pass "a platform migration runs through the dispatcher as root, and its refusal keeps the migration pending"
pass "a platform migration runs through the dispatcher as root, and its refusal or deferral keeps the migration pending"

: >"$tmp/undetermined"
if run_migration >/dev/null 2>&1; then fail "an undetermined platform leaves the migration pending"; fi
Expand Down
Loading