lima-vm/lima · error

failed to create temp file: %w

Error message

failed to create temp file: %w

What it means

This error wraps a failure from os.CreateTemp when daemonInstall tries to stage a rendered launchd plist in a temporary file before installing it to /Library/LaunchDaemons. It means the OS refused to create the temp file, almost always because TMPDIR is unwritable, full, or missing.

Source

Thrown at cmd/limactl/autostart_darwin.go:120

	}

	vars := map[string]string{
		"Binary":   selfExe,
		"Instance": instName,
		"WorkDir":  workDir,
		"UserName": userName,
	}
	if keepAlive {
		vars["KeepAlive"] = "true"
	}
	content, err := textutil.ExecuteTemplate(launchd.DaemonTemplate, vars)
	if err != nil {
		return fmt.Errorf("failed to render daemon plist: %w", err)
	}

	tmp, err := os.CreateTemp("", "io.lima-vm.daemon.*.plist")
	if err != nil {
		return fmt.Errorf("failed to create temp file: %w", err)
	}
	defer os.Remove(tmp.Name())
	if _, err := tmp.Write(content); err != nil {
		return fmt.Errorf("failed to write temp plist: %w", err)
	}
	tmp.Close()

	destPath := launchd.GetDaemonPlistPath(instName)
	svcTarget := "system/" + launchd.DaemonServiceNameFrom(instName)

	_ = runSudo(ctx, "launchctl", "bootout", svcTarget)
	if err := runSudo(ctx, "install", "-m", "644", tmp.Name(), destPath); err != nil {
		return fmt.Errorf("failed to install plist to %s: %w", destPath, err)
	}
	if err := runSudo(ctx, "launchctl", "enable", svcTarget); err != nil {
		return fmt.Errorf("failed to enable LaunchDaemon: %w", err)
	}
	if err := runSudo(ctx, "launchctl", "bootstrap", "system", destPath); err != nil {

View on GitHub (pinned to dd909d0973)

Solutions

  1. Check TMPDIR is set and writable: run `ls -ld "$TMPDIR"` and `touch "$TMPDIR/test"`
  2. Free disk space if the volume is full (`df -h`)
  3. Unset or fix a stale TMPDIR environment variable before rerunning limactl
  4. Rerun the command outside any sandboxed/restricted shell

Example fix

// shell check before retrying
// before: TMPDIR=/nonexistent limactl autostart myinstance --condition=boot
// after:  unset TMPDIR && limactl autostart myinstance --condition=boot
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "$TMPDIR" ]; then TMPDIR=/tmp; fi
if ! touch "$TMPDIR/.lima-write-test" 2>/dev/null; then
  echo "TMPDIR $TMPDIR is not writable"; exit 1
fi
rm -f "$TMPDIR/.lima-write-test"
df -h "$TMPDIR" | awk 'NR==2 && $5+0 >= 95 {print "temp volume nearly full"; exit 1}'

Prevention

When it happens

Trigger: Running `limactl autostart <instance> --condition=boot` on macOS when os.CreateTemp("", "io.lima-vm.daemon.*.plist") fails: read-only or full TMPDIR, TMPDIR pointing at a nonexistent directory, sandbox/MDM restrictions on temp file creation, or TMPDIR being removed mid-session.

Common situations: Disk full on the boot volume; corporate security agents restricting temp dirs; running inside a sandboxed shell with a stale TMPDIR; /tmp mounted noexec/readonly on unusual setups.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/feedc4783763f383. Report an issue: GitHub.