From 5cb6da6f8d4452e3d2c3a46bcefaac2f4c6d54ae Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sat, 9 Sep 2023 12:12:44 +0200 Subject: [PATCH] Add SystemdVersion= match 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 | 20 ++++++++++++++++---- mkosi/resources/mkosi.md | 29 +++++++++++++++++++---------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/mkosi/config.py b/mkosi/config.py index 400d0f504..5f8df6a7b 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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, + ), ) diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index bbfb9b51f..f35a9d84d 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -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 -- 2.47.2