apk3: strange output behavior with install_if packages when trying to "add" a non-existent package
My distribution makes heavy use of install_if, and it generally works well. This is just a harmless but annoying issue with invalid output, with the practical behavior with correct inputs being good.
Since it's hard to explain what's actually going on, here is a way to reproduce it:
$ mkdir testroot
$ apk --root testroot --repository "https://repo.chimera-linux.org/current/main" --allow-untrusted --initdb add chimerautils
fetch https://repo.chimera-linux.org/current/main/x86_64/APKINDEX.tar.gz
(1/16) Installing base-files (0.1-r0)
(2/16) Installing iana-etc (20230313-r0)
(3/16) Installing musl (1.2.3-r0)
(4/16) Installing libbz2 (1.0.8-r0)
(5/16) Installing libcxx (15.0.7-r0)
(6/16) Installing libcrypto3 (3.1.0-r0)
(7/16) Installing ncurses-libs (6.4-r0)
(8/16) Installing ncurses-base (6.4-r0)
(9/16) Installing ncurses (6.4-r0)
(10/16) Installing libedit (20220411-r0)
(11/16) Installing musl-fts (1.2.7-r0)
(12/16) Installing liblzma (5.4.1-r0)
(13/16) Installing musl-rpmatch (1.0-r0)
(14/16) Installing libxo (1.6.0-r0)
(15/16) Installing zlib (1.2.13-r0)
(16/16) Installing chimerautils (13.1.2-r0)
OK: 13 MiB in 16 packages
$ mount --bind /proc testroot/proc
$ mount --bind /sys testroot/sys
$ mount --bind /dev testroot/dev
$ cp /etc/resolv.conf testroot/etc
$ apk --root testroot --repository "https://repo.chimera-linux.org/current/main" --allow-untrusted add base-bootstrap
(1/7) Installing debianutils (5.7-r0)
(2/7) Installing libssl3 (3.1.0-r0)
(3/7) Installing openssl (3.1.0-r0)
(4/7) Installing ca-certificates (20230311-r0)
(5/7) Installing apk-tools (3.0.0_pre0-r0)
(6/7) Installing chimera-repo-main (0.1-r0)
(7/7) Installing base-bootstrap (0.1-r0)
Executing ca-certificates-20230311-r0.trigger
Clearing symlinks in /etc/ssl/certs...
done.
Updating certificates in /etc/ssl/certs...
157 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
OK: 16 MiB in 23 packages
$ chroot testroot /bin/sh
# apk update
fetch https://repo.chimera-linux.org/current/main/x86_64/APKINDEX.tar.gz
[https://repo.chimera-linux.org/current/main]
OK: 3315 distinct packages available
# apk add foobar
ERROR: unable to select packages:
foobar (no such package):
required by: world[foobar]
# apk add dinit-chimera
(1/17) Installing awk (20220303-r0)
(2/17) Installing libblkid (2.38.1-r0)
(3/17) Installing libmount (2.38.1-r0)
(4/17) Installing libsmartcols (2.38.1-r0)
(5/17) Installing util-linux-common (2.38.1-r0)
(6/17) Installing mount (2.38.1-r0)
(7/17) Installing kmod (30-r0)
(8/17) Installing procps (4.0.3-r0)
(9/17) Installing libcap (2.67-r0)
(10/17) Installing libkmod (30-r0)
(11/17) Installing udev (253-r0)
(12/17) Installing base-udev (253-r0)
(13/17) Installing udev-dinit (253-r0)
(14/17) Installing udev-dinit-links (253-r0)
(15/17) Installing dinit (0.16.1-r0)
(16/17) Installing tzdata (2022g-r0)
(17/17) Installing dinit-chimera (0.11-r0)
Executing udev-253-r0.trigger
Updating udev hwdb...
OK: 36 MiB in 40 packages
# apk add foobar
ERROR: unable to select packages:
foobar (no such package):
required by: world[foobar]
udev-dinit (virtual):
note: please select one of the 'provided by' packages explicitly
provided by: udev-dinit
required by: udev-dinit-links-253-r0[udev-dinit=253-r0]
# apk add base-man
(1/21) Installing less (608-r0)
(2/21) Installing less-man (608-r0)
(3/21) Installing mandoc (1.14.6-r0)
(4/21) Installing mandoc-man (1.14.6-r0)
(5/21) Installing base-man (1.14.6-r0)
(6/21) Installing debianutils-man (5.7-r0)
(7/21) Installing openssl-man (3.1.0-r0)
(8/21) Installing libedit-man (20220411-r0)
(9/21) Installing chimerautils-man (13.1.2-r0)
(10/21) Installing apk-tools-man (3.0.0_pre0-r0)
(11/21) Installing ncurses-man (6.4-r0)
(12/21) Installing ca-certificates-man (20230311-r0)
(13/21) Installing musl-man (1.2.3-r0)
(14/21) Installing libxo-man (1.6.0-r0)
(15/21) Installing awk-man (20220303-r0)
(16/21) Installing mount-man (2.38.1-r0)
(17/21) Installing kmod-man (30-r0)
(18/21) Installing procps-man (4.0.3-r0)
(19/21) Installing udev-man (253-r0)
(20/21) Installing dinit-man (0.16.1-r0)
(21/21) Installing dinit-chimera-man (0.11-r0)
Executing mandoc-1.14.6-r0.trigger
Regenerating man db...
OK: 44 MiB in 61 packages
# apk add foobar
ERROR: unable to select packages:
foobar (no such package):
required by: world[foobar]
ncurses (virtual):
note: please select one of the 'provided by' packages explicitly
provided by: ncurses
required by: ncurses-man-6.4-r0[ncurses=6.4-r0]
udev-dinit (virtual):
note: please select one of the 'provided by' packages explicitly
provided by: udev-dinit
required by: udev-dinit-links-253-r0[udev-dinit=253-r0]
In this case, you can see the issue with the ncurses
and udev-dinit
packages. Both packages are real (non-virtual) but are automatically installed. Adding them into world makes them disappear from the list. The udev-dinit
is also automatically installed by install_if
, but ncurses
is not. However, ncurses-man
is automatically installed by install_if
, as is udev-dinit-links
, so the shared thing is that both are implicitly-installed packages treated as dependencies of automatically installed install_if
packages (though in this case, ncurses
would be installed by other things even if not a dependency of an install_if
package).
In larger, more practical systems, this list can get massive, spamming the terminal output when a user makes a typo in package name they are installing. Technically it does not do any other harm, but it's still a UX problem.