commit: a092b9b43be485ef7b79c65f19f12d913109a9b4 Author: Zurab Kvachadze <zurabid2016 <AT> gmail <DOT> com> AuthorDate: Sun Feb 8 19:01:59 2026 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Fri Feb 20 19:09:35 2026 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a092b9b4
nginx-module.eclass: Autogenerate load_module .conf config stubs This commit improves the UX of nginx-module.eclass by adding automatic generation of NGINX configurations stubs which load their repsective modules. The stub is only generated if NGINX_MOD_INSTALL_CONF_STUB is set. With the stub installed, only one invocation of `ln` is necessary to enable the module. There is current work in progress on a more convenient way to toggle modules, i.e. eselect module. Bug: https://bugs.gentoo.org/967022 Signed-off-by: Zurab Kvachadze <zurabid2016 <AT> gmail.com> Signed-off-by: Sam James <sam <AT> gentoo.org> eclass/nginx-module.eclass | 88 ++++++++++++++++++---- www-nginx/ngx_devel_kit/ngx_devel_kit-0.3.4.ebuild | 1 + 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/eclass/nginx-module.eclass b/eclass/nginx-module.eclass index c470fcb5f00c..59a2aa7ce262 100644 --- a/eclass/nginx-module.eclass +++ b/eclass/nginx-module.eclass @@ -11,9 +11,11 @@ # @DESCRIPTION: # The nginx-module.eclass automates configuring, building and installing NGINX's # dynamic modules. Using this eclass is as simple as calling 'inherit nginx-module'. -# This eclass automatically adds dependencies on www-servers/nginx. Henceforth, -# the terms 'package' and 'module' will be used interchangeably to refer to a -# consumer of nginx-module.eclass. +# This eclass automatically adds dependencies on www-servers/nginx. +# Additionally, NGINX_MOD_INSTALL_CONF_STUB may be set to automatically generate +# load_module .conf stubs for NGINX. Henceforth, the terms 'package' and +# 'module' will be used interchangeably to refer to a consumer of +# nginx-module.eclass. # # If a part of package's functionality depends on NGINX configuration (e.g. HMAC # generation support depending on http_ssl module being present), the @@ -221,7 +223,6 @@ ngx_mod_setup_link_modules() { # Check whether this function has already been called. [[ -n ${_NGX_MOD_SETUP_LINK_CALLED} ]] && return 0 declare -g -r _NGX_MOD_SETUP_LINK_CALLED=1 - local moddir moddir="${EPREFIX}/usr/$(get_libdir)/nginx/modules" # Add 'moddir' to the list of directories search by linker and add 'moddir' @@ -476,6 +477,25 @@ declare -g -A NGX_MOD_TO_SONAME+=( # Has no effect if either NGINX_MOD_OPENRESTY_TESTS or NGINX_MOD_TEST_LOAD_ORDER # are not set. +# @ECLASS_VARIABLE: NGINX_MOD_INSTALL_CONF_STUB +# @DEFAULT_UNSET +# @DESCRIPTION: +# Set to a non-empty value before calling nginx-module_src_install() to generate +# and install load_module .conf stub(s) for the package. See +# nginx-module_src_install() for details. + +# @ECLASS_VARIABLE: NGINX_MOD_DONT_INSTALL_CONF_STUB +# @DEFAULT_UNSET +# @DESCRIPTION: +# Set to a non-empty value before calling nginx-module_src_install() to NOT +# generate load_module .conf stub(s) for the package. Setting this variable +# also disables displaying instructions on how to enable the module in +# nginx-module_pkg_postinst(). +# +# Setting this might be useful for modules that are not meant to be used +# directly, for example ngx_devel_kit. See nginx-module_src_install() for +# details. + #-----> *DEPEND stuff <----- # As per upstream documentation, modules must be rebuilt with each NGINX @@ -780,10 +800,34 @@ nginx-module_src_test() { # @FUNCTION: nginx-module_src_install # @DESCRIPTION: # Installs the compiled module(s) into /usr/${libdir}/nginx/modules. +# +# Autogenerates load_module .conf stub(s) and installs them into +# /etc/nginx/modules-available. Afterwards, the installed modules can be +# conveniently enabled or disabled by adding or removing symlinks to +# modules-available from /etc/nginx/modules-enabled. See nginx_src_install() in +# nginx.eclass for more details on how NGINX loads these stubs. nginx-module_src_install() { debug-print-function "${FUNCNAME[0]}" "$@" insinto "/usr/$(get_libdir)/nginx/modules" doins "${NGINX_S}"/build/*.so + + # Install stub configuration files only if NGINX_MOD_INSTALL_CONF_STUB is + # set and NGINX_MOD_DONT_INSTALL_CONF_STUB is not set. The latter is used by + # modules like ngx_devel_kit which are not meant to be enabled manually. + if [[ -n ${NGINX_MOD_INSTALL_CONF_STUB} && + -z ${NGINX_MOD_DONT_INSTALL_CONF_STUB} ]]; then + local mod + local destdir=etc/nginx/modules-available + insinto "${destdir}" + # Create configuration stub for every module in NGINX_MOD_SHARED_OBJECTS. + for mod in "${NGINX_MOD_SHARED_OBJECTS[@]}"; do + newins - "${mod%.so}.conf" <<- EOF + # Autogenerated configuration stub. + + load_module modules/${mod}; + EOF + done + fi } # @FUNCTION: nginx-module_pkg_postinst @@ -792,18 +836,36 @@ nginx-module_src_install() { nginx-module_pkg_postinst() { debug-print-function "${FUNCNAME[0]}" "$@" # ngx_devel_kit is an SDK, it does not need to be enabled manually. - [[ ${PN} == ngx_devel_kit ]] && return 0 - - local mod + [[ -n ${NGINX_MOD_DONT_INSTALL_CONF_STUB} ]] && return 0 + # We differentiate two situations: (1) autogenerated configuration stub is + # used, or (2) no configuration stub is generated. + # + # In the first case, we advise the user to symlink the configuration stub to + # /etc/nginx/modules-enabled to enable the module. + # + # In the second case, manual configuration change is needed, and we print + # the instructions on how to change the main NGINX configuration to use the + # module. elog "${PN} has been compiled." elog "" - elog "To utilise the module, add the following line(s) to your NGINX" - elog "configuration file, which by default is \"${EROOT}/etc/nginx/nginx.conf\"." - elog "" - for mod in "${NGINX_MOD_SHARED_OBJECTS[@]}"; do - elog " load_module modules/${mod};" - done + if [[ -n ${NGINX_MOD_INSTALL_CONF_STUB} ]]; then + elog "To utilise the module(s), enable it/them by executing the following" + elog "command(s)" + elog "" + for mod in "${NGINX_MOD_SHARED_OBJECTS[@]}"; do + mod="${mod%.so}.conf" + elog " ln -s ../modules-available/${mod} ${EROOT}/etc/nginx/modules-enabled/" + done + else + local mod + elog "To utilise the module(s), add the following line(s) to your NGINX" + elog "configuration file, which by default is \"${EROOT}/etc/nginx/nginx.conf\"." + elog "" + for mod in "${NGINX_MOD_SHARED_OBJECTS[@]}"; do + elog " load_module modules/${mod};" + done + fi } fi diff --git a/www-nginx/ngx_devel_kit/ngx_devel_kit-0.3.4.ebuild b/www-nginx/ngx_devel_kit/ngx_devel_kit-0.3.4.ebuild index cd4fdaf60682..192b8d366551 100644 --- a/www-nginx/ngx_devel_kit/ngx_devel_kit-0.3.4.ebuild +++ b/www-nginx/ngx_devel_kit/ngx_devel_kit-0.3.4.ebuild @@ -3,6 +3,7 @@ EAPI=8 +NGINX_MOD_DONT_INSTALL_CONF_STUB=1 inherit flag-o-matic nginx-module DESCRIPTION="An NGINX module that adds generic tools for third-party modules"
