From: Daan De Meyer Date: Sat, 21 Sep 2024 10:13:19 +0000 (+0200) Subject: Read config from mkosi.local/ as well if it exists X-Git-Tag: v25~273^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f18affff9d0cae1002545ed29f2c99953ffca56b;p=thirdparty%2Fmkosi.git Read config from mkosi.local/ as well if it exists --- diff --git a/.gitignore b/.gitignore index 4d1b379d3..6d489f55e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ /mkosi.output /mkosi.nspawn /mkosi.rootpw +mkosi.local mkosi.local.conf /mkosi.key /mkosi.crt diff --git a/mkosi/config.py b/mkosi/config.py index 2c8ecb928..34c1e0de8 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -3782,21 +3782,26 @@ class ParseContext: extras = path.is_dir() if path.is_dir(): - path = path / "mkosi.conf" + path /= "mkosi.conf" if not self.match_config(path): return False if extras: - if local and (path.parent / "mkosi.local.conf").exists(): - self.parse_config_one(path.parent / "mkosi.local.conf") - - # Configuration from mkosi.local.conf should override other file based configuration but not - # the CLI itself so move the finalized values to the CLI namespace. - for s in SETTINGS: - if hasattr(self.config, s.dest): - setattr(self.cli, s.dest, self.finalize_value(s)) - delattr(self.config, s.dest) + if local: + if ( + (localpath := path.parent / "mkosi.local/mkosi.conf").exists() + or (localpath := path.parent / "mkosi.local.conf").exists() + ): # fmt: skip + self.parse_config_one(localpath) + + # Local configuration should override other file based + # configuration but not the CLI itself so move the finalized + # values to the CLI namespace. + for s in SETTINGS: + if hasattr(self.config, s.dest): + setattr(self.cli, s.dest, self.finalize_value(s)) + delattr(self.config, s.dest) for s in SETTINGS: if ( diff --git a/mkosi/resources/man/mkosi.md b/mkosi/resources/man/mkosi.md index a04783688..1602fae77 100644 --- a/mkosi/resources/man/mkosi.md +++ b/mkosi/resources/man/mkosi.md @@ -299,8 +299,9 @@ grouped by section below. Configuration is parsed in the following order: * The command line arguments are parsed. -* `mkosi.local.conf` is parsed if it exists. This file should be in - `.gitignore` (or equivalent) and is intended for local configuration. +* `mkosi.local.conf` or `mkosi.local` is parsed if it exists. This file or + directory should be in `.gitignore` (or equivalent) and is intended for local + configuration. * Any default paths (depending on the option) are configured if the corresponding path exists. * `mkosi.conf` is parsed if it exists in the directory configured with @@ -318,9 +319,9 @@ Note that settings configured via the command line always override settings configured via configuration files. If the same setting is configured more than once via configuration files, later assignments override earlier assignments except for settings that take a collection -of values. Also, settings read from `mkosi.local.conf` will override -settings from configuration files that are parsed later, but not settings -specified on the CLI. +of values. Also, settings read from `mkosi.local` or `mkosi.local.conf` will +override settings from configuration files that are parsed later, but not +settings specified on the CLI. For settings that take a single value, the empty assignment (`SomeSetting=` or `--some-setting=`) can be used to override a previous setting and reset to the