Skip to content

Commit 00c891b

Browse files
committed
cloud-hypervisor: add platformOEMStrings and extraPlatformOpts.
The cloud-hypervisor command line interface unfortunately doesn't support multiple instances of the same arg with a different value, so we have to resort to these extra module options rather than using extraArgs. To make matters even worse, the `--platform` argument (of which there can be only one), is overloaded with different types of sub-args that also need to be provided multiple times. This commit allows the operator to add oem strings (for example to pass systemd credentials), as well as raw platform options as needed.
1 parent d3a9b75 commit 00c891b

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/runners/cloud-hypervisor.nix

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let
77
inherit (pkgs) lib;
88
inherit (microvmConfig) vcpu mem balloonMem deflateOnOOM user interfaces volumes shares socket devices hugepageMem graphics storeDisk storeOnDisk kernel initrdPath;
9-
inherit (microvmConfig.cloud-hypervisor) extraArgs;
9+
inherit (microvmConfig.cloud-hypervisor) platformOEMStrings extraPlatformOpts extraArgs;
1010

1111
kernelPath = {
1212
x86_64-linux = "${kernel.dev}/vmlinux";
@@ -94,6 +94,9 @@ let
9494

9595
supportsNotifySocket = true;
9696

97+
oemStringValues = (lib.optionals supportsNotifySocket ["io.systemd.credential:vmm.notify_socket=vsock-stream:2:8888"]) ++ platformOEMStrings;
98+
oemStringOptions = lib.optionals (oemStringValues != []) ["oem_strings=[${lib.concatStringsSep "," oemStringValues}]"];
99+
platformOps = lib.concatStringsSep "," (oemStringOptions ++ extraPlatformOpts);
97100
in {
98101
inherit tapMultiQueue;
99102

@@ -147,10 +150,10 @@ in {
147150
"--cmdline" "${kernelConsole} reboot=t panic=-1 ${toString microvmConfig.kernelParams}"
148151
"--seccomp" "true"
149152
"--memory" memOps
153+
"--platform" platformOps
150154
]
151155
++
152156
lib.optionals supportsNotifySocket [
153-
"--platform" "oem_strings=[io.systemd.credential:vmm.notify_socket=vsock-stream:2:8888]"
154157
"--vsock" "cid=3,socket=notify.vsock"
155158
]
156159
++

nixos-modules/microvm/options.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,30 @@ in
483483
'';
484484
};
485485

486+
cloud-hypervisor.platformOEMStrings = mkOption {
487+
type = with types; listOf str;
488+
default = [];
489+
description = ''
490+
Extra arguments to pass to cloud-hypervisor's --platform oem_strings= argument.
491+
492+
All the oem strings will be concatenated with a comma (,) and wrapped in oem_string=[].
493+
'';
494+
example = literalExpression /* nix */ ''
495+
[ "io.systemd.credential:APIKEY=supersecret" ]
496+
'';
497+
};
498+
cloud-hypervisor.extraPlatformOpts = mkOption {
499+
type = with types; listOf str;
500+
default = [];
501+
description = ''
502+
Extra arguments to pass to cloud-hypervisor's --platform argument.
503+
All --platform args will be concatended with a comma (,).
504+
'';
505+
example = literalExpression /* nix */ ''
506+
[ "uuid=<dmi_device_uuid>" ]
507+
'';
508+
};
509+
486510
cloud-hypervisor.extraArgs = mkOption {
487511
type = with types; listOf str;
488512
default = [];

0 commit comments

Comments
 (0)