Skip to content

fix(npm-globals): auto-extract bd tarball after bun postinstall failure - #628

Closed
shunkakinoki wants to merge 2 commits into
mainfrom
fix/bd-tarball-extraction
Closed

fix(npm-globals): auto-extract bd tarball after bun postinstall failure#628
shunkakinoki wants to merge 2 commits into
mainfrom
fix/bd-tarball-extraction

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Jan 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Added fixBunPostinstall activation script that runs after installNpmGlobals
  • Detects if @beads/bd tarball exists but binary wasn't extracted
  • Automatically extracts using Nix's gnutar (guaranteed to be in PATH)

Problem

Bun postinstall scripts can fail silently when tar isn't in PATH (common in Nix environments). The @beads/bd package downloads a tarball but fails to extract it.

Test plan

  • make build passes
  • make switch extracts 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

    • Added a fixBunPostinstall activation step that runs after installNpmGlobals.
    • Extracts the beads tarball with Nix’s gnutar and restores bd executable permissions.
  • New Features

    • Sets PKG_CONFIG_PATH, OPENSSL_DIR, OPENSSL_LIB_DIR, OPENSSL_INCLUDE_DIR in bash and fish on Linux so cargo can find OpenSSL.

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

Copilot AI review requested due to automatic review settings January 20, 2026 01:45
@mesa-dot-dev

mesa-dot-dev Bot commented Jan 20, 2026

Copy link
Copy Markdown

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>
@coderabbitai

coderabbitai Bot commented Jan 20, 2026

Copy link
Copy Markdown

Note

Other AI code review bot(s) detected

CodeRabbit 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.

📝 Walkthrough

Summary by CodeRabbit

  • Chores

    • Updated an internal submodule pointer.
    • Added Linux shell environment exports for OpenSSL to improve local build environments.
  • Bug Fixes

    • Added a post-install step that detects missing runtime binaries and automatically extracts/configures bundled tarballs so the binaries become available immediately.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Updates a nested dotagents submodule pointer and adds a Home Manager activation step to extract Bun-related tarballs; also exports OpenSSL-related environment variables in Linux bash and fish shell initializations.

Changes

Cohort / File(s) Summary
Submodule Update
dotagents
Submodule pointer updated from commit 328e14d... to 1d8ef70... (no functional change).
Bun Postinstall Handler
home-manager/modules/npm-globals/default.nix
Added home.activation.fixBunPostinstall activation step that looks for beads_*.tar.gz and extracts it into BD_BIN_DIR if bd is missing, then ensures bd is executable.
Shell OpenSSL env (Linux)
home-manager/programs/bash/default.nix, home-manager/programs/fish/default.nix
Export OpenSSL-related env vars for Linux: augment PKG_CONFIG_PATH with ${pkgs.openssl.dev}/lib/pkgconfig and set OPENSSL_DIR, OPENSSL_LIB_DIR, OPENSSL_INCLUDE_DIR to Nixpkgs OpenSSL paths.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

codex

Poem

🐰 I hopped through commits, soft and spry,
pulled a pointer up to the sky.
Tarballs unwrap, the bd wakes—hooray!
OpenSSL paths pave the way.
A tiny fix, a cheerful sigh.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: fixing Bun postinstall failures by auto-extracting the bd tarball.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem, solution, and testing approach across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/bd-tarball-extraction

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.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 @beads/bd package. By adding a post-installation activation script, the system now proactively checks for and corrects these extraction failures, ensuring that global npm packages are correctly set up and functional.

Highlights

  • Bun Postinstall Fix: Implemented a new fixBunPostinstall activation script to address silent Bun postinstall failures, specifically for tarball extraction.
  • Automated Tarball Extraction: The script automatically detects if the @beads/bd tarball exists but its binary is missing, then extracts it using Nix's gnutar.
  • Submodule Update: The dotagents git submodule has been updated to a newer commit.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mesa-dot-dev

mesa-dot-dev Bot commented Jan 20, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Automated extraction of the @beads/bd binary when bun postinstall fails in Nix environments due to a missing tar executable, and added OpenSSL environment variables for Linux cargo builds.

What changed?

  • home-manager/modules/npm-globals/default.nix: Added a fixBunPostinstall activation script that runs after installNpmGlobals to detect and extract the @beads/bd tarball if the binary is missing, using Nix's gnutar.
  • home-manager/programs/bash/default.nix: Added Linux-specific OpenSSL environment variables (PKG_CONFIG_PATH, OPENSSL_DIR, OPENSSL_LIB_DIR, OPENSSL_INCLUDE_DIR) to the Bash configuration for cargo builds.
  • home-manager/programs/fish/default.nix: Added Linux-specific OpenSSL environment variables (PKG_CONFIG_CONFIG, OPENSSL_DIR, OPENSSL_LIB_DIR, OPENSSL_INCLUDE_DIR) to the Fish shell configuration for cargo builds.

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 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)

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

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

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 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

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 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 fixBunPostinstall activation script to automatically extract the @beads/bd tarball 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)

Copilot AI Jan 20, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
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

Copilot AI Jan 20, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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

Copilot uses AI. Check for mistakes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines +16 to +20
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

@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 2 files

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>

@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

@shunkakinoki
shunkakinoki deleted the fix/bd-tarball-extraction branch January 21, 2026 23:53
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