diff --git a/.chezmoiscripts/.00_helpers.sh b/.chezmoiscripts/.00_helpers.sh index 0002bd6..9174b61 100755 --- a/.chezmoiscripts/.00_helpers.sh +++ b/.chezmoiscripts/.00_helpers.sh @@ -43,6 +43,10 @@ is_linux() { [[ $OSTYPE = linux* ]] } +is_arm64() { + test "$(uname -m)" = "arm64" +} + is_github_codespace() { local -r bool="$(chezmoi execute-template '{{ get .meta.is "github_codespace" }}')" test "${bool}" = "true" diff --git a/.chezmoiscripts/.10_init.darwin.sh b/.chezmoiscripts/.10_init.darwin.sh index 9d24b37..4a00977 100755 --- a/.chezmoiscripts/.10_init.darwin.sh +++ b/.chezmoiscripts/.10_init.darwin.sh @@ -10,6 +10,11 @@ ensure_command_line_tools() { echo "installing command line tools" xcode-select --install fi + + if is_arm64; then + echo "installing rosetta" + /usr/sbin/softwareupdate --install-rosetta --agree-to-license + fi } ensure_homebrew() { @@ -17,6 +22,14 @@ ensure_homebrew() { echo "installing homebrew" bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" fi + + if is_arm64; then + local homebrew_bin="/opt/homebrew/bin" + if ! cat /etc/paths | grep -q "${homebrew_bin}"; then + echo "setting up homebrew binary path for gui apps" + echo -e "${homebrew_bin}\n$(cat /etc/paths)" | sudo tee /etc/paths > /dev/null + fi + fi } ensure_darwin diff --git a/.chezmoiscripts/.20_setup.darwin.sh b/.chezmoiscripts/.20_setup.darwin.sh index c55bac8..6dae5d9 100755 --- a/.chezmoiscripts/.20_setup.darwin.sh +++ b/.chezmoiscripts/.20_setup.darwin.sh @@ -31,8 +31,6 @@ setup_brew_packages() { $(brew --prefix ncurses)/bin/infocmp -x "${term_name}" > "/tmp/${term_name}.info" tic -x -o "${HOME}/.terminfo" -e "${term_name}" "/tmp/${term_name}.info" } - update_terminfo_database alacritty - update_terminfo_database alacritty-direct update_terminfo_database tmux update_terminfo_database tmux-256color @@ -77,8 +75,6 @@ setup_brew_packages() { brew "grc" brew "jq" brew "lf" - brew "luajit", args: ["HEAD"] - brew "neovim", args: ["HEAD"] brew "openssh" brew "p7zip" brew "perl" @@ -100,15 +96,12 @@ setup_brew_packages() { SUB_TASK "Setup Programming Language Version Managers" brewfile=' - tap "rbenv/tap" - brew "autoconf" brew "openssl@1.1" brew "pkg-config" brew "pyenv" brew "pyenv-virtualenv" brew "rbenv" - brew "rbenv/tap/openssl@1.0" brew "readline" brew "ruby-build" brew "sqlite" @@ -117,6 +110,15 @@ setup_brew_packages() { ' brew_bundle + if ! is_arm64; then + brewfile=' + tap "rbenv/tap" + + brew "rbenv/tap/openssl@1.0" + ' + brew_bundle + fi + SUB_TASK "Setup Desktop Apps" brewfile=' cask "alacritty" @@ -128,6 +130,7 @@ setup_brew_packages() { cask "keybase" cask "megasync" cask "postman" + cask "stats" cask "visual-studio-code" cask "vlc" ' @@ -158,9 +161,16 @@ run_setup_scripts() { setup-zed setup-fzf - setup-rust ) + if ! command_exists rustup; then + SETUP_SCRIPTS+=(setup-rust) + fi + + if ! command_exists nvim; then + SETUP_SCRIPTS+=(setup-neovim) + fi + for script in "${SETUP_SCRIPTS[@]}"; do echo "" if command_exists ${script}; then diff --git a/.modules/os.darwin.plugin.sh b/.modules/os.darwin.plugin.sh index 3058006..ab55b57 100644 --- a/.modules/os.darwin.plugin.sh +++ b/.modules/os.darwin.plugin.sh @@ -2,44 +2,56 @@ current_shell="${current_shell:-"$(ps -p$$ -oucomm= | xargs)"}" +is_arm64() { + test "$(uname -m)" = "arm64" +} + manpathmunge() { export MANPATH="${1}:${MANPATH}" } -pathmunge "/usr/local/sbin" +# homebrew +export HOMEBREW_NO_AUTO_UPDATE=1 -brew_prefix="$(brew --prefix)" +if is_arm64; then + ## {{{ start: homebrew on arm64 + eval "$(/opt/homebrew/bin/brew shellenv)" + ## end: homebrew on arm64 }}} +else + export HOMEBREW_PREFIX="$(brew --prefix)" + pathmunge "${HOMEBREW_PREFIX}/sbin" + manpathmunge "${HOMEBREW_PREFIX}/share/man" +fi # gnu programs/tools binaries -pathmunge "${brew_prefix}/opt/gnu-getopt/bin" -pathmunge "${brew_prefix}/opt/util-linux/bin" -pathmunge "${brew_prefix}/opt/util-linux/sbin" -for gnubin_path in ${brew_prefix}/opt/*/libexec/gnubin; do +pathmunge "${HOMEBREW_PREFIX}/opt/gnu-getopt/bin" +pathmunge "${HOMEBREW_PREFIX}/opt/util-linux/bin" +pathmunge "${HOMEBREW_PREFIX}/opt/util-linux/sbin" +for gnubin_path in ${HOMEBREW_PREFIX}/opt/*/libexec/gnubin; do pathmunge "${gnubin_path}" done # gnu programs/tools manpage -manpathmunge "${brew_prefix}/opt/gnu-getopt/share/man" -manpathmunge "${brew_prefix}/opt/util-linux/share/man" -for gnuman_path in ${brew_prefix}/opt/*/libexec/gnuman; do +manpathmunge "${HOMEBREW_PREFIX}/opt/gnu-getopt/share/man" +manpathmunge "${HOMEBREW_PREFIX}/opt/util-linux/share/man" +for gnuman_path in ${HOMEBREW_PREFIX}/opt/*/libexec/gnuman; do manpathmunge "${gnuman_path}" done # google-cloud-sdk -if [[ -d "${brew_prefix}/Caskroom/google-cloud-sdk" ]]; then - pathmunge "${brew_prefix}/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin" - . "${brew_prefix}/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.${current_shell}.inc" +if [[ -d "${HOMEBREW_PREFIX}/Caskroom/google-cloud-sdk" ]]; then + pathmunge "${HOMEBREW_PREFIX}/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin" + . "${HOMEBREW_PREFIX}/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.${current_shell}.inc" fi # openssl -DARWIN_OPENSSL_VERSION="${DARWIN_OPENSSL_VERSION:-"1.1"}" -brew_openssl_prefix="$(brew --prefix openssl@${DARWIN_OPENSSL_VERSION})" -pathmunge "${brew_openssl_prefix}/bin" -export CFLAGS="-I${brew_openssl_prefix}/include" -export CPPFLAGS="-I${brew_openssl_prefix}/include" -export LDFLAGS="-L${brew_openssl_prefix}/lib" -export PKG_CONFIG_PATH="${brew_openssl_prefix}/lib/pkgconfig" -unset brew_openssl_prefix - -# homebrew -export HOMEBREW_NO_AUTO_UPDATE=1 +if ! is_arm64; then + DARWIN_OPENSSL_VERSION="${DARWIN_OPENSSL_VERSION:-"1.1"}" + brew_openssl_prefix="$(brew --prefix openssl@${DARWIN_OPENSSL_VERSION})" + pathmunge "${brew_openssl_prefix}/bin" + export CFLAGS="-I${brew_openssl_prefix}/include" + export CPPFLAGS="-I${brew_openssl_prefix}/include" + export LDFLAGS="-L${brew_openssl_prefix}/lib" + export PKG_CONFIG_PATH="${brew_openssl_prefix}/lib/pkgconfig" + unset brew_openssl_prefix +fi diff --git a/.modules/zsh/plugins/os.darwin/generate.sh b/.modules/zsh/plugins/os.darwin/generate.sh new file mode 100755 index 0000000..29b7420 --- /dev/null +++ b/.modules/zsh/plugins/os.darwin/generate.sh @@ -0,0 +1,34 @@ +# shellcheck shell=zsh + +__generated_file="$(dirname $(realpath $0))/os.darwin.plugin.zsh" + +rm -f "${__generated_file}" +touch "${__generated_file}" + +if test "$(uname -m)" != "arm64"; then + exit 0 +fi + +homebrew_setup_on_arm64() { + local -r marker_start=" ## {{{ start: homebrew on arm64" + local -r marker_end=" ## end: homebrew on arm64 }}}" + + sed -e "/${marker_start}/,/${marker_end}/{//!d;}" -i -- "${__generated_file}" + + local -r homebrew="/opt/homebrew/bin/brew" + + local marker_start_linenr=$(( $(sed -n "/${marker_start}/=" "${__generated_file}") )) + + local content="$({ head -n $(( marker_start_linenr )) "${__generated_file}"; echo "$( + $homebrew shellenv | sed 's/^/ /' + echo "\n FPATH=\"\${HOMEBREW_PREFIX}/share/zsh/site-functions:\${FPATH}\"" + )"; tail -n +$(( marker_start_linenr + 1 )) ${__generated_file}; })" + + echo "${content}" > "${__generated_file}" +} + +cat "${DOTFILES_MODULES}/os.darwin.plugin.sh" > "${__generated_file}" + +homebrew_setup_on_arm64 + +unset __generated_file diff --git a/README.md b/README.md index 5787616..c352eff 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,16 @@ chezmoi apply ### macOS Notes -**Install `python<3.7` with `openssl@1.0`**: +#### Build with `openssl@1.0` + +Run shell in a clean environment with `DARWIN_OPENSSL_VERSION=1.0`. For example: ```sh env DARWIN_OPENSSL_VERSION=1.0 zsh -i -c 'PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA=openssl@1.0 pyenv install ' ``` +_**NOTE**: Not supported on ARM64 (Apple Silicon)._ + ## Resources - [chezmoi](https://www.chezmoi.io) diff --git a/private_dot_config/zsh/dot_zshrc.tmpl b/private_dot_config/zsh/dot_zshrc.tmpl index ee16d79..8c0439b 100644 --- a/private_dot_config/zsh/dot_zshrc.tmpl +++ b/private_dot_config/zsh/dot_zshrc.tmpl @@ -73,7 +73,8 @@ zed load github.com/zpm-zsh/ls zed load "${DOTFILES_MODULES}/aliases.sh" zed load "${DOTFILES_MODULES}/helpers.sh" {{ if eq .chezmoi.os "darwin" -}} - zed load "${DOTFILES_MODULES}/os.darwin.plugin.sh" + zed load "${DOTFILES_MODULES}/zsh/plugins/os.darwin" \ + onpull:'./generate.sh' {{ end -}} zed load "${DOTFILES_MODULES}/gpg.plugin.sh"