fix: add LD_LIBRARY_PATH for bun-installed native addons on NixOS - #1309
Conversation
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>
|
You do not have enough credits to review this pull request. Please purchase more credits to continue. |
📝 WalkthroughWalkthroughThe changes add five native library dependencies (alsa-lib, glib, libsecret, C runtime, zlib) to the Linux package set and configure Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Mesa DescriptionTL;DRConfigured What changed?
Description generated by Mesa. Update settings |
There was a problem hiding this comment.
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.
| # 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}" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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++ (fromstdenv.cc.cc.lib), and zlib. - Add the same library packages to
home-manager/packages/default.nixfor 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_PATHis exported in bothprofileExtraandbashrcExtra, andprofileExtralater 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 inprofileExtraor only inbashrcExtra), or guard thebashrcExtraexport 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.
| # 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 |
There was a problem hiding this comment.
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.
| # 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}" |
There was a problem hiding this comment.
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.
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>
Summary
LD_LIBRARY_PATHwithalsa-lib,glib,libsecret,stdenv.cc.cc.lib, andzlibto fish, bash, and zsh shell configs (Linux only)home-manager/packages/default.nixomp(oh-my-pi) crashing withlibz.so.1: cannot open shared object fileand similar errors for sharp, keytar, copilot, node-llama-cpp, etc.Test plan
omp— should no longer error aboutlibz.so.1lddon bun native addons shows no missing libs🤖 Generated with Claude Code
Summary by cubic
Configure
LD_LIBRARY_PATHforbun-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.LD_LIBRARY_PATHon Linux in bash, zsh, and fish to include libs fromalsa-lib,glib,libsecret,stdenv.cc.cc.lib, andzlib.alsa-libonly on Linux usinglib.optionalsto avoid aarch64-darwin evaluation errors.Written for commit e5bc640. Summary will update on new commits.