diff options
author | Manav Rathi <mx4492@gmail.com> | 2016-11-03 22:32:29 +0530 |
---|---|---|
committer | Domen Kožar <domen@dev.si> | 2016-11-03 18:02:29 +0100 |
commit | eec5409a69054cf21214c3f5846ec0310fcb8228 (patch) | |
tree | 94ea1252280cbf32ebfe81d3a95e00f1e81fc37a /scripts | |
parent | 18b7363a699c0b5a4bf59d2b320dfc2b84dc4e67 (diff) |
installation: allow profile modification to be skipped (#1072)
The current behaviour modifies the first writeable file from amongst
.bash_profile, .bash_login and .profile. So .bash_profile (if it is
writable) would be modified even if a user has already sourced nix.sh
in, say, .profile.
This commit introduces a new environment variable,
NIX_INSTALLER_NO_MODIFY_PROFILE. If this is set during installation,
then the modifications are unconditionally skipped.
This is useful for users who have a manually curated set of dotfiles
that they are porting to a new machine. In such scenarios, nix.sh is
already sourced at a place where the user prefers. Without this
change, the nix installer would insist on modifying .bash_profile if
it exists.
This commit also add documentations for both the current behaviour and
the new override.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/install-nix-from-closure.sh | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/scripts/install-nix-from-closure.sh b/scripts/install-nix-from-closure.sh index 3b8c97ed2..fd38a4528 100644 --- a/scripts/install-nix-from-closure.sh +++ b/scripts/install-nix-from-closure.sh @@ -89,21 +89,25 @@ if [ -z "$_NIX_INSTALLER_TEST" ]; then $nix/bin/nix-channel --update nixpkgs fi -# Make the shell source nix.sh during login. -p=$HOME/.nix-profile/etc/profile.d/nix.sh - added= -for i in .bash_profile .bash_login .profile; do - fn="$HOME/$i" - if [ -w "$fn" ]; then - if ! grep -q "$p" "$fn"; then - echo "modifying $fn..." >&2 - echo "if [ -e $p ]; then . $p; fi # added by Nix installer" >> $fn +if [ -z "$NIX_INSTALLER_NO_MODIFY_PROFILE" ]; then + + # Make the shell source nix.sh during login. + p=$HOME/.nix-profile/etc/profile.d/nix.sh + + for i in .bash_profile .bash_login .profile; do + fn="$HOME/$i" + if [ -w "$fn" ]; then + if ! grep -q "$p" "$fn"; then + echo "modifying $fn..." >&2 + echo "if [ -e $p ]; then . $p; fi # added by Nix installer" >> $fn + fi + added=1 + break fi - added=1 - break - fi -done + done + +fi if [ -z "$added" ]; then cat >&2 <<EOF |