Skip to content

fix(fish): prevent hoisted bun npm stub from shadowing real native bun - #2008

Merged
shunkakinoki merged 1 commit into
mainfrom
fix/bun-path-shadowing
Jul 6, 2026
Merged

fix(fish): prevent hoisted bun npm stub from shadowing real native bun#2008
shunkakinoki merged 1 commit into
mainfrom
fix/bun-path-shadowing

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Problem

which bun resolved to ~/.bun/install/global/node_modules/.bin/bun, a symlink to bun.exe (a Windows placeholder stub, ~450 bytes). The bun npm package gets transitively hoisted into the global tree during install-npm-globals, and its .bin/bun shadowed the real native bun.

Root cause

home-manager/programs/fish/default.nix ordered ~/.bun/install/global/node_modules/.bin ahead of ~/.bun/bin on PATH (both in shellInit and the fish_add_path blocks). Global CLIs are meant to be frontmost, but that also let a hoisted bun/bunx stub win over the real binary at ~/.bun/bin.

Fix

Re-prepend ~/.bun/bin last (frontmost) so the real native bun/bunx always win, while global CLIs still resolve from the node_modules .bin behind it. Applied to shellInit, loginShellInit, and interactiveShellInit.

Also removed the corrupt stub from disk (~/.bun/install/global/node_modules/bun + its .bin symlinks); real bun (1.3.14) now resolves.

Requires make switch / home-manager rebuild to take effect in login shells.


Summary by cubic

Fixes PATH ordering in fish so the real native bun/bunx in ~/.bun/bin always win over a hoisted npm stub in ~/.bun/install/global/node_modules/.bin. This prevents calling the Windows stub and ensures the correct binary runs.

  • Bug Fixes

    • Reordered PATH in shellInit so ~/.bun/bin precedes the global node_modules/.bin.
    • In login and interactive init, added ~/.bun/bin last via fish_add_path so it is frontmost at runtime.
  • Migration

    • Run home-manager rebuild (e.g., make switch) to apply in new shells.

Written for commit baa7a5e. Summary will update on new commits.

Review in cubic

Global node_modules/.bin was ordered ahead of ~/.bun/bin on PATH, so a
transitively hoisted `bun`/`bunx` npm stub (Windows .exe placeholder)
shadowed the real native bun. Re-prepend ~/.bun/bin last so it stays
frontmost while global CLIs still resolve.
@indent-zero

indent-zero Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor
PR Summary

Reorders PATH entries in the fish shell configuration so that ~/.bun/bin (the real native bun/bunx) always precedes ~/.bun/install/global/node_modules/.bin. This prevents a transitively hoisted bun/bunx npm stub (e.g. a Windows .exe placeholder) from shadowing the real native binary when running under macOS/Linux.

  • In shellInit, swapped the order of $HOME/.bun/bin and $HOME/.bun/install/global/node_modules/.bin in the set -gx PATH … line so real bun is leftmost (highest priority).
  • In loginShellInit and interactiveShellInit, moved the fish_add_path -p -m ~/.bun/bin call to AFTER the ~/.bun/install/global/node_modules/.bin call so, per the file's own convention ("last line = highest priority"), ~/.bun/bin ends up frontmost in fish_user_paths.
  • Added inline comments in all three locations documenting the ordering invariant; the global bun CLI directory remains on PATH so globally-installed CLIs still resolve.

Issues

No issues found.

CI Checks

Waiting for CI checks...

@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@shunkakinoki, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 5 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2855bfbc-0048-4702-9fde-e26089bea47f

📥 Commits

Reviewing files that changed from the base of the PR and between 55756b4 and baa7a5e.

📒 Files selected for processing (1)
  • home-manager/programs/fish/default.nix
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bun-path-shadowing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@shunkakinoki
shunkakinoki merged commit f7096a1 into main Jul 6, 2026
28 of 31 checks passed
@shunkakinoki
shunkakinoki deleted the fix/bun-path-shadowing branch July 6, 2026 09:04

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request adjusts the path ordering in the Fish shell configuration to ensure that the native bun binary path (~/.bun/bin) takes precedence over the global node_modules/.bin path, preventing npm stubs from shadowing the real binary. The reviewer suggested refactoring the duplicated fish_add_path blocks in both loginShellInit and interactiveShellInit into a single reusable Nix let binding to adhere to the DRY principle.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +60 to +62
# ~/.bun/bin last => frontmost, so the real native bun/bunx always win over
# any hoisted `bun` npm stub living in the global node_modules/.bin above.
fish_add_path -p -m ~/.bun/bin

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.

medium

The entire block of fish_add_path commands (lines 50-62) is duplicated identically in both loginShellInit and interactiveShellInit (lines 75-87).

To adhere to the DRY (Don't Repeat Yourself) principle and prevent future maintenance issues (such as paths drifting out of sync when added, removed, or reordered), consider extracting this common path setup block into a Nix let binding at the top of the file.

Suggested Refactoring

At the top of home-manager/programs/fish/default.nix:

let
  commonPaths = ''
    # Last line = highest priority (-p -m prepends+moves; last call ends up at front of fish_user_paths)
    fish_add_path -p -m /nix/var/nix/profiles/default/bin
    fish_add_path -p -m ~/.nix-profile/bin
    fish_add_path -p -m /etc/profiles/per-user/${config.home.username}/bin
    fish_add_path -p -m ~/go/bin
    fish_add_path -p -m ~/.local/bin
    fish_add_path -p -m ~/.cargo/bin
    fish_add_path -p -m ~/.local/scripts
    fish_add_path -p -m /opt/homebrew/opt/postgresql@18/bin
    fish_add_path -p -m /opt/homebrew/bin
    fish_add_path -p -m ~/.bun/install/global/node_modules/.bin
    # ~/.bun/bin last => frontmost, so the real native bun/bunx always win over
    # any hoisted `bun` npm stub living in the global node_modules/.bin above.
    fish_add_path -p -m ~/.bun/bin
  '';
in
{
  # ...
}

Then, reference it in both shell initialization blocks:

    loginShellInit = ''
      if test -f /opt/homebrew/bin/brew
          eval "$(/opt/homebrew/bin/brew shellenv)"
      end

      ${commonPaths}
    '';
    interactiveShellInit = ''
      source ${config.home.homeDirectory}/.config/fish/functions/_hm_load_env_file.fish
      _hm_load_env_file
      set fish_greeting
      set fish_theme dracula

      if test -f /opt/homebrew/bin/brew
          eval "$(/opt/homebrew/bin/brew shellenv)"
      end

      ${commonPaths}
      # Worktrunk shell init
      if type -q wt
        wt config shell init fish | source
      end
      # ...
    '';

shunkakinoki added a commit that referenced this pull request Jul 6, 2026
* fix(shell): update test to match bun PATH reorder from #2008

* feat: track moshi-hook entries in dotfiles for all agents

Inline moshi-hook entries into tracked hook configs so home-manager
activation deploys them without needing a separate moshi-hook install.

JSON hooks (claude, codex, cursor, gemini, grok):
- Add moshi-hook entries for PermissionRequest, SessionStart,
  UserPromptSubmit, Stop, SessionEnd, Pre/PostToolUse
- Use bare 'moshi-hook' command (on PATH) instead of hardcoded
  /home/ubuntu/.local/bin path for cross-platform portability

TypeScript plugins (omp, pi, opencode):
- Track auto-generated moshi-hooks.ts via home.file in nix configs
- Replace hardcoded helperBinary path with process.env.HOME

* fix: format moshi-hooks.ts files with biome

* feat: add moshi-update target to sync moshi-hook configs

* fix: format update-moshi-hooks.sh with shfmt

* fix: add moshi-hooks spec, guard moshi-update in CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant