Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] [RFC] use alternatives to manage initramfs regeneration
@ 2022-09-14 16:00 ahesford
  2022-09-14 16:25 ` CameronNemo
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: ahesford @ 2022-09-14 16:00 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1469 bytes --]

There is a new pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages initramfs
https://github.com/void-linux/void-packages/pull/39284

[RFC] use alternatives to manage initramfs regeneration
Yes, I know that XBPS alternatives have some problems, but this seems to be the most sensible approach on balance. Rather than dealing with a bunch of potentially competing initramfs hooks, we can let all packages install custom hooks in `/usr/libexec` and use the alternatives system to symlink the preferred hooks in `/etc/kernel.d`. At that point, we can use the generic alternative script in the XBPS regenerator trigger and avoid the need for a conf file, although it falls back to legacy behavior if the alternative isn't set.

Another option I considered, but decided against, was creating a centralized `initramfs-kernel-hooks` package that installs a common hook and reads the `/etc/default/initramfs-regenerate` file used in the existing XBPS trigger to determine what to execute. All initramfs generators (currently only dracut and mkinitcpio) would have to depend on the common package. This has the drawback that all of the generation knowledge must be centralized instead of located in the package that adds the functionality.

This is not really tested at this point, but I want to get some early comments.

A patch file from https://github.com/void-linux/void-packages/pull/39284.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-initramfs-39284.patch --]
[-- Type: text/x-diff, Size: 7723 bytes --]

From 53b1783b6bb94f0cce75662349fc09ef4de85256 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:30:28 -0400
Subject: [PATCH 1/3] dracut: use alternatives for kernel hooks

---
 srcpkgs/dracut/template | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/dracut/template b/srcpkgs/dracut/template
index 22ffa7a82c4e..e435de954ccd 100644
--- a/srcpkgs/dracut/template
+++ b/srcpkgs/dracut/template
@@ -1,7 +1,7 @@
 # Template file for 'dracut'
 pkgname=dracut
 version=053
-revision=3
+revision=4
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc"
 conf_files="/etc/dracut.conf"
@@ -14,6 +14,10 @@ license="GPL-2.0-or-later, LGPL-2.0-or-later"
 homepage="http://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html"
 distfiles="${KERNEL_SITE}/utils/boot/dracut/dracut-${version}.tar.xz"
 checksum=d5a1b47cdb07919d8225d5b5f538e6ae604988f3df0afbde99a8dc775277b726
+alternatives="
+ initramfs-hooks:/usr/libexec/dracut/kernel-hook-postinst:/etc/kernel.d/post-install/20-initramfs
+ initramfs-hooks:/usr/libexec/dracut/kernel-hook-postrm:/etc/kernel.d/post-remove/20-initramfs
+"
 subpackages="dracut-network"
 # Checks require distfiles come from a git repository
 make_check=no
@@ -34,8 +38,8 @@ esac
 
 post_install() {
 	# kernel hooks.
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-dracut
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-dracut
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/dracut
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/dracut
 
 	# We don't need the systemd stuff.
 	rm -rf ${DESTDIR}/usr/lib/dracut/modules.d/*systemd*
@@ -58,10 +62,14 @@ dracut-uefi_package() {
 	depends="binutils gummiboot-efistub ${sourcepkg}>=${version}_${revision}"
 	short_desc+=" - UEFI bundle hook"
 	conf_files="/etc/default/dracut-uefi-hook"
+	alternatives="
+	 initramfs-hooks:/usr/libexec/dracut/kernel-uefi-post-install:/etc/kernel.d/post-install/20-initramfs
+	 initramfs-hooks:/usr/libexec/dracut/kernel-uefi-post-remove:/etc/kernel.d/post-remove/20-initramfs
+	"
 
 	pkg_install() {
 		vinstall ${FILESDIR}/dracut-uefi-hook.confd 644 etc/default dracut-uefi-hook
-		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 etc/kernel.d/post-install 20-dracut-uefi
-		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 etc/kernel.d/post-remove 20-dracut-uefi
+		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 usr/libexec/dracut
+		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 usr/libexec/dracut
 	}
 }

From cd3e3ad88106f5af4d8cb8027e68a92e8bc44767 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:33:39 -0400
Subject: [PATCH 2/3] mkinitcpio: use alternatives for kernel hooks

---
 srcpkgs/mkinitcpio/files/kernel-hook-postinst |  1 -
 srcpkgs/mkinitcpio/files/kernel-hook-postrm   |  1 -
 srcpkgs/mkinitcpio/template                   | 10 +++++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postinst b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
index 08bf4c0c9514..e051aefea703 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postinst
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
@@ -13,4 +13,3 @@ fi
 
 umask 0077
 usr/bin/mkinitcpio -g boot/initramfs-${VERSION}.img -k ${VERSION}
-exit $?
diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postrm b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
index 028fd097b87a..2db7c51954fa 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postrm
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
@@ -8,4 +8,3 @@ PKGNAME="$1"
 VERSION="$2"
 
 rm -f boot/initramfs-${VERSION}.img
-exit $?
diff --git a/srcpkgs/mkinitcpio/template b/srcpkgs/mkinitcpio/template
index ab00be349a27..b8c700480948 100644
--- a/srcpkgs/mkinitcpio/template
+++ b/srcpkgs/mkinitcpio/template
@@ -1,7 +1,7 @@
 # Template file for 'mkinitcpio'
 pkgname=mkinitcpio
 version=31
-revision=2
+revision=3
 build_style=gnu-makefile
 hostmakedepends="asciidoc"
 depends="busybox-static bsdtar bash"
@@ -13,6 +13,10 @@ homepage="https://git.archlinux.org/mkinitcpio.git"
 distfiles="https://sources.archlinux.org/other/${pkgname}/${pkgname}-${version}.tar.gz"
 checksum=8f2811250b852ab78375bf90e1a7430daa132e57e128b0f6eaadddd9b27bbc63
 conf_files="/etc/mkinitcpio.conf"
+alternatives="
+ initramfs-hooks:/usr/libexec/mkinitcpio/kernel-hook-postinst:/etc/kernel.d/post-install/20-initramfs
+ initramfs-hooks:/usr/libexec/mkinitcpio/kernel-hook-postrm:/etc/kernel.d/post-install/20-initramfs
+"
 replaces="mkinitcpio-udev>=0"
 
 pre_check() {
@@ -38,8 +42,8 @@ post_install() {
 
 	ln -s /usr/bin/busybox.static $DESTDIR/usr/lib/initcpio/busybox
 
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-mkinitcpio
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/mkinitcpio
 }
 
 mkinitcpio-lvm2_package() {

From a3d20fe2f3abc8052d10709188627e45f2a9ab2e Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:51:09 -0400
Subject: [PATCH 3/3] xbps-triggers: use alternatives for kernel hooks

---
 .../xbps-triggers/files/initramfs-regenerate  | 45 +++++++------------
 srcpkgs/xbps-triggers/template                |  2 +-
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/srcpkgs/xbps-triggers/files/initramfs-regenerate b/srcpkgs/xbps-triggers/files/initramfs-regenerate
index 780c3580829f..0ae61958c2b7 100755
--- a/srcpkgs/xbps-triggers/files/initramfs-regenerate
+++ b/srcpkgs/xbps-triggers/files/initramfs-regenerate
@@ -37,36 +37,21 @@ case "$ACTION" in
 		;;
 esac
 
-# Read the configuration, if it exists
-[ -f etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+# Prefer the new alternatives-based initramfs hooks
+HOOK="etc/kernel.d/post-install/20-initramfs"
+if [ ! -x "${HOOK}" ]; then
+	# Otherwise, use legacy trigger behavior to find a preferred hook
+	[ -f etc/default/initramfs-regenerate ] && etc/default/initramfs-regenerate
+	HOOK="etc/kernel.d/post-install/20-${INITRAMFS_GENERATOR:-dracut}"
+	[ -x "${HOOK}" ] || exit 0
+fi
 
-# dracut explicitly sets umask 0077, other generators may not
-umask 0077
-
-case "${INITRAMFS_GENERATOR:-dracut}" in
-	dracut)
-		if command -v dracut >/dev/null 2>&1; then
-			echo "Regenerating initramfs with dracut"
-			dracut -f -q --regenerate-all
-		fi
-		;;
-	mkinitcpio)
-		if command -v mkinitcpio >dev/null 2>&1; then
-			echo "Regenerating initramfs with mkinitcpio"
-			# Regenerate images for every kernel version with modules
-			for kdir in usr/lib/modules/*; do
-				[ -d "${kdir}/kernel" ] || continue
-				kver="${kdir##*/}"
-				mkinitcpio -g "boot/initramfs-${kver}.img" -k "${kver}"
-			done
-		fi
-		;;
-	none)
-		;;
-	*)
-		echo "unrecognized INITRAMFS_GENERATOR for initramfs-regenerate hook"
-		exit 1
-		;;
-esac
+echo "Regenerating initramfs images using kernel hook ${HOOK##*/}"
 
+# Regenerate images for every kernel version with modules
+for kdir in usr/lib/modules/*; do
+	[ -d "${kdir}/kernel" ] || continue
+	kver="${kdir##*/}"
+	"${HOOK}" "${PKGNAME}" "${kver}"
+done
 exit 0
diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template
index f0249f6f9964..aa62e0902528 100644
--- a/srcpkgs/xbps-triggers/template
+++ b/srcpkgs/xbps-triggers/template
@@ -1,6 +1,6 @@
 # Template file for 'xbps-triggers'
 pkgname=xbps-triggers
-version=0.123
+version=0.124
 revision=1
 bootstrap=yes
 short_desc="XBPS triggers for Void Linux"

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
@ 2022-09-14 16:25 ` CameronNemo
  2022-09-14 16:38 ` [PR REVIEW] " CameronNemo
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: CameronNemo @ 2022-09-14 16:25 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

New comment by CameronNemo on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#issuecomment-1247014210

Comment:
>This has the drawback that all of the generation knowledge must be centralized instead of located in the package that adds the functionality.

Is this much of a drawback? How many initramfs generators are we planning to add? More than a dozen? I can only count 5 proposed so far:

* tinyramfs
* mkinitcpio
* initramfs-tools
* booster
* dracut

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PR REVIEW] [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
  2022-09-14 16:25 ` CameronNemo
