From d0567293006f0c7d61e2a9786d7927162a2a90a1 Mon Sep 17 00:00:00 2001
From: Oliver Smith <ollieparanoid@postmarketos.org>
Date: Sun, 1 Dec 2024 14:40:04 +0100
Subject: [PATCH] main/postmarketos-base: pmb_recommends: add doas-sudo-shim
 (MR 5867)

Fix the following error during "pmbootstrap install":

  ERROR: unable to select packages:
    sudo-1.9.16_p1-r1:
      conflicts: doas-sudo-shim-0.1.1-r1[cmd:sudo=1.9.16_p1-r1]
      breaks: doas-sudo-shim-0.1.1-r1[!sudo]
      satisfies: postmarketos-base-38-r0[sudo-virt]
                 postmarketos-base-nofde-38-r0[sudo-virt]
    doas-sudo-shim-0.1.1-r1:
      conflicts: sudo-1.9.16_p1-r1[cmd:sudo=0.1.1-r1]
      satisfies: postmarketos-base-doas-38-r0[doas-sudo-shim]
                 postmarketos-base-38-r0[sudo-virt]
                 postmarketos-base-nofde-38-r0[sudo-virt]

How the error gets triggered:
* postmarketos-base depends on sudo-virt. During "pmbootstrap install",
  pmbootstrap has to resolve this to a sudo implementation (sudo, doas,
  ...).
* pmbootstrap does this by looking at the packages that get installed
  at the same time. Before this patch we did not install doas-sudo-shim
  directly through _pmb_recommends, only indirectly through a
  postmarketos-base-doas subpackage that pulls doas-sudo-shim in via
  install_if.
* pmbootstrap cannot look at install_if as it resolves dependencies,
  so it has to pick one and goes for "sudo".
* pmbootstrap tells apk to install a list of packages including "sudo",
  and because apk also resolves install_if correctly, the solver fails
  at the conflict between "doas-sudo-shim" and "sudo". (This only fails
  since apk-tools-static 2.14.6-r0, apparently beforehand apk just
  installed "doas-sudo-shim" in this scenario.)

Teaching pmbootstrap to look at install_if while resolving packages
would be one way to fix this. But it would be a lot of effort, not
feasible to quickly stop the problem at hand that breaks "pmbootstrap
install" for all edge installs. IMHO it is not worth implementing this
at all in pmbootstrap, as it is just supposed to do some more or less
basic package resolving until apk takes over and does it properly.

Put doas-sudo-shim in _pmb_recommends so pmbootstrap knows that this is
the sudo implementation we want without looking at install_if.

Remove the now obsolete postmarketos-base-doas subpackage. This will
lead to doas-sudo-shim getting removed for old installations on upgrade,
but it can easily be installed back (doas add doas-sudo-shim). I'll make
an edge post about it and put it in the v24.12 release notes. If we
don't remove it here, we would need to keep this legacy subpackage
around forever and I'd rather avoid that to reduce maintenance effort.

Another alternative to this was removing sudo-virt from depends="". But
that would lead to sudo getting uninstalled for users upgrading from
old releases from before we had doas in pmb_recommends, so I've decided
against it.

Fixes: pmaports issue 3340
---
 main/postmarketos-base/APKBUILD | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/main/postmarketos-base/APKBUILD b/main/postmarketos-base/APKBUILD
index b96ac05a3a5..b6bd23e520d 100644
--- a/main/postmarketos-base/APKBUILD
+++ b/main/postmarketos-base/APKBUILD
@@ -1,6 +1,6 @@
 pkgname=postmarketos-base
 pkgver=38
-pkgrel=0
+pkgrel=1
 pkgdesc="Meta package for minimal postmarketOS base"
 url="https://postmarketos.org"
 arch="noarch"
@@ -21,11 +21,11 @@ depends="
 	"
 _pmb_recommends="
 	doas
+	doas-sudo-shim
 "
 install="$pkgname.post-install"
 triggers="$pkgname.trigger=/usr/share/deviceinfo"
 subpackages="
-	$pkgname-doas
 	$pkgname-mesa
 	$pkgname-nftables
 	$pkgname-nftables-openrc:nftables_openrc
@@ -111,13 +111,6 @@ package() {
 	ln -s ../usr/lib/os-release "$pkgdir"/etc/os-release
 }
 
-doas() {
-	install_if="$pkgname=$pkgver-r$pkgrel doas"
-	depends="doas-sudo-shim"
-
-	mkdir "$subpkgdir"
-}
-
 mesa() {
 	replaces=""
 	depends="mesa-dri-gallium mesa-gles"
-- 
GitLab