# rpi-image-gen build config for the headless audio-endpoint image (arm64).
#
# UNVERIFIED AGAINST THE REAL TOOL — see hosts/audio-endpoint/README.md's
# prominent callout. rpi-image-gen's exact layer/config YAML schema was not
# hands-on validated while writing this (no ARM build environment or the tool
# itself available). This is a best-effort, structurally sound attempt based on
# rpi-image-gen's documented config/layer/device/image directory structure and
# `rpi-image-gen build -c <config>.yaml` invocation. If a real build rejects
# this file:
#   rpi-image-gen layer --list
#   rpi-image-gen layer --describe <name>
# on the actual build host is the authoritative source — adjust the *keys*
# below to match what that reports. The intent behind each section (device
# target, packages, files to inject, which service to enable, and the
# build-time hook) should carry over even if the exact key names don't.

image:
  name: audio-endpoint
  arch: arm64

device:
  # Any 40-pin-header Raspberry Pi works — Zero 2 W is the cheapest that's
  # enough for a single Spotify Connect stream. Change if targeting a
  # different specific model.
  board: raspberrypi-zero2w
  os: bookworm

# Base packages the image needs regardless of which Spotify Connect backend
# ends up installed (see scripts/install-spotify-connect.sh, run via the
# hook below) — alsa-utils for the userspace ALSA tools, no PipeWire/desktop
# stack at all (see hosts/audio-endpoint/README.md's "Audio output" section).
packages:
  - alsa-utils

# Files copied into the target rootfs. Paths are relative to this config file.
files:
  - src: ../../configs/spotify-connect.service
    dst: /etc/systemd/system/spotify-connect.service
  - src: ../../configs/spotify-connect-start
    dst: /usr/local/bin/spotify-connect-start
    mode: "0755"
  - src: ../systemd/spotify-connect.service.d/10-alsa-device.conf
    dst: /etc/systemd/system/spotify-connect.service.d/10-alsa-device.conf
  - src: ../config.txt.d/hifiberry-amp2.txt
    dst: /boot/firmware/config.txt
    append: true

# Runs chrooted into the target rootfs at build time — the apt-first/
# documented-fallback Spotify Connect install (see that script's own header)
# plus enabling the resulting unit. This is the single most likely key name
# to need adjusting against the real tool's hook mechanism.
hooks:
  chroot:
    - ../scripts/install-spotify-connect.sh

# REWRITTEN PER ROOM AT BUILD TIME. tools/build-audio-endpoint-image-arm64.sh
# substitutes the endpoint's hostname from CoreSystemConfig.json into the `set:`
# line below and writes a generated-<hostname>.yaml alongside this file; this
# value is only the fallback for a hand-run build.
#
# Don't edit it to a room name — that would be a second place a room name lives,
# which is the duplication the whole tools/ build system exists to remove. Add
# the room to the config's "audio_endpoints" array instead.
#
# The hostname matters beyond identification: spotify-connect-start reads
# $(hostname) at service-start time, so this is also the room's Spotify Connect
# device name.
hostname:
  set: audio-endpoint
