Skip to content

Re-apply hardware pacman repos after a refresh restore - #9878

Open
hudsonwa wants to merge 2 commits into
omacom:quattrofrom
hudsonwa:fix/9853-pacman-hardware-repos
Open

hudsonwa wants to merge 2 commits into
omacom:quattrofrom
hudsonwa:fix/9853-pacman-hardware-repos

Conversation

@hudsonwa

@hudsonwa hudsonwa commented Sep 2, 2026

Copy link
Copy Markdown

Fixes #9853

What broke

omarchy refresh pacman overwrites /etc/pacman.conf with the channel template and never re-applies hardware-specific repository additions. On Apple T2 Macs that silently drops the [arch-mact2] stanza, so linux-t2 (the running kernel), t2fanrd, apple-t2-audio-config and apple-bcm-firmware lose their update source with no visible symptom.

The install path does this correctly: install/post-install/pacman.sh sources install/hardware/pacman.sh, which appends the T2 stanza and is idempotent (it guards on grep -q '^\[arch-mact2\]'). That same file states the intent in its own comment: the extension "must survive the final pacman.conf restore". The refresh path never copies it.

Fix

After the template restore, source $OMARCHY_PATH/install/hardware/pacman.sh the same way the install path does:

if [[ -f $OMARCHY_PATH/install/hardware/pacman.sh ]]; then
  sudo bash -c "source '$OMARCHY_PATH/install/hardware/pacman.sh'"
fi

Notes on why this shape:

  • The issue's suggested source "$OMARCHY_INSTALL/hardware/pacman.sh" cannot work in bin/omarchy-refresh-pacman: $OMARCHY_INSTALL is not defined at runtime (only omarchy-apply-hardware/omarchy-apply-system set it). At runtime the tree lives at $OMARCHY_PATH/install/ (docs/file-layout.md maps install/** to /usr/share/omarchy/install/).
  • The file appends to /etc/pacman.conf, so it must run as root; the copy steps just above already use sudo, so the script runs as the user and elevates.
  • Placed before the pre-refresh-pacman user hook, matching the issue's ordering, so user hooks see the final repo set.
  • The [[ -f ]] guard keeps the refresh a no-op on anything where the install tree is absent, and if install/hardware/pacman.sh is ever removed the refresh simply skips it.

Security context

install/hardware/pacman.sh is also in the sights of open security PRs #8709 (arms verification on the T2 stanza) and #9461 (draft: remove the unsigned source). This PR deliberately does not take a side: it sources whatever the packaged file contains at runtime, so if #8709 lands the refresh re-applies the armed stanza, and if a removal lands the -f guard no-ops. Only the "refresh drops hardware repos" bug is fixed here.

Tests

New test/shell.d/refresh-pacman-test.sh runs the command against a sandboxed /etc/pacman.conf (absolute paths rewritten) with stubbed lspci/sudo/pacman/omarchy-hook:

  • T2 (lspci shows 106b:1801): [arch-mact2] with the mirror server is present after the refresh, the user hook still runs, and pacman -Syyuu still runs.
  • Second run: the stanza is not duplicated.
  • Non-T2: nothing is added.

All four assertions pass here, and the test fails against the pre-fix command (RED → GREEN). Honest host note: this is an Apple Silicon macOS machine with no bash 4+ and no Wayland, so the repo's full ./test/shell cannot complete here (${var,,}-style and compositor tests are environment-bound); the new test is bash-3.2 compatible and was run directly, and it never touches the real /etc/pacman.conf. Real-T2 end-to-end validation (an actual omarchy refresh pacman on a T2 Mac) remains for someone with that hardware.

One scope note: a migration that repairs already-upgraded machines was intentionally left out — I did not want to guess at maintainer preferences on machine-wide repairs, and the refresh fix covers every future refresh. Happy to add one if you want it.

omarchy refresh pacman overwrites /etc/pacman.conf from the channel
template, which silently drops hardware-specific repositories like
[arch-mact2] on Apple T2 Macs, orphaning linux-t2 and friends. The install
path already re-applies them from install/hardware/pacman.sh; mirror that
here (as root, since the file appends to /etc/pacman.conf) before the user
hook and the upgrade run. Idempotent and a no-op on other hardware.
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed by Claude Opus 5 in Claude Code, with a second opinion from Codex (gpt-5.6-sol) at xhigh reasoning. Everything executable ran on a disposable Omarchy 4.0.0 VM, never against this machine's own /etc/pacman.conf.

