lima-vm/lima · error

field UID must not be 0

Error message

field UID must not be 0

What it means

ValidateTemplateArgs (pkg/cidata/template.go:177) requires a non-zero UID for the guest user. UID 0 is the root UID and is disallowed because Lima provisions a regular non-root user; generation fails fast with this error.

Source

Thrown at pkg/cidata/template.go:177

		return fmt.Errorf("failed to get ISO label: %w", err)
	}

	t.IsWindowsServer = !strings.HasPrefix(label, windowsClientISOLabelPrefix)

	return nil
}

func ValidateTemplateArgs(args *TemplateArgs) error {
	if err := identifiers.Validate(args.Name); err != nil {
		return err
	}
	// args.User is intentionally not validated here; the user can override with any name they want
	// limayaml.FillDefault will validate the default (local) username, but not an explicit setting
	if args.User == "root" {
		return errors.New("field User must not be `root`")
	}
	if args.UID == 0 {
		return errors.New("field UID must not be 0")
	}
	if args.Home == "" {
		return errors.New("field Home must be set")
	}
	if args.Shell == "" {
		return errors.New("field Shell must be set")
	}
	if len(args.SSHPubKeys) == 0 {
		return errors.New("field SSHPubKeys must be set")
	}
	for i, m := range args.Mounts {
		f := m.MountPoint
		if !path.IsAbs(f) {
			return fmt.Errorf("field mounts[%d] must be absolute, got %#q", i, f)
		}
	}
	return nil
}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Ensure the UID is populated (e.g. 1000 or from `id -u` of the host user) before calling generation
  2. If constructing TemplateArgs manually, set args.UID to a valid non-zero value
  3. Let limayaml.FillDefault run so UID defaults correctly instead of bypassing it

Example fix

// before
args := &cidata.TemplateArgs{Name: inst.Name, User: "myuser"}
// after
args := &cidata.TemplateArgs{Name: inst.Name, User: "myuser", UID: 1000, Home: "/home/myuser.linux"}
Defensive patterns

Strategy: validation

Validate before calling

if args.UID == 0 {
    return errors.New("UID must be a non-zero value (e.g. 1000)")
}

Try / catch

if err := cidata.ValidateTemplateArgs(args); err != nil {
    if strings.Contains(err.Error(), "UID must not be 0") {
        return fmt.Errorf("populate TemplateArgs.UID before generation: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling the cidata generation API with TemplateArgs.UID == 0 - e.g. constructing TemplateArgs manually in tests/tools without setting UID, or a config/builder path that fails to default the UID (limayaml.FillDefault skipped or its validation bypassed).

Common situations: Custom tooling building TemplateArgs directly, or a lima.yaml where explicit user settings skip FillDefault's defaulting so UID stays 0.

Related errors


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