# Shared forgeOS packages. build-packages.sh supplies files.tar and its checksum.
pkgbase=forgeos
pkgname=('forgeos-release' 'forgeos-keyring' 'forgeos-base' 'forgeos-desktop' 'forgeos-upgrade' 'forgeos-installer' 'forgeos-nvidia'
	'forgeos-tuning' 'forgeos-tweaks' 'forgeos-calendar')
pkgver=2026.10.12
pkgrel=48
pkgdesc='Shared identity, desktop, upgrade, installer, and NVIDIA policy for forgeOS'
arch=('any')
options=('!debug')
# forgeos-tweaks renders its default theme files at package time.
makedepends=('python')
source=('files.tar')

package_forgeos-release() {
	pkgdesc='Operating system identity for forgeOS'
	depends=('filesystem')
	backup=('etc/os-release')

	# Arch owns /usr/lib/os-release. /etc/os-release is the distro override.
	install -Dm0644 "$srcdir/files/release/os-release" "$pkgdir/etc/os-release"
}

package_forgeos-keyring() {
	pkgdesc='Public key that signs the forgeOS package repository (forgeos.isengard.no)'
	depends=('pacman')
	# pacman-key --populate forgeos on install and upgrade.
	install=forgeos-keyring.install

	local keyring_file
	for keyring_file in forgeos.gpg forgeos-trusted forgeos-revoked; do
		install -Dm0644 "$srcdir/files/keyring/$keyring_file" "$pkgdir/usr/share/pacman/keyrings/$keyring_file"
	done
}

package_forgeos-base() {
	pkgdesc='Base system dependencies and package configuration for forgeOS'
	# The installed pacman.conf lists [forgeos], so the key that signs it comes along.
	depends=("forgeos-release=$pkgver-$pkgrel" "forgeos-keyring=$pkgver-$pkgrel" "forgeos-upgrade=$pkgver-$pkgrel"
		"forgeos-tuning=$pkgver-$pkgrel" 'base' 'linux-firmware' 'networkmanager' 'sudo' 'scx-scheds' 'scx-tools' 'inetutils')

	# The installer applies this template; pacman retains ownership of its config.
	install -Dm0644 "$srcdir/files/base/pacman.conf" "$pkgdir/usr/share/forgeos/pacman.conf"
	install -Dm0644 "$srcdir/files/base/profile/00-forgeos-local-bin.sh" "$pkgdir/etc/profile.d/00-forgeos-local-bin.sh"
}

