]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add UnitProperties= setting 2680/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 3 May 2024 22:04:57 +0000 (00:04 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 4 May 2024 10:52:23 +0000 (12:52 +0200)
This allows configuring properties on the scopes spawned by
systemd-nspawn or systemd-run.

mkosi/__init__.py
mkosi/config.py
mkosi/qemu.py
mkosi/resources/mkosi.md
tests/test_json.py

index 01fc8488e212d18bc11e877963b005ee18108810..7238c2f68bfdb08da0ad0eba12e182f0c26bbd81 100644 (file)
@@ -3971,6 +3971,9 @@ def run_shell(args: Args, config: Config) -> None:
                     "--set-credential=journal.forward_to_socket:/run/host/journal/socket",
                 ]
 
+        for p in config.unit_properties:
+            cmdline += ["--property", p]
+
         if args.verb == Verb.boot:
             # Add nspawn options first since systemd-nspawn ignores all options after the first argument.
             cmdline += args.cmdline
index 806da3d516d63ffdd9c5a9ba7c90470b54ad84d0..a9cdbf907254028442e34d643e49e3201819dc08 100644 (file)
@@ -1496,6 +1496,7 @@ class Config:
     runtime_scratch: ConfigFeature
     runtime_network: Network
     runtime_build_sources: bool
+    unit_properties: list[str]
     ssh_key: Optional[Path]
     ssh_certificate: Optional[Path]
     machine: Optional[str]
@@ -2868,6 +2869,13 @@ SETTINGS = (
         parse=config_parse_boolean,
         help="Mount build sources and build directory in /work when booting the image",
     ),
+    ConfigSetting(
+        dest="unit_properties",
+        long="--unit-property",
+        metavar="PROPERTY",
+        section="Host",
+        parse=config_make_list_parser(delimiter=" ", unescape=True),
+    ),
     ConfigSetting(
         dest="ssh_key",
         metavar="PATH",
@@ -4052,6 +4060,7 @@ def summary(config: Config) -> str:
                     Runtime Scratch: {config.runtime_scratch}
                     Runtime Network: {config.runtime_network}
               Runtime Build Sources: {config.runtime_build_sources}
+                    Unit Properties: {line_join_list(config.unit_properties)}
                     SSH Signing Key: {none_to_none(config.ssh_key)}
                     SSH Certificate: {none_to_none(config.ssh_certificate)}
                             Machine: {config.machine_or_name()}
index 7d4ae560c33f0c3d63b3d4505a8dd3ab3b57460f..19ff8ad7ece15e3aa44f944cfb91ed62fde0873c 100644 (file)
@@ -688,6 +688,7 @@ def scope_cmd(
     description: str,
     user: Optional[int] = None,
     group: Optional[int] = None,
+    properties: Sequence[str] = (),
 ) -> list[str]:
     return [
         "systemd-run",
@@ -699,6 +700,7 @@ def scope_cmd(
         "--collect",
         *(["--uid", str(user)] if user is not None else []),
         *(["--gid", str(group)] if group is not None else []),
+        *([f"--property={p}" for p in properties]),
     ]
 
 
@@ -1141,7 +1143,11 @@ def run_qemu(args: Args, config: Config) -> None:
             log=False,
             foreground=True,
             sandbox=config.sandbox(binary=None, network=True, devices=True, relaxed=True),
-            scope=scope_cmd(name=name, description=f"mkosi Virtual Machine {name}"),
+            scope=scope_cmd(
+                name=name,
+                description=f"mkosi Virtual Machine {name}",
+                properties=config.unit_properties,
+            ),
         ) as (proc, innerpid):
             # We have to close these before we wait for qemu otherwise we'll deadlock as qemu will never exit.
             for fd in qemu_device_fds.values():
index c0eff6cc3393232017cfc7725e9f84eaef1b1709..7e52a7d82c1b1f522ee288d3067f41d597568057 100644 (file)
@@ -1879,6 +1879,13 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
   they were mounted to when running the build script when using `mkosi
   boot` or `mkosi qemu`.
 
+`UnitProperties=`, `--unit-property=`
+
+: Configure systemd unit properties to add to the systemd scopes
+  allocated when using `mkosi boot` or `mkosi qemu`. These are passed
+  directly to the `--property` options of `systemd-nspawn` and
+  `systemd-run` respectively.
+
 `SshKey=`, `--ssh-key=`
 
 : Path to the X509 private key in PEM format to use to connect to a
index e503db04675da233599eb2e21aae54d6bfb15388..a759ecf0b7ef8201ac5bfc18eea447853e801606 100644 (file)
@@ -331,6 +331,9 @@ def test_config() -> None:
                 "abc"
             ],
             "UnifiedKernelImages": "auto",
+            "UnitProperties": [
+                "PROPERTY=VALUE"
+            ],
             "UseSubvolumes": "auto",
             "VerityCertificate": "/path/to/cert",
             "VerityKey": null,
@@ -488,6 +491,7 @@ def test_config() -> None:
         tools_tree_release=None,
         tools_tree_repositories=["abc"],
         unified_kernel_images=ConfigFeature.auto,
+        unit_properties=["PROPERTY=VALUE"],
         use_subvolumes=ConfigFeature.auto,
         verity_certificate=Path("/path/to/cert"),
         verity_key=None,