fix(npm-globals): auto-extract bd tarball after bun postinstall failure - #628
fix(npm-globals): auto-extract bd tarball after bun postinstall failure#628shunkakinoki wants to merge 2 commits into
Conversation
|
You do not have enough credits to review this pull request. Please purchase more credits to continue. |
Bun postinstall scripts can fail silently when tar isn't in PATH (common in Nix environments). Added fixBunPostinstall activation that extracts @beads/bd tarball if binary is missing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughUpdates a nested Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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 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 |
Summary of ChangesHello @shunkakinoki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a targeted fix for a common problem encountered in Nix environments where Bun's postinstall scripts might fail to extract necessary binaries from tarballs, specifically for the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Mesa DescriptionTL;DRAutomated extraction of the What changed?
Description generated by Mesa. Update settings |
There was a problem hiding this comment.
Code Review
This pull request introduces a targeted fix for a silent bun postinstall failure affecting the @beads/bd package within Nix environments. The solution involves a new home.activation script that correctly identifies and extracts the package tarball if the binary is missing. The approach is logical and effectively resolves the issue. I've included a couple of suggestions to enhance the script's robustness and make it easier to debug should any issues arise.
| BD_BIN_DIR="$HOME/.bun/install/global/node_modules/@beads/bd/bin" | ||
| if [ -d "$BD_BIN_DIR" ]; then | ||
| # Check if tarball exists but binary doesn't | ||
| TARBALL=$(find "$BD_BIN_DIR" -name "beads_*.tar.gz" 2>/dev/null | head -1) |
There was a problem hiding this comment.
To make the find command more precise and prevent it from searching into subdirectories unexpectedly, it's good practice to add -maxdepth 1. This ensures you're only looking for the tarball directly within $BD_BIN_DIR.
TARBALL=$(find "$BD_BIN_DIR" -maxdepth 1 -name "beads_*.tar.gz" 2>/dev/null | head -1)
| if [ -n "$TARBALL" ] && [ ! -f "$BD_BIN_DIR/bd" ]; then | ||
| echo "Extracting bd binary from tarball..." | ||
| ${pkgs.gnutar}/bin/tar -xzf "$TARBALL" -C "$BD_BIN_DIR" | ||
| chmod +x "$BD_BIN_DIR/bd" 2>/dev/null || true |
There was a problem hiding this comment.
The redirection to /dev/null (2>/dev/null) is somewhat redundant when you are already using || true to prevent script failure. By removing 2>/dev/null, you allow chmod to print any errors to stderr (e.g., if the 'bd' binary was not found after extraction). This provides useful feedback for debugging while still ensuring the activation script doesn't exit on error.
chmod +x "$BD_BIN_DIR/bd" || true
There was a problem hiding this comment.
Pull request overview
This PR addresses a silent failure in Bun's postinstall scripts for the @beads/bd package when tar is unavailable in the PATH (common in Nix environments). It introduces an activation script that runs after npm global installation to detect and extract any tarballs that weren't processed during postinstall.
Changes:
- Added
fixBunPostinstallactivation script to automatically extract the@beads/bdtarball when the binary is missing - Updated dotagents submodule reference
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| home-manager/modules/npm-globals/default.nix | Adds activation script to detect and extract bd tarball using Nix's gnutar |
| dotagents | Submodule reference update |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| BD_BIN_DIR="$HOME/.bun/install/global/node_modules/@beads/bd/bin" | ||
| if [ -d "$BD_BIN_DIR" ]; then | ||
| # Check if tarball exists but binary doesn't | ||
| TARBALL=$(find "$BD_BIN_DIR" -name "beads_*.tar.gz" 2>/dev/null | head -1) |
There was a problem hiding this comment.
The wildcard pattern beads_*.tar.gz may match multiple files if old tarballs aren't cleaned up. Consider adding logic to handle this scenario explicitly, or document the assumption that only one tarball should exist.
| TARBALL=$(find "$BD_BIN_DIR" -name "beads_*.tar.gz" 2>/dev/null | head -1) | |
| TARBALLS=$(find "$BD_BIN_DIR" -name "beads_*.tar.gz" 2>/dev/null | sed '/^$/d') | |
| TARBALL_COUNT=$(printf '%s\n' "$TARBALLS" | sed '/^$/d' | wc -l | tr -d ' ') | |
| TARBALL="" | |
| if [ "$TARBALL_COUNT" -eq 1 ]; then | |
| TARBALL="$TARBALLS" | |
| elif [ "$TARBALL_COUNT" -gt 1 ]; then | |
| echo "Warning: multiple beads_*.tar.gz tarballs found in $BD_BIN_DIR; skipping automatic extraction." | |
| fi |
| if [ -n "$TARBALL" ] && [ ! -f "$BD_BIN_DIR/bd" ]; then | ||
| echo "Extracting bd binary from tarball..." | ||
| ${pkgs.gnutar}/bin/tar -xzf "$TARBALL" -C "$BD_BIN_DIR" | ||
| chmod +x "$BD_BIN_DIR/bd" 2>/dev/null || true |
There was a problem hiding this comment.
The chmod command assumes the extracted binary is named exactly 'bd'. If the tarball structure changes and the binary is in a subdirectory or has a different name, this will silently fail. Consider verifying the extraction was successful or making the binary name configurable.
| chmod +x "$BD_BIN_DIR/bd" 2>/dev/null || true | |
| BD_BIN_PATH=$(find "$BD_BIN_DIR" -type f \( -name "bd" -o -name "bd*" \) 2>/dev/null | head -n1) | |
| if [ -n "$BD_BIN_PATH" ]; then | |
| chmod +x "$BD_BIN_PATH" 2>/dev/null || true | |
| else | |
| echo "Warning: Could not locate bd binary in $BD_BIN_DIR after extraction." | |
| fi |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@home-manager/modules/npm-globals/default.nix`:
- Around line 16-20: The current install block only extracts and chmods when
"$BD_BIN_DIR/bd" is missing; change the logic to also handle non‑executable
files by testing for execute permission (use [ -x "$BD_BIN_DIR/bd" ] or its
negation) and run chmod +x regardless if the file exists but is not executable;
locate the block using the TARBALL, BD_BIN_DIR and bd symbols (and the tar/chmod
calls) and update the condition so extraction still occurs if missing, and chmod
+x is executed when bd exists but lacks execute bit.
| TARBALL=$(find "$BD_BIN_DIR" -name "beads_*.tar.gz" 2>/dev/null | head -1) | ||
| if [ -n "$TARBALL" ] && [ ! -f "$BD_BIN_DIR/bd" ]; then | ||
| echo "Extracting bd binary from tarball..." | ||
| ${pkgs.gnutar}/bin/tar -xzf "$TARBALL" -C "$BD_BIN_DIR" | ||
| chmod +x "$BD_BIN_DIR/bd" 2>/dev/null || true |
There was a problem hiding this comment.
Handle non‑executable bd binaries, not just missing ones.
Right now the fix only runs when the file is absent. If bd exists but lacks the execute bit (a plausible postinstall failure), this block won’t repair it. Consider checking -x and applying chmod even when the file exists.
🔧 Suggested tweak
- if [ -n "$TARBALL" ] && [ ! -f "$BD_BIN_DIR/bd" ]; then
- echo "Extracting bd binary from tarball..."
- ${pkgs.gnutar}/bin/tar -xzf "$TARBALL" -C "$BD_BIN_DIR"
- chmod +x "$BD_BIN_DIR/bd" 2>/dev/null || true
- fi
+ if [ -n "$TARBALL" ] && [ ! -x "$BD_BIN_DIR/bd" ]; then
+ if [ ! -f "$BD_BIN_DIR/bd" ]; then
+ echo "Extracting bd binary from tarball..."
+ ${pkgs.gnutar}/bin/tar -xzf "$TARBALL" -C "$BD_BIN_DIR"
+ fi
+ chmod +x "$BD_BIN_DIR/bd" 2>/dev/null || true
+ fi🤖 Prompt for AI Agents
In `@home-manager/modules/npm-globals/default.nix` around lines 16 - 20, The
current install block only extracts and chmods when "$BD_BIN_DIR/bd" is missing;
change the logic to also handle non‑executable files by testing for execute
permission (use [ -x "$BD_BIN_DIR/bd" ] or its negation) and run chmod +x
regardless if the file exists but is not executable; locate the block using the
TARBALL, BD_BIN_DIR and bd symbols (and the tar/chmod calls) and update the
condition so extraction still occurs if missing, and chmod +x is executed when
bd exists but lacks execute bit.
Set PKG_CONFIG_PATH, OPENSSL_DIR, OPENSSL_LIB_DIR, OPENSSL_INCLUDE_DIR in both bash and fish so cargo can find OpenSSL without nix-shell. Fixes: cargo build failing with "openssl-sys: system library not found" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
fixBunPostinstallactivation script that runs afterinstallNpmGlobals@beads/bdtarball exists but binary wasn't extractedProblem
Bun postinstall scripts can fail silently when
tarisn't in PATH (common in Nix environments). The@beads/bdpackage downloads a tarball but fails to extract it.Test plan
make buildpassesmake switchextracts bd tarball if present🤖 Generated with Claude Code
Summary by cubic
Automatically extracts the @beads/bd binary when Bun’s postinstall fails in Nix environments, and sets OpenSSL env vars on Linux so cargo can build openssl-sys.
Bug Fixes
New Features
Written for commit e21e640. Summary will update on new commits.