package_forgeos-desktop() {
	pkgdesc='Hyprland desktop dependencies and default user configuration for forgeOS'
	depends=(
		"forgeos-base=$pkgver-$pkgrel"
		# The default configs in /etc/skel include the theme files forgeos-tweaks generates.
		"forgeos-tweaks=$pkgver-$pkgrel"
		# The top bar clock opens the calendar popup.
		"forgeos-calendar=$pkgver-$pkgrel"

		# --- Hyprland compositor + ecosystem ---------------------------------------
		hyprland
		hyprpaper
		hyprlock
		hypridle
		hyprcursor

		# --- Boot splash (forgeOS Plymouth theme; the installer enables it) ---------
		plymouth

		# --- Graphical login (greetd runs the Quickshell greeter in a bare Hyprland) --
		greetd
		quickshell
		hyprpolkitagent
		xdg-desktop-portal-hyprland
		xdg-desktop-portal-gtk

		# --- Bar / launcher / terminal / notifications -----------------------------
		waybar
		wofi
		kitty
		zsh
		zsh-completions
		zsh-autosuggestions
		zsh-syntax-highlighting
		mako

		# --- Desktop utilities -----------------------------------------------------
		grim
		slurp
		satty
		wl-clipboard
		cliphist
		brightnessctl
		btop
		# Displays: monitor layout GUI; saves ~/.config/hypr/monitors.lua, which hyprland.lua loads.
		nwg-displays
		playerctl
		polkit
		xdg-user-dirs
		xdg-utils

		# --- Graphics + Wayland app support ----------------------------------------
		mesa
		lib32-mesa
		vulkan-icd-loader
		lib32-vulkan-icd-loader
		xorg-xwayland
		qt5-wayland
		qt6-wayland

		# --- Audio (PipeWire) ------------------------------------------------------
		pipewire
		pipewire-alsa
		pipewire-pulse
		wireplumber
		pipewire-jack
		rtkit
		alsa-utils
		pavucontrol

		# --- Network (NetworkManager tray applet; live ISO uses NetworkManager too) --
		network-manager-applet
		zerotier-one

		# --- Bluetooth (blueman tray applet; PipeWire plays to Bluetooth speakers) ---
		bluez
		bluez-utils
		blueman

		# --- Applications ----------------------------------------------------------
		# Browsers (Vivaldi, Firefox) are chosen in the installer; the ISO adds Vivaldi.
		thunar
		thunar-volman
		tumbler
		gvfs
		imv
		mpv
		pinta
		halloy
		keepassxc
		# Remote desktop; RDP and VNC are optional plugins in Arch, so name them.
		remmina
		freerdp
		libvncserver

		# --- Fonts + theming -------------------------------------------------------
		ttf-jetbrains-mono-nerd
		noto-fonts
		noto-fonts-emoji
		noto-fonts-cjk
		papirus-icon-theme
		adwaita-icon-theme
		# Adwaita-dark for GTK3 apps (blueman, pavucontrol, thunar); dark mode needs it.
		gnome-themes-extra
	)

	backup=(
		'etc/pam.d/forgeos-lock'
		'etc/profile.d/forgeos-desktop.sh'
		'etc/skel/.zshrc'
		'etc/skel/.config/gtk-3.0/settings.ini'
		'etc/skel/.config/mimeapps.list'
		'etc/skel/.config/gtk-4.0/settings.ini'
		'etc/skel/.config/hypr/hypridle.conf'
		'etc/skel/.config/hypr/hyprland.lua'
		'etc/skel/.config/hypr/hyprlock.conf'
		'etc/skel/.config/kitty/kitty.conf'
		'etc/skel/.config/mako/config'
		'etc/skel/.config/waybar/config.jsonc'
		'etc/skel/.config/waybar/style.css'
		'etc/skel/.config/wofi/config'
	)
	local configuration_file
	cd "$srcdir/files/desktop/.config"
	while IFS= read -r -d '' configuration_file; do
		configuration_file="${configuration_file#./}"
		install -Dm0644 "$configuration_file" "$pkgdir/etc/skel/.config/$configuration_file"
	done < <(find . -type f -print0 | sort -z)

	install -Dm0644 "$srcdir/files/desktop/home/.zshrc" "$pkgdir/etc/skel/.zshrc"
	install -Dm0644 "$srcdir/files/desktop/pipewire/10-forgeos-sample-rates.conf" "$pkgdir/usr/share/pipewire/pipewire.conf.d/10-forgeos-sample-rates.conf"
	install -Dm0644 "$srcdir/files/desktop/share/wallpaper.png" "$pkgdir/usr/share/forgeos/wallpaper.png"
	# One desktop wallpaper per Tweaks preset (tweaks/defaults.json preset_wallpapers).
	# hyprpaper.conf itself is generated by forgeos-tweaks.
	local wallpaper_file
	for wallpaper_file in "$srcdir"/files/desktop/share/wallpapers/*.png; do
		install -Dm0644 "$wallpaper_file" "$pkgdir/usr/share/forgeos/wallpapers/${wallpaper_file##*/}"
	done
	install -Dm0644 "$srcdir/files/desktop/share/logo.png" "$pkgdir/usr/share/forgeos/logo.png"
	# Greeter, lock screen and overview share one Quickshell folder: Quickshell only
	# finds components (ForgeLogo.qml) inside the folder of the file it runs.
	local quickshell_file
	for quickshell_file in "$srcdir"/files/quickshell/*.qml; do
		install -Dm0644 "$quickshell_file" "$pkgdir/usr/share/forgeos/quickshell/${quickshell_file##*/}"
	done
	install -Dm0755 "$srcdir/files/lock/forgeos-lock" "$pkgdir/usr/bin/forgeos-lock"
	install -Dm0644 "$srcdir/files/lock/forgeos-lock.pam" "$pkgdir/etc/pam.d/forgeos-lock"
	install -Dm0644 "$srcdir/files/greeter/hyprland.lua" "$pkgdir/usr/share/forgeos/greeter/hyprland.lua"
	install -Dm0755 "$srcdir/files/greeter/forgeos-greeter" "$pkgdir/usr/lib/forge/greeter"
	install -Dm0644 "$srcdir/files/greeter/10-forgeos-retain-splash.conf" "$pkgdir/usr/lib/systemd/system/plymouth-quit.service.d/10-forgeos-retain-splash.conf"
	local splash_file
	for splash_file in "$srcdir"/files/splash/*; do
		install -Dm0644 "$splash_file" "$pkgdir/usr/share/plymouth/themes/forgeos/${splash_file##*/}"
	done
	install -Dm0644 "$srcdir/files/desktop/share/keybinds.md" "$pkgdir/usr/share/forgeos/keybinds.md"
	install -Dm0755 "$srcdir/files/desktop/bin/forgeos-session" "$pkgdir/usr/bin/forgeos-session"
	install -Dm0755 "$srcdir/files/desktop/bin/forgeos-power-menu" "$pkgdir/usr/bin/forgeos-power-menu"
	install -Dm0644 "$srcdir/files/desktop/profile/forgeos-desktop.sh" "$pkgdir/etc/profile.d/forgeos-desktop.sh"
	install -Dm0755 "$srcdir/files/desktop/bin/forgeos-graphics-devices" "$pkgdir/usr/lib/forge/graphics-devices"
	install -Dm0644 "$srcdir/files/desktop/share/graphics.json" "$pkgdir/usr/share/forgeos/graphics.json"
}