@ 2022-09-14 16:38 ` CameronNemo
  2022-09-14 17:05 ` ahesford
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: CameronNemo @ 2022-09-14 16:38 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 385 bytes --]

New review comment by CameronNemo on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#discussion_r971058187

Comment:
Are UEFI generators really an "alternative" to traditional initramfs generators? Do they conflict? And what would happen in this case, if someone runs `xbps-install dracut-uefi`? They would have to switch the alternative after, right?

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PR REVIEW] [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
  2022-09-14 16:25 ` CameronNemo
  2022-09-14 16:38 ` [PR REVIEW] " CameronNemo
@ 2022-09-14 17:05 ` ahesford
  2022-09-14 17:07 ` ahesford
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-14 17:05 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 680 bytes --]

New review comment by ahesford on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#discussion_r971085307

Comment:
Yes and no. I was torn about adding an alternative here because it doesn't conflict in the same way as mkinitcpio/dracut, but presumably somebody interested in spitting out a UEFI bundle doesn't care about a separate initramfs in `/boot`. We could skip the alternative here and just install the hooks as they are now, or a user who wishes for both a separate initramfs and a UEFI bundle could manually link to the new hooks in `/usr/libexec`.

Motivation for this comes from https://github.com/void-linux/void-packages/pull/39282.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (2 preceding siblings ...)
  2022-09-14 17:05 ` ahesford
@ 2022-09-14 17:07 ` ahesford
  2022-09-14 19:15 ` [PR REVIEW] " dmarto
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-14 17:07 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 425 bytes --]

New comment by ahesford on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#issuecomment-1247063139

Comment:
You're right that the number of initramfs generators that would be added is not likely to be large, so centralized logic wouldn't be a major bottleneck. That's why I mentioned this additional option: to try to find a consensus on the best way to make initramfs generators pluggable.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PR REVIEW] [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (3 preceding siblings ...)
  2022-09-14 17:07 ` ahesford
@ 2022-09-14 19:15 ` dmarto
  2022-09-15  1:29 ` [PR PATCH] [Updated] " ahesford
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: dmarto @ 2022-09-14 19:15 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 166 bytes --]

New review comment by dmarto on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#discussion_r971204167

