# HyprCosmic, as one Arch package.
#
# There is no build() here, and no source array. This PKGBUILD packages a tree
# that `just install` has already staged, which tools/make-packages.sh points at
# through $HYPRCOSMIC_STAGEDIR. The reasoning is in packaging/fedora/hyprcosmic.spec
# and applies identically: building 27 Rust components a second time under
# makepkg, to produce bytes that already exist, costs hours and creates a way
# for the packaged desktop and the built one to drift apart.
#
# The consequence, same as there: this package is only valid on the Arch that
# built it. make-packages.sh builds it inside archlinux:base-devel so that is a
# current Arch rather than whatever the host is.

pkgname=hyprcosmic
pkgver=${HYPRCOSMIC_VERSION:-0.1.0}
pkgrel=1
pkgdesc="COSMIC configured in Hyprland's idiom, with a HyDE shell"
arch=('x86_64')
url="https://github.com/outbackdingo/hyprcosmic"
license=('GPL-3.0-only')

# cosmic-session is COSMIC itself, which this runs on rather than replaces: one
# entry pulls the whole desktop, and cosmic-settings, cosmic-osd, the portal and
# the rest are taken from the repositories at the version they were tested at.
#
# The rest is the HyDE shell. Without those the session starts to a blank
# screen: no bar, no launcher, no wallpaper.
depends=('cosmic-session' 'waybar' 'rofi-wayland' 'wayland' 'libxkbcommon'
         'libinput' 'seatd' 'mesa' 'pixman' 'libdisplay-info' 'systemd-libs')

# awww is in the AUR rather than in the repositories, so it cannot be a hard
# depends without making the package uninstallable for anyone who has not built
# it. Without it there is no wallpaper, which is recoverable; an unsatisfiable
# dependency is not.
optdepends=('awww: wallpaper daemon, required for HyDE theme wallpapers'
            'ttf-nerd-fonts-symbols: glyphs the waybar config draws with'
            'qt5ct: Qt application theming to match the GTK theme')

# No conflicts and no provides, deliberately. This installs beside COSMIC: its
# binaries are hyprcosmic-comp, hyprcosmic-session and hyprcosmic-conf, and it
# writes no path that cosmic-comp or cosmic-session owns. An earlier revision
# took the cosmic-* names and could not be installed over a COSMIC system
# without erasing the desktop it forked.

options=('!strip' '!debug')

package() {
    # Points at a tree `just install` has already staged. Failing loudly here
    # beats producing an empty package, which is what a bare `cp -a "$unset/."`
    # would do. The workflow sets it; by hand it is
    #   just install "$PWD/stage" /usr
    #   HYPRCOSMIC_STAGEDIR="$PWD/stage" makepkg --nodeps
    if [ -z "$HYPRCOSMIC_STAGEDIR" ] || [ ! -d "$HYPRCOSMIC_STAGEDIR/usr" ]; then
        echo "HYPRCOSMIC_STAGEDIR unset or has no usr/; see .github/workflows/packages.yml" >&2
        return 1
    fi
    cp -a "$HYPRCOSMIC_STAGEDIR/." "$pkgdir/"

    # No desktop-file-validate on the session entry. It rejects DesktopNames,
    # the key a display manager reads to set XDG_CURRENT_DESKTOP, because the
    # Desktop Entry Specification registers keys for application launchers and
    # this is a session file. The copy Fedora ships as cosmic-session-1.5.0-1.fc44
    # fails the identical check -- so this is the validator's gap, not something
    # the fork introduced. The workflow checks what actually matters instead --
    # that Exec names a file this package installs -- against the staged tree,
    # before makepkg sees it.
}
