]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add SystemdVersion= match 1889/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 9 Sep 2023 10:12:44 +0000 (12:12 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 9 Sep 2023 12:37:36 +0000 (14:37 +0200)
This matches against the systemd version on the host. This is
useful for conditionally using a tools tree if the systemd version
on the host is too old.

mkosi/config.py
mkosi/resources/mkosi.md

index 400d0f50406cd5c08795437c2536d83265b5a348..5f8df6a7b0d7616443b7ffcfbded61f65924059f 100644 (file)
@@ -383,8 +383,8 @@ def config_make_list_parser(delimiter: str,
     return config_parse_list
 
 
-def config_match_image_version(match: str, value: str) -> bool:
-    image_version = GenericVersion(value)
+def config_match_version(match: str, value: str) -> bool:
+    version = GenericVersion(value)
 
     for sigil, opfunc in {
         "==": operator.eq,
@@ -404,7 +404,7 @@ def config_match_image_version(match: str, value: str) -> bool:
         comp_version = GenericVersion(match)
 
     # all constraints must be fulfilled
-    if not op(image_version, comp_version):
+    if not op(version, comp_version):
         return False
 
     return True
@@ -479,6 +479,14 @@ def config_parse_root_password(value: Optional[str], old: Optional[tuple[str, bo
     return (value, hashed)
 
 
+def match_systemd_version(value: str) -> bool:
+    if not value:
+        return False
+
+    version = run(["systemctl", "--version"], stdout=subprocess.PIPE).stdout.strip().split()[1]
+    return config_match_version(value, version)
+
+
 @dataclasses.dataclass(frozen=True)
 class MkosiConfigSetting:
     dest: str
@@ -1026,7 +1034,7 @@ SETTINGS = (
     ),
     MkosiConfigSetting(
         dest="image_version",
-        match=config_match_image_version,
+        match=config_match_version,
         section="Output",
         help="Set version for image",
         paths=("mkosi.version",),
@@ -1657,6 +1665,10 @@ MATCHES = (
         name="PathExists",
         match=match_path_exists,
     ),
+    MkosiMatch(
+        name="SystemdVersion",
+        match=match_systemd_version,
+    ),
 )
 
 
index bbfb9b51f4474b85722ec0860b55c4be90fddb04..f35a9d84dccb60ecf861c4fc33787016093c584c 100644 (file)
@@ -316,7 +316,7 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
 
 : Matches against the configured image version. Image versions can be prepended by the operators `==`, `!=`,
   `>=`, `<=`, `<`, `>` for rich version comparisons according to the UAPI group version format specification.
-  If no operator is prepended, the equality operator is assumed by default If this condition is used and no
+  If no operator is prepended, the equality operator is assumed by default. If this condition is used and no
   image version has been explicitly configured yet, this condition fails.
 
 `Bootable=`
@@ -328,15 +328,24 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
 : Matches against the configured value for the `Format=` option. Takes
   an output format (see the `Format=` option).
 
-| Matcher         | Globs | Rich Comparisons | Default                 |
-|-----------------|-------|------------------|-------------------------|
-| `Distribution=` | no    | no               | match host distribution |
-| `Release=`      | no    | no               | match host release      |
-| `PathExists=`   | no    | no               | match fails             |
-| `ImageId=`      | yes   | no               | match fails             |
-| `ImageVersion=` | no    | yes              | match fails             |
-| `Bootable=`     | no    | no               | match auto feature      |
-| `Format=`       | no    | no               | match default format    |
+`SystemdVersion=`
+
+: Matches against the systemd version on the host (as reported by
+  `systemctl --version`). Values can be prepended by the operators `==`,
+  `!=`, `>=`, `<=`, `<`, `>` for rich version comparisons according to
+  the UAPI group version format specification. If no operator is
+  prepended, the equality operator is assumed by default.
+
+| Matcher           | Globs | Rich Comparisons | Default                 |
+|-------------------|-------|------------------|-------------------------|
+| `Distribution=`   | no    | no               | match host distribution |
+| `Release=`        | no    | no               | match host release      |
+| `PathExists=`     | no    | no               | match fails             |
+| `ImageId=`        | yes   | no               | match fails             |
+| `ImageVersion=`   | no    | yes              | match fails             |
+| `Bootable=`       | no    | no               | match auto feature      |
+| `Format=`         | no    | no               | match default format    |
+| `SystemdVersion=` | no    | yes              | match fails             |
 
 ### [Preset] Section