Skip to content

Commit a887694

Browse files
committed
cloud-hypervisor: allow overriding --serial and --console arguments
Check if --serial or --console are provided in extraArgs before adding defaults. This allows users to specify custom values like file output or socket connections instead of being forced to use the hardcoded defaults. We skip the default kernel serial parameter when serial is not set to tty. Fixes microvm-nix#376
1 parent 3323b70 commit a887694

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/runners/cloud-hypervisor.nix

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,26 @@ let
99
inherit (microvmConfig) vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces volumes shares socket devices hugepageMem graphics storeDisk storeOnDisk kernel initrdPath;
1010
inherit (microvmConfig.cloud-hypervisor) platformOEMStrings extraArgs;
1111

12+
hasUserConsole = (extractOptValues "--console" extraArgs).values != [];
13+
hasUserSerial = (extractOptValues "--serial" extraArgs).values != [];
14+
userSerial = if hasUserSerial then (extractOptValues "--serial" extraArgs).values else "";
15+
1216
kernelPath = {
1317
x86_64-linux = "${kernel.dev}/vmlinux";
1418
aarch64-linux = "${kernel.out}/${pkgs.stdenv.hostPlatform.linux-kernel.target}";
1519
}.${pkgs.stdenv.system};
1620

17-
kernelConsole =
21+
kernelConsoleDefault =
1822
if pkgs.stdenv.system == "x86_64-linux"
1923
then "earlyprintk=ttyS0 console=ttyS0"
2024
else if pkgs.stdenv.system == "aarch64-linux"
2125
then "console=ttyAMA0"
2226
else "";
2327

28+
kernelConsole = if (hasUserSerial && userSerial == "tty") then kernelConsoleDefault else "";
29+
30+
kernelCmdLine = "${kernelConsole} reboot=t panic=-1 ${builtins.unsafeDiscardStringContext (toString microvmConfig.kernelParams)}";
31+
2432
useHotPlugMemory = hotplugMem > 0;
2533

2634
useVirtiofs = builtins.any ({ proto, ... }: proto == "virtiofs") shares;
@@ -145,16 +153,18 @@ in {
145153
)
146154
"--cpus" "boot=${toString vcpu}"
147155
"--watchdog"
148-
"--console" "null"
149-
"--serial" "tty"
150156
"--kernel" kernelPath
151157
"--initramfs" initrdPath
152-
"--cmdline" "${kernelConsole} reboot=t panic=-1 ${builtins.unsafeDiscardStringContext (toString microvmConfig.kernelParams)}"
158+
"--cmdline" kernelCmdLine
153159
"--seccomp" "true"
154160
"--memory" memOps
155161
"--platform" platformOps
156162
]
157163
++
164+
lib.optionals (!hasUserConsole) ["--console" "null"]
165+
++
166+
lib.optionals (!hasUserSerial) ["--serial" "tty"]
167+
++
158168
lib.optionals supportsNotifySocket [
159169
"--vsock" "cid=3,socket=notify.vsock"
160170
]

0 commit comments

Comments
 (0)