Skip to content

Prepend the Omarchy bin dir in dev-link mode only - #7239

Closed
omarchybot wants to merge 1 commit into
quattrofrom
fix/issue-6977
Closed

omarchybot wants to merge 1 commit into
quattrofrom
fix/issue-6977

Conversation

@omarchybot

Copy link
Copy Markdown
Collaborator

default/hypr/envs.lua puts $OMARCHY_PATH/bin first on PATH for the whole graphical session unconditionally, and default/hypr/autostart.lua imports that into the systemd user manager, so every terminal in the session inherits it. On a production install that directory is /usr/share/omarchy/bin, a symlink farm holding only the binaries the omarchy package itself ships — so it shadows a complete /usr/bin with an incomplete copy. Since bin/omarchy resolves subcommands by globbing its own directory with no PATH fallback, every omarchy-* command another package installs to /usr/bin loses its route inside the session while still working from a login shell.

default/bash/env-bootstrap already guards the identical prepend with [ "$OMARCHY_PATH" != /usr/share/omarchy ], and docs/file-layout.md states that as the intended policy. envs.lua is the half that never got the guard. This adds it, and normalizes a trailing slash so a hand-edited path cannot slip past the comparison.

The reported symptom is omarchy debug, but the blast radius is wider than the five commands named in the issues: it is every omarchy-* route shipped by a package other than omarchy. Today that is omarchy-debug, omarchy-debug-idle and omarchy-upload-log from omarchy-settings, omarchy-nvim-setup and omarchy-nvim-refresh from omarchy-nvim, plus four from omarchy-emacs and one each from omarchy-fish and omarchy-zsh — eleven routes, growing with every optional package that follows the same pattern.

Fixing it here rather than by adding mirror symlinks keeps the invariant in one place: the alternative is editing six PKGBUILDs to drop files into a directory another package owns, and requiring every future package to remember. Dev-link installs are unaffected — omarchy-dev-link writes a canonicalized path that is not /usr/share/omarchy, so the prepend still fires there.

Worth noting there is no test harness for envs.lua; test/shell.d/dev-env-path-test.sh covers the env-bootstrap side only and is untouched here.

Fixes #6977

envs.lua put $OMARCHY_PATH/bin first on PATH for the whole graphical
session unconditionally, while env-bootstrap deliberately does it only
in dev-link mode. On a production install the two directories are not
interchangeable: /usr/share/omarchy/bin holds symlinks for the omarchy
package's binaries alone, so it shadowed a complete /usr/bin with an
incomplete copy. Since bin/omarchy resolves subcommands by globbing its
own directory, every omarchy-* command another package ships to /usr/bin
lost its route inside the session while still working from a login
shell -- omarchy debug, omarchy debug idle and omarchy upload log from
omarchy-settings, omarchy nvim setup and omarchy nvim refresh from
omarchy-nvim, and anything a future package adds the same way.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adjusts how PATH is manipulated in Hyprland session env setup to avoid shadowing system binaries in production installs, while keeping dev-link behavior consistent with other bootstrap scripts.

Changes:

  • Adds a production-vs-dev guard to only prepend OMARCHY_PATH/bin in non-production (dev-link) setups.
  • Normalizes paths.omarchy_path by trimming trailing slashes before comparisons.
  • Expands inline documentation explaining why prepending /usr/share/omarchy/bin is harmful in production.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread default/hypr/envs.lua
Comment on lines +30 to 47
-- Prepend only in dev-link mode, matching default/bash/env-bootstrap. On a
-- production install /usr/share/omarchy/bin holds symlinks for the `omarchy`
-- package's binaries alone, so putting it first shadows the complete /usr/bin
-- with an incomplete copy -- and the dispatcher scans its own directory, so
-- every omarchy-* command another package ships to /usr/bin (omarchy-debug,
-- omarchy-debug-idle, omarchy-upload-log from omarchy-settings;
-- omarchy-nvim-setup, omarchy-nvim-refresh from omarchy-nvim) loses its route
-- for the whole graphical session.
local omarchy_path = paths.omarchy_path:gsub("/+$", "")
if omarchy_path ~= "/usr/share/omarchy" then
local bin_dir = omarchy_path .. "/bin"
local kept = {}
for entry in (os.getenv("PATH") or "/usr/local/bin:/usr/bin"):gmatch("[^:]+") do
if entry ~= bin_dir then table.insert(kept, entry) end
end
table.insert(kept, 1, bin_dir)
hl.env("PATH", table.concat(kept, ":"))
end
Comment thread default/hypr/envs.lua
Comment on lines +38 to +43
local omarchy_path = paths.omarchy_path:gsub("/+$", "")
if omarchy_path ~= "/usr/share/omarchy" then
local bin_dir = omarchy_path .. "/bin"
local kept = {}
for entry in (os.getenv("PATH") or "/usr/local/bin:/usr/bin"):gmatch("[^:]+") do
if entry ~= bin_dir then table.insert(kept, entry) end
@Z3l20

Z3l20 commented Sep 3, 2026

Copy link
Copy Markdown

