From: Malte Poll Date: Fri, 25 Aug 2023 09:30:04 +0000 (+0200) Subject: add config setting seed to set systemd-repart --seed X-Git-Tag: v16~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0c151f06831d2628d4c002dcb350170a117fbf7;p=thirdparty%2Fmkosi.git add config setting seed to set systemd-repart --seed Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index bd39ec8d9..e64caf925 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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, ] diff --git a/mkosi/config.py b/mkosi/config.py index 790cccb50..edd2da748 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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)} diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 9002f8d32..12a3a8f37 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -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`