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
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,
"--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)