]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
add config setting seed to set systemd-repart --seed
authorMalte Poll <mp@edgeless.systems>
Fri, 25 Aug 2023 09:30:04 +0000 (11:30 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 25 Aug 2023 14:12:33 +0000 (16:12 +0200)
Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
mkosi/__init__.py
mkosi/config.py
mkosi/resources/mkosi.md

index bd39ec8d9b44f24da53c92bf9a326359e3bd0c6d..e64caf925085835e03f7868b5bb7b544f1e398dc 100644 (file)
@@ -1633,6 +1633,7 @@ def make_image(state: MkosiState, skip: Sequence[str] = [], split: bool = False)
         "--no-pager",
         "--offline=yes",
         "--root", state.root,
+        "--seed", str(state.config.seed) if state.config.seed else "random",
         state.staging / state.config.output_with_format,
     ]
 
index 790cccb5092e1d5e91359e3936c84ad4c2d124fc..edd2da748af1bd7bc59e97331ecca25c20f9253c 100644 (file)
@@ -19,6 +19,7 @@ import shutil
 import subprocess
 import sys
 import textwrap
+import uuid
 from collections.abc import Iterable, Sequence
 from pathlib import Path
 from typing import Any, Callable, Optional, Type, Union, cast
@@ -248,6 +249,16 @@ def config_parse_compression(value: Optional[str], old: Optional[Compression]) -
     except KeyError:
         return Compression.zst if parse_boolean(value) else Compression.none
 
+def config_parse_seed(value: Optional[str], old: Optional[str]) -> Optional[uuid.UUID]:
+    if not value or value == "random":
+        return None
+
+    try:
+        return uuid.UUID(value)
+    except ValueError:
+        die(f"{value} is not a valid UUID")
+
+
 
 def config_default_release(namespace: argparse.Namespace) -> str:
     # If we encounter Release in [Match] and no distribution has been set yet, configure the default
@@ -635,6 +646,7 @@ class MkosiConfig:
     sector_size: Optional[str]
     overlay: bool
     use_subvolumes: ConfigFeature
+    seed: Optional[uuid.UUID]
 
     packages: list[str]
     build_packages: list[str]
@@ -994,6 +1006,13 @@ class MkosiConfigParser:
             parse=config_parse_feature,
             help="Use btrfs subvolumes for faster directory operations where possible",
         ),
+         MkosiConfigSetting(
+            dest="seed",
+            metavar="UUID",
+            section="Output",
+            parse=config_parse_seed,
+            help="Set the seed for systemd-repart",
+        ),
 
         MkosiConfigSetting(
             dest="packages",
@@ -2134,6 +2153,10 @@ def none_to_na(s: Optional[object]) -> str:
     return "n/a" if s is None else str(s)
 
 
+def none_to_random(s: Optional[object]) -> str:
+    return "random" if s is None else str(s)
+
+
 def none_to_none(s: Optional[object]) -> str:
     return "none" if s is None else str(s)
 
@@ -2206,6 +2229,7 @@ def summary(args: MkosiArgs, config: MkosiConfig) -> str:
                    Sector Size: {none_to_default(config.sector_size)}
                        Overlay: {yes_no(config.overlay)}
                 Use Subvolumes: {yes_no_auto(config.use_subvolumes)}
+                          Seed: {none_to_random(config.seed)}
 
     {bold("CONTENT")}:
                       Packages: {line_join_list(config.packages)}
index 9002f8d328e9787f80aacc81e47b32c858ec355a..12a3a8f37cc6010d0e143cc8326d25c59c573ca5 100644 (file)
@@ -563,6 +563,14 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
   created, an error is raised. If `auto`, missing `btrfs` or failures to
   create subvolumes are ignored.
 
+`Seed=`, `--seed=`
+
+: Takes a UUID as argument or the special value `random`.
+  Overrides the seed that [`systemd-repart(8)`](https://www.freedesktop.org/software/systemd/man/systemd-repart.service.html)
+  uses when building a disk image. This is useful to achieve reproducible
+  builds, where deterministic UUIDs and other partition metadata should be
+  derived on each build.
+
 ### [Content] Section
 
 `Packages=`, `--package=`, `-p`