From 3e443e1aeec5504b2f378fc9a9f53c2e85dc72f9 Mon Sep 17 00:00:00 2001 From: Sam Estep Date: Tue, 14 Jul 2026 19:17:24 -0400 Subject: [PATCH] Give Lima's autostart graceful shutdown time to finish On SIGTERM, Lima's hostagent gracefully powers off the guest and waits up to 30s for it to halt (pkg/driver/vz/vz_driver_darwin.go). But its autostart plists set no ExitTimeOut, so launchd's 5s default SIGKILLs the hostagent when the Mac shuts down --- force-killing the guest mid-flush, which corrupts Git repos and drops recent writes. Patch the embedded LaunchAgent/LaunchDaemon plist templates to set ExitTimeOut=60 (>= the driver's 30s stop timeout) so the graceful stop can complete during host shutdown. To try it out: # 1. Rebuild so the new limactl is on PATH: home-manager switch --flake ~/github/samestep/env#samueles # 2. Regenerate the installed plist (it does not update itself): limactl autostart disable sandbox-arm64 && limactl autostart enable sandbox-arm64 # 3. Confirm it took (expect: exit timeout = 60): launchctl print gui/$(id -u)/io.lima-vm.autostart.sandbox-arm64 | grep -i 'exit timeout' # 4. After the next "Shut Down...", boot back up and, inside the guest, look # for a full shutdown sequence (Stopping.../Unmounted/Power-Off) that was # previously absent --- its span will often exceed the old 5s window: journalctl -b -1 -o short-precise | tail -30 Co-Authored-By: Claude Opus 4.8 --- flake.nix | 7 +++++++ lima-exit-timeout.patch | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 lima-exit-timeout.patch diff --git a/flake.nix b/flake.nix index 2da4404..e6df197 100644 --- a/flake.nix +++ b/flake.nix @@ -122,6 +122,13 @@ hash = "sha256-eyvz7XbZKUVQZdSVmDmYlHQSCKFE23OeIH4N4hNDg3M="; }; vendorHash = "sha256-nwNDuE76fVncegDKI/Fztpc30NX8/shNbSfzkrwTPDk="; + # On SIGTERM, Lima's hostagent gracefully powers off the guest and + # waits up to 30s for it to halt (pkg/driver/vz/vz_driver_darwin.go). + # But its autostart plists set no ExitTimeOut, so launchd's 5s default + # SIGKILLs the hostagent when the Mac shuts down --- force-killing the + # guest mid-flush, which corrupts Git repos and drops recent writes. + # Give the graceful stop room to finish (>= the driver's 30s timeout). + patches = (old.patches or [ ]) ++ [ ./lima-exit-timeout.patch ]; }); }) ]; diff --git a/lima-exit-timeout.patch b/lima-exit-timeout.patch new file mode 100644 index 0000000..20dbbbc --- /dev/null +++ b/lima-exit-timeout.patch @@ -0,0 +1,24 @@ +diff --git a/pkg/autostart/launchd/io.lima-vm.autostart.INSTANCE.plist b/pkg/autostart/launchd/io.lima-vm.autostart.INSTANCE.plist +index 0e777962..15c62d29 100644 +--- a/pkg/autostart/launchd/io.lima-vm.autostart.INSTANCE.plist ++++ b/pkg/autostart/launchd/io.lima-vm.autostart.INSTANCE.plist +@@ -25,5 +25,7 @@ + {{ .WorkDir }} + ProcessType + Background ++ ExitTimeOut ++ 60 + + +diff --git a/pkg/autostart/launchd/io.lima-vm.daemon.INSTANCE.plist b/pkg/autostart/launchd/io.lima-vm.daemon.INSTANCE.plist +index 2da849eb..5af817c9 100644 +--- a/pkg/autostart/launchd/io.lima-vm.daemon.INSTANCE.plist ++++ b/pkg/autostart/launchd/io.lima-vm.daemon.INSTANCE.plist +@@ -27,5 +27,7 @@ + {{ .WorkDir }} + ProcessType + Background ++ ExitTimeOut ++ 60 + +