Page MenuHomePhabricator

[Nix] Write Nix path to user shell files upon install
ClosedPublic

Authored by jon on Jan 3 2023, 10:39 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Sep 18, 9:31 PM
Unknown Object (File)
Wed, Sep 18, 9:31 PM
Unknown Object (File)
Wed, Sep 18, 9:30 PM
Unknown Object (File)
Wed, Sep 18, 9:19 PM
Unknown Object (File)
Tue, Sep 17, 2:32 AM
Unknown Object (File)
Sun, Sep 15, 10:16 PM
Unknown Object (File)
Tue, Sep 10, 9:09 PM
Unknown Object (File)
Sun, Sep 8, 9:39 PM
Subscribers

Details

Summary

Avoid situtations where Apple updates "delete" nix from
PATH by adding nix to the PATH of user zsh and bash shells.

~/.zshenv, ~/.profile, ~/.bashrc, and ~/.bash_profile were chosen
to reflect the files that rustup also writes to.

Part of https://linear.app/comm/issue/ENG-2566

Test Plan
./scripts/install_nix.sh

# Should see it emit that it writes to ~/.zshenv
# and potentionally others

# Assert that it was written
cat ~/.zshenv

# Open new shell
echo $PATH

# Nix should have multiple paths if /etc/zshrc still sources Nix logic

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

scripts/install_nix.sh
30–35 ↗(On Diff #20525)

Should we include ~/.zshrc?

ashoat added inline comments.
scripts/install_nix.sh
32–33 ↗(On Diff #20525)

Do we really need both of these?

jon added inline comments.
scripts/install_nix.sh
30–35 ↗(On Diff #20525)

~/.zshenv always gets sourced, and I can avoid having to write to both ~/.zprofile (login shells) and ~/.zshrc (interactive shells).

32–33 ↗(On Diff #20525)

potentially yes. ~/.bash_profile is for a login shell, and ~/.bashrc is for an interactive shells.

Terminal on OS X will by default use a login shell for each new session, so if a user configures bash to be their default interpreter it will only source ~/.bash_profile. If they launch bash from zsh, then it will source ~/.bashrc.

Having the line potentially execute multiple times shouldn't mess with any logic.

jon added inline comments.
scripts/install_nix.sh
32–33 ↗(On Diff #20525)

Should also mention that users can also configure iterm and Terminal to launch as interactive shell. So you can't really make assumptions.

scripts/install_nix.sh
32–33 ↗(On Diff #20525)

Doesn't the default version of .bash_profile on macOS source .bashrc at the start?

scripts/install_nix.sh
32–33 ↗(On Diff #20525)

We would need ~/.bashrc to source ~/.bash_profile for it work in every case.

Once I get home again, I can check the reset m1 what the defaults are (forgot to enable ssh access after resetting last week)

I was just following what rustup does, as I assume they have had many years of refining what files need to be written to.

In D6149#184392, @jon wrote:

I was just following what rustup does, as I assume they have had many years of refining what files need to be written to.

This is really helpful context, would've been great to mention this at the start. Can you link to what you used as inspiration?

ashoat requested changes to this revision.Jan 4 2023, 6:08 PM

(Removing from my queue and passing to @jon's queue with the above question)

This revision now requires changes to proceed.Jan 4 2023, 6:08 PM

During install:

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
...
This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /Users/jon/.profile
  /Users/jon/.bash_profile
  /Users/jon/.bashrc
  /Users/jon/.zshenv

Used the reset m1 to inspect what was written.

This is really helpful context, would've been great to mention this at the start.

It was in the secondary paragraph of the summary.

~/.zshenv, ~/.profile, ~/.bashrc, and ~/.bash_profile were chosen to reflect the files that rustup also writes to.

This revision is now accepted and ready to land.Jan 9 2023, 8:39 AM
This revision was automatically updated to reflect the committed changes.
jon marked an inline comment as done.