]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add WithRecommends=
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 13 Oct 2023 07:54:39 +0000 (09:54 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 13 Oct 2023 08:43:36 +0000 (10:43 +0200)
While this can already be configured using dropins. The concept of
recommended packages seems widespread enough that we can provide an
option to enable/disable it via the configuration file.

mkosi/config.py
mkosi/installer/apt.py
mkosi/installer/dnf.py
mkosi/installer/zypper.py
mkosi/resources/mkosi.md
tests/test_json.py

index c008c554520c4ef74abfa7c2fc9438b3c86d299b..77dbb4ace63b7ceca492bc32a1eb3886156c21e8 100644 (file)
@@ -735,6 +735,7 @@ class MkosiConfig:
 
     packages: list[str]
     build_packages: list[str]
+    with_recommends: bool
     with_docs: bool
 
     base_trees: list[Path]
@@ -1274,6 +1275,14 @@ SETTINGS = (
         parse=config_make_list_parser(delimiter=","),
         help="Additional packages needed for build scripts",
     ),
+    MkosiConfigSetting(
+        dest="with_recommends",
+        metavar="BOOL",
+        nargs="?",
+        section="Content",
+        parse=config_parse_boolean,
+        help="Install recommended packages",
+    ),
     MkosiConfigSetting(
         dest="with_docs",
         metavar="BOOL",
index ca1f201952b446ec6317f90b526f46436b34580f..0a7472812aa0b47c7222646ce3c047c00920fbfb 100644 (file)
@@ -43,8 +43,8 @@ def setup_apt(state: MkosiState, repos: Sequence[str]) -> None:
         # Anything that users can override with dropins is written into the config file.
         config.write_text(
             textwrap.dedent(
-                """\
-                APT::Install-Recommends "false";
+                f"""\
+                APT::Install-Recommends "{str(state.config.with_recommends).lower()}";
                 """
             )
         )
index ca302842d937edc0b2bd8544bf525bf4020a280c..a6410b6868a7cdd4e94639b4418afc30ed1aa7e9 100644 (file)
@@ -52,9 +52,9 @@ def setup_dnf(state: MkosiState, repos: Iterable[Repo], filelists: bool = True)
         with config.open("w") as f:
             f.write(
                 textwrap.dedent(
-                    """\
+                    f"""\
                     [main]
-                    install_weak_deps=0
+                    install_weak_deps={int(state.config.with_recommends)}
                     """
                 )
             )
index 3b4b7f575ee49141de9c0557a68fecbc3182a8c8..a922536ce73fb80dbdb8c9777affb87cdc1057f8 100644 (file)
@@ -2,6 +2,7 @@
 import textwrap
 from collections.abc import Sequence
 
+from mkosi.config import yes_no
 from mkosi.installer.dnf import Repo, fixup_rpmdb_location
 from mkosi.run import apivfs_cmd, bwrap
 from mkosi.state import MkosiState
@@ -18,8 +19,8 @@ def setup_zypper(state: MkosiState, repos: Sequence[Repo]) -> None:
                 textwrap.dedent(
                     f"""\
                     [main]
-                    rpm.install.excludedocs = {"no" if state.config.with_docs else "yes"}
-                    solver.onlyRequires = yes
+                    rpm.install.excludedocs = {yes_no(not state.config.with_docs)}
+                    solver.onlyRequires = {yes_no(not state.config.with_recommends)}
                     """
                 )
             )
index 6e5e7f19c2eddca4465883186411c7bac656a4fa..c5230452e549157686fdb79d2c527187668c4a3f 100644 (file)
@@ -694,6 +694,14 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
   `mkosi.build` scripts require to operate. Note that packages listed
   here will be absent in the final image.
 
+`WithRecommends=`, `--with-recommends=`
+
+: Configures whether to install recommended or weak dependencies,
+  depending on how they are named by the used package manager, or not.
+  By default, recommended packages are not installed. This is only used
+  for package managers that support the concept, which are currently
+  apt, dnf and zypper.
+
 `WithDocs=`, `--with-docs`
 
 : Include documentation in the image built. By default if the
index e137e936c58f04da7a7cc9e7175ddaf4a50ce4cf..ccfa26b009bf87294da8412f939b65566209dff8 100644 (file)
@@ -242,6 +242,7 @@ def test_config() -> None:
             "VerityKey": null,
             "WithDocs": true,
             "WithNetwork": false,
+            "WithRecommends": true,
             "WithTests": true,
             "WorkspaceDirectory": "/cwd"
         }
@@ -349,6 +350,7 @@ def test_config() -> None:
         verity_key = None,
         with_docs = True,
         with_network = False,
+        with_recommends = True,
         with_tests =  True,
         workspace_dir = Path("/cwd"),
     )