View Raw Ebuild
# Copyright 2024-2025 JacksonChen666
# Distributed under the terms of the GNU General Public License v2
EAPI=8
inherit go-module systemd tmpfiles
DESCRIPTION="Simple pub-sub notification service"
HOMEPAGE="https://ntfy.sh"
SRC_URI="https://github.com/binwiederhier/ntfy/archive/v${PV}.tar.gz -> ${P}.tar.gz"
# TODO on every version update
GIT_COMMIT=a03a37f
# https://wiki.gentoo.org/wiki/Writing_go_Ebuilds#Vendor_tarball
SRC_URI+=" https://files.jacksonchen666.com/gentoo/${P}-vendor.tar.xz"
# packing node_modules for offline builds
#
# NOTE: this is arch specific because esbuild complained about wrong
# architecture in node_modules (packed in amd64, failed on arm64). when
# adding new architecture support, also modify the src_prepare section, and
# test the full build process.
#
# after `npm ci` in ./web/:
# XZ_OPT='-T0 -9' tar -acf ntfy-2.11.0-node_modules-amd64.tar.xz ntfy-2.11.0/web/node_modules/
#
# TODO: build host architecture instead (web build results should be arch
# independent)
SRC_URI+="
web? (
amd64? ( https://files.jacksonchen666.com/gentoo/${P}-node_modules-amd64.tar.xz )
arm64? ( https://files.jacksonchen666.com/gentoo/${P}-node_modules-arm64.tar.xz )
)
"
# TODO: GPL-2 or later?
LICENSE="|| ( Apache-2.0 GPL-2 )"
# third party deps
#
# for go
# checked on ntfy 2.11.0
# (https://wiki.gentoo.org/wiki/Writing_go_Ebuilds#Licenses)
LICENSE+=" Apache-2.0 MIT BSD BSD-2"
# for node/npm
# checked on ntfy 2.11.0 (npm ci, only packages.json)
#
# find . -name package.json -exec jq -rc --arg filename "{}" \
# 'if has("license") then .license else {"no":$filename} end' "{}" \;
#
# then manually find source of multiple licenses and "no"s. most may be
# subpackages(?) with no license or anything for some reason though
# TODO: licenses in https://github.com/binwiederhier/ntfy/?tab=readme-ov-file#license
LICENSE+="
|| ( AFL-2.1 BSD )
Apache-2.0
BSD-2
BSD
CC0-1.0
CC-BY-4.0
ISC
MIT
|| ( MIT CC0-1.0 )
MPL-2.0
PYTHON
Unlicense
"
SLOT="0"
KEYWORDS="~amd64 ~arm64"
DEPEND="
acct-group/ntfy
acct-user/ntfy
"
RDEPEND="${DEPEND}"
BDEPEND="
doc? (
dev-python/mkdocs
dev-python/mkdocs-material
dev-python/mkdocs-minify-plugin
)
web? (
net-libs/nodejs[npm]
)
${DEPEND}
"
IUSE="+server +web doc test"
RESTRICT="!test? ( test )"
# the web UI assets are bundled with the binary and served by ntfy when
# running the server. building it and then not having a server part is
# pointless, because it's not external.
#
# tests do require the web UI to be built, as that's checked (not
# documentation though).
REQUIRED_USE="
web? ( server )
test? ( server web )
"
# TESTS NOTE (2.12.0): the TestCLI_Access_Grant_And_Publish works, except if
# you have a /etc/ntfy/client.yml or ~/.config/ntfy/client.yml with a
# default server configured inside, which would use the wrong non-testing
# server. therefore ntfy tests should be run in an isolated sandbox (which
# the `ebuild` doesn't do). discussed in
# https://discord.com/channels/874398661709295626/874398661709295629/1379492323364180169
# disabled due to lack of mirrors
RESTRICT+=" mirror"
# see node_modules SRC_URI for more info
RESTRICT+=" network-sandbox"
pkg_pretend() {
if use server && ! use web; then
elog "web USE flag is disabled, there will be no web interface when running the server!"
elog "This will not increase your security."
fi
if use web && ! use doc; then
elog "web USE flag is enabled but doc USE flag isn't, documentation linked on"
elog "the web UI will not be available!"
fi
}
src_configure() {
default
# extracted from goreleaser files
if use server; then
# TODO: unbundling?
GOFLAGS+=" -tags=sqlite_omit_load_extension,osusergo,netgo -ldflags=-linkmode=external -ldflags=-extldflags=-static -ldflags=-s -ldflags=-w"
CGO_ENABLED=1
else
GOFLAGS+=" -tags=noserver"
CGO_ENABLED=0
fi
}
src_prepare() {
default
# packed `node_modules` is unfortunately arch specific, see NOTE near
# SRC_URI for `node_modules`
#if use server && ! ( use amd64 || use arm64 ); then
if use web; then
if [ ! -d "web/node_modules/" ]; then
elog "A packed node_modules is not available for your architecture. npm ci will be"
elog "executed, which will use the network and take a while."
cd web/
npm ci
fi
fi
}
src_compile() {
# web UI placeholder
emake cli-deps-static-sites
if use server && ! use web; then
# in case someone forgot that they disabled the web UI
cp "${FILESDIR}/no-web-ui.html" "${S}/server/site/app.html"
fi
# pre-requisites, embedded in binary
if use web; then
emake -j1 web-build
fi
if use doc; then
mkdocs build || die
fi
# ldflags idea taken from dev-go/golangci-lint::gentoo
ego build "${myargs[@]}" -ldflags "
-X main.version=${PV}
-X main.commit=${GIT_COMMIT}
-X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
src_install() {
dobin ntfy
# https://github.com/binwiederhier/ntfy/blob/9d3fc20e583564e40af5afb90233f4714fdfcb4c/.goreleaser.yml#L82-L100
# random png
insinto /usr/share/${PF}/
cp web/public/static/images/ntfy.png web/public/static/images/logo.png || die
doins web/public/static/images/logo.png
chown -R ntfy:ntfy "${D}/usr/share/${PF}/" || die
# configuration
insinto /etc/${PN}/
cp client/client.yml client/client.yml.example || die
doins client/client.yml.example
if use server; then
cp server/server.yml server/server.yml.example || die
doins server/server.yml.example
fi
# referenced folders in example server config
if use server; then
dodir /var/lib/${PN}/
keepdir /var/lib/${PN}/
# the cache folder
dotmpfiles "${FILESDIR}/tmpfiles.d/ntfy.conf"
fi
# init files
systemd_dounit client/ntfy-client.service
systemd_douserunit client/user/ntfy-client.service
doinitd "${FILESDIR}"/init.d/ntfy-client
doconfd "${FILESDIR}"/conf.d/ntfy-client
if use server; then
systemd_dounit server/ntfy.service
doinitd "${FILESDIR}"/init.d/ntfy
doconfd "${FILESDIR}"/conf.d/ntfy
fi
# docs
HTML_DOCS="server/docs/" einstalldocs
}
src_test() {
# go tests
emake testv
}
pkg_postinst() {
chown ntfy:ntfy "/etc/${PN}/" || die
chmod 0700 "/etc/${PN}/" || die
if use server; then
tmpfiles_process ntfy.conf
chown ntfy:ntfy "/var/lib/${PN}/" || die
chmod 0700 "/var/lib/${PN}/" || die
fi
}