2
2
, microvmConfig
3
3
, macvtapFds
4
4
, extractOptValues
5
+ , extractParamValue
5
6
, ...
6
7
} :
7
8
8
9
let
9
10
inherit ( pkgs ) lib ;
10
- inherit ( microvmConfig ) vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces volumes shares socket devices hugepageMem graphics storeDisk storeOnDisk kernel initrdPath ;
11
+ inherit ( microvmConfig ) vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces volumes shares socket devices hugepageMem graphics storeDisk storeOnDisk kernel initrdPath vsock ;
11
12
inherit ( microvmConfig . cloud-hypervisor ) platformOEMStrings extraArgs ;
12
13
14
+ # extract all the extra args that we merge with up front
15
+ processedExtraArgs = builtins . foldl'
16
+ ( args : opt : ( extractOptValues opt args ) . args )
17
+ extraArgs
18
+ [ "--vsock" "--platform" ] ;
19
+
13
20
hasUserConsole = ( extractOptValues "--console" extraArgs ) . values != [ ] ;
14
21
hasUserSerial = ( extractOptValues "--serial" extraArgs ) . values != [ ] ;
15
22
userSerial = if hasUserSerial then ( extractOptValues "--serial" extraArgs ) . values else "" ;
30
37
31
38
kernelCmdLine = "${ kernelConsole } reboot=t panic=-1 ${ builtins . unsafeDiscardStringContext ( toString microvmConfig . kernelParams ) } " ;
32
39
40
+
41
+ userVSockOpts = ( extractOptValues "--vsock" extraArgs ) . values ;
42
+ userVSockStr = if userVSockOpts == [ ] then null else builtins . head userVSockOpts ;
43
+ userVSockPath = extractParamValue "socket" userVSockStr ;
44
+ userVSockCID = extractParamValue "cid" userVSockStr ;
45
+ vsockCID = if vsock . cid != null && userVSockCID != null
46
+ then throw "Cannot set vsock.cid and --vsock 'cid=${ userVSockCID } ...' at the same time"
47
+ else if vsock . cid != null
48
+ then vsock . cid
49
+ else userVSockCID ;
50
+ supportsNotifySocket = vsockCID != null ;
51
+ vsockPath = if userVSockPath != null then userVSockPath else "notify.vsock" ;
52
+ vsockOpts =
53
+ if vsockCID == null then
54
+ lib . warn "cloud-hypervisor supports systemd-notify via vsock, but `microvm.vsock.cid` must be set to enable this." ""
55
+ else
56
+ "cid=${ toString vsockCID } ,socket=${ vsockPath } " ;
57
+
33
58
useHotPlugMemory = hotplugMem > 0 ;
34
59
35
60
useVirtiofs = builtins . any ( { proto , ... } : proto == "virtiofs" ) shares ;
@@ -101,14 +126,18 @@ let
101
126
vulkan = true ;
102
127
} ;
103
128
104
- supportsNotifySocket = true ;
105
-
106
129
oemStringValues = platformOEMStrings ++ lib . optional supportsNotifySocket "io.systemd.credential:vmm.notify_socket=vsock-stream:2:8888" ;
107
130
oemStringOptions = lib . optional ( oemStringValues != [ ] ) "oem_strings=[${ lib . concatStringsSep "," oemStringValues } ]" ;
108
131
platformExtracted = extractOptValues "--platform" extraArgs ;
109
132
extraArgsWithoutPlatform = platformExtracted . args ;
110
133
userPlatformOpts = platformExtracted . values ;
111
- platformOps = lib . concatStringsSep "," ( oemStringOptions ++ userPlatformOpts ) ;
134
+ userPlatformStr = if userPlatformOpts == [ ] then "" else builtins . head userPlatformOpts ;
135
+ userHasOemStrings = ( extractParamValue "oem_strings" userPlatformStr ) != null ;
136
+ platformOps =
137
+ if userHasOemStrings then
138
+ throw "Use `microvm.cloud-hypervisor.platformOEMStrings` instead of passing oem_strings via --platform"
139
+ else
140
+ lib . concatStringsSep "," ( oemStringOptions ++ userPlatformOpts ) ;
112
141
in {
113
142
inherit tapMultiQueue ;
114
143
@@ -122,13 +151,13 @@ in {
122
151
123
152
'' + lib . optionalString supportsNotifySocket ''
124
153
# Ensure notify sockets are removed if cloud-hypervisor didn't exit cleanly the last time
125
- rm -f notify.vsock notify.vsock_8888
154
+ rm -f ${ vsockPath } ${ vsockPath } _8888
126
155
127
156
# Start socat to forward systemd notify socket over vsock
128
157
if [ -n "'' ${NOTIFY_SOCKET:-}" ]; then
129
158
# -T2 is required because cloud-hypervisor does not handle partial
130
159
# shutdown of the stream, like systemd v256+ does.
131
- ${ pkgs . socat } /bin/socat -T2 UNIX-LISTEN:notify.vsock_8888 ,fork UNIX-SENDTO:$NOTIFY_SOCKET &
160
+ ${ pkgs . socat } /bin/socat -T2 UNIX-LISTEN:${ vsockPath } _8888 ,fork UNIX-SENDTO:$NOTIFY_SOCKET &
132
161
fi
133
162
'' + lib . optionalString graphics . enable ''
134
163
rm -f ${ graphics . socket }
142
171
done
143
172
'' ;
144
173
145
- inherit supportsNotifySocket ;
146
174
147
175
command =
148
176
if user != null
167
195
++
168
196
lib . optionals ( ! hasUserSerial ) [ "--serial" "tty" ]
169
197
++
170
- lib . optionals supportsNotifySocket [
171
- "--vsock" "cid=3,socket=notify.vsock"
172
- ]
198
+ lib . optionals ( vsockOpts != "" ) [ "--vsock" vsockOpts ]
173
199
++
174
200
lib . optionals graphics . enable [
175
201
"--gpu" "socket=${ graphics . socket } "
240
266
usb = throw "USB passthrough is not supported on cloud-hypervisor" ;
241
267
} . ${ bus } ) devices
242
268
)
243
- ) + " " + lib . escapeShellArgs extraArgsWithoutPlatform ;
269
+ ) + " " + lib . escapeShellArgs processedExtraArgs ;
244
270
245
271
canShutdown = socket != null ;
246
272
0 commit comments