# Homebrew on macOS.
#
# Useful for sandboxing `brew` in an isolated environment.

minimumLimaVersion: 2.1.0

base:
- template:_images/macos
# Remove this line to disable the mounts
- template:_default/mounts

# The macOS installer seems to require the display device to be present.
video:
  display: "default"

message: |
  The user password for GUI session is stored in the `~/password` file in the guest.
  Consider changing it after the first login.

provision:
- mode: data
  path: /usr/local/bin/lima-sudo-askpass.sh
  permissions: 755
  content: |
    #!/bin/sh
    set -eu
    # This script is expected to be used only for the initial setup.
    # This script stops working after the user changes the password.
    cat "$HOME/password"
- mode: user
  script: |
    #!/bin/bash
    set -eux -o pipefail
    [ -e /opt/homebrew ] && exit 0
    curl -o homebrew-install.sh -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
    SUDO_ASKPASS=/usr/local/bin/lima-sudo-askpass.sh NONINTERACTIVE=1 /bin/bash homebrew-install.sh
    rm -f homebrew-install.sh
    # No /etc/profile.d on macOS
    echo >> ~/.zprofile
    echo 'eval "$(/opt/homebrew/bin/brew shellenv zsh)"' >> ~/.zprofile
    echo >> ~/.bash_profile
    echo 'eval "$(/opt/homebrew/bin/brew shellenv bash)"' >> ~/.bash_profile
