Skip to content

Commit df9df1b

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 f30ae9b commit df9df1b

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 balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem 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";
@@ -93,6 +93,9 @@ let
9393

9494
supportsNotifySocket = true;
9595

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

@@ -146,10 +149,10 @@ in {
146149
"--cmdline" "${kernelConsole} reboot=t panic=-1 ${builtins.unsafeDiscardStringContext (toString microvmConfig.kernelParams)}"
147150
"--seccomp" "true"
148151
"--memory" memOps
152+
"--platform" platformOps
149153
]
150154
++
151155
lib.optionals supportsNotifySocket [
152-
"--platform" "oem_strings=[io.systemd.credential:vmm.notify_socket=vsock-stream:2:8888]"
153156
"--vsock" "cid=3,socket=notify.vsock"
154157
]
155158
++

nixos-modules/microvm/options.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,30 @@ in
515515
'';
516516
};
517517

518+
cloud-hypervisor.platformOEMStrings = mkOption {
519+
type = with types; listOf str;
520+
default = [];
521+
description = ''
522+
Extra arguments to pass to cloud-hypervisor's --platform oem_strings= argument.
523+
524+
All the oem strings will be concatenated with a comma (,) and wrapped in oem_string=[].
525+
'';
526+
example = literalExpression /* nix */ ''
527+
[ "io.systemd.credential:APIKEY=supersecret" ]
528+
'';
529+
};
530+
cloud-hypervisor.extraPlatformOpts = mkOption {
531+
type = with types; listOf str;
532+
default = [];
533+
description = ''
534+
Extra arguments to pass to cloud-hypervisor's --platform argument.
535+
All --platform args will be concatended with a comma (,).
536+
'';
537+
example = literalExpression /* nix */ ''
538+
[ "uuid=<dmi_device_uuid>" ]
539+
'';
540+
};
541+
518542
cloud-hypervisor.extraArgs = mkOption {
519543
type = with types; listOf str;
520544
default = [];

0 commit comments

Comments
 (0)