package_forgeos-tweaks() {
	pkgdesc='forgeOS Tweaks: theme colors, fonts and sizes for the forgeOS desktop (forge tweaks)'
	depends=("forgeos-upgrade=$pkgver-$pkgrel" 'python>=3.11' 'quickshell' 'procps-ng')

	install -Dm0644 "$srcdir/files/tweaks/defaults.json" "$pkgdir/usr/share/forgeos/tweaks/defaults.json"
	install -Dm0644 "$srcdir/files/tweaks/forgeos-tweaks.desktop" "$pkgdir/usr/share/applications/forgeos-tweaks.desktop"
	local module_file
	for module_file in "$srcdir"/files/tweaks/lib/forge_tweaks/*.py; do
		install -Dm0644 "$module_file" "$pkgdir/usr/lib/forge/forge_tweaks/${module_file##*/}"
	done
	# Default theme files for new accounts, and the resolved default theme the
	# Quickshell screens fall back to (the greeter always uses it).
	PYTHONPATH="$srcdir/files/tweaks/lib" FORGE_TWEAKS_DEFAULTS="$srcdir/files/tweaks/defaults.json" 		python -B -c 'import sys; from forge_tweaks import cli; sys.exit(cli.main(sys.argv[1:]))' 		render-defaults "$pkgdir/etc/skel/.config" "$pkgdir/usr/share/forgeos/tweaks/theme-default.json"
}

package_forgeos-calendar() {
	pkgdesc='forgeOS Calendar: Google Calendar in the forgeOS top bar, read-only (forge calendar)'
	depends=("forgeos-upgrade=$pkgver-$pkgrel" 'python>=3.11' 'quickshell' 'khal' 'vdirsyncer'
		'python-aiohttp-oauthlib' 'kitty')

	install -Dm0755 "$srcdir/files/calendar/forgeos-calendar" "$pkgdir/usr/bin/forgeos-calendar"
	install -Dm0644 "$srcdir/files/calendar/forgeos-calendar.desktop" "$pkgdir/usr/share/applications/forgeos-calendar.desktop"
	# Beside the other forgeOS Quickshell screens, for the shared Theme.qml.
	install -Dm0644 "$srcdir/files/calendar/calendar.qml" "$pkgdir/usr/share/forgeos/quickshell/calendar.qml"
	install -Dm0644 "$srcdir/files/calendar/systemd/forgeos-calendar-sync.service" "$pkgdir/usr/lib/systemd/user/forgeos-calendar-sync.service"
	install -Dm0644 "$srcdir/files/calendar/systemd/forgeos-calendar-sync.timer" "$pkgdir/usr/lib/systemd/user/forgeos-calendar-sync.timer"
	local module_file
	for module_file in "$srcdir"/files/calendar/lib/forge_calendar/*.py; do
		install -Dm0644 "$module_file" "$pkgdir/usr/lib/forge/forge_calendar/${module_file##*/}"
	done
}

package_forgeos-upgrade() {
	pkgdesc='Btrfs snapshot and isolated trial upgrade workflow for forgeOS'
	depends=('python>=3.11' 'btrfs-progs' 'pacman' 'util-linux' 'coreutils' 'systemd' 'mkinitcpio' 'sudo')
	backup=('etc/forge/system-upgrade.json')

	install -Dm0755 "$srcdir/files/upgrade/bin/forge" "$pkgdir/usr/bin/forge"
	install -Dm0644 "$srcdir/files/upgrade/config/system-upgrade.json" "$pkgdir/etc/forge/system-upgrade.json"
	install -Dm0644 "$srcdir/files/upgrade/README.md" "$pkgdir/usr/share/doc/forgeos-upgrade/README.md"
	local module_file
	cd "$srcdir/files/upgrade/lib"
	while IFS= read -r -d '' module_file; do
		install -Dm0644 "$module_file" "$pkgdir/usr/lib/forge/$module_file"
	done < <(find forge_upgrade -type f -name '*.py' -print0 | sort -z)
}

