class Specifier:
char: str
callback: Callable[[argparse.Namespace, Path], str]
+ depends: tuple[str, ...] = tuple()
class CustomHelpFormatter(argparse.HelpFormatter):
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}
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 == "%":
| `%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
ConfigRootDirectory=%D
ConfigRootConfdir=%C
ConfigRootPwd=%P
+ Filesystem=%F
"""
)
"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