lima icon indicating copy to clipboard operation
lima copied to clipboard

autostart: launchd agent can't find qemu-system-* because plist doesn't set PATH

Open capsidimit opened this issue 2 months ago • 1 comments

Description

The LaunchAgent generated by limactl autostart enable does not set PATH. launchd starts agents with a minimal environment (/usr/bin:/bin:/usr/sbin:/sbin), so on Homebrew installs (/opt/homebrew/bin) limactl cannot resolve the QEMU binary and the instance fails to start at login. The same instance starts fine from an interactive shell.

Steps to reproduce

  1. Install lima and qemu via Homebrew on Apple Silicon.
  2. Create an instance that uses the QEMU driver (e.g. arch: x86_64, or vmType: qemu).
  3. Run limactl start-at-login <instance>.
  4. Log out/in (or launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/io.lima-vm.autostart.<instance>.plist).

Expected behavior

Instance starts at login, same as limactl start <instance> from a shell.

Actual behavior

~/.lima/<instance>/launchd.stderr.log:

level=info msg="Starting the instance `docker` with internal VM driver `qemu`"
level=fatal msg="failed to find the QEMU binary for the architecture `x86_64`: exec: \"qemu-system-x86_64\": executable file not found in $PATH"

Generated plist (~/Library/LaunchAgents/io.lima-vm.autostart.docker.plist) contains no EnvironmentVariables key:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>io.lima-vm.autostart.docker</string>
	<key>ProgramArguments</key>
	<array>
		<string>/opt/homebrew/bin/limactl</string>
		<string>start</string>
		<string>docker</string>
		<string>--foreground</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>launchd.stderr.log</string>
	<key>StandardOutPath</key>
	<string>launchd.stdout.log</string>
	<key>WorkingDirectory</key>
	<string>~/.lima/docker</string>
	<key>ProcessType</key>
	<string>Background</string>
</dict>
</plist>

Workaround

Add PATH manually to the plist:

<key>EnvironmentVariables</key>
<dict>
    <key>PATH</key>
    <string>/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>

The edit is lost if limactl autostart enable regenerates the file.

Suggested fix

One of:

  • Write the caller's PATH into EnvironmentVariables when generating the plist.
  • Resolve the QEMU binary to an absolute path at generation time.
  • Have the QEMU driver also search the directory containing limactl / known Homebrew prefixes when lookup via PATH fails.

Related: the plist sets ProcessType to Background, which lets macOS throttle CPU. With QEMU TCG (x86_64 guest on Apple Silicon) this contributes to guest soft lockups and systemd watchdog timeouts. Interactive (or no ProcessType) may be a better default.

Environment

  • Lima: 2.2.0
  • QEMU: 11.1.1
  • macOS: 26.6.2, Apple Silicon
  • Install method: Homebrew
  • Instance template: docker (Ubuntu 26.04), arch: x86_64, VM driver qemu

capsidimit avatar Sep 24 '26 17:09 capsidimit

I add a PATH entry to the launchd plist's EnvironmentVariables, filled with the PATH of the shell that registers the instance, the same way LIMA_HOME is already set. (PR: #5579)

Sarthak-Shreshtha01 avatar Oct 05 '26 11:10 Sarthak-Shreshtha01