Comment:
missing `.`/`source`

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PR PATCH] [Updated] [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (4 preceding siblings ...)
  2022-09-14 19:15 ` [PR REVIEW] " dmarto
@ 2022-09-15  1:29 ` ahesford
  2022-09-15  1:29 ` [PR REVIEW] " ahesford
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-15  1:29 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1474 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages initramfs
https://github.com/void-linux/void-packages/pull/39284

[RFC] use alternatives to manage initramfs regeneration
Yes, I know that XBPS alternatives have some problems, but this seems to be the most sensible approach on balance. Rather than dealing with a bunch of potentially competing initramfs hooks, we can let all packages install custom hooks in `/usr/libexec` and use the alternatives system to symlink the preferred hooks in `/etc/kernel.d`. At that point, we can use the generic alternative script in the XBPS regenerator trigger and avoid the need for a conf file, although it falls back to legacy behavior if the alternative isn't set.

Another option I considered, but decided against, was creating a centralized `initramfs-kernel-hooks` package that installs a common hook and reads the `/etc/default/initramfs-regenerate` file used in the existing XBPS trigger to determine what to execute. All initramfs generators (currently only dracut and mkinitcpio) would have to depend on the common package. This has the drawback that all of the generation knowledge must be centralized instead of located in the package that adds the functionality.

This is not really tested at this point, but I want to get some early comments.

A patch file from https://github.com/void-linux/void-packages/pull/39284.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-initramfs-39284.patch --]
[-- Type: text/x-diff, Size: 7725 bytes --]

From 53b1783b6bb94f0cce75662349fc09ef4de85256 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:30:28 -0400
Subject: [PATCH 1/3] dracut: use alternatives for kernel hooks

---
 srcpkgs/dracut/template | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/dracut/template b/srcpkgs/dracut/template
index 22ffa7a82c4e..e435de954ccd 100644
--- a/srcpkgs/dracut/template
+++ b/srcpkgs/dracut/template
@@ -1,7 +1,7 @@
 # Template file for 'dracut'
 pkgname=dracut
 version=053
-revision=3
+revision=4
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc"
 conf_files="/etc/dracut.conf"
@@ -14,6 +14,10 @@ license="GPL-2.0-or-later, LGPL-2.0-or-later"
 homepage="http://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html"
 distfiles="${KERNEL_SITE}/utils/boot/dracut/dracut-${version}.tar.xz"
 checksum=d5a1b47cdb07919d8225d5b5f538e6ae604988f3df0afbde99a8dc775277b726
+alternatives="
+ initramfs-hooks:/usr/libexec/dracut/kernel-hook-postinst:/etc/kernel.d/post-install/20-initramfs
+ initramfs-hooks:/usr/libexec/dracut/kernel-hook-postrm:/etc/kernel.d/post-remove/20-initramfs
+"
 subpackages="dracut-network"
 # Checks require distfiles come from a git repository
 make_check=no
@@ -34,8 +38,8 @@ esac
 
 post_install() {
 	# kernel hooks.
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-dracut
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-dracut
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/dracut
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/dracut
 
 	# We don't need the systemd stuff.
 	rm -rf ${DESTDIR}/usr/lib/dracut/modules.d/*systemd*
@@ -58,10 +62,14 @@ dracut-uefi_package() {
 	depends="binutils gummiboot-efistub ${sourcepkg}>=${version}_${revision}"
 	short_desc+=" - UEFI bundle hook"
 	conf_files="/etc/default/dracut-uefi-hook"
+	alternatives="
+	 initramfs-hooks:/usr/libexec/dracut/kernel-uefi-post-install:/etc/kernel.d/post-install/20-initramfs
+	 initramfs-hooks:/usr/libexec/dracut/kernel-uefi-post-remove:/etc/kernel.d/post-remove/20-initramfs
+	"
 
 	pkg_install() {
 		vinstall ${FILESDIR}/dracut-uefi-hook.confd 644 etc/default dracut-uefi-hook
-		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 etc/kernel.d/post-install 20-dracut-uefi
-		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 etc/kernel.d/post-remove 20-dracut-uefi
+		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 usr/libexec/dracut
+		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 usr/libexec/dracut
 	}
 }

From cd3e3ad88106f5af4d8cb8027e68a92e8bc44767 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:33:39 -0400
Subject: [PATCH 2/3] mkinitcpio: use alternatives for kernel hooks

---
 srcpkgs/mkinitcpio/files/kernel-hook-postinst |  1 -
 srcpkgs/mkinitcpio/files/kernel-hook-postrm   |  1 -
 srcpkgs/mkinitcpio/template                   | 10 +++++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postinst b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
index 08bf4c0c9514..e051aefea703 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postinst
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
@@ -13,4 +13,3 @@ fi
 
 umask 0077
 usr/bin/mkinitcpio -g boot/initramfs-${VERSION}.img -k ${VERSION}
-exit $?
diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postrm b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
index 028fd097b87a..2db7c51954fa 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postrm
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
@@ -8,4 +8,3 @@ PKGNAME="$1"
 VERSION="$2"
 
 rm -f boot/initramfs-${VERSION}.img
-exit $?
diff --git a/srcpkgs/mkinitcpio/template b/srcpkgs/mkinitcpio/template
index ab00be349a27..b8c700480948 100644
--- a/srcpkgs/mkinitcpio/template
+++ b/srcpkgs/mkinitcpio/template
@@ -1,7 +1,7 @@
 # Template file for 'mkinitcpio'
 pkgname=mkinitcpio
 version=31
-revision=2
+revision=3
 build_style=gnu-makefile
 hostmakedepends="asciidoc"
 depends="busybox-static bsdtar bash"
@@ -13,6 +13,10 @@ homepage="https://git.archlinux.org/mkinitcpio.git"
 distfiles="https://sources.archlinux.org/other/${pkgname}/${pkgname}-${version}.tar.gz"
 checksum=8f2811250b852ab78375bf90e1a7430daa132e57e128b0f6eaadddd9b27bbc63
 conf_files="/etc/mkinitcpio.conf"
+alternatives="
+ initramfs-hooks:/usr/libexec/mkinitcpio/kernel-hook-postinst:/etc/kernel.d/post-install/20-initramfs
+ initramfs-hooks:/usr/libexec/mkinitcpio/kernel-hook-postrm:/etc/kernel.d/post-install/20-initramfs
+"
 replaces="mkinitcpio-udev>=0"
 
 pre_check() {
@@ -38,8 +42,8 @@ post_install() {
 
 	ln -s /usr/bin/busybox.static $DESTDIR/usr/lib/initcpio/busybox
 
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-mkinitcpio
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/mkinitcpio
 }
 
 mkinitcpio-lvm2_package() {

From e56a34531f6347f5bd6fc9f88f8d5dc14ec8006b Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:51:09 -0400
Subject: [PATCH 3/3] xbps-triggers: use alternatives for kernel hooks

---
 .../xbps-triggers/files/initramfs-regenerate  | 45 +++++++------------
 srcpkgs/xbps-triggers/template                |  2 +-
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/srcpkgs/xbps-triggers/files/initramfs-regenerate b/srcpkgs/xbps-triggers/files/initramfs-regenerate
index 780c3580829f..441357ce340f 100755
--- a/srcpkgs/xbps-triggers/files/initramfs-regenerate
+++ b/srcpkgs/xbps-triggers/files/initramfs-regenerate
@@ -37,36 +37,21 @@ case "$ACTION" in
 		;;
 esac
 
-# Read the configuration, if it exists
-[ -f etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+# Prefer the new alternatives-based initramfs hooks
+HOOK="etc/kernel.d/post-install/20-initramfs"
+if [ ! -x "${HOOK}" ]; then
+	# Otherwise, use legacy trigger behavior to find a preferred hook
+	[ -r etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+	HOOK="etc/kernel.d/post-install/20-${INITRAMFS_GENERATOR:-dracut}"
+	[ -x "${HOOK}" ] || exit 0
+fi
 
-# dracut explicitly sets umask 0077, other generators may not
-umask 0077
-
-case "${INITRAMFS_GENERATOR:-dracut}" in
-	dracut)
-		if command -v dracut >/dev/null 2>&1; then
-			echo "Regenerating initramfs with dracut"
-			dracut -f -q --regenerate-all
-		fi
-		;;
-	mkinitcpio)
-		if command -v mkinitcpio >dev/null 2>&1; then
-			echo "Regenerating initramfs with mkinitcpio"
-			# Regenerate images for every kernel version with modules
-			for kdir in usr/lib/modules/*; do
-				[ -d "${kdir}/kernel" ] || continue
-				kver="${kdir##*/}"
-				mkinitcpio -g "boot/initramfs-${kver}.img" -k "${kver}"
-			done
-		fi
-		;;
-	none)
-		;;
-	*)
-		echo "unrecognized INITRAMFS_GENERATOR for initramfs-regenerate hook"
-		exit 1
-		;;
-esac
+echo "Regenerating initramfs images using kernel hook ${HOOK##*/}"
 
+# Regenerate images for every kernel version with modules
+for kdir in usr/lib/modules/*; do
+	[ -d "${kdir}/kernel" ] || continue
+	kver="${kdir##*/}"
+	"${HOOK}" "${PKGNAME}" "${kver}"
+done
 exit 0
diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template
index f0249f6f9964..aa62e0902528 100644
--- a/srcpkgs/xbps-triggers/template
+++ b/srcpkgs/xbps-triggers/template
@@ -1,6 +1,6 @@
 # Template file for 'xbps-triggers'
 pkgname=xbps-triggers
-version=0.123
+version=0.124
 revision=1
 bootstrap=yes
 short_desc="XBPS triggers for Void Linux"

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PR REVIEW] [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (5 preceding siblings ...)
  2022-09-15  1:29 ` [PR PATCH] [Updated] " ahesford
@ 2022-09-15  1:29 ` ahesford
  2022-09-15 10:26 ` classabbyamp
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-15  1:29 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 166 bytes --]

New review comment by ahesford on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#discussion_r971435083

Comment:
Good catch, thanks

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (6 preceding siblings ...)
  2022-09-15  1:29 ` [PR REVIEW] " ahesford
@ 2022-09-15 10:26 ` classabbyamp
  2022-09-18 17:55 ` [PR PATCH] [Updated] " ahesford
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: classabbyamp @ 2022-09-15 10:26 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 184 bytes --]

New comment by classabbyamp on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#issuecomment-1247904996

Comment:
I think this is a reasonable approach

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PR PATCH] [Updated] [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (7 preceding siblings ...)
  2022-09-15 10:26 ` classabbyamp
@ 2022-09-18 17:55 ` ahesford
  2022-09-18 18:39 ` ahesford
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-18 17:55 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1474 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages initramfs
https://github.com/void-linux/void-packages/pull/39284

[RFC] use alternatives to manage initramfs regeneration
Yes, I know that XBPS alternatives have some problems, but this seems to be the most sensible approach on balance. Rather than dealing with a bunch of potentially competing initramfs hooks, we can let all packages install custom hooks in `/usr/libexec` and use the alternatives system to symlink the preferred hooks in `/etc/kernel.d`. At that point, we can use the generic alternative script in the XBPS regenerator trigger and avoid the need for a conf file, although it falls back to legacy behavior if the alternative isn't set.

Another option I considered, but decided against, was creating a centralized `initramfs-kernel-hooks` package that installs a common hook and reads the `/etc/default/initramfs-regenerate` file used in the existing XBPS trigger to determine what to execute. All initramfs generators (currently only dracut and mkinitcpio) would have to depend on the common package. This has the drawback that all of the generation knowledge must be centralized instead of located in the package that adds the functionality.

This is not really tested at this point, but I want to get some early comments.

A patch file from https://github.com/void-linux/void-packages/pull/39284.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-initramfs-39284.patch --]
[-- Type: text/x-diff, Size: 7723 bytes --]

From 4687ad4e505a178baec8b5d43292e2e5d94f8ece Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:30:28 -0400
Subject: [PATCH 1/3] dracut: use alternatives for kernel hooks

---
 srcpkgs/dracut/template | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/dracut/template b/srcpkgs/dracut/template
index 22ffa7a82c4e..e435de954ccd 100644
--- a/srcpkgs/dracut/template
+++ b/srcpkgs/dracut/template
@@ -1,7 +1,7 @@
 # Template file for 'dracut'
 pkgname=dracut
 version=053
-revision=3
+revision=4
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc"
 conf_files="/etc/dracut.conf"
@@ -14,6 +14,10 @@ license="GPL-2.0-or-later, LGPL-2.0-or-later"
 homepage="http://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html"
 distfiles="${KERNEL_SITE}/utils/boot/dracut/dracut-${version}.tar.xz"
 checksum=d5a1b47cdb07919d8225d5b5f538e6ae604988f3df0afbde99a8dc775277b726
+alternatives="
+ initramfs-hooks:/usr/libexec/dracut/kernel-hook-postinst:/etc/kernel.d/post-install/20-initramfs
+ initramfs-hooks:/usr/libexec/dracut/kernel-hook-postrm:/etc/kernel.d/post-remove/20-initramfs
+"
 subpackages="dracut-network"
 # Checks require distfiles come from a git repository
 make_check=no
@@ -34,8 +38,8 @@ esac
 
 post_install() {
 	# kernel hooks.
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-dracut
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-dracut
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/dracut
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/dracut
 
 	# We don't need the systemd stuff.
 	rm -rf ${DESTDIR}/usr/lib/dracut/modules.d/*systemd*
@@ -58,10 +62,14 @@ dracut-uefi_package() {
 	depends="binutils gummiboot-efistub ${sourcepkg}>=${version}_${revision}"
 	short_desc+=" - UEFI bundle hook"
 	conf_files="/etc/default/dracut-uefi-hook"
+	alternatives="
+	 initramfs-hooks:/usr/libexec/dracut/kernel-uefi-post-install:/etc/kernel.d/post-install/20-initramfs
+	 initramfs-hooks:/usr/libexec/dracut/kernel-uefi-post-remove:/etc/kernel.d/post-remove/20-initramfs
+	"
 
 	pkg_install() {
 		vinstall ${FILESDIR}/dracut-uefi-hook.confd 644 etc/default dracut-uefi-hook
-		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 etc/kernel.d/post-install 20-dracut-uefi
-		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 etc/kernel.d/post-remove 20-dracut-uefi
+		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 usr/libexec/dracut
+		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 usr/libexec/dracut
 	}
 }

From a468e15729aa38ee620c4a323013068ee4df8c43 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:33:39 -0400
Subject: [PATCH 2/3] mkinitcpio: use alternatives for kernel hooks

---
 srcpkgs/mkinitcpio/files/kernel-hook-postinst |  1 -
 srcpkgs/mkinitcpio/files/kernel-hook-postrm   |  1 -
 srcpkgs/mkinitcpio/template                   | 10 +++++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postinst b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
index 08bf4c0c9514..e051aefea703 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postinst
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
@@ -13,4 +13,3 @@ fi
 
 umask 0077
 usr/bin/mkinitcpio -g boot/initramfs-${VERSION}.img -k ${VERSION}
-exit $?
diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postrm b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
index 028fd097b87a..2db7c51954fa 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postrm
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
@@ -8,4 +8,3 @@ PKGNAME="$1"
 VERSION="$2"
 
 rm -f boot/initramfs-${VERSION}.img
-exit $?
diff --git a/srcpkgs/mkinitcpio/template b/srcpkgs/mkinitcpio/template
index ab00be349a27..b8c700480948 100644
--- a/srcpkgs/mkinitcpio/template
+++ b/srcpkgs/mkinitcpio/template
@@ -1,7 +1,7 @@
 # Template file for 'mkinitcpio'
 pkgname=mkinitcpio
 version=31
-revision=2
+revision=3
 build_style=gnu-makefile
 hostmakedepends="asciidoc"
 depends="busybox-static bsdtar bash"
@@ -13,6 +13,10 @@ homepage="https://git.archlinux.org/mkinitcpio.git"
 distfiles="https://sources.archlinux.org/other/${pkgname}/${pkgname}-${version}.tar.gz"
 checksum=8f2811250b852ab78375bf90e1a7430daa132e57e128b0f6eaadddd9b27bbc63
 conf_files="/etc/mkinitcpio.conf"
+alternatives="
+ initramfs-hooks:/usr/libexec/mkinitcpio/kernel-hook-postinst:/etc/kernel.d/post-install/20-initramfs
+ initramfs-hooks:/usr/libexec/mkinitcpio/kernel-hook-postrm:/etc/kernel.d/post-install/20-initramfs
+"
 replaces="mkinitcpio-udev>=0"
 
 pre_check() {
@@ -38,8 +42,8 @@ post_install() {
 
 	ln -s /usr/bin/busybox.static $DESTDIR/usr/lib/initcpio/busybox
 
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-mkinitcpio
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/mkinitcpio
 }
 
 mkinitcpio-lvm2_package() {

From ef6baf4a0d432b2919c5784e3a3156e8b290a80f Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:51:09 -0400
Subject: [PATCH 3/3] xbps-triggers: use alternatives for kernel hooks

---
 .../xbps-triggers/files/initramfs-regenerate  | 45 +++++++------------
 srcpkgs/xbps-triggers/template                |  2 +-
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/srcpkgs/xbps-triggers/files/initramfs-regenerate b/srcpkgs/xbps-triggers/files/initramfs-regenerate
index 780c3580829f..0ae61958c2b7 100755
--- a/srcpkgs/xbps-triggers/files/initramfs-regenerate
+++ b/srcpkgs/xbps-triggers/files/initramfs-regenerate
@@ -37,36 +37,21 @@ case "$ACTION" in
 		;;
 esac
 
-# Read the configuration, if it exists
-[ -f etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+# Prefer the new alternatives-based initramfs hooks
+HOOK="etc/kernel.d/post-install/20-initramfs"
+if [ ! -x "${HOOK}" ]; then
+	# Otherwise, use legacy trigger behavior to find a preferred hook
+	[ -f etc/default/initramfs-regenerate ] && etc/default/initramfs-regenerate
+	HOOK="etc/kernel.d/post-install/20-${INITRAMFS_GENERATOR:-dracut}"
+	[ -x "${HOOK}" ] || exit 0
+fi
 
-# dracut explicitly sets umask 0077, other generators may not
-umask 0077
-
-case "${INITRAMFS_GENERATOR:-dracut}" in
-	dracut)
-		if command -v dracut >/dev/null 2>&1; then
-			echo "Regenerating initramfs with dracut"
-			dracut -f -q --regenerate-all
-		fi
-		;;
-	mkinitcpio)
-		if command -v mkinitcpio >dev/null 2>&1; then
-			echo "Regenerating initramfs with mkinitcpio"
-			# Regenerate images for every kernel version with modules
-			for kdir in usr/lib/modules/*; do
-				[ -d "${kdir}/kernel" ] || continue
-				kver="${kdir##*/}"
-				mkinitcpio -g "boot/initramfs-${kver}.img" -k "${kver}"
-			done
-		fi
-		;;
-	none)
-		;;
-	*)
-		echo "unrecognized INITRAMFS_GENERATOR for initramfs-regenerate hook"
-		exit 1
-		;;
-esac
+echo "Regenerating initramfs images using kernel hook ${HOOK##*/}"
 
+# Regenerate images for every kernel version with modules
+for kdir in usr/lib/modules/*; do
+	[ -d "${kdir}/kernel" ] || continue
+	kver="${kdir##*/}"
+	"${HOOK}" "${PKGNAME}" "${kver}"
+done
 exit 0
diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template
index f0249f6f9964..aa62e0902528 100644
--- a/srcpkgs/xbps-triggers/template
+++ b/srcpkgs/xbps-triggers/template
@@ -1,6 +1,6 @@
 # Template file for 'xbps-triggers'
 pkgname=xbps-triggers
-version=0.123
+version=0.124
 revision=1
 bootstrap=yes
 short_desc="XBPS triggers for Void Linux"

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PR PATCH] [Updated] [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (8 preceding siblings ...)
  2022-09-18 17:55 ` [PR PATCH] [Updated] " ahesford
@ 2022-09-18 18:39 ` ahesford
  2022-09-18 18:49 ` ahesford
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-18 18:39 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1474 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages initramfs
https://github.com/void-linux/void-packages/pull/39284

[RFC] use alternatives to manage initramfs regeneration
Yes, I know that XBPS alternatives have some problems, but this seems to be the most sensible approach on balance. Rather than dealing with a bunch of potentially competing initramfs hooks, we can let all packages install custom hooks in `/usr/libexec` and use the alternatives system to symlink the preferred hooks in `/etc/kernel.d`. At that point, we can use the generic alternative script in the XBPS regenerator trigger and avoid the need for a conf file, although it falls back to legacy behavior if the alternative isn't set.

Another option I considered, but decided against, was creating a centralized `initramfs-kernel-hooks` package that installs a common hook and reads the `/etc/default/initramfs-regenerate` file used in the existing XBPS trigger to determine what to execute. All initramfs generators (currently only dracut and mkinitcpio) would have to depend on the common package. This has the drawback that all of the generation knowledge must be centralized instead of located in the package that adds the functionality.

This is not really tested at this point, but I want to get some early comments.

A patch file from https://github.com/void-linux/void-packages/pull/39284.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-initramfs-39284.patch --]
[-- Type: text/x-diff, Size: 7725 bytes --]

From 4687ad4e505a178baec8b5d43292e2e5d94f8ece Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:30:28 -0400
Subject: [PATCH 1/3] dracut: use alternatives for kernel hooks

---
 srcpkgs/dracut/template | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/dracut/template b/srcpkgs/dracut/template
index 22ffa7a82c4e..e435de954ccd 100644
--- a/srcpkgs/dracut/template
+++ b/srcpkgs/dracut/template
@@ -1,7 +1,7 @@
 # Template file for 'dracut'
 pkgname=dracut
 version=053
-revision=3
+revision=4
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc"
 conf_files="/etc/dracut.conf"
@@ -14,6 +14,10 @@ license="GPL-2.0-or-later, LGPL-2.0-or-later"
 homepage="http://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html"
 distfiles="${KERNEL_SITE}/utils/boot/dracut/dracut-${version}.tar.xz"
 checksum=d5a1b47cdb07919d8225d5b5f538e6ae604988f3df0afbde99a8dc775277b726
+alternatives="
+ initramfs-hooks:/usr/libexec/dracut/kernel-hook-postinst:/etc/kernel.d/post-install/20-initramfs
+ initramfs-hooks:/usr/libexec/dracut/kernel-hook-postrm:/etc/kernel.d/post-remove/20-initramfs
+"
 subpackages="dracut-network"
 # Checks require distfiles come from a git repository
 make_check=no
@@ -34,8 +38,8 @@ esac
 
 post_install() {
 	# kernel hooks.
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-dracut
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-dracut
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/dracut
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/dracut
 
 	# We don't need the systemd stuff.
 	rm -rf ${DESTDIR}/usr/lib/dracut/modules.d/*systemd*
@@ -58,10 +62,14 @@ dracut-uefi_package() {
 	depends="binutils gummiboot-efistub ${sourcepkg}>=${version}_${revision}"
 	short_desc+=" - UEFI bundle hook"
 	conf_files="/etc/default/dracut-uefi-hook"
+	alternatives="
+	 initramfs-hooks:/usr/libexec/dracut/kernel-uefi-post-install:/etc/kernel.d/post-install/20-initramfs
+	 initramfs-hooks:/usr/libexec/dracut/kernel-uefi-post-remove:/etc/kernel.d/post-remove/20-initramfs
+	"
 
 	pkg_install() {
 		vinstall ${FILESDIR}/dracut-uefi-hook.confd 644 etc/default dracut-uefi-hook
-		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 etc/kernel.d/post-install 20-dracut-uefi
-		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 etc/kernel.d/post-remove 20-dracut-uefi
+		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 usr/libexec/dracut
+		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 usr/libexec/dracut
 	}
 }

From a468e15729aa38ee620c4a323013068ee4df8c43 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:33:39 -0400
Subject: [PATCH 2/3] mkinitcpio: use alternatives for kernel hooks

---
 srcpkgs/mkinitcpio/files/kernel-hook-postinst |  1 -
 srcpkgs/mkinitcpio/files/kernel-hook-postrm   |  1 -
 srcpkgs/mkinitcpio/template                   | 10 +++++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postinst b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
index 08bf4c0c9514..e051aefea703 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postinst
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
@@ -13,4 +13,3 @@ fi
 
 umask 0077
 usr/bin/mkinitcpio -g boot/initramfs-${VERSION}.img -k ${VERSION}
-exit $?
diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postrm b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
index 028fd097b87a..2db7c51954fa 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postrm
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
@@ -8,4 +8,3 @@ PKGNAME="$1"
 VERSION="$2"
 
 rm -f boot/initramfs-${VERSION}.img
-exit $?
diff --git a/srcpkgs/mkinitcpio/template b/srcpkgs/mkinitcpio/template
index ab00be349a27..b8c700480948 100644
--- a/srcpkgs/mkinitcpio/template
+++ b/srcpkgs/mkinitcpio/template
@@ -1,7 +1,7 @@
 # Template file for 'mkinitcpio'
 pkgname=mkinitcpio
 version=31
-revision=2
+revision=3
 build_style=gnu-makefile
 hostmakedepends="asciidoc"
 depends="busybox-static bsdtar bash"
@@ -13,6 +13,10 @@ homepage="https://git.archlinux.org/mkinitcpio.git"
 distfiles="https://sources.archlinux.org/other/${pkgname}/${pkgname}-${version}.tar.gz"
 checksum=8f2811250b852ab78375bf90e1a7430daa132e57e128b0f6eaadddd9b27bbc63
 conf_files="/etc/mkinitcpio.conf"
+alternatives="
+ initramfs-hooks:/usr/libexec/mkinitcpio/kernel-hook-postinst:/etc/kernel.d/post-install/20-initramfs
+ initramfs-hooks:/usr/libexec/mkinitcpio/kernel-hook-postrm:/etc/kernel.d/post-install/20-initramfs
+"
 replaces="mkinitcpio-udev>=0"
 
 pre_check() {
@@ -38,8 +42,8 @@ post_install() {
 
 	ln -s /usr/bin/busybox.static $DESTDIR/usr/lib/initcpio/busybox
 
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-mkinitcpio
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/mkinitcpio
 }
 
 mkinitcpio-lvm2_package() {

From fce17943c4513883a39a7c179d0a2f7bf4091516 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:51:09 -0400
Subject: [PATCH 3/3] xbps-triggers: use alternatives for kernel hooks

---
 .../xbps-triggers/files/initramfs-regenerate  | 45 +++++++------------
 srcpkgs/xbps-triggers/template                |  2 +-
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/srcpkgs/xbps-triggers/files/initramfs-regenerate b/srcpkgs/xbps-triggers/files/initramfs-regenerate
index 780c3580829f..20fd9982d74f 100755
--- a/srcpkgs/xbps-triggers/files/initramfs-regenerate
+++ b/srcpkgs/xbps-triggers/files/initramfs-regenerate
@@ -37,36 +37,21 @@ case "$ACTION" in
 		;;
 esac
 
-# Read the configuration, if it exists
-[ -f etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+# Prefer the new alternatives-based initramfs hooks
+HOOK="etc/kernel.d/post-install/20-initramfs"
+if [ ! -x "${HOOK}" ]; then
+	# Otherwise, use legacy trigger behavior to find a preferred hook
+	[ -f etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+	HOOK="etc/kernel.d/post-install/20-${INITRAMFS_GENERATOR:-dracut}"
+	[ -x "${HOOK}" ] || exit 0
+fi
 
-# dracut explicitly sets umask 0077, other generators may not
-umask 0077
-
-case "${INITRAMFS_GENERATOR:-dracut}" in
-	dracut)
-		if command -v dracut >/dev/null 2>&1; then
-			echo "Regenerating initramfs with dracut"
-			dracut -f -q --regenerate-all
-		fi
-		;;
-	mkinitcpio)
-		if command -v mkinitcpio >dev/null 2>&1; then
-			echo "Regenerating initramfs with mkinitcpio"
-			# Regenerate images for every kernel version with modules
-			for kdir in usr/lib/modules/*; do
-				[ -d "${kdir}/kernel" ] || continue
-				kver="${kdir##*/}"
-				mkinitcpio -g "boot/initramfs-${kver}.img" -k "${kver}"
-			done
-		fi
-		;;
-	none)
-		;;
-	*)
-		echo "unrecognized INITRAMFS_GENERATOR for initramfs-regenerate hook"
-		exit 1
-		;;
-esac
+echo "Regenerating initramfs images using kernel hook ${HOOK##*/}"
 
+# Regenerate images for every kernel version with modules
+for kdir in usr/lib/modules/*; do
+	[ -d "${kdir}/kernel" ] || continue
+	kver="${kdir##*/}"
+	"${HOOK}" "${PKGNAME}" "${kver}"
+done
 exit 0
diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template
index f0249f6f9964..aa62e0902528 100644
--- a/srcpkgs/xbps-triggers/template
+++ b/srcpkgs/xbps-triggers/template
@@ -1,6 +1,6 @@
 # Template file for 'xbps-triggers'
 pkgname=xbps-triggers
-version=0.123
+version=0.124
 revision=1
 bootstrap=yes
 short_desc="XBPS triggers for Void Linux"

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PR PATCH] [Updated] [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (9 preceding siblings ...)
  2022-09-18 18:39 ` ahesford
@ 2022-09-18 18:49 ` ahesford
  2022-09-18 18:57 ` ahesford
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-18 18:49 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1474 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages initramfs
https://github.com/void-linux/void-packages/pull/39284

[RFC] use alternatives to manage initramfs regeneration
Yes, I know that XBPS alternatives have some problems, but this seems to be the most sensible approach on balance. Rather than dealing with a bunch of potentially competing initramfs hooks, we can let all packages install custom hooks in `/usr/libexec` and use the alternatives system to symlink the preferred hooks in `/etc/kernel.d`. At that point, we can use the generic alternative script in the XBPS regenerator trigger and avoid the need for a conf file, although it falls back to legacy behavior if the alternative isn't set.

Another option I considered, but decided against, was creating a centralized `initramfs-kernel-hooks` package that installs a common hook and reads the `/etc/default/initramfs-regenerate` file used in the existing XBPS trigger to determine what to execute. All initramfs generators (currently only dracut and mkinitcpio) would have to depend on the common package. This has the drawback that all of the generation knowledge must be centralized instead of located in the package that adds the functionality.

This is not really tested at this point, but I want to get some early comments.

A patch file from https://github.com/void-linux/void-packages/pull/39284.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-initramfs-39284.patch --]
[-- Type: text/x-diff, Size: 7309 bytes --]

From 1900eea0f07c33e07cc7bff5b75a1595937cfb8d Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:30:28 -0400
Subject: [PATCH 1/3] dracut: use alternatives for kernel hooks

---
 srcpkgs/dracut/template | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/dracut/template b/srcpkgs/dracut/template
index 22ffa7a82c4e..c705a8886eef 100644
--- a/srcpkgs/dracut/template
+++ b/srcpkgs/dracut/template
@@ -1,7 +1,7 @@
 # Template file for 'dracut'
 pkgname=dracut
 version=053
-revision=3
+revision=4
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc"
 conf_files="/etc/dracut.conf"
@@ -14,6 +14,10 @@ license="GPL-2.0-or-later, LGPL-2.0-or-later"
 homepage="http://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html"
 distfiles="${KERNEL_SITE}/utils/boot/dracut/dracut-${version}.tar.xz"
 checksum=d5a1b47cdb07919d8225d5b5f538e6ae604988f3df0afbde99a8dc775277b726
+alternatives="
+ initramfs:/etc/kernel.d/post-install/20-initramfs:/usr/libexec/dracut/kernel-hook-postinst
+ initramfs:/etc/kernel.d/post-remove/20-initramfs:/usr/libexec/dracut/kernel-hook-postrm
+"
 subpackages="dracut-network"
 # Checks require distfiles come from a git repository
 make_check=no
@@ -34,8 +38,8 @@ esac
 
 post_install() {
 	# kernel hooks.
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-dracut
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-dracut
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/dracut
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/dracut
 
 	# We don't need the systemd stuff.
 	rm -rf ${DESTDIR}/usr/lib/dracut/modules.d/*systemd*
@@ -61,7 +65,7 @@ dracut-uefi_package() {
 
 	pkg_install() {
 		vinstall ${FILESDIR}/dracut-uefi-hook.confd 644 etc/default dracut-uefi-hook
-		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 etc/kernel.d/post-install 20-dracut-uefi
-		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 etc/kernel.d/post-remove 20-dracut-uefi
+		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 usr/libexec/dracut
+		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 usr/libexec/dracut
 	}
 }

From f24120d3c669f20475235a1863175ac63488c27a Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:33:39 -0400
Subject: [PATCH 2/3] mkinitcpio: use alternatives for kernel hooks

---
 srcpkgs/mkinitcpio/files/kernel-hook-postinst |  1 -
 srcpkgs/mkinitcpio/files/kernel-hook-postrm   |  1 -
 srcpkgs/mkinitcpio/template                   | 10 +++++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postinst b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
index 08bf4c0c9514..e051aefea703 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postinst
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
@@ -13,4 +13,3 @@ fi
 
 umask 0077
 usr/bin/mkinitcpio -g boot/initramfs-${VERSION}.img -k ${VERSION}
-exit $?
diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postrm b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
index 028fd097b87a..2db7c51954fa 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postrm
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
@@ -8,4 +8,3 @@ PKGNAME="$1"
 VERSION="$2"
 
 rm -f boot/initramfs-${VERSION}.img
-exit $?
diff --git a/srcpkgs/mkinitcpio/template b/srcpkgs/mkinitcpio/template
index ab00be349a27..c9a6b62f26c6 100644
--- a/srcpkgs/mkinitcpio/template
+++ b/srcpkgs/mkinitcpio/template
@@ -1,7 +1,7 @@
 # Template file for 'mkinitcpio'
 pkgname=mkinitcpio
 version=31
-revision=2
+revision=3
 build_style=gnu-makefile
 hostmakedepends="asciidoc"
 depends="busybox-static bsdtar bash"
@@ -13,6 +13,10 @@ homepage="https://git.archlinux.org/mkinitcpio.git"
 distfiles="https://sources.archlinux.org/other/${pkgname}/${pkgname}-${version}.tar.gz"
 checksum=8f2811250b852ab78375bf90e1a7430daa132e57e128b0f6eaadddd9b27bbc63
 conf_files="/etc/mkinitcpio.conf"
+alternatives="
+ initramfs:/etc/kernel.d/post-install/20-initramfs:/usr/libexec/mkinitcpio/kernel-hook-postinst
+ initramfs:/etc/kernel.d/post-remove/20-initramfs:/usr/libexec/mkinitcpio/kernel-hook-postrm
+"
 replaces="mkinitcpio-udev>=0"
 
 pre_check() {
@@ -38,8 +42,8 @@ post_install() {
 
 	ln -s /usr/bin/busybox.static $DESTDIR/usr/lib/initcpio/busybox
 
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-mkinitcpio
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/mkinitcpio
 }
 
 mkinitcpio-lvm2_package() {

From 40c6bde46ece2940a6905f8a6bbd8ed8c592a603 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:51:09 -0400
Subject: [PATCH 3/3] xbps-triggers: use alternatives for kernel hooks

---
 .../xbps-triggers/files/initramfs-regenerate  | 45 +++++++------------
 srcpkgs/xbps-triggers/template                |  2 +-
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/srcpkgs/xbps-triggers/files/initramfs-regenerate b/srcpkgs/xbps-triggers/files/initramfs-regenerate
index 780c3580829f..20fd9982d74f 100755
--- a/srcpkgs/xbps-triggers/files/initramfs-regenerate
+++ b/srcpkgs/xbps-triggers/files/initramfs-regenerate
@@ -37,36 +37,21 @@ case "$ACTION" in
 		;;
 esac
 
-# Read the configuration, if it exists
-[ -f etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+# Prefer the new alternatives-based initramfs hooks
+HOOK="etc/kernel.d/post-install/20-initramfs"
+if [ ! -x "${HOOK}" ]; then
+	# Otherwise, use legacy trigger behavior to find a preferred hook
+	[ -f etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+	HOOK="etc/kernel.d/post-install/20-${INITRAMFS_GENERATOR:-dracut}"
+	[ -x "${HOOK}" ] || exit 0
+fi
 
-# dracut explicitly sets umask 0077, other generators may not
-umask 0077
-
-case "${INITRAMFS_GENERATOR:-dracut}" in
-	dracut)
-		if command -v dracut >/dev/null 2>&1; then
-			echo "Regenerating initramfs with dracut"
-			dracut -f -q --regenerate-all
-		fi
-		;;
-	mkinitcpio)
-		if command -v mkinitcpio >dev/null 2>&1; then
-			echo "Regenerating initramfs with mkinitcpio"
-			# Regenerate images for every kernel version with modules
-			for kdir in usr/lib/modules/*; do
-				[ -d "${kdir}/kernel" ] || continue
-				kver="${kdir##*/}"
-				mkinitcpio -g "boot/initramfs-${kver}.img" -k "${kver}"
-			done
-		fi
-		;;
-	none)
-		;;
-	*)
-		echo "unrecognized INITRAMFS_GENERATOR for initramfs-regenerate hook"
-		exit 1
-		;;
-esac
+echo "Regenerating initramfs images using kernel hook ${HOOK##*/}"
 
