]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Respect SYSTEMD_TINT_BACKGROUND and SYSTEMD_ADJUST_TERMINAL_TITLE
authorQuentin Deslandes <qde@naccy.de>
Sun, 26 Oct 2025 10:53:40 +0000 (11:53 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 26 Oct 2025 12:48:25 +0000 (13:48 +0100)
When mkosi creates a new console with systemd-pty-forward, it sets a
custom (dark) color, which might not play nice depending on your
terminal theme. Environment variables SYSTEMD_TINT_BACKGROUND and
SYSTEMD_ADJUST_TERMINAL_TITLE allow the user the customize this behaviour, but
they were ignored until a recent change in systemd (c.f. 9c3359f).

Modify mkosi behaviour to respect SYSTEMD_TINT_BACKGROUND and
SYSTEMD_ADJUST_TERMINAL_TITLE when calling systemd-pty-forward.

mkosi/__init__.py
mkosi/config.py
mkosi/qemu.py

index 4bbd5e6c621f9baedf0f5cb67ae25992151d72af..83f7d47ffbc8d76e686044603b06b799b1a0b5c9 100644 (file)
@@ -80,6 +80,7 @@ from mkosi.config import (
     parse_config,
     resolve_deps,
     summary,
+    systemd_pty_forward,
     systemd_tool_version,
     want_kernel,
     want_selinux_relabel,
@@ -4059,13 +4060,8 @@ def run_box(args: Args, config: Config) -> None:
 
     cmdline = [*args.cmdline]
 
-    if sys.stdin.isatty() and sys.stdout.isatty() and config.find_binary("systemd-pty-forward"):
-        cmdline = [
-            "systemd-pty-forward",
-            "--title=mkosi-sandbox",
-            "--background=48;2;12;51;51",  # cyan
-            *cmdline,
-        ]
+    if sys.stdin.isatty() and sys.stdout.isatty():
+        cmdline = systemd_pty_forward(config, "48;2;12;51;51", "mkosi-sandbox") + cmdline
 
     with contextlib.ExitStack() as stack:
         if config.tools() != Path("/"):
index 31c1990884c691d570f6ef5312d3e4c11728cbf8..b572d41f7c6b3687e2ca444b0ec7b55cf48889c5 100644 (file)
@@ -6036,3 +6036,24 @@ def systemd_tool_version(*tool: PathString, sandbox: SandboxProtocol = nosandbox
     logging.debug(f"Version reported by {tool[-1]} is {version}")
 
     return version
+
+
+def systemd_pty_forward(config: Config, background: str, title: str) -> list[str]:
+    tint_bg = parse_boolean(config.environment.get("SYSTEMD_TINT_BACKGROUND", "1")) and parse_boolean(
+        os.environ.get("SYSTEMD_TINT_BACKGROUND", "1")
+    )
+    adjust_title = parse_boolean(
+        config.environment.get("SYSTEMD_ADJUST_TERMINAL_TITLE", "1")
+    ) and parse_boolean(os.environ.get("SYSTEMD_ADJUST_TERMINAL_TITLE", "1"))
+
+    if not tint_bg and not adjust_title:
+        return []
+    if not config.find_binary("systemd-pty-forward"):
+        return []
+
+    cmd = ["systemd-pty-forward"]
+    if tint_bg:
+        cmd += [f"--background={background}"]
+    if adjust_title:
+        cmd += ["--title=", title]
+    return cmd
index 86f3db30dfdb3a954c3f5cf9a769b6328dd7e587..85eb88a6af750505c55a6f2653604a277ad070c6 100644 (file)
@@ -43,6 +43,7 @@ from mkosi.config import (
     VsockCID,
     finalize_term,
     format_bytes,
+    systemd_pty_forward,
     systemd_tool_version,
     want_selinux_relabel,
     yes_no,
@@ -1183,10 +1184,9 @@ def run_qemu(args: Args, config: Config) -> None:
     cmdline: list[PathString] = []
 
     if config.console in (ConsoleMode.interactive, ConsoleMode.read_only):
-        cmdline += [
-            "systemd-pty-forward", "--background=48;2;12;51;19",  # green
-            "--title", f"Virtual Machine {config.machine_or_name()}",
-        ]  # fmt: skip
+        cmdline += systemd_pty_forward(
+            config, "48;2;12;51;19", f"Virtual Machine {config.machine_or_name()}"
+        )
 
         if config.console == ConsoleMode.read_only:
             cmdline += ["--read-only"]