]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Merge pull request #1836 from DaanDeMeyer/defaults
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 28 Aug 2023 08:52:39 +0000 (10:52 +0200)
committerGitHub <noreply@github.com>
Mon, 28 Aug 2023 08:52:39 +0000 (10:52 +0200)
Support configuring default values for settings

1  2 
mkosi/config.py
mkosi/resources/mkosi.md

diff --cc mkosi/config.py
index edd2da748af1bd7bc59e97331ecca25c20f9253c,bff37517a989c386ef6a83e0cf17401185116cc6..f60a642e0052984a0964408d467c0b77d4da8b95
@@@ -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 {
index 12a3a8f37cc6010d0e143cc8326d25c59c573ca5,7d2718b07da98f61ca685ddc7f2fe810cfaca12e..92e318c5e3d3ba30c83a30657026ab4e2bb0b55e
@@@ -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