+# Regenerate images for every kernel version with modules
+for kdir in usr/lib/modules/*; do
+	[ -d "${kdir}/kernel" ] || continue
+	kver="${kdir##*/}"
+	"${HOOK}" "${PKGNAME}" "${kver}"
+done
 exit 0
diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template
index f0249f6f9964..aa62e0902528 100644
--- a/srcpkgs/xbps-triggers/template
+++ b/srcpkgs/xbps-triggers/template
@@ -1,6 +1,6 @@
 # Template file for 'xbps-triggers'
 pkgname=xbps-triggers
-version=0.123
+version=0.124
 revision=1
 bootstrap=yes
 short_desc="XBPS triggers for Void Linux"

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PR PATCH] [Updated] [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (10 preceding siblings ...)
  2022-09-18 18:49 ` ahesford
@ 2022-09-18 18:57 ` ahesford
  2022-09-18 18:58 ` ahesford
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-18 18:57 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1474 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages initramfs
https://github.com/void-linux/void-packages/pull/39284

[RFC] use alternatives to manage initramfs regeneration
Yes, I know that XBPS alternatives have some problems, but this seems to be the most sensible approach on balance. Rather than dealing with a bunch of potentially competing initramfs hooks, we can let all packages install custom hooks in `/usr/libexec` and use the alternatives system to symlink the preferred hooks in `/etc/kernel.d`. At that point, we can use the generic alternative script in the XBPS regenerator trigger and avoid the need for a conf file, although it falls back to legacy behavior if the alternative isn't set.

Another option I considered, but decided against, was creating a centralized `initramfs-kernel-hooks` package that installs a common hook and reads the `/etc/default/initramfs-regenerate` file used in the existing XBPS trigger to determine what to execute. All initramfs generators (currently only dracut and mkinitcpio) would have to depend on the common package. This has the drawback that all of the generation knowledge must be centralized instead of located in the package that adds the functionality.

This is not really tested at this point, but I want to get some early comments.

A patch file from https://github.com/void-linux/void-packages/pull/39284.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-initramfs-39284.patch --]
[-- Type: text/x-diff, Size: 6825 bytes --]

From 1b8b02a6b7cbac29f73800653842be59ea3f14e2 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:30:28 -0400
Subject: [PATCH 1/3] dracut: use alternatives for kernel hooks

---
 srcpkgs/dracut/template | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/srcpkgs/dracut/template b/srcpkgs/dracut/template
index 22ffa7a82c4e..5fb0bdd9a222 100644
--- a/srcpkgs/dracut/template
+++ b/srcpkgs/dracut/template
@@ -1,7 +1,7 @@
 # Template file for 'dracut'
 pkgname=dracut
 version=053
-revision=3
+revision=4
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc"
 conf_files="/etc/dracut.conf"
@@ -14,6 +14,10 @@ license="GPL-2.0-or-later, LGPL-2.0-or-later"
 homepage="http://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html"
 distfiles="${KERNEL_SITE}/utils/boot/dracut/dracut-${version}.tar.xz"
 checksum=d5a1b47cdb07919d8225d5b5f538e6ae604988f3df0afbde99a8dc775277b726
+alternatives="
+ initramfs:/etc/kernel.d/post-install/20-initramfs:/usr/libexec/dracut/kernel-hook-postinst
+ initramfs:/etc/kernel.d/post-remove/20-initramfs:/usr/libexec/dracut/kernel-hook-postrm
+"
 subpackages="dracut-network"
 # Checks require distfiles come from a git repository
 make_check=no
@@ -34,8 +38,8 @@ esac
 
 post_install() {
 	# kernel hooks.
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-dracut
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-dracut
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/dracut
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/dracut
 
 	# We don't need the systemd stuff.
 	rm -rf ${DESTDIR}/usr/lib/dracut/modules.d/*systemd*

From fa7b16e460a5f538e292d3c3017131f9947d8e12 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:33:39 -0400
Subject: [PATCH 2/3] mkinitcpio: use alternatives for kernel hooks

---
 srcpkgs/mkinitcpio/files/kernel-hook-postinst |  1 -
 srcpkgs/mkinitcpio/files/kernel-hook-postrm   |  1 -
 srcpkgs/mkinitcpio/template                   | 10 +++++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postinst b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
index 08bf4c0c9514..e051aefea703 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postinst
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
@@ -13,4 +13,3 @@ fi
 
 umask 0077
 usr/bin/mkinitcpio -g boot/initramfs-${VERSION}.img -k ${VERSION}
-exit $?
diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postrm b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
index 028fd097b87a..2db7c51954fa 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postrm
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
@@ -8,4 +8,3 @@ PKGNAME="$1"
 VERSION="$2"
 
 rm -f boot/initramfs-${VERSION}.img
-exit $?
diff --git a/srcpkgs/mkinitcpio/template b/srcpkgs/mkinitcpio/template
index ab00be349a27..c9a6b62f26c6 100644
--- a/srcpkgs/mkinitcpio/template
+++ b/srcpkgs/mkinitcpio/template
@@ -1,7 +1,7 @@
 # Template file for 'mkinitcpio'
 pkgname=mkinitcpio
 version=31
-revision=2
+revision=3
 build_style=gnu-makefile
 hostmakedepends="asciidoc"
 depends="busybox-static bsdtar bash"
@@ -13,6 +13,10 @@ homepage="https://git.archlinux.org/mkinitcpio.git"
 distfiles="https://sources.archlinux.org/other/${pkgname}/${pkgname}-${version}.tar.gz"
 checksum=8f2811250b852ab78375bf90e1a7430daa132e57e128b0f6eaadddd9b27bbc63
 conf_files="/etc/mkinitcpio.conf"
+alternatives="
+ initramfs:/etc/kernel.d/post-install/20-initramfs:/usr/libexec/mkinitcpio/kernel-hook-postinst
+ initramfs:/etc/kernel.d/post-remove/20-initramfs:/usr/libexec/mkinitcpio/kernel-hook-postrm
+"
 replaces="mkinitcpio-udev>=0"
 
 pre_check() {
@@ -38,8 +42,8 @@ post_install() {
 
 	ln -s /usr/bin/busybox.static $DESTDIR/usr/lib/initcpio/busybox
 
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-mkinitcpio
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/mkinitcpio
 }
 
 mkinitcpio-lvm2_package() {

From ac742e742d2dba03a02fbee1af6eb1798f5be219 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:51:09 -0400
Subject: [PATCH 3/3] xbps-triggers: use alternatives for kernel hooks

---
 .../xbps-triggers/files/initramfs-regenerate  | 45 +++++++------------
 srcpkgs/xbps-triggers/template                |  2 +-
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/srcpkgs/xbps-triggers/files/initramfs-regenerate b/srcpkgs/xbps-triggers/files/initramfs-regenerate
index 780c3580829f..20fd9982d74f 100755
--- a/srcpkgs/xbps-triggers/files/initramfs-regenerate
+++ b/srcpkgs/xbps-triggers/files/initramfs-regenerate
@@ -37,36 +37,21 @@ case "$ACTION" in
 		;;
 esac
 
-# Read the configuration, if it exists
-[ -f etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+# Prefer the new alternatives-based initramfs hooks
+HOOK="etc/kernel.d/post-install/20-initramfs"
+if [ ! -x "${HOOK}" ]; then
+	# Otherwise, use legacy trigger behavior to find a preferred hook
+	[ -f etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+	HOOK="etc/kernel.d/post-install/20-${INITRAMFS_GENERATOR:-dracut}"
+	[ -x "${HOOK}" ] || exit 0
+fi
 
-# dracut explicitly sets umask 0077, other generators may not
-umask 0077
-
-case "${INITRAMFS_GENERATOR:-dracut}" in
-	dracut)
-		if command -v dracut >/dev/null 2>&1; then
-			echo "Regenerating initramfs with dracut"
-			dracut -f -q --regenerate-all
-		fi
-		;;
-	mkinitcpio)
-		if command -v mkinitcpio >dev/null 2>&1; then
-			echo "Regenerating initramfs with mkinitcpio"
-			# Regenerate images for every kernel version with modules
-			for kdir in usr/lib/modules/*; do
-				[ -d "${kdir}/kernel" ] || continue
-				kver="${kdir##*/}"
-				mkinitcpio -g "boot/initramfs-${kver}.img" -k "${kver}"
-			done
-		fi
-		;;
-	none)
-		;;
-	*)
-		echo "unrecognized INITRAMFS_GENERATOR for initramfs-regenerate hook"
-		exit 1
-		;;
-esac
+echo "Regenerating initramfs images using kernel hook ${HOOK##*/}"
 
+# Regenerate images for every kernel version with modules
+for kdir in usr/lib/modules/*; do
+	[ -d "${kdir}/kernel" ] || continue
+	kver="${kdir##*/}"
+	"${HOOK}" "${PKGNAME}" "${kver}"
+done
 exit 0
diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template
index f0249f6f9964..aa62e0902528 100644
--- a/srcpkgs/xbps-triggers/template
+++ b/srcpkgs/xbps-triggers/template
@@ -1,6 +1,6 @@
 # Template file for 'xbps-triggers'
 pkgname=xbps-triggers
-version=0.123
+version=0.124
 revision=1
 bootstrap=yes
 short_desc="XBPS triggers for Void Linux"

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (11 preceding siblings ...)
  2022-09-18 18:57 ` ahesford
@ 2022-09-18 18:58 ` ahesford
  2022-09-19  8:19 ` thypon
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-18 18:58 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 314 bytes --]

