Repository navigation
fix(image): bake writable on-PATH npm global prefix - #734
Merged
c-vigo merged 3 commits intoJun 29, 2026
Merged
Conversation
Cover the npm global-prefix bug: in the Nix image npm's default prefix is the read-only nodejs nix-store path whose bin/ is off PATH, so `npm install -g` succeeds but the binary is unresolvable. Add tests asserting the npm global prefix bin/ is writable and on PATH, that a real `npm install -g` is runnable, and that NPM_CONFIG_PREFIX is baked. Refs: #728
npm's default global prefix was the read-only nodejs nix-store path, whose bin/ is off PATH, so `npm install -g <tool>` succeeded but the binary was unresolvable. Bake NPM_CONFIG_PREFIX=/usr/local (already on the image PATH) and create a writable /usr/local/bin in the bootstrap layer so globally installed CLIs resolve on PATH. Scope the install test to PATH resolution (command -v), independent of the /usr/bin/env shebang interpreter that #727 provides. Refs: #728
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the Nix-built image, npm's global prefix defaults to the read-only
nodejsnix-store path (/nix/store/...-nodejs-slim-<ver>), whosebin/is not onPATH(imagePATHis/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin). Sonpm install -g <tool>reports success (exit 0, "changed N packages") but the binary lands in the storebin/where nothing onPATHcan see it — e.g.npm install -g tsxthencommand -v tsx-> not found.Fix
NPM_CONFIG_PREFIX=/usr/localinto the imageconfig.Env./usr/local/binis already on the bakedPATH./usr/local/binin thebootstraplayer (the image has no FHS/usr/local), so the prefix exists and is writable at runtime (root,HOME=/root).Now
npm install -g <tool>lands the binary at/usr/local/bin/<tool>, which resolves onPATH.Tests (TDD)
Added
TestNodeEnvironmentintests/test_image.py:test_npm_installedtest_npm_global_prefix_bin_on_path— prefixbin/is onPATHand writabletest_npm_global_install_resolves_on_path—npm install -g tsxthencommand -v tsxresolvesPlus
NPM_CONFIG_PREFIX=/usr/localadded to thetest_env_vars_setparametrization.Verified RED on the pre-fix image (3 fix-related tests fail:
command -v tsxnot found,NPM_CONFIG_PREFIXunset, prefix bin off PATH) and GREEN after the fix.Coordination with #727
The install test is deliberately scoped to PATH resolution (
command -v), not execution. Executing an installed CLI relies on the#!/usr/bin/envshebang interpreter that #727 provides; this change stands alone and does not depend on it.Closes #728