]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add SplitArtifacts=repart-definitions
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 9 Dec 2025 11:59:35 +0000 (12:59 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 9 Dec 2025 12:53:37 +0000 (12:53 +0000)
For use in mkosi-obs

mkosi/__init__.py
mkosi/config.py
mkosi/resources/man/mkosi.1.md

index a7be4899abfd8da88da42601972d9d72d9a56435..a012d45fc77923fb850d838a030a68faf2c35fd8 100644 (file)
@@ -2458,6 +2458,28 @@ def copy_initrd(context: Context) -> None:
         break
 
 
+def copy_repart_definitions(context: Context) -> None:
+    if ArtifactOutput.repart_definitions not in context.config.split_artifacts:
+        return
+
+    if context.config.output_format == OutputFormat.esp:
+        definitions = [context.workspace / "esp-definitions"]
+    elif context.config.output_format.is_extension_or_portable_image():
+        definitions = [extension_or_portable_image_repart_definitions(context)]
+    elif (d := context.workspace / "repart-definitions").exists():
+        definitions = [d]
+    elif context.config.output_format == OutputFormat.disk:
+        definitions = context.config.repart_dirs
+    else:
+        definitions = []
+
+    if not definitions:
+        return
+
+    for d in definitions:
+        copy_tree(d, context.config.output_dir_or_cwd() / context.config.output_split_repart_definitions)
+
+
 def calculate_sha256sum(context: Context) -> None:
     if not context.config.checksum:
         return
@@ -3729,7 +3751,7 @@ def write_split_roothash(context: Context, partitions: Sequence[Partition]) -> N
         (context.staging / context.config.output_split_roothash).write_text(roothash.partition("=")[2])
 
 
-def make_extension_or_portable_image(context: Context, output: Path) -> None:
+def extension_or_portable_image_repart_definitions(context: Context) -> Path:
     if context.config.verity == Verity.disabled or (
         context.config.verity == Verity.auto
         and (not context.config.verity_key or not context.config.verity_certificate)
@@ -3738,7 +3760,11 @@ def make_extension_or_portable_image(context: Context, output: Path) -> None:
     else:
         unsigned = ""
 
-    r = context.resources / f"repart/definitions/{context.config.output_format}{unsigned}.repart.d"
+    return context.resources / f"repart/definitions/{context.config.output_format}{unsigned}.repart.d"
+
+
+def make_extension_or_portable_image(context: Context, output: Path) -> None:
+    definitions = extension_or_portable_image_repart_definitions(context)
 
     cmdline: list[PathString] = [
         "systemd-repart",
@@ -3750,7 +3776,7 @@ def make_extension_or_portable_image(context: Context, output: Path) -> None:
         "--seed", str(context.config.seed) if context.config.seed else "random",
         "--empty=create",
         "--size=auto",
-        "--definitions", workdir(r),
+        "--definitions", workdir(definitions),
         workdir(output),
     ]  # fmt: skip
     options: list[PathString] = [
@@ -3759,7 +3785,7 @@ def make_extension_or_portable_image(context: Context, output: Path) -> None:
         "--become-root",
         "--bind", output.parent, workdir(output.parent),
         *context.rootoptions(readonly=True),
-        "--ro-bind", r, workdir(r),
+        "--ro-bind", definitions, workdir(definitions),
     ]  # fmt: skip
 
     if not context.config.architecture.is_native():
@@ -4019,6 +4045,7 @@ def build_image(context: Context) -> None:
     copy_uki(context)
     copy_vmlinuz(context)
     copy_initrd(context)
+    copy_repart_definitions(context)
 
     if context.config.output_format == OutputFormat.tar:
         make_tar(context.root, context.staging / context.config.output_with_format, sandbox=context.sandbox)
index 961ddfc2657b57fa519c1aa8f6688e372ac8024f..e84c328ff312b7dd23240f7500b98527533a32a2 100644 (file)
@@ -633,6 +633,7 @@ class ArtifactOutput(StrEnum):
     roothash = enum.auto()
     os_release = enum.auto()
     kernel_modules_initrd = enum.auto()
+    repart_definitions = enum.auto()
 
     @staticmethod
     def compat_no() -> list["ArtifactOutput"]:
@@ -2297,6 +2298,10 @@ class Config:
     def output_split_kernel_modules_initrd(self) -> str:
         return f"{self.output}.kernel-modules-initrd"
 
+    @property
+    def output_split_repart_definitions(self) -> str:
+        return f"{self.output}.repart.d"
+
     @property
     def output_nspawn_settings(self) -> str:
         return f"{self.output}.nspawn"
@@ -2339,6 +2344,7 @@ class Config:
             self.output_split_roothash,
             self.output_split_os_release,
             self.output_split_kernel_modules_initrd,
+            self.output_split_repart_definitions,
             self.output_nspawn_settings,
             self.output_checksum,
             self.output_signature,
index b34eeb1efec77757b5e4991d48bfddc34b598f50..4cb8a1e48e00710d18bb67e3b44e3d3dda5afc60 100644 (file)
@@ -692,7 +692,7 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
 `SplitArtifacts=`, `--split-artifacts=`
 :   The artifact types to split out of the final image. A comma-delimited
     list consisting of `uki`, `kernel`, `initrd`, `os-release`, `prcs`, `partitions`,
-    `roothash`, `kernel-modules-initrd` and `tar`. When building a bootable image `kernel`
+    `roothash`, `kernel-modules-initrd`, `repart-definitions` and `tar`. When building a bootable image `kernel`
     and `initrd` correspond to their artifact found in the image (or in the UKI),
     while `uki` copies out the entire UKI. If `pcrs` is specified, a JSON
     file containing the pre-calculated TPM2 digests is written out, according
@@ -719,6 +719,11 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
     initrd inspection tools don't properly handle multiple initrds appended to each
     other.
 
+    When `repart-definitions` is specified, a directory containing the used repart
+    definition files is written to the output directory. If multiple directories are
+    configured via `RepartDirectories=`, they are merged, with later directories
+    taking priority over earlier ones when files with identical names exist.
+
     By default `uki`, `kernel` and `initrd` are split out.
 
 `RepartDirectories=`, `--repart-directory=`