Skip to content

Commit 1b3e2e9

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 #376
1 parent 3b39c12 commit 1b3e2e9

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
@@ -10,18 +10,26 @@ let
1010
inherit (microvmConfig) vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces volumes shares socket devices hugepageMem graphics storeDisk storeOnDisk kernel initrdPath;
1111
inherit (microvmConfig.cloud-hypervisor) platformOEMStrings extraArgs;
1212

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

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

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

2735
useVirtiofs = builtins.any ({ proto, ... }: proto == "virtiofs") shares;
@@ -147,16 +155,18 @@ in {
147155
)
148156
"--cpus" "boot=${toString vcpu}"
149157
"--watchdog"
150-
"--console" "null"
151-
"--serial" "tty"
152158
"--kernel" kernelPath
153159
"--initramfs" initrdPath
154-
"--cmdline" "${kernelConsole} reboot=t panic=-1 ${builtins.unsafeDiscardStringContext (toString microvmConfig.kernelParams)}"
160+
"--cmdline" kernelCmdLine
155161
"--seccomp" "true"
156162
"--memory" memOps
157163
"--platform" platformOps
158164
]
159165
++
166+
lib.optionals (!hasUserConsole) ["--console" "null"]
167+
++
168+
lib.optionals (!hasUserSerial) ["--serial" "tty"]
169+
++
160170
lib.optionals supportsNotifySocket [
161171
"--vsock" "cid=3,socket=notify.vsock"
162172
]

0 commit comments

Comments
 (0)