Skip to content

Fix omarchy update under sudo: unset OMARCHY_PATH and yay-as-root - #12796

Open
mrpink77it wants to merge 4 commits into
omacom:quattrofrom
mrpink77it:fix/update-under-sudo
Open

mrpink77it wants to merge 4 commits into
omacom:quattrofrom
mrpink77it:fix/update-under-sudo

Conversation

@mrpink77it

Copy link
Copy Markdown

Problem

Running omarchy update the way the package advertises it — sudo omarchy update (# omarchy:requires-sudo=true) — resets the environment with sudo, so OMARCHY_PATH is unset and every step runs as root. Three update helpers break under that, and the AUR step cannot work at all as root:

  • omarchy-update-dev and omarchy-update-available abort with OMARCHY_PATH: unbound variable (both use set -euo pipefail and reference $OMARCHY_PATH unguarded), instead of treating the checkout as package-backed and moving on.
  • omarchy-update-aur-pkgs runs yay as root; makepkg refuses root, so yay -Sua fails exit status 10 and the AUR packages are never updated.
  • omarchy-update-restart's final shell restart prints Omarchy shell config not found: /shell and skips the restart, because root's own user manager carries no OMARCHY_PATH.

Everything is currently gated behind path != /usr/share/omarchy, which assumes the variable is always set (true in a session, false under sudo).

Changes

  • omarchy-update-dev / omarchy-update-available: treat an unset OMARCHY_PATH as the package-backed checkout (${OMARCHY_PATH:-/usr/share/omarchy}), matching the precedent in omarchy-migrate, omarchy-version, and provision-*.
  • omarchy-update-aur-pkgs: when running as root, run yay as the SUDO_USER who started the update (with a clean HOME/XDG environment, since makepkg refuses root); skip with a clear message if there is no owner user to run it as.
  • omarchy-restart-shell: when OMARCHY_PATH is empty and SUDO_USER is set, fall back to that user's manager (systemctl --user --machine "$SUDO_USER@.host" show-environment), then to the packaged path, so the post-update shell restart actually happens.

Tests

Added hermetic coverage for each fix and ran the related suites:

test/shell.d/update-dev-test.sh        ✓
test/shell.d/update-available-test.sh  ✓
test/shell.d/restart-shell-test.sh     ✓
test/shell.d/bin-style-test.sh         ✓
test/shell.d/update-status-test.sh     ✓
test/shell.d/update-sequence-test.sh   ✓
test/shell.d/update-lock-test.sh       ✓
test/shell.d/update-disk-space-test.sh ✓
./test/cli                             ✓

Note

These were reproduced and validated on a shipped omarchy 4.0.4 install (sudo omarchy update), where a full update run went through cleanly after applying the same changes locally.

@llstrk

llstrk commented Sep 21, 2026

Copy link
Copy Markdown

Verified: The unset-path fixes work in the tested cases, but supporting sudo omarchy update still leaves user-scoped work in root's context.

The newly unblocked pipeline retains root's home

With OMARCHY_PATH unset, baseline stops at omarchy-update-dev; the PR continues into omarchy-migrate, hooks and subsequent steps without changing user. A controlled pipeline trace confirms that continuation. Source inspection shows that migrations use $HOME/.local/state/omarchy/migrations, while hooks and restart markers likewise use the caller's home.

sudo update, OMARCHY_PATH unset
  baseline: update-dev aborts
  PR:       update-dev skips -> migrate -> hooks -> ... -> restart
                                root HOME remains in effect

Impact: With sudo setting HOME=/root, migration selection and state target root rather than the initiating user, and that user's hooks and restart markers are not consulted. The pipeline documentation explicitly describes migrations as per-user. Actual migrations were not executed as root in this review.

Suggested change: Either reject root invocation with guidance to run omarchy update as the user, or delegate the pipeline to SUDO_USER with the appropriate home/session environment. The existing omarchy-upgrade-to-quattro user-session helpers provide a precedent; delegating only yay does not cover the other user-scoped steps.

Shell config discovery does not restore session targeting

In bin/omarchy-restart-shell:11-17, the new manager query extracts only OMARCHY_PATH. With runtime/signature variables cleared, subsequent discovery still uses /run/user/$UID/hypr, which is /run/user/0/hypr for root.

An isolated namespace-root test used a mocked user manager, real hyprctl, and a synthetic compositor socket:

Head condition Observed result
Caller config found, runtime unset HYPRLAND_INSTANCE_SIGNATURE not set!; no restart dispatch
Same fixture, caller runtime restored Restart dispatch reaches the synthetic socket

Impact: The original config-path error is avoided, but the advertised sudo restart remains incomplete when sudo clears session variables. omarchy-update-restart ignores this helper's failure, so a successful update exit does not establish that the shell refreshed. This is a residual sudo failure, not a demonstrated regression in ordinary user sessions.

Suggested change: Execute the restart in the initiating user's session context, covering Hyprland, Quickshell IPC and invitation-unit restarts. Restoring the runtime in the diagnostic control proves dispatch reachability only, not a complete graphical restart.

Optional test improvement: The new sudo restart case passes against unchanged baseline because the plain systemctl --user show-environment stub already returns the path. Make that query fail in the sudo case and supply the path only through --machine. That diagnostic adjustment made the test fail on baseline and pass on head.

Verified: The new unset-path cases for update-dev and update-available fail on baseline and pass on head. Isolated AUR tests confirm the intended delegation arguments, XDG-variable removal and no-owner skip, not a real credential switch or package installation.


Review information

Test scope: Head ca12d2ab324bc4f87318b7d63f7da5cc14a5c9f3, compared with merge-base 8f324c90b82790d31ab33565441e07cbdb8d2308. Changed shell suites, bin-style checks, controlled pipeline traces and targeted command tests. Real sudo policy, migrations, AUR builds/installation and live graphical restart were not exercised; systemd and Quickshell were mocked in the session-targeting test.

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Automated AI review: Astra initial source inspection, independent Fable 5.1 and separate Astra technical reviews, followed by verification of claims against targeted evidence.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed against current quattro (821ae58) and checked on an Omarchy worker VM. On today's quattro, the failure this fixes can no longer happen, so I'm recommending to the maintainer that this be closed rather than ported.

What reproduces. On this PR's base (8f324c9), omarchy-update-dev and omarchy-update-available fail under sudo with OMARCHY_PATH unset (line 7 / line 9: OMARCHY_PATH: unbound variable). On the head, both exit normally. The three changed test files pass on the worker: update-dev-test.sh 6/6, update-available-test.sh 9/9, restart-shell-test.sh 8/8.

Why it no longer applies on quattro:

  • bin/omarchy-update is now a bash -p entrypoint that calls omarchy_security_require_source_root (bin/omarchy-security-functions:47-59) before doing anything else. That check fails when OMARCHY_PATH is unset. On the worker, sudo env -u OMARCHY_PATH bin/omarchy-update -y from quattro exits 1 with OMARCHY_PATH does not match this Omarchy command. It never reaches omarchy-update-dev, the AUR step or the restart.
  • The update is now meant to be run as your own user. It asks for sudo once on its own (authorize_update, from Ask for the sudo password once per omarchy update #13323), and # omarchy:requires-sudo=true only marks the command as one that uses sudo (agents/skills/command-metadata.md:18). Before the AUR step it deliberately drops that sudo authorization and routes yay through the sudo-no-update wrapper, so PKGBUILD code never runs with cached root access. Running yay as SUDO_USER from a root process, as this PR does in omarchy-update-aur-pkgs, works around that design rather than fitting into it. That file is also where the merge conflict is.
  • The other callers of these helpers are fine. The bar widget (shell/plugins/bar/widgets/SystemUpdate.qml:41) runs in the session, which has OMARCHY_PATH set. omarchy-upgrade-to-quattro runs them through run_as_user_omarchy.

If running the update as root still needs handling, the small fix would be for omarchy-update to refuse root with a message saying to run it as yourself. The community review above suggested the same. Whether to add that is the maintainer's call, so I haven't pushed anything.

Who checked it: Claude Opus 5.5 reviewed it. The second opinion, Codex Medium, did not run: the reviewer is reachable (omabot review --ping answered), but omabot's daily review allowance was used up. So this is one model's review.

Waiting on the maintainer to decide whether to close this.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants