From: Daan De Meyer Date: Fri, 5 Jul 2024 07:19:51 +0000 (+0200) Subject: Add %F to access the default filesystem of a distribution X-Git-Tag: v24~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50946d3fdf7381fe1a1c004a0ed6c668b2f7d38f;p=thirdparty%2Fmkosi.git Add %F to access the default filesystem of a distribution One annoyance about using mkosi.repart has always been that to keep using the default filesystem per distribution you have to write a lot of matches. Now that systemd-repart supports $SYSTEMD_REPART_OVERRIDE_FSTYPE_ROOT, let's add a specifier to access the default filesystem so that it can be combined with the environment variable to get the same result. --- diff --git a/mkosi/config.py b/mkosi/config.py index 8395116b3..3775757a1 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -1174,6 +1174,7 @@ class Match: class Specifier: char: str callback: Callable[[argparse.Namespace, Path], str] + depends: tuple[str, ...] = tuple() class CustomHelpFormatter(argparse.HelpFormatter): @@ -3072,6 +3073,11 @@ SPECIFIERS = ( char="D", callback=lambda ns, config: os.fspath(ns.directory.resolve()), ), + Specifier( + char="F", + callback=lambda ns, config: ns.distribution.filesystem(), + depends=("distribution",), + ), ) SPECIFIERS_LOOKUP_BY_CHAR = {s.char: s for s in SPECIFIERS} @@ -3313,7 +3319,17 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu result += str(v) elif specifier := SPECIFIERS_LOOKUP_BY_CHAR.get(c): - result += specifier.callback(namespace, path) + for d in specifier.depends: + setting = SETTINGS_LOOKUP_BY_DEST[d] + + if finalize_default(setting) is None: + logging.warning( + f"Setting {setting.name} which specifier '%{c}' in {text} depends on is not yet set, " + "ignoring" + ) + break + else: + result += specifier.callback(namespace, path) else: logging.warning(f"Unknown specifier '%{c}' found in {text}, ignoring") elif c == "%": diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 8ccbfa284..844a6eb5c 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -1845,6 +1845,12 @@ There are also specifiers that are independent of settings: | `%P` | Current working directory | | `%D` | Directory that mkosi was invoked in | +Finally, there are specifiers that are derived from a setting: + +| Specifier | Value | +|-----------|-------------------------------------------------------| +| `%F` | The default filesystem of the configured distribution | + Note that the current working directory changes as mkosi parses its configuration. Specifically, each time mkosi parses a directory containing a `mkosi.conf` file, mkosi changes its working directory to diff --git a/tests/test_config.py b/tests/test_config.py index dc9332179..712764622 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -966,6 +966,7 @@ def test_specifiers(tmp_path: Path) -> None: ConfigRootDirectory=%D ConfigRootConfdir=%C ConfigRootPwd=%P + Filesystem=%F """ ) @@ -1008,6 +1009,7 @@ def test_specifiers(tmp_path: Path) -> None: "ConfigQedDirectory": os.fspath(d), "ConfigQedConfdir": os.fspath(d / "mkosi.conf.d/qed"), "ConfigQedPwd": os.fspath(d / "mkosi.conf.d/qed"), + "Filesystem": "ext4", } assert {k: v for k, v in config.environment.items() if k in expected} == expected