Skip to content

fix: add LD_LIBRARY_PATH for bun-installed native addons on NixOS - #1309

Merged
shunkakinoki merged 3 commits into
mainfrom
fix/ld-library-path-bun-natives
Apr 1, 2026
Merged

fix: add LD_LIBRARY_PATH for bun-installed native addons on NixOS#1309
shunkakinoki merged 3 commits into
mainfrom
fix/ld-library-path-bun-natives

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Apr 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add LD_LIBRARY_PATH with alsa-lib, glib, libsecret, stdenv.cc.cc.lib, and zlib to fish, bash, and zsh shell configs (Linux only)
  • Install corresponding packages in home-manager/packages/default.nix
  • Fixes omp (oh-my-pi) crashing with libz.so.1: cannot open shared object file and similar errors for sharp, keytar, copilot, node-llama-cpp, etc.

Test plan

  • Rebuild NixOS / home-manager switch
  • Run omp — should no longer error about libz.so.1
  • Verify ldd on bun native addons shows no missing libs

🤖 Generated with Claude Code


Summary by cubic

Configure LD_LIBRARY_PATH for bun-installed native addons on NixOS and install system libs to stop load failures. Fixes errors like "libz.so.1: cannot open shared object file" in @oh-my-pi/pi-natives, sharp, keytar, node-llama-cpp, and others.

  • Bug Fixes
    • Export LD_LIBRARY_PATH on Linux in bash, zsh, and fish to include libs from alsa-lib, glib, libsecret, stdenv.cc.cc.lib, and zlib.
    • Add the same packages to Home Manager Linux packages so the libraries are present.
    • Append alsa-lib only on Linux using lib.optionals to avoid aarch64-darwin evaluation errors.

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

Bun-installed packages with native .node addons (oh-my-pi, sharp, keytar,
copilot, node-llama-cpp, etc.) fail on NixOS because shared libraries
aren't in standard paths. Add alsa-lib, glib, libsecret, stdenv.cc.cc.lib,
and zlib to LD_LIBRARY_PATH in fish, bash, and zsh shell configs, and
install the corresponding packages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 1, 2026 05:15
@mesa-dot-dev

mesa-dot-dev Bot commented Apr 1, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@coderabbitai

coderabbitai Bot commented Apr 1, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The changes add five native library dependencies (alsa-lib, glib, libsecret, C runtime, zlib) to the Linux package set and configure LD_LIBRARY_PATH environment variables in bash, fish, and zsh shell initialization to expose these library paths.

Changes

Cohort / File(s) Summary
Linux Package Dependencies
home-manager/packages/default.nix
Added five native library packages (alsa-lib, glib, libsecret, stdenv.cc.cc.lib, zlib) to the Linux-only package set.
Shell Library Path Configuration
home-manager/programs/bash/default.nix, home-manager/programs/fish/default.nix, home-manager/programs/zsh/default.nix
Set LD_LIBRARY_PATH environment variable in shell initialization to prepend native library paths from the added dependencies, applied to both interactive and login shells.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

bug

Poem

🐰 Hop, hop! The libraries find their way,
LD paths now clear as morning hay,
Bash, fish, and zsh all aligned,
Native libs of every kind!
Linux systems now so grand,
Built with a rabbit's careful hand! 🌿

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding LD_LIBRARY_PATH for bun-installed native addons on NixOS, which is exactly what the changeset does across multiple shell configurations and package lists.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description clearly explains the purpose of the changes: adding LD_LIBRARY_PATH configuration for bun-installed native addons to fix library loading failures. It directly relates to all the changeset modifications across multiple shell config files and package declarations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ld-library-path-bun-natives

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 and usage tips.

@mesa-dot-dev

mesa-dot-dev Bot commented Apr 1, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Configured LD_LIBRARY_PATH for bun-installed native addons on NixOS and installed needed system libraries to resolve load failures like "libz.so.1: cannot open shared object file" for packages such as @oh-my-pi/pi-natives, sharp, and keytar, while also preventing macOS evaluation errors.

What changed?

  • home-manager/packages/default.nix: Added glib, libsecret, stdenv.cc.cc.lib, and zlib as universal dependencies, and alsa-lib specifically for Linux systems.
  • home-manager/programs/bash/default.nix: Extended the LD_LIBRARY_PATH environment variable to include alsa-lib, glib, libsecret, stdenv.cc.cc.lib, and zlib.
  • home-manager/programs/fish/default.nix: Updated the fish shell configuration to include LD_LIBRARY_PATH with alsa-lib, glib, libsecret, stdenv.cc.cc.lib, and zlib.
  • home-manager/programs/zsh/default.nix: Added an LD_LIBRARY_PATH export to the zsh configuration, incorporating alsa-lib, glib, libsecret, and zlib.

