From 70ecdbfa230258ee88d3ed42ec8bbcd91e27bba3 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 3 Sep 2024 12:53:23 +0200 Subject: [PATCH 1/2] mkosi: Make systemd package filtering more robust Let's not just filter everything with systemd in the name, but instead use the same list of volatile packages that we install to do the filtering. --- mkosi.conf.d/10-arch/mkosi.prepare | 8 +++++--- mkosi.conf.d/10-centos-fedora/mkosi.prepare | 2 +- mkosi.conf.d/10-debian-ubuntu/mkosi.prepare | 3 ++- mkosi.conf.d/10-opensuse/mkosi.prepare | 8 +++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/mkosi.conf.d/10-arch/mkosi.prepare b/mkosi.conf.d/10-arch/mkosi.prepare index aac7b3d76f9..76f67c14e52 100755 --- a/mkosi.conf.d/10-arch/mkosi.prepare +++ b/mkosi.conf.d/10-arch/mkosi.prepare @@ -6,9 +6,11 @@ if [[ "$1" == "build" ]]; then exit 0 fi +mapfile -t PACKAGES < <(jq --raw-output .VolatilePackages[] <"$MKOSI_CONFIG") + DEPS="" -while read -r PACKAGE; do +for PACKAGE in "${PACKAGES[@]}"; do DEPS="$DEPS $( pacman --sync --info "$PACKAGE" | sed '1,/^$/d' | # Only keep result from first repository (delete everything after first blank line). @@ -23,11 +25,11 @@ while read -r PACKAGE; do sed 's/ *\(.*\):.*/\1/' | # Drop descriptions (everything after first colon for all lines). tr '\n' ' ' # Transform newlines to whitespace. )" -done < <(jq --raw-output .VolatilePackages[] <"$MKOSI_CONFIG") +done echo "$DEPS" | xargs | # Remove extra whitespace. tr ' ' '\n' | - grep --invert-match --regexp systemd --regexp None | # systemd packages will be installed later on. + grep --extended-regexp --invert-match --regexp "$(IFS=\| ; echo "${PACKAGES[*]}")" --regexp None | # systemd packages will be installed later on. sort --unique | xargs --delimiter '\n' --no-run-if-empty mkosi-install diff --git a/mkosi.conf.d/10-centos-fedora/mkosi.prepare b/mkosi.conf.d/10-centos-fedora/mkosi.prepare index 9e74aabae2e..9aca0096d5b 100755 --- a/mkosi.conf.d/10-centos-fedora/mkosi.prepare +++ b/mkosi.conf.d/10-centos-fedora/mkosi.prepare @@ -13,7 +13,7 @@ for DEPS in --requires --recommends --suggests; do # --latest-limit=1 is per . so we have to pass --arch= explicitly to make sure i686 packages # are not considered on x86-64. dnf repoquery --arch="$DISTRIBUTION_ARCHITECTURE,noarch" --latest-limit=1 --quiet "$DEPS" "${PACKAGES[@]}" | - grep --invert-match --regexp systemd --regexp udev --regexp /bin/sh --regexp grubby --regexp sdubby --regexp libcurl-minimal | + grep --extended-regexp --invert-match --regexp "$(IFS=\| ; echo "${PACKAGES[*]}")" --regexp /bin/sh --regexp grubby --regexp sdubby --regexp libcurl-minimal | sort --unique | xargs --delimiter '\n' --no-run-if-empty mkosi-install done diff --git a/mkosi.conf.d/10-debian-ubuntu/mkosi.prepare b/mkosi.conf.d/10-debian-ubuntu/mkosi.prepare index acab113b8c1..ffff10d2a42 100755 --- a/mkosi.conf.d/10-debian-ubuntu/mkosi.prepare +++ b/mkosi.conf.d/10-debian-ubuntu/mkosi.prepare @@ -9,7 +9,8 @@ fi mapfile -t PACKAGES < <(jq --raw-output .VolatilePackages[] <"$MKOSI_CONFIG") apt-cache depends "${PACKAGES[@]}" | - grep --invert-match --regexp "<" --regexp "|" --regexp systemd | # Remove e.g. and |dbus-broker like results + grep --invert-match --regexp "<" --regexp "|" | # Remove e.g. and |dbus-broker like results + grep --extended-regexp --invert-match --regexp "$(IFS=\| ; echo "${PACKAGES[*]}")" | grep --extended-regexp "Depends|Suggests|Recommends" | sed --quiet 's/.*: //p' | # Get every line with ": " in it and strip it at the same time. sort --unique | diff --git a/mkosi.conf.d/10-opensuse/mkosi.prepare b/mkosi.conf.d/10-opensuse/mkosi.prepare index 6ee0af2de93..728b502b133 100755 --- a/mkosi.conf.d/10-opensuse/mkosi.prepare +++ b/mkosi.conf.d/10-opensuse/mkosi.prepare @@ -6,18 +6,20 @@ if [[ "$1" == "build" ]]; then exit 0 fi +mapfile -t PACKAGES < <(jq --raw-output .VolatilePackages[] <"$MKOSI_CONFIG") + DEPS="" -while read -r PACKAGE; do +for PACKAGE in "${PACKAGES[@]}"; do # zypper's output is not machine readable so we make do with sed instead. DEPS="$DEPS\n$( zypper info --requires --recommends --suggests "$PACKAGE" | sed '/Requires/,$!d' | # Remove everything before Requires line sed --quiet 's/^ //p' # All indented lines have dependencies )" -done < <(jq --raw-output .VolatilePackages[] <"$MKOSI_CONFIG") +done echo -e "$DEPS" | - grep --invert-match --regexp systemd --regexp udev --regexp qemu | + grep --extended-regexp --invert-match --regexp "$(IFS=\| ; echo "${PACKAGES[*]}")" --regexp qemu | sort --unique | xargs --delimiter '\n' --no-run-if-empty mkosi-install From 89c579788d1f864778c4d6f47b30bf37d04c4947 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 3 Sep 2024 15:18:49 +0200 Subject: [PATCH 2/2] mkosi: Use apt patterns to install dependencies on Debian/Ubuntu Instead of parsing the human readable output of apt-cache, let's use apt patterns to figure out the dependencies. We also filter out virtual packages as apt will fail and say we need to install an implementation of the virtual package even if a package that provides the virtual package is already installed. --- mkosi.conf.d/10-debian-ubuntu/mkosi.prepare | 27 +++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mkosi.conf.d/10-debian-ubuntu/mkosi.prepare b/mkosi.conf.d/10-debian-ubuntu/mkosi.prepare index ffff10d2a42..bf2c5eb91f6 100755 --- a/mkosi.conf.d/10-debian-ubuntu/mkosi.prepare +++ b/mkosi.conf.d/10-debian-ubuntu/mkosi.prepare @@ -8,10 +8,23 @@ fi mapfile -t PACKAGES < <(jq --raw-output .VolatilePackages[] <"$MKOSI_CONFIG") -apt-cache depends "${PACKAGES[@]}" | - grep --invert-match --regexp "<" --regexp "|" | # Remove e.g. and |dbus-broker like results - grep --extended-regexp --invert-match --regexp "$(IFS=\| ; echo "${PACKAGES[*]}")" | - grep --extended-regexp "Depends|Suggests|Recommends" | - sed --quiet 's/.*: //p' | # Get every line with ": " in it and strip it at the same time. - sort --unique | - xargs --delimiter '\n' --no-run-if-empty mkosi-install +PATTERNS=() + +# The ?reverse-depends() pattern for some weird reason lists all the packages providing systemd-sysusers +# instead of just excluding it, so we add another pattern to filter out anything that conflicts with +# any other systemd packages so we filter out both opensysusers and systemd-sysusers-standalone. We also +# exclude packages that belong to the systemd source package as we'll install these later. Finally, we +# exclude virtual packages as trying to install these makes apt fail with an error saying we need to install +# a specific implementation even if one is already installed. +COMMON="?not(?virtual), ?not(?reverse-conflicts(?source-package(^systemd$))), ?not(?reverse-breaks(?source-package(^systemd$))), ?not(?source-package(^systemd$))" + +for PACKAGE in "${PACKAGES[@]}"; do + # Get all the dependencies of the systemd packages including recommended and suggested dependencies. + PATTERNS+=( + "?and(?reverse-depends(?exact-name($PACKAGE)), $COMMON)" + "?and(?reverse-recommends(?exact-name($PACKAGE)), $COMMON)" + "?and(?reverse-suggests(?exact-name($PACKAGE)), $COMMON)" + ) +done + +mkosi-install "${PATTERNS[@]}"