This fixes the production case, but the dev-link branch keeps the half of the behaviour that clobbers user PATH order, and I think it's worth closing here rather than in a follow-up.

env-bootstrap guards the prepend twice, not once:

if [ "$OMARCHY_PATH" != /usr/share/omarchy ]; then   # 1. dev-link only
  case ":$PATH:" in
    *":${OMARCHY_PATH%/}/bin:"*) ;;                  # 2. already present
    *) PATH="${OMARCHY_PATH%/}/bin${PATH:+:$PATH}" ;;
  esac
fi

This PR ports guard 1. Guard 2 is still missing, so inside dev-link mode the strip-and-prepend continues to move an entry that is already on PATH to position 1, demoting anything deliberately placed ahead of it. 4f031e1 describes that pass as "a dedup pass so reloads don't accumulate the bin/ prefix" — dedup does not require reordering, so this looks like a side effect rather than intended precedence policy.

Concretely, on a portable install ($OMARCHY_PATH under ~/.local/share) with a directory of wrapper scripts placed ahead of $OMARCHY_PATH/bin, every process Hyprland spawns silently resolves to the checkout instead of the wrappers, while login shells resolve correctly. Because autostart.lua imports that environment into the systemd user manager, anything launched via uwsm-app inherits it too — including the menu's Update → Omarchy row, which execs bash -c and sources no rc files. A shell-based check reports the correct order throughout, so the failure is invisible from a terminal.

Suggested addition, keeping the dedup and prepending only when absent:

local bin_dir = omarchy_path .. "/bin"
local kept, seen_bin = {}, false
for entry in (os.getenv("PATH") or "/usr/local/bin:/usr/bin"):gmatch("[^:]+") do
  if entry ~= bin_dir then
    table.insert(kept, entry)
  elseif not seen_bin then
    seen_bin = true
    table.insert(kept, entry)
  end
end

if not seen_bin then
  table.insert(kept, 1, bin_dir)
end

hl.env("PATH", table.concat(kept, ":"))

luac -p clean. Behaviour: absent → prepended as now; already first → unchanged; present later → left where it is; repeated → deduped in place, so the reload-accumulation case 4f031e1 targeted still holds.

@omarchybot

Copy link
Copy Markdown
Collaborator Author

Reviewed at 037242e against quattro 3faafba, which has not changed default/hypr/envs.lua since this branched. The bug is real, this fixes it, and #13351 is the better fix for the same bug.

Reproduced on a worker built from the Omarchy ISO (omarchy 4.0.4, set up as a production install with OMARCHY_PATH=/usr/share/omarchy). From a process Hyprland spawned, with quattro's envs.lua, PATH starts with /usr/share/omarchy/bin, omarchy resolves to /usr/share/omarchy/bin/omarchy, and omarchy debug --no-sudo --print fails with "Unknown Omarchy command". The systemd user manager holds the same PATH. With this head's envs.lua, PATH no longer carries that directory, omarchy resolves to /usr/bin/omarchy, and omarchy debug runs. With the fix reverted it fails again. Linked as a dev checkout, the session still gets the checkout's bin first. ./test/cli (116 ok, 0 failed), dev-env-path-test.sh and panel-command-path-test.sh passed on the worker. A Lua harness over trailing-slash and already-present cases behaved as the description says.

Why #13351 is preferable. It deletes the PATH block from envs.lua instead of guarding it. uwsm sources default/bash/env-bootstrap through default/uwsm/env.d/10-omarchy before Hyprland starts, and that already prepends the checkout's bin in dev-link mode, and only when it is absent. On the worker, Hyprland's own environment already had the checkout's bin before envs.lua ran. Since 64581ec made omarchy dev link require a reboot, the Hyprland-side prepend has nothing left to do. Keeping it, even guarded, keeps a second PATH policy. In dev-link mode it still moves an existing checkout entry to the front, ahead of anything a user put before it. That is @Z3l20's point above, and it holds: /w:/checkout/bin:/usr/bin becomes /checkout/bin:/w:/usr/bin at this head. #13351 fixes the production case, has no reordering problem, and adds a regression test.

Second opinion: Codex Medium was asked to pick between the two fixes without being told which one this review favoured. It chose #13351 for the same reason. It also checked #13351's test, which fails against this branch and passes with #13351's change applied, and found no defect in that pull request. It flagged that this branch's gmatch("[^:]+") drops empty PATH components. That was already true on quattro and does not matter if the block is removed. Independence is not guaranteed, since the reviewer can read this session's working files.

Waiting on the maintainer to choose between the two. If #13351 lands, this one can be closed. #13351 does not reference #6977, so linking it there would close the issue on merge.

@omarchybot

Copy link
Copy Markdown
Collaborator Author

Thank you for this, @omarchybot. #13351 fixes the same problem in a way the review judged better, so this is closed in favour of it. If it does not cover your case, please say so there.

Closed at the maintainer's request. The review comment above has the details; it was done by Claude Opus 5.5 with Codex Medium as a second opinion, whose agreement is not independent.

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.

omarchy debug and four other commands are unreachable inside the Hyprland session: envs.lua prepends an incomplete bin dir

3 participants