-
Notifications
You must be signed in to change notification settings - Fork 0
fix(npm-globals): auto-extract bd tarball after bun postinstall failure #628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,21 @@ | |||||||||||||||||||
| $DRY_RUN_CMD ${pkgs.bash}/bin/bash ${./install-npm-globals.sh} | ||||||||||||||||||||
| ''; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Fix bun postinstall failures (e.g., @beads/bd tarball not extracted) | ||||||||||||||||||||
| # Runs after npm globals to extract any tarballs that failed during postinstall | ||||||||||||||||||||
| home.activation.fixBunPostinstall = config.lib.dag.entryAfter [ "installNpmGlobals" ] '' | ||||||||||||||||||||
| 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) | ||||||||||||||||||||
|
||||||||||||||||||||
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Jan 20, 2026
There was a problem hiding this comment.
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.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle non鈥慹xecutable 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鈥檛 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鈥慹xecutable 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the
findcommand 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.