---
- name: Install base packages
  homebrew:
    name:
      - zsh # Changing shell
      - curl # Installing
      - luarocks # Spacehammer/fennel
      - antigen # Shell config
    state: present

- name: Restore all packages
  command: brew bundle --file=Brewfile
  tags: [brew, extra]

- name: Link emacs
  become: yes
  file:
    state: link
    src: /usr/local/Cellar/emacs-plus@28/28.0.50/Emacs.app
    dest: /Applications/Emacs.app

# - name: Link openssl
#   file:
#     path: /usr/local/lib/{{ item }}.dylib
#     src: /usr/local/opt/openssl/lib/{{ item }}.dylib
#     state: link
#   with_items:
#     - libssl
#     - libcrypto

- name: Add brew zsh as allowed shell
  become: yes
  template:
    src: templates/shells.j2
    dest: /etc/shells
  tags: [zsh]

- name: Set loginshell
  become: true
  shell: chsh -s /usr/local/bin/zsh
  tags: [zsh]

---
- name: Create custom brew cache
  become: yes
  file:
    state: directory
    path: /opt/HomebrewCache
    owner: mattias

- name: Install base packages
  homebrew:
    name:
      - zsh # Changing shell
      - curl # Installing
      - luarocks # Spacehammer/fennel
      - antigen # Shell config
    state: present
  env:
    HOMEBREW_CACHE: /opt/HomebrewCache

- name: Restore all packages
  command: brew bundle --file=Brewfile
  tags: [brew, extra]
  env:
    HOMEBREW_CACHE: /opt/HomebrewCache

- name: Link emacs
  become: yes
  file:
    state: link
    src: /usr/local/Cellar/emacs-plus@28/28.0.50/Emacs.app
    dest: /Applications/Emacs.app

# - name: Link openssl
#   file:
#     path: /usr/local/lib/{{ item }}.dylib
#     src: /usr/local/opt/openssl/lib/{{ item }}.dylib
#     state: link
#   with_items:
#     - libssl
#     - libcrypto

- name: Add brew zsh as allowed shell
  become: yes
  template:
    src: templates/shells.j2
    dest: /etc/shells
  tags: [zsh]

- name: Set loginshell
  become: true
  shell: chsh -s /usr/local/bin/zsh
  tags: [zsh]

Move homebrew cache to /opt
Move homebrew cache to /opt