Description generated by Mesa. Update settings

@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 adds several native libraries, including alsa-lib, glib, libsecret, and zlib, to the Home Manager package list and configures the LD_LIBRARY_PATH environment variable across Bash, Fish, and Zsh to support Bun-installed packages. A review comment identifies a redundancy in the Bash configuration where the same LD_LIBRARY_PATH export is added to both bashrcExtra and profileExtra, which would cause the paths to be prepended twice in login shells.

Comment on lines +99 to +100
# Native libraries for bun-installed packages (e.g. @oh-my-pi/pi-natives, sharp, keytar)
export LD_LIBRARY_PATH="${pkgs.alsa-lib}/lib:${pkgs.glib.out}/lib:${pkgs.libsecret}/lib:${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.zlib}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

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

This addition is redundant. The same LD_LIBRARY_PATH is already exported in bashrcExtra (lines 56-57). Since profileExtra explicitly sources ~/.bashrc at line 105, these paths will be prepended twice in login shells, leading to unnecessarily long and duplicated environment variables. You should rely on the definition in bashrcExtra for both interactive and login shells.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 4 files

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

This PR addresses runtime linker failures for bun-installed native addons on NixOS by ensuring common native library dependencies are discoverable via LD_LIBRARY_PATH in user shells (Linux-only), and by adding the corresponding packages to the Home Manager package set.

Changes:

  • Export LD_LIBRARY_PATH (Linux-only) in bash, zsh, and fish to include alsa-lib, glib, libsecret, libstdc++ (from stdenv.cc.cc.lib), and zlib.
  • Add the same library packages to home-manager/packages/default.nix for Linux systems.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
home-manager/programs/zsh/default.nix Adds Linux-only LD_LIBRARY_PATH export in .zshenv via envExtra.
home-manager/programs/fish/default.nix Adds Linux-only LD_LIBRARY_PATH export in shellInit.
home-manager/programs/bash/default.nix Adds Linux-only LD_LIBRARY_PATH export in both bashrcExtra and profileExtra.
home-manager/packages/default.nix Adds the referenced native library packages to the Linux Home Manager package list.
Comments suppressed due to low confidence (1)

home-manager/programs/bash/default.nix:104

  • LD_LIBRARY_PATH is exported in both profileExtra and bashrcExtra, and profileExtra later sources ~/.bashrc. For login shells this will run the export twice, resulting in duplicated path entries (e.g. …/lib:…/lib:…/lib:…/lib). Consider defining the value once (only in profileExtra or only in bashrcExtra), or guard the bashrcExtra export so it only prepends when the entries aren’t already present.
          export LD_LIBRARY_PATH="${pkgs.alsa-lib}/lib:${pkgs.glib.out}/lib:${pkgs.libsecret}/lib:${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.zlib}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
      fi

      # Source .bashrc for login shells to get PATH and other settings
      if [ -f ~/.bashrc ]; then

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +56 to 58
# Native libraries for bun-installed packages (e.g. @oh-my-pi/pi-natives, sharp, keytar)
export LD_LIBRARY_PATH="${pkgs.alsa-lib}/lib:${pkgs.glib.out}/lib:${pkgs.libsecret}/lib:${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.zlib}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
fi

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

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

This block exports LD_LIBRARY_PATH, but the same export also exists in profileExtra. Since profileExtra sources ~/.bashrc, login shells will end up with duplicated entries. Consider removing one of the two exports or making the export idempotent.

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +45
# Native libraries for bun-installed packages (e.g. @oh-my-pi/pi-natives, sharp, keytar)
export LD_LIBRARY_PATH="${pkgs.alsa-lib}/lib:${pkgs.glib.out}/lib:${pkgs.libsecret}/lib:${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.zlib}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

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

The LD_LIBRARY_PATH library list is duplicated across bash/zsh/fish (and twice within bash). To reduce drift when the set of required libs changes, consider factoring the list into a shared Nix value (e.g. a let bunNativeLibs = [...] + generated path string) and reusing it across shells.

Copilot uses AI. Check for mistakes.
shunkakinoki and others added 2 commits April 1, 2026 14:31
alsa-lib is Linux-only in nixpkgs meta.platforms, causing nix eval to
throw on aarch64-darwin even inside lib.optionals. Use lib.optional as
a separate single-member append to avoid eager evaluation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shunkakinoki
shunkakinoki merged commit 0c8c496 into main Apr 1, 2026
27 of 31 checks passed
@shunkakinoki
shunkakinoki deleted the fix/ld-library-path-bun-natives branch April 1, 2026 05:40
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.

2 participants