New comment by ahesford on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#issuecomment-1250367086

Comment:
Did some testing and think this is ready for review. Fixed some bugs and dropped the alternative in `dracut-uefi`.

Looking for comments from @void-linux/pkg-committers.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (12 preceding siblings ...)
  2022-09-18 18:58 ` ahesford
@ 2022-09-19  8:19 ` thypon
  2022-09-19  9:23 ` classabbyamp
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: thypon @ 2022-09-19  8:19 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 235 bytes --]

New comment by thypon on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#issuecomment-1250710022

Comment:
+1 on my side. I pushed for a similar change in the early days, but it was a bit aversed then.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (13 preceding siblings ...)
  2022-09-19  8:19 ` thypon
@ 2022-09-19  9:23 ` classabbyamp
  2022-09-19 11:04 ` ahesford
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: classabbyamp @ 2022-09-19  9:23 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 221 bytes --]

New comment by classabbyamp on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#issuecomment-1250779567

Comment:
I believe dracut and mkinitcpio need `xbps-triggers>=0.124` in depends now

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (14 preceding siblings ...)
  2022-09-19  9:23 ` classabbyamp
@ 2022-09-19 11:04 ` ahesford
  2022-09-19 20:33 ` classabbyamp
  2022-09-26 12:17 ` [PR PATCH] [Merged]: " ahesford
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-19 11:04 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 337 bytes --]

