Skip to content

Commit 42eca33

Browse files
committed
Implement Sandro's suggestion from the PR review
1 parent 3bbb732 commit 42eca33

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

lib/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ rec {
107107
=> { values = ["linux"]; args = ["-vnc" ":0" "-usb"]; }
108108
109109
# Extract multiple occurrences:
110-
extractOptValues "-platform" ["-a" "a" "-b" "b" "-c" "c" "-b" "b2"]
110+
extractOptValues "-b" ["-a" "a" "-b" "b" "-c" "c" "-b" "b2"]
111111
=> { values = ["b" "b2"]; args = ["-b" "b" "-c" "c"]; }
112112
113113
# Extract with multiple flag aliases:

lib/runner.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ let
88

99
inherit (microvmConfig) hostName;
1010

11-
inherit (import ./. { inherit lib; }) createVolumesScript makeMacvtap withDriveLetters;
11+
inherit (import ./. { inherit lib; }) createVolumesScript makeMacvtap withDriveLetters extractOptValues;
1212
inherit (makeMacvtap {
1313
inherit microvmConfig hypervisorConfig;
1414
}) openMacvtapFds macvtapFds;
1515

1616
hypervisorConfig = import (./runners + "/${microvmConfig.hypervisor}.nix") {
17-
inherit pkgs microvmConfig macvtapFds withDriveLetters;
17+
inherit pkgs microvmConfig macvtapFds withDriveLetters extractOptValues;
1818
};
1919

2020
inherit (hypervisorConfig) command canShutdown shutdownCommand;

lib/runners/cloud-hypervisor.nix

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{ pkgs
22
, microvmConfig
33
, macvtapFds
4+
, extractOptValues
45
, ...
56
}:
67

78
let
89
inherit (pkgs) lib;
9-
inherit (import ../. { inherit (pkgs) lib; }) extractOptValues;
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

@@ -95,10 +95,11 @@ let
9595

9696
supportsNotifySocket = true;
9797

98-
oemStringValues = (lib.optionals supportsNotifySocket ["io.systemd.credential:vmm.notify_socket=vsock-stream:2:8888"]) ++ platformOEMStrings;
99-
oemStringOptions = lib.optionals (oemStringValues != []) ["oem_strings=[${lib.concatStringsSep "," oemStringValues}]"];
100-
extraArgsWithoutPlatform = (extractOptValues "--platform" extraArgs).args;
101-
userPlatformOpts = (extractOptValues "--platform" extraArgs).values;
98+
oemStringValues = platformOEMStrings ++ lib.optional supportsNotifySocket "io.systemd.credential:vmm.notify_socket=vsock-stream:2:8888";
99+
oemStringOptions = lib.optional (oemStringValues != []) "oem_strings=[${lib.concatStringsSep "," oemStringValues}]";
100+
platformExtracted = extractOptValues "--platform" extraArgs;
101+
extraArgsWithoutPlatform = platformExtracted.args;
102+
userPlatformOpts = platformExtracted.values;
102103
platformOps = lib.concatStringsSep "," (oemStringOptions ++ userPlatformOpts);
103104
in {
104105
inherit tapMultiQueue;

nixos-modules/microvm/asserts.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,17 @@ lib.mkIf config.microvm.guest.enable {
105105
message = ''
106106
MicroVM ${hostName}: `config.microvm.forwardPorts` works only with qemu and one network interface with `type = "user"`
107107
'';
108+
} ]
109+
++
110+
# cloud-hypervisor specific asserts
111+
lib.optionals (config.microvm.hypervisor == "cloud-hypervisor") [ {
112+
assertion = ! (lib.any (str: lib.hasInfix "oem_strings" str) config.microvm.cloud-hypervisor.platformOEMStrings);
113+
message = ''
114+
MicroVM ${hostName}: `config.microvm.cloud-hypervisor.platformOEMStrings` items must not contain `oem_strings`
115+
'';
108116
} ];
109117

118+
110119
warnings =
111120
# 32 MB is just an optimistic guess, not based on experience
112121
lib.optional (config.microvm.mem < 32) ''

nixos-modules/microvm/options.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,17 @@ in
519519
type = with types; listOf str;
520520
default = [];
521521
description = ''
522-
Extra arguments to pass to cloud-hypervisor's --platform oem_strings= argument.
522+
Extra arguments to pass to cloud-hypervisor's --platform oem_strings=[] argument.
523523
524524
All the oem strings will be concatenated with a comma (,) and wrapped in oem_string=[].
525525
526+
Do not include oem_string= or the [] brackets in the value.
527+
526528
The resulting string will be combined with any --platform options in
527529
`config.microvm.cloud-hypervisor.extraArgs` and passed as a single
528530
--platform option to cloud-hypervisor
529531
'';
530-
example = lib.literalExpression /* nix */ ''
531-
[ "io.systemd.credential:APIKEY=supersecret" ]
532-
'';
532+
example = lib.literalExpression /* nix */ ''[ "io.systemd.credential:APIKEY=supersecret" ]'';
533533
};
534534

535535
cloud-hypervisor.extraArgs = mkOption {

0 commit comments

Comments
 (0)