The fix is correct and I pushed nothing. The two properties worth checking hardest both hold.

Idempotence. The append cannot duplicate the stanza, because the template cp on line 19 lands first and install/hardware/pacman.sh guards on grep -q '^\[arch-mact2\]' against the file it has just rewritten. Verified end to end on the worker with a stubbed lspci reporting 106b:1801 and a stubbed pacman: five consecutive omarchy-refresh-pacman stable runs against the VM's real /etc/pacman.conf leave exactly one [arch-mact2]. This matters more than it looks — a duplicate does not fail the parse, pacman prints error: could not register 'arch-mact2' database (database already registered) and quietly uses the first, which is how a later ordering change becomes ineffective with no symptom. It does not happen here.

Ordering. The stanza lands at EOF, after [omarchy]; on the edge template that is after the commented-out [*-debug] block, and it still parses and registers there. Open PR #7583 ("Order the Omarchy repository above Arch's") touches only default/pacman/pacman-*.conf and its own migration, so there is no textual conflict with this PR and no ordering interaction either way: [arch-mact2] stays last, and its packages (linux-t2, t2fanrd, apple-t2-audio-config, apple-bcm-firmware) have no Arch counterpart that could shadow them. Non-T2 was checked with the real lspci on non-Apple hardware: nothing is appended.

Tests, all on the worker: ./test/cli green. ./test/shell green on 225 of 227 files; the two failures are ascii-test.sh (a figlet column-width assertion) and branding-about-animation-test.sh, both environment-bound and reading nothing this PR touches. Your test/shell.d/refresh-pacman-test.sh is not vacuous — with the eight added lines removed from bin/omarchy-refresh-pacman it fails at the first assertion, and passes with them.

Two things for the maintainer rather than defects in the diff:

1. omarchy update never runs this command, so already-stripped machines stay stripped. The only callers of omarchy-refresh-pacman are bin/omarchy-channel-set:86 and bin/omarchy-reinstall-pkgs:11; bin/omarchy-update goes omarchy-update-system-pkgs → omarchy-migrate and never touches it. You said this in the PR body and leaving the repair migration to the maintainer is the right call, especially with #8709 and #9461 both arguing about whether that repository should exist at all. It does mean the Fixes #9853 keyword will auto-close an issue whose reporter's machine is still orphaned until they type omarchy refresh pacman by hand.

2. A non-zero exit from the sourced script is swallowed. omarchy-refresh-pacman has no set -e and line 27's status is unchecked, so if the re-apply ever fails the refresh prints nothing, returns 0, and runs pacman -Syyuu with the repository absent — the exact silent failure #9853 is about. It cannot happen against today's install/hardware/pacman.sh, which is why I did not push a change. It can happen the moment #8709 lands: that PR gives the file an exit 1 when the pinned t2linux key cannot be imported from keyserver.ubuntu.com, and its elif ! grep -q '^\[arch-mact2\]' branch is the one this call site always takes, since the cp just removed the stanza. Reproduced on the worker with a stand-in script that exits 1 — refresh exited 0, [arch-mact2] absent, pacman -Syyuu ran anyway. If #8709 lands, line 27 wants a || echo at minimum; and #8709's side should know that this call site would put a keyserver fetch in every refresh on a T2 Mac.

One more, confirmed on the worker: a user who applied the workaround #9853 suggests — a pre-refresh-pacman.d hook that re-adds the stanza — ends up with two copies once this lands, because the hook runs after the new append. Nothing this PR can fix, but a release-note line would save those users a puzzling pacman error.

On the second opinion: most of what Codex returned was in answer to questions I put to it, so read it as agreement rather than independent discovery, and its independence is not currently guaranteed in this setup. What it added on its own: that a checkout path containing an apostrophe would break the bash -c string on line 27 (true, and not worth a commit — omarchy-refresh-pacman has no NOPASSWD sudoers entry, so no privilege boundary is crossed), and a concurrency variant of the duplicate finding, which I rejected: two simultaneous omarchy refresh pacman runs is not a real scenario.

