From: Daan De Meyer Date: Fri, 13 Oct 2023 07:54:39 +0000 (+0200) Subject: Add WithRecommends= X-Git-Tag: v19~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4564de61b4e0304998591af64795de30f1285a5;p=thirdparty%2Fmkosi.git Add WithRecommends= 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. --- diff --git a/mkosi/config.py b/mkosi/config.py index c008c5545..77dbb4ace 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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", diff --git a/mkosi/installer/apt.py b/mkosi/installer/apt.py index ca1f20195..0a7472812 100644 --- a/mkosi/installer/apt.py +++ b/mkosi/installer/apt.py @@ -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()}"; """ ) ) diff --git a/mkosi/installer/dnf.py b/mkosi/installer/dnf.py index ca302842d..a6410b686 100644 --- a/mkosi/installer/dnf.py +++ b/mkosi/installer/dnf.py @@ -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)} """ ) ) diff --git a/mkosi/installer/zypper.py b/mkosi/installer/zypper.py index 3b4b7f575..a922536ce 100644 --- a/mkosi/installer/zypper.py +++ b/mkosi/installer/zypper.py @@ -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)} """ ) ) diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 6e5e7f19c..c5230452e 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -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 diff --git a/tests/test_json.py b/tests/test_json.py index e137e936c..ccfa26b00 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -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"), )