# Copyright 2026 Nadeŭka <me+oss@nadevko.cc>
# Distributed under the terms of the GNU General Public License v2
EAPI=8

RUST_MIN_VER=1.95.0
inherit cargo git-r3 tmpfiles

DESCRIPTION='Stylish graphical console greeter for greetd'
HOMEPAGE=https://github.com/tuigreet/tuigreet
EGIT_REPO_URI=https://github.com/${PN}/${PN}.git

LICENSE='Apache-2.0 CC0-1.0 GPL-3 GPL-3+ ISC MIT MPL-2.0 Unicode-3.0 ZLIB'
SLOT=0

IUSE='+man'

DEPEND='
	acct-group/greetd
	acct-user/greetd
	gui-libs/greetd
'
RDEPEND="${DEPEND}"
BDEPEND='
	virtual/pkgconfig
	man? ( app-text/scdoc )
'

src_unpack() {
	git-r3_src_unpack
	cargo_live_src_unpack
}

src_compile() {
	cargo_src_compile -p tuigreet

	if use man; then
		scdoc < contrib/man/tuigreet-1.scd > tuigreet.1 ||
			die 'Failed to generate man page with scdoc'
	fi
}

src_install() {
	# bins & wrappers
	cargo_src_install --path crates/tuigreet

	# man pages
	use man && doman tuigreet.1

	# configs
	insinto /etc/tuigreet
	newins contrib/example.config.toml config.toml

	# docs
	einstalldocs

	# permissions & security
	newtmpfiles - ${PN}.conf <<-EOF
		d /var/cache/tuigreet 0755 greetd greetd -
	EOF
}

pkg_postinst() {
	tmpfiles_process ${PN}.conf
}