diff --git a/src/nix/install.sh b/src/nix/install.sh index 0030c2b18..ca19f658a 100755 --- a/src/nix/install.sh +++ b/src/nix/install.sh @@ -113,10 +113,8 @@ fi chmod +x,o+r ${FEATURE_DIR} ${FEATURE_DIR}/post-install-steps.sh if [ "${MULTIUSER}" = "true" ]; then /usr/local/share/nix-entrypoint.sh - su ${USERNAME} -c " - . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh - ${FEATURE_DIR}/post-install-steps.sh - " + . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh + NIX_FEATURE_INSTALL_PROFILE=/nix/var/nix/profiles/default ${FEATURE_DIR}/post-install-steps.sh else su ${USERNAME} -c " . \$HOME/.nix-profile/etc/profile.d/nix.sh diff --git a/src/nix/post-install-steps.sh b/src/nix/post-install-steps.sh index 68f93a391..94cfed8a3 100755 --- a/src/nix/post-install-steps.sh +++ b/src/nix/post-install-steps.sh @@ -2,6 +2,14 @@ set -e echo "(*) Executing post-installation steps..." +# In multi-user mode, install into the default profile that is on PATH. +NIX_ENV_PROFILE_ARGS=() +NIX_PROFILE_INSTALL_ARGS=() +if [ -n "${NIX_FEATURE_INSTALL_PROFILE}" ]; then + NIX_ENV_PROFILE_ARGS=(-p "${NIX_FEATURE_INSTALL_PROFILE}") + NIX_PROFILE_INSTALL_ARGS=(--profile "${NIX_FEATURE_INSTALL_PROFILE}") +fi + # if not starts with "nixpkgs." add it as prefix to package name add_nixpkgs_prefix() { local packages=$1 @@ -20,17 +28,17 @@ if [ ! -z "${PACKAGES}" ] && [ "${PACKAGES}" != "none" ]; then if [ "${USEATTRIBUTEPATH}" = "true" ]; then PACKAGES=$(add_nixpkgs_prefix "$PACKAGES") echo "Installing packages \"${PACKAGES}\" in profile..." - nix-env -iA ${PACKAGES} + nix-env "${NIX_ENV_PROFILE_ARGS[@]}" -iA ${PACKAGES} else echo "Installing packages \"${PACKAGES}\" in profile..." - nix-env --install ${PACKAGES} + nix-env "${NIX_ENV_PROFILE_ARGS[@]}" --install ${PACKAGES} fi fi # Install Nix flake in profile if specified if [ ! -z "${FLAKEURI}" ] && [ "${FLAKEURI}" != "none" ]; then echo "Installing flake ${FLAKEURI} in profile..." - nix profile install "${FLAKEURI}" + nix profile install "${NIX_PROFILE_INSTALL_ARGS[@]}" "${FLAKEURI}" fi nix-collect-garbage --delete-old diff --git a/test/nix/packages.sh b/test/nix/packages.sh index ad896e9e0..c59a6e6d9 100755 --- a/test/nix/packages.sh +++ b/test/nix/packages.sh @@ -29,6 +29,7 @@ check "nix-env" type nix-env check "vim_installed" type vim check "node_installed" type node check "yarn_installed" type yarn +check "vim_in_default_profile" bash -lc "nix-env -p /nix/var/nix/profiles/default -q | grep -q '^vim'" # Report result # If any of the checks above exited with a non-zero exit code, the test will fail. diff --git a/test/nix/scenarios.json b/test/nix/scenarios.json index 38eed0268..3fb839629 100644 --- a/test/nix/scenarios.json +++ b/test/nix/scenarios.json @@ -86,7 +86,7 @@ "remoteUser": "vscode", "features": { "nix": { - "packages": "nodePackages.nodejs,nixpkgs.vim,nixpkgs.yarn", + "packages": "nodejs,nixpkgs.vim,nixpkgs.yarn", "useAttributePath": true } }