From f765fcd6331a97e798a4315f71df19d12b6c46d4 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Sun, 4 Feb 2024 12:23:25 +0800 Subject: [PATCH] fix: `conda init` failed because ~/.zshrc not modifiable --- home/darwin/shell.nix | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/home/darwin/shell.nix b/home/darwin/shell.nix index 6fe3a707..b4f107f8 100644 --- a/home/darwin/shell.nix +++ b/home/darwin/shell.nix @@ -2,6 +2,23 @@ let envExtra = '' export PATH="$PATH:/opt/homebrew/bin:/usr/local/bin" ''; + initExtra = '' + arch=$(uname -m) + + if [ "aarch64" = "$arch" ] || [ "arm64" = "$arch" ]; then + # >>> (miniforge)conda initialize >>> + # !! Contents within this block are managed by 'conda init' !! + if [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then + . "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" + else + export PATH="/opt/homebrew/Caskroom/miniforge/base/bin:$PATH" + fi + # <<< conda initialize <<< + elif [[ "x86_64" = "$arch" ]]; then + # do nothing + true + fi + ''; in { # Homebrew's default install location: # /opt/homebrew for Apple Silicon @@ -10,10 +27,10 @@ in { # in /opt/homebrew for Apple Silicon and /usr/local for Rosetta 2 to coexist and use bottles. programs.bash = { enable = true; - bashrcExtra = envExtra; + bashrcExtra = envExtra + initExtra; }; programs.zsh = { enable = true; - inherit envExtra; + inherit envExtra initExtra; }; }