]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Have WithRecommends= override package manager trees
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 13 Dec 2023 09:03:03 +0000 (10:03 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 13 Dec 2023 11:51:36 +0000 (12:51 +0100)
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.

mkosi/distributions/opensuse.py
mkosi/installer/apt.py
mkosi/installer/dnf.py
mkosi/installer/zypper.py

index f6c6cc67e1bda721a33fc2416ea0883baf7fdc7b..a549e54ab0e398c5e10dd94887fc39a984d49c13 100644 (file)
@@ -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)
 
index 7e0e2bffda4b8bdb258f047f88b5778b9076a5e5..23c5009d16a9ed3d96a98e8e790172428be0ee11 100644 (file)
@@ -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",
index 738d9b828d60e974f184180f388f7afe7818c4d2..69abc6a6ca8d29ed07f9957e476dfe48e39c07ce 100644 (file)
@@ -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",
index bb2cdefd2aa197e1be614c8bf8db0872ec1bbdb6..8d8797f3a73c9c8f9228562880f043a1f6e72501 100644 (file)
@@ -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():