Skip to content

Commit a439229

Browse files
boukastro
authored andcommitted
Forward NOTIFY_SOCKET over vsock for cloud-hypervisor
This will forward the systemd ready notification inside the VM so the systemd service status reflects whether the VM has finished booting. Fixes #205
1 parent 9d3cc92 commit a439229

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/runner.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ let
1616
};
1717

1818
inherit (hypervisorConfig) command canShutdown shutdownCommand;
19+
supportsNotifySocket = hypervisorConfig.supportsNotifySocket or false;
1920
preStart = hypervisorConfig.preStart or microvmConfig.preStart;
2021
tapMultiQueue = hypervisorConfig.tapMultiQueue or false;
2122

@@ -56,7 +57,7 @@ pkgs.buildPackages.runCommand "microvm-${microvmConfig.hypervisor}-${microvmConf
5657
# for `nix run`
5758
meta.mainProgram = "microvm-run";
5859
passthru = {
59-
inherit canShutdown;
60+
inherit canShutdown supportsNotifySocket;
6061
inherit (microvmConfig) hypervisor;
6162
};
6263
} ''

lib/runners/cloud-hypervisor.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ in {
8888
# stumbling over a preexisting socket
8989
rm -f '${socket}'
9090
''}
91+
92+
# Start socat to forward systemd notify socket over vsock
93+
if [ -n "$NOTIFY_SOCKET" ]; then
94+
${pkgs.socat}/bin/socat UNIX-LISTEN:notify.vsock_8888,fork UNIX-SENDTO:$NOTIFY_SOCKET &
95+
fi
9196
'' + lib.optionalString graphics.enable ''
9297
rm -f ${graphics.socket}
9398
${pkgs.crosvm}/bin/crosvm device gpu \
@@ -100,6 +105,8 @@ in {
100105
done
101106
'';
102107

108+
supportsNotifySocket = true;
109+
103110
command =
104111
if user != null
105112
then throw "cloud-hypervisor will not change user"
@@ -118,6 +125,8 @@ in {
118125
"--cmdline" "console=ttyS0 reboot=t panic=-1 ${toString microvmConfig.kernelParams}"
119126
"--seccomp" "true"
120127
"--memory" memOps
128+
"--platform" "oem_strings=[io.systemd.credential:vmm.notify_socket=vsock-stream:2:8888]"
129+
"--vsock" "cid=3,socket=notify.vsock"
121130
]
122131
++
123132
lib.optionals graphics.enable [

nixos-modules/host/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ in
235235
# we also have to include a trigger here.
236236
restartTriggers = [guestConfig.system.build.toplevel];
237237
overrideStrategy = "asDropin";
238+
serviceConfig.Type = lib.mkIf guestConfig.microvm.declaredRunner.supportsNotifySocket "notify";
238239
};
239240
"microvm-tap-interfaces@${name}" = {
240241
serviceConfig.X-RestartIfChanged = [ "" microvmConfig.restartIfChanged ];
@@ -446,6 +447,7 @@ in
446447
Group = group;
447448
SyslogIdentifier = "microvm@%i";
448449
LimitNOFILE = 1048576;
450+
NotifyAccess = "all";
449451
LimitMEMLOCK = "infinity";
450452
};
451453
};

0 commit comments

Comments
 (0)