Skip to content

fix(image): bake writable on-PATH npm global prefix - #734

Merged
c-vigo merged 3 commits into
feature/625-nix-claude-migrationfrom
bugfix/728-npm-global-prefix
Jun 29, 2026
Merged

c-vigo merged 3 commits into
feature/625-nix-claude-migrationfrom
bugfix/728-npm-global-prefix

Conversation

@c-vigo

@c-vigo c-vigo commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Problem

In the Nix-built image, npm's global prefix defaults to the read-only nodejs nix-store path (/nix/store/...-nodejs-slim-<ver>), whose bin/ is not on PATH (image PATH is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin). So npm install -g <tool> reports success (exit 0, "changed N packages") but the binary lands in the store bin/ where nothing on PATH can see it — e.g. npm install -g tsx then command -v tsx -> not found.

Fix

  • Bake NPM_CONFIG_PREFIX=/usr/local into the image config.Env. /usr/local/bin is already on the baked PATH.
  • Create a writable /usr/local/bin in the bootstrap layer (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 on PATH.

Tests (TDD)

Added TestNodeEnvironment in tests/test_image.py:

  • test_npm_installed
  • test_npm_global_prefix_bin_on_path — prefix bin/ is on PATH and writable
  • test_npm_global_install_resolves_on_path — npm install -g tsx then command -v tsx resolves

Plus NPM_CONFIG_PREFIX=/usr/local added to the test_env_vars_set parametrization.

Verified RED on the pre-fix image (3 fix-related tests fail: command -v tsx not found, NPM_CONFIG_PREFIX unset, 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/env shebang interpreter that #727 provides; this change stands alone and does not depend on it.

Closes #728

c-vigo added 3 commits June 29, 2026 10:15
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
@c-vigo
c-vigo merged commit 31c77a5 into feature/625-nix-claude-migration Jun 29, 2026
2 checks passed
@c-vigo
c-vigo deleted the bugfix/728-npm-global-prefix branch June 29, 2026 08:42
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.

1 participant