# Maintainer: Scott Jones <scottajones@gmail.com>
# Ported from omarchy-mac/omarchy-pkgs-aarch64 pkgbuilds/omarchy-mac at 02ed7b250f7edcf7c5f748acaf7b21ef0a764e9d.

pkgname=omarchy-mac
# pkgver matches omarchy-mac/version at _commit. Bump pkgrel to re-pin or
# rebuild the same add-on version; reset it to 1 when pkgver increases.
pkgver=0.1.0
pkgrel=12
pkgdesc='Apple Silicon configuration and support services for Omarchy'
arch=('aarch64')
groups=('omarchy-platform-apple-silicon')
# Owns /usr/share/omarchy-platform: one platform package per machine. Nothing
# may depend on omarchy-platform; the provide exists only for the conflict.
provides=('omarchy-platform')
conflicts=('omarchy-platform')
url='https://github.com/omacom/omarchy-mac-pkgs'
license=('MIT')
makedepends=('git' 'findutils')
checkdepends=('diffutils' 'python' 'systemd')
# An exact omarchy-mac-pkgs main commit, never a branch.
_commit=2a3ed89eb20c5695f6291698b6646a49f8f6489d
source=("omarchy-mac-pkgs::git+https://github.com/omacom/omarchy-mac-pkgs.git#commit=${_commit}")
sha256sums=('ab951984268adadff8352009f63f1b001c3b09d14d47454b9efe06a54b3019ab')

prepare() {
  # Tests and staging must not be able to read the other package's tree.
  rm -rf "$srcdir/addon"
  cp -a "$srcdir/omarchy-mac-pkgs/omarchy-mac" "$srcdir/addon"
  [[ $(<"$srcdir/addon/version") == "$pkgver" ]]
  [[ $(git -C "$srcdir/omarchy-mac-pkgs" rev-parse HEAD) == "$_commit" ]]
}

check() {
  "$srcdir/addon/test/all"
}

package() {
  # Runtime-only: the builder does not need the Omarchy desktop to stage or
  # test the add-on. What every Mac needs comes from here, so an image's first
  # boot has it offline and no owner can remove it: the speaker stack (whose
  # speakersafetyd unit this package presets), audio routing, the GPU's Vulkan
  # driver and the keyring of the Asahi repository the platform root names.
  # The runtime's Apple package list keeps the removable defaults (video
  # decode, wf-recorder, widevine, asahi-bless).
  depends=('omarchy' 'bash' 'coreutils' 'diffutils' 'grep' 'sed' 'gawk' 'systemd' 'pciutils' 'kmod'
           'mkinitcpio' 'networkmanager' 'iwd' 'python' 'pipewire' 'pipewire-pulse' 'libpulse' 'wireplumber'
           'asahi-audio' 'speakersafetyd' 'alsa-ucm-conf-asahi' 'rtkit' 'pipewire-alsa'
           'vulkan-asahi' 'asahi-alarm-keyring')

  "$srcdir/addon/install" "$pkgdir"
  install -Dm644 "$srcdir/addon/README.md" "$pkgdir/usr/share/doc/$pkgname/README.md"
  install -Dm644 "$srcdir/addon/ORIGINS.md" "$pkgdir/usr/share/doc/$pkgname/ORIGINS.md"
  printf '%s\n' "$_commit" >"$pkgdir/usr/share/omarchy-mac/source-revision"
}