package_forgeos-installer() {
	pkgdesc='Interactive whole-disk Btrfs installer for the forgeOS live medium'
	depends=('python>=3.11' 'arch-install-scripts' 'btrfs-progs' 'cryptsetup' 'dosfstools'
		'gptfdisk' 'parted' 'util-linux' 'systemd>=258' 'pacman' 'coreutils' 'kbd' 'tzdata'
		'sudo' 'kitty' "forgeos-desktop=$pkgver-$pkgrel")

	install -Dm0755 "$srcdir/files/installer/bin/forgeos-install" "$pkgdir/usr/bin/forgeos-install"
	install -Dm0644 "$srcdir/files/installer/share/forgeos-install.desktop" "$pkgdir/usr/share/applications/forgeos-install.desktop"
	install -Dm0644 "$srcdir/files/installer/README.md" "$pkgdir/usr/share/doc/forgeos-installer/README.md"
	local module_file
	cd "$srcdir/files/installer/lib"
	while IFS= read -r -d '' module_file; do
		install -Dm0644 "$module_file" "$pkgdir/usr/lib/forge/$module_file"
	done < <(find forge_installer -type f -name '*.py' -print0 | sort -z)
}

package_forgeos-nvidia() {
	pkgdesc='Modern NVIDIA graphics, PRIME offload, and Wayland boot configuration for forgeOS'
	# The kernel module comes from NVIDIA-MODULE: nvidia-open-dkms (installed systems,
	# built for linux-forgeos) or linux-forgeos-nvidia-open (live ISO, prebuilt).
	depends=('NVIDIA-MODULE' 'nvidia-utils>=595' 'nvidia-settings' 'lib32-nvidia-utils' 'nvidia-prime'
		'vulkan-icd-loader' 'lib32-vulkan-icd-loader' 'mkinitcpio')
	backup=('etc/modprobe.d/forgeos-nvidia.conf' 'etc/mkinitcpio.conf.d/20-forgeos-nvidia.conf')

	install -Dm0644 "$srcdir/files/nvidia/modprobe/forgeos-nvidia.conf" "$pkgdir/etc/modprobe.d/forgeos-nvidia.conf"
	install -Dm0644 "$srcdir/files/nvidia/mkinitcpio/20-forgeos-nvidia.conf" "$pkgdir/etc/mkinitcpio.conf.d/20-forgeos-nvidia.conf"
	install -Dm0644 "$srcdir/files/nvidia/hooks/95-forgeos-nvidia-initramfs.hook" "$pkgdir/usr/share/libalpm/hooks/95-forgeos-nvidia-initramfs.hook"
	install -Dm0644 "$srcdir/files/nvidia/README.md" "$pkgdir/usr/share/doc/forgeos-nvidia/README.md"
}

package_forgeos-tuning() {
	pkgdesc='Gaming, audio and I/O tuning for forgeOS, from CachyOS-Settings'
	license=('GPL-3.0-only')
	# zram-generator: compressed RAM swap. realtime-privileges: realtime group for DAWs.
	depends=('zram-generator' 'realtime-privileges' 'systemd' 'bash')
	backup=('etc/security/limits.d/20-audio.conf')

	local tuning_file mode
	cd "$srcdir/files/tuning"
	while IFS= read -r -d '' tuning_file; do
		tuning_file="${tuning_file#./}"
		mode=0644
		[[ -x "$tuning_file" || $tuning_file == */xswap-generator || $tuning_file == */audio-pm-ctl ]] && mode=0755
		install -Dm"$mode" "$tuning_file" "$pkgdir/$tuning_file"
	done < <(find usr etc -type f -print0 | sort -z)
	install -Dm0644 upstream-LICENSE.md "$pkgdir/usr/share/licenses/forgeos-tuning/LICENSE.md"
	install -Dm0644 README.md "$pkgdir/usr/share/doc/forgeos-tuning/README.md"
}

sha256sums=('71607822efd9cdb2195c9f21261c128db3a91051d1d711b4f1c5f2d7e415bb8d')
