]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add env variable to configure nspawn executable to use
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 5 May 2022 09:22:54 +0000 (11:22 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 5 May 2022 10:23:56 +0000 (12:23 +0200)
Useful when working on nspawn to configure mkosi to use nspawn
from the build directory instead of system nspawn.

mkosi.md
mkosi/__init__.py
mkosi/backend.py

index 499551dac2605d7a0cc26eabbfe8c95187c76b8e..85a416fafabc3a096871cccbb54ada1e335c2495 100644 (file)
--- a/mkosi.md
+++ b/mkosi.md
@@ -1254,6 +1254,13 @@ Those settings cannot be configured in the configuration files.
   each build in a series will have a version number one higher then
   the previous one.
 
+### Environment Variables
+
+`MKOSI_NSPAWN_EXECUTABLE`
+
+: Takes a path. If specified, mkosi will use this path as the systemd-nspawn
+  executable instead of the system installation of systemd-nspawn.
+
 ## Supported distributions
 
 Images may be created containing installations of the
index 54119e7e8357be29f63653d7bdde3329af34a049..3cbfa177cfb84515b520f4136e10fa48a8a7f23d 100644 (file)
@@ -82,6 +82,7 @@ from .backend import (
     die,
     install_grub,
     is_rpm_distribution,
+    nspawn_executable,
     nspawn_params_for_blockdev_access,
     nspawn_rlimit_params,
     patch_file,
@@ -7248,7 +7249,7 @@ def install_dir(args: MkosiArgs, root: Path) -> Path:
 
 
 def nspawn_knows_arg(arg: str) -> bool:
-    return bytes("unrecognized option", "UTF-8") not in run(["systemd-nspawn", arg], stderr=PIPE, check=False).stderr
+    return bytes("unrecognized option", "UTF-8") not in run([nspawn_executable(), arg], stderr=PIPE, check=False).stderr
 
 
 def run_build_script(args: MkosiArgs, root: Path, raw: Optional[BinaryIO]) -> None:
@@ -7263,7 +7264,7 @@ def run_build_script(args: MkosiArgs, root: Path, raw: Optional[BinaryIO]) -> No
         with_network = 1 if args.with_network is True else 0
 
         cmdline = [
-            "systemd-nspawn",
+            nspawn_executable(),
             "--quiet",
             target,
             f"--uuid={args.machine_id}",
@@ -7548,7 +7549,7 @@ def run_shell_cmdline(args: MkosiArgs, pipe: bool = False, commands: Optional[Se
     else:
         target = f"--image={args.output}"
 
-    cmdline = ["systemd-nspawn", "--quiet", target]
+    cmdline = [nspawn_executable(), "--quiet", target]
 
     # Redirecting output correctly when not running directly from the terminal.
     console_arg = f"--console={'interactive' if not pipe else 'pipe'}"
index b63f3bd8d741a98587cd9be1c41aa5a1bbb239fc..384494db68beb116e4c7f217a76ff9eba8f7b464 100644 (file)
@@ -627,6 +627,10 @@ def nspawn_rlimit_params() -> Sequence[str]:
     ]
 
 
+def nspawn_executable() -> str:
+    return os.getenv("MKOSI_NSPAWN_EXECUTABLE", "systemd-nspawn")
+
+
 def run_workspace_command(
     args: MkosiArgs,
     root: Path,
@@ -637,7 +641,7 @@ def run_workspace_command(
     capture_stdout: bool = False,
 ) -> Optional[str]:
     nspawn = [
-        "systemd-nspawn",
+        nspawn_executable(),
         "--quiet",
         f"--directory={root}",
         "--uuid=" + args.machine_id,