From: Daan De Meyer Date: Thu, 5 May 2022 09:22:54 +0000 (+0200) Subject: Add env variable to configure nspawn executable to use X-Git-Tag: v13~43^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=968e31d99db929e167d55ef93d9e33d21eeb14f1;p=thirdparty%2Fmkosi.git Add env variable to configure nspawn executable to use Useful when working on nspawn to configure mkosi to use nspawn from the build directory instead of system nspawn. --- diff --git a/mkosi.md b/mkosi.md index 499551dac..85a416faf 100644 --- 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 diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 54119e7e8..3cbfa177c 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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'}" diff --git a/mkosi/backend.py b/mkosi/backend.py index b63f3bd8d..384494db6 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -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,