Skip to content

fix(nix): Resolve PATH mismatch for packages option in multi-user mode#1691

Open
V-Subhankar-infy wants to merge 2 commits into
devcontainers:mainfrom
V-Subhankar-infy:patch-nix
Open

fix(nix): Resolve PATH mismatch for packages option in multi-user mode#1691
V-Subhankar-infy wants to merge 2 commits into
devcontainers:mainfrom
V-Subhankar-infy:patch-nix

Conversation

@V-Subhankar-infy

@V-Subhankar-infy V-Subhankar-infy commented Jul 22, 2026

Copy link
Copy Markdown
Member

fix(nix): Resolve PATH mismatch and attribute-path error for packages in multi-user mode

Issues Fixed

Issue 1 — Packages installed to wrong profile in multi-user mode { Reported As Issue on Feb-16-2026 at #1573 }

Problem: In multi-user Nix installs, packages specified via the packages option were silently installed into the calling user's ~/.nix-profile (inside a su subshell) instead of /nix/var/nix/profiles/default — the global profile that is on PATH at runtime.

Reproduction:

# devcontainer-feature.json: multiUser: true, packages: "nixpkgs.vim"
$ type vim
# → vim: command not found

$ nix-env -p /nix/var/nix/profiles/default -q
# → vim is absent from the default profile

Root Cause: install.sh ran post-install-steps.sh inside su ${USERNAME} -c "...". Inside that subshell, nix-env defaulted to ~/.nix-profile. Since only /nix/var/nix/profiles/default/bin is on PATH at runtime, the installs were unreachable.

Fix:

  • src/nix/install.sh — Removed the su subshell in the multi-user branch. nix-daemon.sh is sourced in the root context and NIX_FEATURE_INSTALL_PROFILE=/nix/var/nix/profiles/default is passed as a prefixed env var to post-install-steps.sh.
  • src/nix/post-install-steps.sh — When NIX_FEATURE_INSTALL_PROFILE is set, constructs -p/--profile arg arrays and forwards them to every nix-env and nix profile install invocation. Single-user mode is unaffected (arrays remain empty).

Issue 2 — Wrong attribute path for nodejs in packages scenario

Problem: The packages test scenario in scenarios.json used nodePackages.nodejs with useAttributePath: true. The correct nixpkgs attribute path is simply nodejs; the nodePackages. prefix resolves a different attribute set and caused the scenario to fail at build time.

Reproduction:

# scenarios.json: packages: "nodePackages.nodejs,...", useAttributePath: true
$ nix-env -iA nixpkgs.nodePackages.nodejs
# → error: attribute 'nodePackages.nodejs' in selection path not found

Fix:

  • test/nix/scenarios.json — Corrected nodePackages.nodejsnodejs in the packages string for the useAttributePath scenario.

Tests

  • Added check "vim_in_default_profile" to test/nix/packages.sh — runs nix-env -p /nix/var/nix/profiles/default -q | grep '^vim' to directly assert packages land in the global profile.
  • Existing vim_installed / node_installed / yarn_installed checks confirm end-to-end PATH visibility at runtime.
  • Corrected scenarios.json ensures the useAttributePath + packages scenario no longer fails on attribute resolution before the profile bug is even exercised.

Impact

  • Multi-user containers with packages now correctly expose installed packages on PATH.
  • The useAttributePath packages CI scenario is unblocked and runs cleanly.
  • Single-user installs and the public feature interface are unchanged.

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 updates the Nix feature’s multi-user installation flow so that configured packages (and optionally flakes) are installed into the default system profile that’s on users’ PATH, addressing PATH/profile mismatches in multi-user mode.

Changes:

  • Install packages via nix-env and flakes via nix profile into a configurable target profile (used for multi-user default profile).
  • In multi-user mode, run post-install steps against /nix/var/nix/profiles/default to align installs with the profile on PATH.
  • Extend Nix feature tests to assert the default profile contains expected packages.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
test/nix/scenarios.json Updates the attribute-path packages scenario to use nodejs (to be prefixed to nixpkgs.nodejs).
test/nix/packages.sh Adds a test assertion that vim is present in the default Nix profile.
src/nix/post-install-steps.sh Adds support for installing packages/flakes into a specified Nix profile (via -p/--profile).
src/nix/install.sh Switches multi-user post-install execution to target /nix/var/nix/profiles/default directly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@V-Subhankar-infy
V-Subhankar-infy marked this pull request as ready for review July 23, 2026 09:36
@V-Subhankar-infy
V-Subhankar-infy requested a review from a team as a code owner July 23, 2026 09:36
@V-Subhankar-infy V-Subhankar-infy linked an issue Jul 23, 2026 that may be closed by this pull request
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.

Nix Feature: Packages Installing but not in PATH

2 participants