Nothing pushed to your branch. Waiting on the maintainer for the repair-migration question and for how this sequences against #8709 and #9461.

A failing re-apply used to be swallowed: the command has no set -e, so the
refresh printed nothing, returned 0 and ran pacman -Syyuu with the
repository absent, the exact silent failure omacom#9853 is about. Stop before the
upgrade and say why.
@hudsonwa

hudsonwa commented Sep 3, 2026

Copy link
Copy Markdown
Author

Thanks for the worker verification, it is exactly the scrutiny this needed. I took the exit-status point further: since the whole bug class here is silent failure, a failed re-apply now aborts the refresh before the upgrade instead of only echoing. The command has no set -e, so the step is checked explicitly; test/shell.d/refresh-pacman-test.sh gained a failing-hardware-script case that fails on the unchecked version and passes now. The repair-migration question I am leaving to the maintainer as agreed: a migration that re-adds the unsigned stanza would collide with #8709 and #9461, so I did not touch it. The pre-refresh-pacman double-append note is worth a release line.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at e19100d2 by Claude Opus 5 in Claude Code, with an independent second opinion from Codex (gpt-5.6-sol) at xhigh reasoning. Everything executable ran on a fresh disposable Omarchy 4.0.0 worker VM, destroyed afterwards; nothing ran against this machine's own /etc/pacman.conf. Only the new commit is covered here.

The abort is right and I pushed nothing. Checking the step explicitly is the correct answer to the swallowed status, and dropping bash -euo pipefail from run_refresh was the right call rather than a loosening: omarchy-refresh-pacman has no set -e, so the strict form was testing a shell production never runs, and it would have made the new block pass for the wrong reason. Your case is load-bearing — reverting lines 29-32 to the unchecked sudo bash -c "source …" makes the file fail at not ok - a failed hardware re-apply aborts the refresh.

Non-T2 machines cannot be aborted by this, which was the thing worth checking hardest, since a hardware fix that fires on every machine is how this goes wrong. Measured on the worker rather than inferred from the test: install/hardware/pacman.sh exits 0 with the real lspci on non-Apple hardware, 0 on a stubbed T2 that appends, and 0 on a stubbed T2 that already has the stanza. An if with no else and no branch taken returns 0, and a missing lspci leaves grep's 1 as the pipeline status with pipefail off, so the branch is skipped and the file still returns 0. The only status that reaches the new check is a failing append.

One thing the abort does not do: put the machine back. Lines 19-20 have already replaced /etc/pacman.conf and the mirrorlist by the time line 31 fires, so the abort leaves exactly the configuration #9853 is about — the template, without [arch-mact2] — and only stops the upgrade. Worse, line 6 backs up unconditionally on every invocation, and omarchy refresh pacman is precisely what a user retries. Measured on the worker with a hardware script that exits 1:

run 1: exit=1  pacman.conf=#TEMPLATE (no [arch-mact2])  pacman.conf.bak=#ORIGINAL-GOOD
run 2: exit=1  pacman.conf=#TEMPLATE                    pacman.conf.bak=#TEMPLATE
       upgrade never ran, hook never ran

The second attempt overwrites the only good recovery copy with the damaged one. Restoring both .bak files before exit 1 would close it, and I did not push that: on the omarchy-channel-set path it also decides whether a half-applied channel switch reverts, and install/hardware/pacman.sh is being rewritten by two open PRs, so what state the abort should leave behind is a decision rather than a repair.

This is now live the moment #8709 lands, in a stronger form than I described last time. #8709 gives install/hardware/pacman.sh an exit 1 when pacman-key --recv-keys … --keyserver keyserver.ubuntu.com fails, in its elif ! grep -q '^\[arch-mact2\]' branch — and that is the branch this call site always takes, because line 19 has just removed the stanza and the templates carry no SigLevel = Never line for the other branch to match. Before your commit that failure continued into pacman -Syyuu with the repository absent. After it, a T2 Mac that cannot reach the keyserver gets no refresh and no channel switch at all, and a retry costs it the backup. That is a better failure than the silent one, but it makes keyserver reachability a hard dependency of omarchy refresh pacman on T2 hardware, and it is the maintainer's sequencing call rather than a defect in your diff.

