From 43438277d8dc7243fd2e64ca984c6061dd742e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=AD=C3=B0=20Steinn=20Geirsson?= Date: Sat, 21 Mar 2026 20:10:06 +0000 Subject: [PATCH] fix: use screen -dmS with Type=forking for console drain service screen -dmS forks to background (daemon mode), which should work without a controlling terminal. Type=forking tells systemd to expect the fork. Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 2 +- modules/scripts.nix | 10 +++++----- modules/services.nix | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8d100bc..1981c91 100644 --- a/README.md +++ b/README.md @@ -540,7 +540,7 @@ vm-shell --ssh # SSH into VM as user vm-shell --ssh --root # SSH into VM as root ``` -The default serial console mode connects via a `tmux` session. Press `Ctrl+B, D` to detach. No configuration required. +The default serial console mode connects via a `screen` session. Press `Ctrl+A, D` to detach. No configuration required. SSH mode requires SSH keys configured in per-VM `guestConfig` (see Advanced Configuration). For cloud-hypervisor VMs, `--ssh` automatically connects via a ProxyCommand over the vsock socket — no IP routing required. diff --git a/modules/scripts.nix b/modules/scripts.nix index 461f2db..1e68e7a 100644 --- a/modules/scripts.nix +++ b/modules/scripts.nix @@ -1399,8 +1399,8 @@ let echo " --ssh Use SSH over vsock (requires SSH keys configured)" >&2 echo " --root Connect as root (only with --ssh)" >&2 echo "" >&2 - echo "Without --ssh, connects to serial console via tmux." >&2 - echo "Detach with Ctrl+B, D" >&2 + echo "Without --ssh, connects to serial console via screen." >&2 + echo "Detach with Ctrl+A, D" >&2 exit 1 } @@ -1454,13 +1454,13 @@ let "${vm.name}) exec ${pkgs.openssh}/bin/ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ProxyCommand=${lib.escapeShellArg "${proxyCmd}"} \$USER_NAME@localhost ;;" )} else - if ! ${pkgs.tmux}/bin/tmux has-session -t vmsilo-$VM_NAME 2>/dev/null; then + if ! ${pkgs.screen}/bin/screen -ls vmsilo-$VM_NAME >/dev/null 2>&1; then echo "No console session found for $VM_NAME" >&2 echo "Is the VM running? Use: vm-start $VM_NAME" >&2 exit 1 fi - echo "Detach with Ctrl+B, D" - exec ${pkgs.tmux}/bin/tmux attach -t vmsilo-$VM_NAME + echo "Detach with Ctrl+A, D" + exec ${pkgs.screen}/bin/screen -x vmsilo-$VM_NAME fi ''; in diff --git a/modules/services.nix b/modules/services.nix index 68c240f..7a34e6c 100644 --- a/modules/services.nix +++ b/modules/services.nix @@ -472,7 +472,7 @@ in ) (lib.filter (vm: vm.hypervisor == "crosvm") (lib.attrValues cfg.nixosVms)) ++ # Console screen services (one per VM) - # Attaches a tmux session to the console PTY to keep the buffer drained + # Attaches a screen session to the console PTY to keep the buffer drained map ( vm: let @@ -488,7 +488,7 @@ in echo "Timeout waiting for console PTY" >&2 exit 1 fi - exec ${pkgs.tmux}/bin/tmux new-session -s vmsilo-${vm.name} -x 200 -y 50 "cat /run/vmsilo/${vm.name}/console" + ${pkgs.screen}/bin/screen -dmS vmsilo-${vm.name} -h 10000 /run/vmsilo/${vm.name}/console ''; in lib.nameValuePair "vmsilo-${vm.name}-console-screen" { @@ -499,11 +499,11 @@ in bindsTo = [ "vmsilo-${vm.name}-vm.service" ]; serviceConfig = { - Type = "simple"; + Type = "forking"; User = cfg.user; - ExecStartPre = "-${pkgs.tmux}/bin/tmux kill-session -t vmsilo-${vm.name}"; + ExecStartPre = "-${pkgs.screen}/bin/screen -S vmsilo-${vm.name} -X quit"; ExecStart = "${screenScript}"; - ExecStopPost = "-${pkgs.tmux}/bin/tmux kill-session -t vmsilo-${vm.name}"; + ExecStopPost = "-${pkgs.screen}/bin/screen -S vmsilo-${vm.name} -X quit"; }; } ) (lib.attrValues cfg.nixosVms)