Skip to content

Commit e068a39

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 bde4522 commit e068a39

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

1212
kernelPath = {
1313
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 ${builtins.unsafeDiscardStringContext (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
@@ -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)