Caller propagation checked and correct: omarchy-channel-set:7 has set -euo pipefail and omarchy-reinstall-pkgs:6 has set -e, both call this as a bare statement, so the non-zero exit stops each before its pacman. Worth knowing on the dev path: link_dev_checkout and omarchy-state set reboot-required have already run by line 86, so an abort there leaves that half applied.

Tests, all on the worker: ./test/cli green, refresh-pacman-test.sh green including the new case, channel-test.sh green. Idempotence still holds after the change — two sourced runs against the same file leave exactly one [arch-mact2].

Codex reviewed the same head at xhigh and reached the exit-status enumeration and the caller propagation I had already written down, so read those as agreement rather than independent discovery; its independence is not currently guaranteed here, since read-only sandboxing restricts writes and not reads. It contributed the retry step of the backup finding — that the second attempt destroys the good copy — which I had not reasoned about and then measured. One thing of its I did not act on: that sudo bash -c runs the helper without -e while the installer sources it under bash -eE at install/helpers/logging.sh:54, so a future helper of the form false; successful_append would pass here and fail during install. True, but it describes no current helper; it is worth knowing on #8709's side, which is where that file is being rewritten.

Nothing pushed. Waiting on the maintainer, for the abort's rollback state and for how this sequences against #8709 and #9461.

@omarchybot

Copy link
Copy Markdown
Collaborator

Looked at again by Claude Opus 5.5 in Claude Code, with a second opinion from Codex Medium, because this branch no longer merges into quattro. Nothing was run this time: the head is the same e19100d2 the last comment covered, and running it again would not say anything about the quattro it now has to land on.

The bug is still there on quattro. bin/omarchy-refresh-pacman still copies the channel template over /etc/pacman.conf and goes on to the hook and the upgrade without re-applying install/hardware/pacman.sh, so a refresh still drops [arch-mact2] on a T2 Mac. The fix is still wanted.

The conflict is with a security rewrite of the same script, landed on quattro in the last few days (1136a71 through 43b9116): it now starts as #!/bin/bash -p, sources bin/omarchy-security-functions, requires OMARCHY_PATH to be the command's own source root, revokes the sudo timestamp up front and around the pre-refresh-pacman hook, and runs sudo through default/omarchy/sudo-no-update/sudo, which is sudo -N. Porting the block into that is not a matter of picking sides in the conflict:

  • Placement. It belongs after the two template copies and before the first revocation around the hook, which keeps your ordering — hardware repos first, user hook second — and leaves the hook's credential boundary alone. The abort has to exit through the cleanup traps the script now installs, which exit 1 there does.
  • One more authentication on every refresh. Hardware detection happens inside the elevated shell, so under sudo -N the sudo bash -c is a separately authorised call on every machine, T2 or not. Checking lspci -nn for 106b:180[12] before elevating would keep that to the machines that need it.
  • The test needs rebuilding, not rebasing. test/shell.d/refresh-pacman-test.sh runs a copy of the command with bash (dropping -p, which the script now refuses), without the security library beside it, from a path that fails the source-root check, and stubs sudo on PATH, which the script now replaces and its revocations bypass with /usr/bin/sudo. test/shell.d/fixtures/sudo-boundary-test.sh and test/shell.d/channel-sudo-boundary-test.sh on quattro show how its own tests drive these scripts, and the T2, non-T2, idempotence and failing-helper cases would fit on that fixture.

Codex Medium reached the same three points when asked about each; its independence is not guaranteed in this setup, so read that as agreement. It found nothing new in the diff itself beyond the two earlier comments here.

Nothing pushed. Waiting on you for the port onto quattro, since the test is yours to rebuild; once it merges cleanly again it gets run on a worker against quattro. The maintainer questions from the last comment — what state the abort leaves behind, and sequencing against #8709 and #9461 — still stand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working compatibility Make Omarchy work better on everything!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omarchy-refresh-pacman drops hardware-specific repos (arch-mact2 on T2 Macs), silently orphaning linux-t2

2 participants