]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
nspawn: check if --console is available before using it 569/head
authorLuca Boccassi <luca.boccassi@microsoft.com>
Fri, 11 Dec 2020 15:56:44 +0000 (15:56 +0000)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Fri, 11 Dec 2020 23:35:29 +0000 (23:35 +0000)
On Debian Buster nspawn doesn't support this parameter (v241)

mkosi/__init__.py

index 8a28438781b7e7e503ff2bef40f54080d0c88a19..6b687f804b8530fac16c40d5b716a65af787c905 100644 (file)
@@ -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)