From 1a8cd7bd8151c6a806ee56fe67c7d0c6f32f1c3c Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Fri, 11 Dec 2020 15:56:44 +0000 Subject: [PATCH] nspawn: check if --console is available before using it On Debian Buster nspawn doesn't support this parameter (v241) --- mkosi/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 8a2843878..6b687f804 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -5240,6 +5240,9 @@ def one_zero(b: bool) -> str: return "1" if b else "0" +def nspawn_knows_arg(arg: str) -> bool: + return bytes("unrecognized option", "UTF-8") not in run(["systemd-nspawn", arg], stderr=PIPE, check=False).stderr + def run_build_script(args: CommandLineArguments, root: str, raw: Optional[BinaryIO]) -> None: if args.build_script is None: return @@ -5251,8 +5254,6 @@ def run_build_script(args: CommandLineArguments, root: str, raw: Optional[Binary target = "--directory=" + root if raw is None else "--image=" + raw.name cmdline = ["systemd-nspawn", - # TODO: Use --autopipe once systemd v247 is widely available. - f"--console={'interactive' if sys.stdout.isatty() else 'pipe'}", '--quiet', target, "--uuid=" + args.machine_id, @@ -5266,6 +5267,11 @@ def run_build_script(args: CommandLineArguments, root: str, raw: Optional[Binary "--setenv=WITH_NETWORK=" + one_zero(args.with_network), "--setenv=DESTDIR=/root/dest"] + # TODO: Use --autopipe once systemd v247 is widely available. + console_arg = f"--console={'interactive' if sys.stdout.isatty() else 'pipe'}" + if nspawn_knows_arg(console_arg): + cmdline.append(console_arg) + if args.default_path is not None: cmdline.append("--setenv=MKOSI_DEFAULT=" + args.default_path) -- 2.47.2