diff --git a/scripts/install-darwin-multi-user.sh b/scripts/install-darwin-multi-user.sh index 0326d34150e..cd343a8ba6c 100644 --- a/scripts/install-darwin-multi-user.sh +++ b/scripts/install-darwin-multi-user.sh @@ -222,3 +222,32 @@ EOF failure "This script needs a /nix volume with global permissions! This may require running sudo /usr/sbin/diskutil enableOwnership /nix." fi } + +# appended to shell init +poly_extra_init_for_zshenv() { + cat <<'EOF' + +# wrap path_helper to keep it from pushing nix rightwards +/usr/libexec/path_helper() { + case "$1" in + "-c") + # don't interfere if this gets invoked with -c + command /usr/libexec/path_helper "$@" + ;; + *) + ( + # subshell to see what path_helper would do to PATH. inject a + # separator for splitting (saving previous PATH can duplicate + # entries, and people tend to see that as a smell) + eval "$(PATH="nixpathsep:$PATH" command /usr/libexec/path_helper "$@")" + local prefixed="${PATH%%:nixpathsep:*}" pushed_back="${PATH##*:nixpathsep:}" + + # re-emit what path_helper would; remove function to avoid rerunning + echo "PATH=\"${pushed_back}:${prefixed}\"; export PATH; unset -f /usr/libexec/path_helper;" + ) + ;; + esac +} + +EOF +} diff --git a/scripts/install-multi-user.sh b/scripts/install-multi-user.sh index a08f62333dc..3d27f6c7a87 100644 --- a/scripts/install-multi-user.sh +++ b/scripts/install-multi-user.sh @@ -33,7 +33,7 @@ NIX_BUILD_USER_NAME_TEMPLATE="nixbld%d" readonly NIX_ROOT="/nix" readonly NIX_EXTRA_CONF=${NIX_EXTRA_CONF:-} -readonly PROFILE_TARGETS=("/etc/bashrc" "/etc/profile.d/nix.sh" "/etc/zshrc" "/etc/bash.bashrc" "/etc/zsh/zshrc") +readonly PROFILE_TARGETS=("/etc/bashrc" "/etc/profile.d/nix.sh" "/etc/zshenv" "/etc/bash.bashrc" "/etc/zsh/zshrc") readonly PROFILE_BACKUP_SUFFIX=".backup-before-nix" readonly PROFILE_NIX_FILE="$NIX_ROOT/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" @@ -845,6 +845,16 @@ EOF ) } +extra_shell_init() { + case "$1" in + /etc/zshenv) + poly_extra_init_for_zshenv;; + *) + ;; + esac +} + +# $1 == file we're generating for shell_source_lines() { cat <