Skip to content

Commit ff09390

Browse files
fix(nix): Resolve PATH mismatch for packages option in multi-user mode
1 parent 765e8eb commit ff09390

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/nix/install.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ fi
113113
chmod +x,o+r ${FEATURE_DIR} ${FEATURE_DIR}/post-install-steps.sh
114114
if [ "${MULTIUSER}" = "true" ]; then
115115
/usr/local/share/nix-entrypoint.sh
116-
su ${USERNAME} -c "
117-
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
118-
${FEATURE_DIR}/post-install-steps.sh
119-
"
116+
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
117+
NIX_FEATURE_INSTALL_PROFILE=/nix/var/nix/profiles/default ${FEATURE_DIR}/post-install-steps.sh
120118
else
121119
su ${USERNAME} -c "
122120
. \$HOME/.nix-profile/etc/profile.d/nix.sh

src/nix/post-install-steps.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
set -e
33
echo "(*) Executing post-installation steps..."
44

5+
# In multi-user mode, install into the default profile that is on PATH.
6+
NIX_ENV_PROFILE_ARGS=()
7+
NIX_PROFILE_INSTALL_ARGS=()
8+
if [ -n "${NIX_FEATURE_INSTALL_PROFILE}" ]; then
9+
NIX_ENV_PROFILE_ARGS=(-p "${NIX_FEATURE_INSTALL_PROFILE}")
10+
NIX_PROFILE_INSTALL_ARGS=(--profile "${NIX_FEATURE_INSTALL_PROFILE}")
11+
fi
12+
513
# if not starts with "nixpkgs." add it as prefix to package name
614
add_nixpkgs_prefix() {
715
local packages=$1
@@ -20,17 +28,17 @@ if [ ! -z "${PACKAGES}" ] && [ "${PACKAGES}" != "none" ]; then
2028
if [ "${USEATTRIBUTEPATH}" = "true" ]; then
2129
PACKAGES=$(add_nixpkgs_prefix "$PACKAGES")
2230
echo "Installing packages \"${PACKAGES}\" in profile..."
23-
nix-env -iA ${PACKAGES}
31+
nix-env "${NIX_ENV_PROFILE_ARGS[@]}" -iA ${PACKAGES}
2432
else
2533
echo "Installing packages \"${PACKAGES}\" in profile..."
26-
nix-env --install ${PACKAGES}
34+
nix-env "${NIX_ENV_PROFILE_ARGS[@]}" --install ${PACKAGES}
2735
fi
2836
fi
2937

3038
# Install Nix flake in profile if specified
3139
if [ ! -z "${FLAKEURI}" ] && [ "${FLAKEURI}" != "none" ]; then
3240
echo "Installing flake ${FLAKEURI} in profile..."
33-
nix profile install "${FLAKEURI}"
41+
nix profile install "${NIX_PROFILE_INSTALL_ARGS[@]}" "${FLAKEURI}"
3442
fi
3543

3644
nix-collect-garbage --delete-old

test/nix/packages.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ check "nix-env" type nix-env
2929
check "vim_installed" type vim
3030
check "node_installed" type node
3131
check "yarn_installed" type yarn
32+
check "vim_in_default_profile" bash -lc "nix-env -p /nix/var/nix/profiles/default -q | grep -q '^vim'"
3233

3334
# Report result
3435
# If any of the checks above exited with a non-zero exit code, the test will fail.

0 commit comments

Comments
 (0)