From: Daan De Meyer Date: Mon, 28 Aug 2023 08:52:39 +0000 (+0200) Subject: Merge pull request #1836 from DaanDeMeyer/defaults X-Git-Tag: v16~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7030d76ae957d35d5b49e72c54c1d7f771cc4cac;p=thirdparty%2Fmkosi.git Merge pull request #1836 from DaanDeMeyer/defaults Support configuring default values for settings --- 7030d76ae957d35d5b49e72c54c1d7f771cc4cac diff --cc mkosi/config.py index edd2da748,bff37517a..f60a642e0 --- a/mkosi/config.py +++ b/mkosi/config.py @@@ -249,28 -248,18 +249,28 @@@ def config_parse_compression(value: Opt 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 - # distribution as well since the default release depends on the selected distribution. - if "distribution" not in namespace: - setattr(namespace, "distribution", detect_distribution()[0]) + def config_default_compression(namespace: argparse.Namespace) -> Compression: + if namespace.output_format == OutputFormat.cpio: + return Compression.xz if namespace.distribution.is_centos_variant() and int(namespace.release) <= 8 else Compression.zst + else: + return Compression.none - d = getattr(namespace, "distribution") + def config_default_release(namespace: argparse.Namespace) -> str: # If the configured distribution matches the host distribution, use the same release as the host. hd, hr = detect_distribution() - if d == hd and hr is not None: + if namespace.distribution == hd and hr is not None: return hr return { diff --cc mkosi/resources/mkosi.md index 12a3a8f37,7d2718b07..92e318c5e --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@@ -274,9 -277,15 +274,15 @@@ is prefixed with `!`, all existing inst are removed. Values prefixed with `!` can be globs to remove more than one value. + If a setting's name in the configuration file is prefixed with `@`, it + configures the default value used for that setting if no explicit + default value is set. This can be used to set custom default values in + configuration files that can still be overridden by specifying the + setting explicitly via the CLI. + To conditionally include configuration files, the `[Match]` section can -be used. Matches can use a pipe symbol ("|") after the equals sign -("…=|…"), which causes the match to become a triggering match. The +be used. Matches can use a pipe symbol (`|`) after the equals sign +(`…=|…`), which causes the match to become a triggering match. The config file will be included if the logical AND of all non-triggering matches and the logical OR of all triggering matches is satisfied. To negate the result of a match, prefix the argument with an exclamation