147147 else "" ;
148148
149149 supportsNotifySocket = vsock . cid != null ;
150+ vsockHostPortOffset = 600000 ;
150151
151152in
152153lib . warnIf ( mem == 2048 ) ''
@@ -163,15 +164,11 @@ lib.warnIf (mem == 2048) ''
163164 # Clean up temporary files.
164165 ${ pkgs . coreutils } /bin/rm -f ./socat.log ./notify_socket.cred
165166 # Default value: for running without systemd.
166- NOTIFY_VSOCK_PORT=8888
167+ NOTIFY_VSOCK_PORT=${ toString ( vsockHostPortOffset + vsock . cid ) }
167168 # Start socat to forward systemd notify socket over vsock
168169 if [ -n "'' ${NOTIFY_SOCKET-}" ]; then
169- ${ pkgs . socat } /bin/socat -d -d VSOCK-LISTEN:-1,fork UNIX-SENDTO:$NOTIFY_SOCKET 2> ./socat.log &
170- NOTIFY_VSOCK_PORT=$({ ${ pkgs . coreutils } /bin/tail -f ./socat.log || true; } | ${ pkgs . gawk } /bin/awk '/listening on/ { if (match($0, /port:[0-9]*/)) { print substr($0, RSTART + 5, RLENGTH - 5); exit; } }')
171- echo "Picked port for notify vsock: $NOTIFY_VSOCK_PORT"
170+ ${ pkgs . socat } /bin/socat -d -d VSOCK-LISTEN:$NOTIFY_VSOCK_PORT,fork UNIX-SENDTO:$NOTIFY_SOCKET 2> ./socat.log &
172171 fi
173- echo -n "vsock-stream:2:$NOTIFY_VSOCK_PORT" > ./notify_socket.cred
174-
175172 '' ;
176173
177174 command = lib . escapeShellArgs (
@@ -322,7 +319,7 @@ lib.warnIf (mem == 2048) ''
322319 # tried, SMBIOS Type 11 entries simply don't work. It looks like it might
323320 # be broken on QEMU side. Why? I don't know.
324321 "-fw_cfg"
325- "name=opt/io.systemd.credentials/vmm.notify_socket,file=./notify_socket.cred "
322+ "name=opt/io.systemd.credentials/vmm.notify_socket,string=vsock-stream:2: ${ toString ( vsockHostPortOffset + vsock . cid ) } "
326323 ]
327324 ++
328325 extraArgs
0 commit comments