From: Daan De Meyer Date: Fri, 5 Apr 2024 19:01:56 +0000 (+0200) Subject: Introduce --append argument X-Git-Tag: v23~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b88752bb4c985cafba95ac9194369f584c52ea4d;p=thirdparty%2Fmkosi.git Introduce --append argument In systemd, we want to have a default set of kernel command line arguments and override a few of them via the command line. Introduce --append so that we can specify settings via the command line that are parsed after all configuration have files have been parsed to make this possible. --- diff --git a/mkosi/config.py b/mkosi/config.py index 4a8c92d1a..1a7bae4f7 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -3098,6 +3098,11 @@ def create_argument_parser(action: type[argparse.Action]) -> argparse.ArgumentPa action="store_true", default=False, ) + parser.add_argument( + "--append", + help="All settings passed after this argument will be parsed after all configuration files are parsed", + action="store_true", + ) # These can be removed once mkosi v15 is available in LTS distros and compatibility with <= v14 # is no longer needed in build infrastructure (e.g.: OBS). parser.add_argument( @@ -3196,6 +3201,7 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu defaults = argparse.Namespace() parsed_includes: set[tuple[int, int]] = set() immutable_settings: set[str] = set() + append = False def expand_specifiers(text: str, path: Path) -> str: percent = False @@ -3273,6 +3279,9 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu ) -> None: assert option_string is not None + if getattr(namespace, "append", False) != append: + return + if values is None and self.nargs == "?": values = self.const or "yes" @@ -3548,6 +3557,11 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu finalize_defaults() images = [namespace] + append = True + + for ns in images: + argparser.parse_args(argv, ns) + for s in vars(cli_ns): if s not in SETTINGS_LOOKUP_BY_DEST: continue diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 04953b64a..762955c7d 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -255,6 +255,15 @@ Those settings cannot be configured in the configuration files. : Show the summary output as JSON-SEQ. +`--append` + +: All settings passed after this argument will be parsed after all + configuration files have been parsed. + +: Note that any setting passed this way will not have any affect on + `[Match]` sections as they will only be parsed after all `[Match]` + sections have already been evaluated. + ## Supported output formats The following output formats are supported: