From: Daan De Meyer Date: Wed, 13 Dec 2023 09:03:03 +0000 (+0100) Subject: Have WithRecommends= override package manager trees X-Git-Tag: v20~69^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e9a12a7e5d578eccd21b21bd2a21555f362834c;p=thirdparty%2Fmkosi.git Have WithRecommends= override package manager trees Now that we have an explicit setting for this, let's have it override any configuration from the package manager config file. Let's also make sure that WithDocs= overrides package manager trees when using zypper. --- diff --git a/mkosi/distributions/opensuse.py b/mkosi/distributions/opensuse.py index f6c6cc67e..a549e54ab 100644 --- a/mkosi/distributions/opensuse.py +++ b/mkosi/distributions/opensuse.py @@ -129,7 +129,11 @@ class Installer(DistributionInstaller): @classmethod def install_packages(cls, state: MkosiState, packages: Sequence[str], apivfs: bool = True) -> None: if shutil.which("zypper"): - invoke_zypper(state, "install", packages, ["--download", "in-advance"], apivfs=apivfs) + options = [ + "--download", "in-advance", + "--recommends" if state.config.with_recommends else "--no-recommends", + ] + invoke_zypper(state, "install", packages, options, apivfs=apivfs) else: invoke_dnf(state, "install", packages, apivfs=apivfs) diff --git a/mkosi/installer/apt.py b/mkosi/installer/apt.py index 7e0e2bffd..23c5009d1 100644 --- a/mkosi/installer/apt.py +++ b/mkosi/installer/apt.py @@ -38,17 +38,6 @@ def setup_apt(state: MkosiState, repos: Sequence[str]) -> None: ) ) - config = state.pkgmngr / "etc/apt/apt.conf" - if not config.exists(): - # Anything that users can override with dropins is written into the config file. - config.write_text( - textwrap.dedent( - f"""\ - APT::Install-Recommends "{str(state.config.with_recommends).lower()}"; - """ - ) - ) - sources = state.pkgmngr / "etc/apt/sources.list" if not sources.exists(): with sources.open("w") as f: @@ -75,6 +64,7 @@ def apt_cmd(state: MkosiState, command: str) -> list[PathString]: command, "-o", f"APT::Architecture={debarch}", "-o", f"APT::Architectures={debarch}", + "-o", f"APT::Install-Recommends={str(state.config.with_recommends).lower()}", "-o", "APT::Immediate-Configure=off", "-o", "APT::Get::Assume-Yes=true", "-o", "APT::Get::AutomaticRemove=true", diff --git a/mkosi/installer/dnf.py b/mkosi/installer/dnf.py index 738d9b828..69abc6a6c 100644 --- a/mkosi/installer/dnf.py +++ b/mkosi/installer/dnf.py @@ -51,19 +51,10 @@ def setup_dnf(state: MkosiState, repositories: Iterable[RpmRepository], filelist if not config.exists(): config.parent.mkdir(exist_ok=True, parents=True) with config.open("w") as f: - f.write( - textwrap.dedent( - f"""\ - [main] - install_weak_deps={int(state.config.with_recommends)} - """ - ) - ) - # Make sure we download filelists so all dependencies can be resolved. # See https://bugzilla.redhat.com/show_bug.cgi?id=2180842 if dnf_executable(state).endswith("dnf5") and filelists: - f.write("optional_metadata_types=filelists\n") + f.write("[main]\noptional_metadata_types=filelists\n") repofile = state.pkgmngr / "etc/yum.repos.d/mkosi.repo" if not repofile.exists(): @@ -122,6 +113,7 @@ def dnf_cmd(state: MkosiState) -> list[PathString]: f"--setopt=reposdir={state.pkgmngr / 'etc/yum.repos.d'}", f"--setopt=varsdir={state.pkgmngr / 'etc/dnf/vars'}", f"--setopt=persistdir={state.pkgmngr / 'var/lib/dnf'}", + f"--setopt=install_weak_deps={int(state.config.with_recommends)}", "--setopt=check_config_file_age=0", "--disable-plugin=*" if dnf.endswith("dnf5") else "--disableplugin=*", "--enable-plugin=builddep" if dnf.endswith("dnf5") else "--enableplugin=builddep", diff --git a/mkosi/installer/zypper.py b/mkosi/installer/zypper.py index bb2cdefd2..8d8797f3a 100644 --- a/mkosi/installer/zypper.py +++ b/mkosi/installer/zypper.py @@ -12,18 +12,19 @@ from mkosi.util import sort_packages def setup_zypper(state: MkosiState, repos: Sequence[RpmRepository]) -> None: config = state.pkgmngr / "etc/zypp/zypp.conf" - if not config.exists(): - config.parent.mkdir(exist_ok=True, parents=True) - with config.open("w") as f: - f.write( - textwrap.dedent( - f"""\ - [main] - rpm.install.excludedocs = {yes_no(not state.config.with_docs)} - solver.onlyRequires = {yes_no(not state.config.with_recommends)} - """ - ) + config.parent.mkdir(exist_ok=True, parents=True) + + # rpm.install.excludedocs can only be configured in zypp.conf so we append + # to any user provided config file. + with config.open("a") as f: + f.write( + textwrap.dedent( + f""" + [main] + rpm.install.excludedocs = {yes_no(not state.config.with_docs)} + """ ) + ) repofile = state.pkgmngr / "etc/zypp/repos.d/mkosi.repo" if not repofile.exists():