New comment by ahesford on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#issuecomment-1250873077

Comment:
An `xbps-triggers` dependency isn't needed because the existing trigger is independent of the initramfs kernel hooks. It will continue to work even if somebody updates only dracut or mkinitcpio.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (15 preceding siblings ...)
  2022-09-19 11:04 ` ahesford
@ 2022-09-19 20:33 ` classabbyamp
  2022-09-26 12:17 ` [PR PATCH] [Merged]: " ahesford
  17 siblings, 0 replies; 19+ messages in thread
From: classabbyamp @ 2022-09-19 20:33 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 174 bytes --]

New comment by classabbyamp on void-packages repository

https://github.com/void-linux/void-packages/pull/39284#issuecomment-1251519860

Comment:
tested and works for me, +1

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PR PATCH] [Merged]: [RFC] use alternatives to manage initramfs regeneration
  2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
                   ` (16 preceding siblings ...)
  2022-09-19 20:33 ` classabbyamp
@ 2022-09-26 12:17 ` ahesford
  17 siblings, 0 replies; 19+ messages in thread
From: ahesford @ 2022-09-26 12:17 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1314 bytes --]

There's a merged pull request on the void-packages repository

[RFC] use alternatives to manage initramfs regeneration
https://github.com/void-linux/void-packages/pull/39284

Description:
Yes, I know that XBPS alternatives have some problems, but this seems to be the most sensible approach on balance. Rather than dealing with a bunch of potentially competing initramfs hooks, we can let all packages install custom hooks in `/usr/libexec` and use the alternatives system to symlink the preferred hooks in `/etc/kernel.d`. At that point, we can use the generic alternative script in the XBPS regenerator trigger and avoid the need for a conf file, although it falls back to legacy behavior if the alternative isn't set.

Another option I considered, but decided against, was creating a centralized `initramfs-kernel-hooks` package that installs a common hook and reads the `/etc/default/initramfs-regenerate` file used in the existing XBPS trigger to determine what to execute. All initramfs generators (currently only dracut and mkinitcpio) would have to depend on the common package. This has the drawback that all of the generation knowledge must be centralized instead of located in the package that adds the functionality.

This is not really tested at this point, but I want to get some early comments.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-09-26 12:17 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
2022-09-14 16:25 ` CameronNemo
2022-09-14 16:38 ` [PR REVIEW] " CameronNemo
2022-09-14 17:05 ` ahesford
2022-09-14 17:07 ` ahesford
2022-09-14 19:15 ` [PR REVIEW] " dmarto
2022-09-15  1:29 ` [PR PATCH] [Updated] " ahesford
2022-09-15  1:29 ` [PR REVIEW] " ahesford
2022-09-15 10:26 ` classabbyamp
2022-09-18 17:55 ` [PR PATCH] [Updated] " ahesford
2022-09-18 18:39 ` ahesford
2022-09-18 18:49 ` ahesford
2022-09-18 18:57 ` ahesford
2022-09-18 18:58 ` ahesford
2022-09-19  8:19 ` thypon
2022-09-19  9:23 ` classabbyamp
2022-09-19 11:04 ` ahesford
2022-09-19 20:33 ` classabbyamp
2022-09-26 12:17 ` [PR PATCH] [Merged]: " ahesford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).