From: Daan De Meyer Date: Fri, 14 Feb 2025 12:39:48 +0000 (+0100) Subject: Make Linux= support delayed specifiers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3509%2Fhead;p=thirdparty%2Fmkosi.git Make Linux= support delayed specifiers In mkosi-kernel, I want to add the following: ``` Linux=&b/kernel/arch/x86_64/boot/bzImage ``` So that I can run `mkosi -t none` to rebuild the kernel image and `mkosi qemu` to boot into it. To make this work, let's add support for a delayed specifier to Linux= that expands to the finalized build directory. --- diff --git a/mkosi/config.py b/mkosi/config.py index 21675e643..040f8676e 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -1986,7 +1986,7 @@ class Config: removable: bool firmware: Firmware firmware_variables: Optional[Path] - linux: Optional[Path] + linux: Optional[str] drives: list[Drive] qemu_args: list[str] @@ -2208,6 +2208,16 @@ class Config: return expand_delayed_specifiers(specifiers, key) + def expand_linux_specifiers(self) -> Path: + assert self.linux + + specifiers = { + "&": "&", + "b": os.fspath(self.build_subdir) if self.build_dir else "", + } + + return parse_path(expand_delayed_specifiers(specifiers, self.linux)) + def to_dict(self) -> dict[str, Any]: d = dataclasses.asdict(self, dict_factory=dict_with_capitalised_keys_factory) @@ -3894,7 +3904,7 @@ SETTINGS: list[ConfigSetting[Any]] = [ dest="linux", metavar="PATH", section="Runtime", - parse=config_make_path_parser(), + parse=config_parse_string, help="Specify the kernel to use for direct kernel boot", compat_longs=("--qemu-kernel",), compat_names=("QemuKernel",), diff --git a/mkosi/qemu.py b/mkosi/qemu.py index 0fedb9a98..67fcdd29b 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -1156,7 +1156,7 @@ def run_qemu(args: Args, config: Config) -> None: die(f"Console mode {config.console} requested but systemd-pty-forward not found") if config.linux: - kernel = config.linux + kernel = config.expand_linux_specifiers() elif "-kernel" in args.cmdline: kernel = Path(args.cmdline[args.cmdline.index("-kernel") + 1]) else: diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index d1363bf5e..d1afa882b 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -1729,7 +1729,7 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, `Linux=`, `--linux=` : Set the kernel image to use for **qemu** direct kernel boot. If not specified, **mkosi** will use the kernel provided via the command line - (`-kernel` option) or latest the kernel that was installed into + (`-kernel` option) or the latest kernel that was installed into the image (or fail if no kernel was installed into the image). Note that when the `cpio` output format is used, direct kernel boot is @@ -1737,6 +1737,18 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, configured firmware, **qemu** might boot the kernel itself or using the configured firmware. + This setting may include both the regular specifiers (see + **Specifiers**) and special delayed specifiers, that are expanded + after config parsing has finished, instead of during config parsing, + which are described below. + + The following specifiers may be used: + + | Specifier | Value | + |-----------|----------------------------------------------------| + | `&&` | `&` character | + | `&b` | The final build directory (including subdirectory) | + `Drives=`, `--drive=` : Add a drive. Takes a colon-delimited string of format `:[:[:[:]]]`. `id` specifies diff --git a/mkosi/vmspawn.py b/mkosi/vmspawn.py index a96ff2b03..dd5623256 100644 --- a/mkosi/vmspawn.py +++ b/mkosi/vmspawn.py @@ -39,7 +39,7 @@ def run_vmspawn(args: Args, config: Config) -> None: if config.firmware_variables and config.firmware_variables != Path("microsoft"): die("mkosi vmspawn does not support FirmwareVariables=") - kernel = config.linux + kernel = config.expand_linux_specifiers() if config.linux else None firmware = finalize_firmware(config, kernel) if not kernel and firmware == Firmware.linux: