Repository: lima-vm/lima (2025-08-27T10:40:41Z)

Issue:
`limactl prune --keep-referred` crashes since 6aceec31e50369425f83258b2355acf0b9b6d876
> 6aceec31e50369425f83258b2355acf0b9b6d876 causes this.
> That also broke `limactl prune`, ~~`limactl restart`~~:
> ```console
> ➜ ~14:28:10 14:28:21~ ((6aceec31)) limactl prune --keep-referred 
> WARN[0000] Both top-level 'rosetta' and 'vmOpts.vz.rosetta' are configured. Using vmOpts.vz.rosetta. Top-level 'rosetta' is deprecated. 
> panic: runtime error: invalid memory address or nil pointer dereference
> [signal SIGSEGV: segmentation violation code=0x2 addr=0x58 pc=0x103051cbc]
> 
> goroutine 1 [running]:
> main.locationsFromLimaYAML(0x0)
> 	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/prune.go:110 +0x2c
> main.knownLocations({0x103642cb0, 0x104648f60})
> 	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/prune.go:83 +0x90
> main.pruneAction(0x140004f5b08?, {0x140004d8900?, 0x4?, 0x1030bd571?})
> 	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/prune.go:52 +0xbc
> github.com/spf13/cobra.(*Command).execute(0x140004f5b08, {0x140004d88e0, 0x2, 0x2})
> 	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1015 +0x7d4
> github.com/spf13/cobra.(*Command).ExecuteC(0x140004f4008)
> 	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1148 +0x350
> github.com/spf13/cobra.(*Command).Execute(...)
> 	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1071
> main.executeWithPluginSupport(0x140004f4008?, {0x14000142010?, 0x3?, 0x3?})
> 	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/main.go:227 +0xbc
> main.main()
> 	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/main.go:46 +0x54

 _Originally posted by @norio-nomura in [#3914](https://github.com/lima-vm/lima/issues/3914#issuecomment-3222676677)_

with 1262923b68d9ac0f7dfec1fdb9c8175c1b6045bf:
```console
➜ ~15:04:30 15:04:43~ (master) limactl prune --keep-referred
WARN[0000] Both top-level 'rosetta' and 'vmOpts.vz.rosetta' are configured. Using vmOpts.vz.rosetta. Top-level 'rosetta' is deprecated. 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1054b5af8]

goroutine 1 [running]:
github.com/lima-vm/lima/v2/pkg/driver/vz.(*LimaVzDriver).Validate(0x140005635c0, {0x140008175f8?, 0x0?})
	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driver/vz/vz_driver_darwin.go:232 +0x198
github.com/lima-vm/lima/v2/pkg/driver/vz.(*LimaVzDriver).AcceptConfig(0x140005635c0, 0x14000ac8908, {0x140000b43c6?, 0x14000afc840?})
	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driver/vz/vz_driver_darwin.go:208 +0x3a8
github.com/lima-vm/lima/v2/pkg/driverutil.validateConfigAgainstDriver({0x105ad3690, 0x106add060}, 0x14000ac8908, {0x140000b43c6, 0x20}, {0x10554e630, 0x2})
	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driverutil/vm.go:44 +0x68
github.com/lima-vm/lima/v2/pkg/driverutil.ResolveVMType({0x105ad3690?, 0x106add060?}, 0x1400032a800?, {0x140000b43c6?, 0x712?})
	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driverutil/vm.go:31 +0xdc
main.knownLocations({0x105ad3690, 0x106add060})
	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/prune.go:100 +0x178
main.pruneAction(0x14000573b08?, {0x14000556900?, 0x4?, 0x10554f611?})
	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/prune.go:52 +0xbc
github.com/spf13/cobra.(*Command).execute(0x14000573b08, {0x140005568e0, 0x2, 0x2})
	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1015 +0x7d4
github.com/spf13/cobra.(*Command).ExecuteC(0x14000572008)
	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1148 +0x350
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1071
main.executeWithPluginSupport(0x14000572008?, {0x140001ba010?, 0x3?, 0x3?})
	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/main.go:227 +0xbc
main.main()
	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/main.go:46 +0x54
➜ ~15:04:43 15:04:48~ (master) limactl --version
limactl version 1.2.0-219-g1262923b
```
`limactl edit` crashes since 6aceec31e50369425f83258b2355acf0b9b6d876
> `limactl edit` too:
> ```console
> $ ./hack/update-template.sh templates/_images/centos-stream-9.yaml
> Processing templates/_images/centos-stream-9.yaml
> {
>   "location": "https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-20250825.1.x86_64.qcow2",
>   "arch": "x86_64",
>   "digest": "sha256:54b86ad383c7ccdb296771acfe281b2d6cb130ada6c062f98374779834e21025"
> }
> panic: runtime error: invalid memory address or nil pointer dereference
> [signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x104c5dd18]
> 
> goroutine 1 [running]:
> github.com/lima-vm/lima/v2/pkg/driver/vz.(*LimaVzDriver).Validate(0x1400056b5c0, {0x0?, 0x0?})
> 	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driver/vz/vz_driver_darwin.go:232 +0x198
> github.com/lima-vm/lima/v2/pkg/driver/vz.(*LimaVzDriver).AcceptConfig(0x1400056b5c0, 0x140005abb08, {0x14000451c70?, 0x105025200?})
> 	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driver/vz/vz_driver_darwin.go:208 +0x3a8
> github.com/lima-vm/lima/v2/pkg/driverutil.validateConfigAgainstDriver(0x140005abb08, {0x14000451c70, 0x4f}, {0x104cf6b30, 0x2})
> 	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driverutil/vm.go:41 +0x60
> github.com/lima-vm/lima/v2/pkg/driverutil.ResolveVMType(0x105284170?, {0x14000451c70?, 0x140000c2800?})
> 	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driverutil/vm.go:28 +0xd4
> main.editAction(0x1400058cf08, {0x1400056c280?, 0x4?, 0x104cf7b16?})
> 	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/edit.go:124 +0x3e4
> github.com/spf13/cobra.(*Command).execute(0x1400058cf08, {0x1400056c230, 0x5, 0x5})
> 	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1015 +0x7d4
> github.com/spf13/cobra.(*Command).ExecuteC(0x1400057c008)
> 	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1148 +0x350
> github.com/spf13/cobra.(*Command).Execute(...)
> 	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1071
> main.executeWithPluginSupport(0x1400057c008?, {0x140001c0010?, 0x6?, 0x6?})
> 	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/main.go:249 +0xbc
> main.main()
> 	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/main.go:68 +0xd8
> ``` 

 _Originally posted by @norio-nomura in [#3914](https://github.com/lima-vm/lima/issues/3914#issuecomment-3224055603)_

With 1262923b68d9ac0f7dfec1fdb9c8175c1b6045bf:
```console
➜ ~15:04:48 15:07:55~ (master) ./hack/update-template.sh templates/_images/centos-stream-9.yaml
Processing templates/_images/centos-stream-9.yaml
{
  "location": "https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-20250825.1.x86_64.qcow2",
  "arch": "x86_64",
  "digest": "sha256:54b86ad383c7ccdb296771acfe281b2d6cb130ada6c062f98374779834e21025"
}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x103ad1af8]

goroutine 1 [running]:
github.com/lima-vm/lima/v2/pkg/driver/vz.(*LimaVzDriver).Validate(0x1400028a930, {0x14000817788?, 0x0?})
	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driver/vz/vz_driver_darwin.go:232 +0x198
github.com/lima-vm/lima/v2/pkg/driver/vz.(*LimaVzDriver).AcceptConfig(0x1400028a930, 0x14000697b08, {0x140002d6190?, 0x1400055c860?})
	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driver/vz/vz_driver_darwin.go:208 +0x3a8
github.com/lima-vm/lima/v2/pkg/driverutil.validateConfigAgainstDriver({0x1040ef690, 0x1050f9060}, 0x14000697b08, {0x140002d6190, 0x4f}, {0x103b6a630, 0x2})
	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driverutil/vm.go:44 +0x68
github.com/lima-vm/lima/v2/pkg/driverutil.ResolveVMType({0x1040ef690?, 0x1050f9060?}, 0x14000031000?, {0x140002d6190?, 0x800?})
	/Users/norio/ghq/github.com/lima-vm/lima/pkg/driverutil/vm.go:31 +0xdc
main.editAction(0x140002f6f08, {0x14000296280?, 0x4?, 0x103b6b611?})
	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/edit.go:124 +0x3f0
github.com/spf13/cobra.(*Command).execute(0x140002f6f08, {0x14000296230, 0x5, 0x5})
	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1015 +0x7d4
github.com/spf13/cobra.(*Command).ExecuteC(0x140002de008)
	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1148 +0x350
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/norio/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1071
main.executeWithPluginSupport(0x140002de008?, {0x1400003c080?, 0x6?, 0x6?})
	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/main.go:227 +0xbc
main.main()
	/Users/norio/ghq/github.com/lima-vm/lima/cmd/limactl/main.go:46 +0x54
➜ ~15:07:55 15:08:04~ (master) limactl --version
limactl version 1.2.0-219-g1262923b
```


Discussion:
Sorry, this issue should be separated with each crash log.
Second crash log is fixed by #3923 and closed.
First crash log is opened as #3935





Patch:
diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go
index 09248aab51d..94c192f0cd4 100644
--- a/pkg/driver/driver.go
+++ b/pkg/driver/driver.go
@@ -79,10 +79,13 @@ type Driver interface {
 	Info() Info
 
 	// Configure sets the configuration for the instance.
+	// TODO: merge Configure and FillConfig?
+	// Or come up with a better name to clarify the difference.
 	Configure(inst *limatype.Instance) *ConfiguredDriver
 
-	AcceptConfig(cfg *limatype.LimaYAML, filePath string) error
-	FillConfig(cfg *limatype.LimaYAML, filePath string) error
+	// FillConfig fills and validates the configuration for the instance.
+	// The config is not set to the instance.
+	FillConfig(ctx context.Context, cfg *limatype.LimaYAML, filePath string) error
 
 	SSHAddress(ctx context.Context) (string, error)
 }
diff --git a/pkg/driver/external/client/methods.go b/pkg/driver/external/client/methods.go
index af9d974b0f7..b26114bed14 100644
--- a/pkg/driver/external/client/methods.go
+++ b/pkg/driver/external/client/methods.go
@@ -115,11 +115,7 @@ func (d *DriverClient) Delete(ctx context.Context) error {
 	return nil
 }
 
-func (d *DriverClient) AcceptConfig(_ *limatype.LimaYAML, _ string) error {
-	return errors.New("pre-configured driver action not implemented in client driver")
-}
-
-func (d *DriverClient) FillConfig(_ *limatype.LimaYAML, _ string) error {
+func (d *DriverClient) FillConfig(_ context.Context, _ *limatype.LimaYAML, _ string) error {
 	return errors.New("pre-configured driver action not implemented in client driver")
 }
 
diff --git a/pkg/driver/external/server/server.go b/pkg/driver/external/server/server.go
index a6068be6b79..bc69ffe8c78 100644
--- a/pkg/driver/external/server/server.go
+++ b/pkg/driver/external/server/server.go
@@ -57,7 +57,7 @@ func Serve(ctx context.Context, driver driver.Driver) {
 	inspectStatus := flag.Bool("inspect-status", false, "Inspect status of the driver")
 	flag.Parse()
 	if *preConfiguredDriverAction {
-		handlePreConfiguredDriverAction(driver)
+		handlePreConfiguredDriverAction(ctx, driver)
 		return
 	}
 	if *inspectStatus {
@@ -188,7 +188,7 @@ func handleInspectStatus(driver driver.Driver) {
 	}
 }
 
-func handlePreConfiguredDriverAction(driver driver.Driver) {
+func handlePreConfiguredDriverAction(ctx context.Context, driver driver.Driver) {
 	decoder := json.NewDecoder(os.Stdin)
 	encoder := json.NewEncoder(os.Stdout)
 
@@ -198,11 +198,7 @@ func handlePreConfiguredDriverAction(driver driver.Driver) {
 	}
 
 	config := &payload.Config
-	if err := driver.AcceptConfig(config, payload.FilePath); err != nil {
-		fmt.Fprintf(os.Stderr, "Failed to accept config: %v", err)
-	}
-
-	if err := driver.FillConfig(config, payload.FilePath); err != nil {
+	if err := driver.FillConfig(ctx, config, payload.FilePath); err != nil {
 		fmt.Fprintf(os.Stderr, "Failed to fill config: %v", err)
 	}
 
diff --git a/pkg/driver/qemu/qemu_driver.go b/pkg/driver/qemu/qemu_driver.go
index 303c95c7901..191874882a2 100644
--- a/pkg/driver/qemu/qemu_driver.go
+++ b/pkg/driver/qemu/qemu_driver.go
@@ -77,26 +77,37 @@ func (l *LimaQemuDriver) Configure(inst *limatype.Instance) *driver.ConfiguredDr
 }
 
 func (l *LimaQemuDriver) Validate(ctx context.Context) error {
+	return validateConfig(ctx, l.Instance.Config)
+}
+
+func validateConfig(ctx context.Context, cfg *limatype.LimaYAML) error {
+	if cfg == nil {
+		return errors.New("configuration is nil")
+	}
 	if runtime.GOOS == "darwin" {
-		if err := l.checkBinarySignature(ctx); err != nil {
+		var vmArch string
+		if cfg.Arch != nil {
+			vmArch = *cfg.Arch
+		}
+		if err := checkBinarySignature(ctx, vmArch); err != nil {
 			return err
 		}
 	}
-	if err := l.validateMountType(); err != nil {
+	if err := validateMountType(cfg); err != nil {
 		return err
 	}
 
+	if cfg.VMOpts.QEMU.MinimumVersion != nil {
+		if _, err := semver.NewVersion(*cfg.VMOpts.QEMU.MinimumVersion); err != nil {
+			return fmt.Errorf("field `vmOpts.qemu.minimumVersion` must be a semvar value, got %q: %w", *cfg.VMOpts.QEMU.MinimumVersion, err)
+		}
+	}
+
 	return nil
 }
 
 // Helper method for mount type validation.
-func (l *LimaQemuDriver) validateMountType() error {
-	if l.Instance == nil || l.Instance.Config == nil {
-		return errors.New("instance configuration is not set")
-	}
-
-	cfg := l.Instance.Config
-
+func validateMountType(cfg *limatype.LimaYAML) error {
 	if cfg.MountType != nil && *cfg.MountType == limatype.VIRTIOFS && runtime.GOOS != "linux" {
 		return fmt.Errorf("field `mountType` must be %q or %q for QEMU driver on non-Linux, got %q",
 			limatype.REVSSHFS, limatype.NINEP, *cfg.MountType)
@@ -111,7 +122,7 @@ func (l *LimaQemuDriver) validateMountType() error {
 	return nil
 }
 
-func (l *LimaQemuDriver) FillConfig(cfg *limatype.LimaYAML, filePath string) error {
+func (l *LimaQemuDriver) FillConfig(ctx context.Context, cfg *limatype.LimaYAML, filePath string) error {
 	if cfg.VMType == nil {
 		cfg.VMType = ptr.Of(limatype.QEMU)
 	}
@@ -174,57 +185,7 @@ func (l *LimaQemuDriver) FillConfig(cfg *limatype.LimaYAML, filePath string) err
 		return fmt.Errorf("mount type %q is explicitly unsupported", *cfg.MountType)
 	}
 
-	return nil
-}
-
-func (l *LimaQemuDriver) AcceptConfig(cfg *limatype.LimaYAML, _ string) error {
-	if l.Instance == nil {
-		l.Instance = &limatype.Instance{}
-	}
-	l.Instance.Config = cfg
-
-	if err := l.Validate(context.Background()); err != nil {
-		return fmt.Errorf("config not supported by the QEMU driver: %w", err)
-	}
-
-	if cfg.VMOpts.QEMU.MinimumVersion != nil {
-		if _, err := semver.NewVersion(*cfg.VMOpts.QEMU.MinimumVersion); err != nil {
-			return fmt.Errorf("field `vmOpts.qemu.minimumVersion` must be a semvar value, got %q: %w", *cfg.VMOpts.QEMU.MinimumVersion, err)
-		}
-	}
-
-	if runtime.GOOS == "darwin" {
-		if cfg.Arch != nil && limayaml.IsNativeArch(*cfg.Arch) {
-			logrus.Debugf("ResolveVMType: resolved VMType %q (non-native arch=%q is specified in []*LimaYAML{o,y,d})", "qemu", *cfg.Arch)
-			return nil
-		}
-		if limayaml.ResolveArch(cfg.Arch) == limatype.X8664 && cfg.Firmware.LegacyBIOS != nil && *cfg.Firmware.LegacyBIOS {
-			logrus.Debugf("ResolveVMType: resolved VMType %q (firmware.legacyBIOS is specified in []*LimaYAML{o,y,d} on x86_64)", "qemu")
-			return nil
-		}
-		if cfg.MountType != nil && *cfg.MountType == limatype.NINEP {
-			logrus.Debugf("ResolveVMType: resolved VMType %q (mountType=%q is specified in []*LimaYAML{o,y,d})", "qemu", limatype.NINEP)
-			return nil
-		}
-		if cfg.Audio.Device != nil {
-			switch *cfg.Audio.Device {
-			case "", "none", "default", "vz":
-				// NOP
-			default:
-				logrus.Debugf("ResolveVMType: resolved VMType %q (audio.device=%q is specified in []*LimaYAML{o,y,d})", "qemu", *cfg.Audio.Device)
-				return nil
-			}
-		}
-		if cfg.Video.Display != nil {
-			display := *cfg.Video.Display
-			if display != "" && display != "none" && display != "default" && display != "vz" {
-				logrus.Debugf("ResolveVMType: resolved VMType %q (video.display=%q is specified in []*LimaYAML{o,y,d})", "qemu", display)
-				return nil
-			}
-		}
-	}
-
-	return nil
+	return validateConfig(ctx, cfg)
 }
 
 func (l *LimaQemuDriver) BootScripts() (map[string][]byte, error) {
@@ -414,18 +375,18 @@ func waitFileExists(path string, timeout time.Duration) error {
 
 // Ask the user to sign the qemu binary with the "com.apple.security.hypervisor" if needed.
 // Workaround for https://github.com/lima-vm/lima/issues/1742
-func (l *LimaQemuDriver) checkBinarySignature(ctx context.Context) error {
+func checkBinarySignature(ctx context.Context, vmArch string) error {
 	macOSProductVersion, err := osutil.ProductVersion()
 	if err != nil {
 		return err
 	}
 	// The codesign --xml option is only available on macOS Monterey and later
-	if !macOSProductVersion.LessThan(*semver.New("12.0.0")) && l.Instance.Arch != "" {
-		qExe, _, err := Exe(l.Instance.Arch)
+	if !macOSProductVersion.LessThan(*semver.New("12.0.0")) && vmArch != "" {
+		qExe, _, err := Exe(vmArch)
 		if err != nil {
-			return fmt.Errorf("failed to find the QEMU binary for the architecture %q: %w", l.Instance.Arch, err)
+			return fmt.Errorf("failed to find the QEMU binary for the architecture %q: %w", vmArch, err)
 		}
-		if accel := Accel(l.Instance.Arch); accel == "hvf" {
+		if accel := Accel(vmArch); accel == "hvf" {
 			entitlementutil.AskToSignIfNotSignedProperly(ctx, qExe)
 		}
 	}
diff --git a/pkg/driver/vz/vz_driver_darwin.go b/pkg/driver/vz/vz_driver_darwin.go
index 85b7a55d8f8..0125de1d7b8 100644
--- a/pkg/driver/vz/vz_driver_darwin.go
+++ b/pkg/driver/vz/vz_driver_darwin.go
@@ -11,7 +11,6 @@ import (
 	"errors"
 	"fmt"
 	"net"
-	"os"
 	"path/filepath"
 	"runtime"
 	"time"
@@ -22,7 +21,6 @@ import (
 
 	"github.com/lima-vm/lima/v2/pkg/driver"
 	"github.com/lima-vm/lima/v2/pkg/limatype"
-	"github.com/lima-vm/lima/v2/pkg/limatype/filenames"
 	"github.com/lima-vm/lima/v2/pkg/limayaml"
 	"github.com/lima-vm/lima/v2/pkg/osutil"
 	"github.com/lima-vm/lima/v2/pkg/ptr"
@@ -113,7 +111,7 @@ func (l *LimaVzDriver) Configure(inst *limatype.Instance) *driver.ConfiguredDriv
 	}
 }
 
-func (l *LimaVzDriver) FillConfig(cfg *limatype.LimaYAML, _ string) error {
+func (l *LimaVzDriver) FillConfig(ctx context.Context, cfg *limatype.LimaYAML, _ string) error {
 	if cfg.VMType == nil {
 		cfg.VMType = ptr.Of(limatype.VZ)
 	}
@@ -139,7 +137,7 @@ func (l *LimaVzDriver) FillConfig(cfg *limatype.LimaYAML, _ string) error {
 		cfg.VMOpts.VZ.Rosetta.BinFmt = ptr.Of(false)
 	}
 
-	return nil
+	return validateConfig(ctx, cfg)
 }
 
 func isEmpty(r limatype.Rosetta) bool {
@@ -171,48 +169,14 @@ func (l *LimaVzDriver) BootScripts() (map[string][]byte, error) {
 	return scripts, nil
 }
 
-func (l *LimaVzDriver) AcceptConfig(cfg *limatype.LimaYAML, filePath string) error {
-	if dir, basename := filepath.Split(filePath); dir != "" && basename == filenames.LimaYAML && limayaml.IsExistingInstanceDir(dir) {
-		vzIdentifier := filepath.Join(dir, filenames.VzIdentifier) // since Lima v0.14
-		if _, err := os.Lstat(vzIdentifier); !errors.Is(err, os.ErrNotExist) {
-			logrus.Debugf("ResolveVMType: resolved VMType %q (existing instance, with %q)", "vz", vzIdentifier)
-		}
-	}
-
-	for i, nw := range cfg.Networks {
-		field := fmt.Sprintf("networks[%d]", i)
-		switch {
-		case nw.Lima != "":
-			if nw.VZNAT != nil && *nw.VZNAT {
-				return fmt.Errorf("field `%s.lima` and field `%s.vzNAT` are mutually exclusive", field, field)
-			}
-		case nw.Socket != "":
-			if nw.VZNAT != nil && *nw.VZNAT {
-				return fmt.Errorf("field `%s.socket` and field `%s.vzNAT` are mutually exclusive", field, field)
-			}
-		case nw.VZNAT != nil && *nw.VZNAT:
-			if nw.Lima != "" {
-				return fmt.Errorf("field `%s.vzNAT` and field `%s.lima` are mutually exclusive", field, field)
-			}
-			if nw.Socket != "" {
-				return fmt.Errorf("field `%s.vzNAT` and field `%s.socket` are mutually exclusive", field, field)
-			}
-		}
-	}
-
-	if l.Instance == nil {
-		l.Instance = &limatype.Instance{}
-	}
-	l.Instance.Config = cfg
-
-	if err := l.Validate(context.Background()); err != nil {
-		return fmt.Errorf("config not supported by the VZ driver: %w", err)
-	}
-
-	return nil
+func (l *LimaVzDriver) Validate(ctx context.Context) error {
+	return validateConfig(ctx, l.Instance.Config)
 }
 
-func (l *LimaVzDriver) Validate(_ context.Context) error {
+func validateConfig(_ context.Context, cfg *limatype.LimaYAML) error {
+	if cfg == nil {
+		return errors.New("configuration is nil")
+	}
 	macOSProductVersion, err := osutil.ProductVersion()
 	if err != nil {
 		return err
@@ -223,67 +187,86 @@ func (l *LimaVzDriver) Validate(_ context.Context) error {
 	if runtime.GOARCH == "amd64" && macOSProductVersion.LessThan(*semver.New("15.5.0")) {
 		logrus.Warnf("vmType %s: On Intel Mac, macOS 15.5 or later is required to run Linux 6.12 or later. "+
 			"Update macOS, or change vmType to \"qemu\" if the VM does not start up. (https://github.com/lima-vm/lima/issues/3334)",
-			*l.Instance.Config.VMType)
+			*cfg.VMType)
 	}
-	if l.Instance.Config.MountType != nil && *l.Instance.Config.MountType == limatype.NINEP {
-		return fmt.Errorf("field `mountType` must be %q or %q for VZ driver , got %q", limatype.REVSSHFS, limatype.VIRTIOFS, *l.Instance.Config.MountType)
+	if cfg.MountType != nil && *cfg.MountType == limatype.NINEP {
+		return fmt.Errorf("field `mountType` must be %q or %q for VZ driver , got %q", limatype.REVSSHFS, limatype.VIRTIOFS, *cfg.MountType)
 	}
-	if *l.Instance.Config.Firmware.LegacyBIOS {
-		logrus.Warnf("vmType %s: ignoring `firmware.legacyBIOS`", *l.Instance.Config.VMType)
+	if *cfg.Firmware.LegacyBIOS {
+		logrus.Warnf("vmType %s: ignoring `firmware.legacyBIOS`", *cfg.VMType)
 	}
-	for _, f := range l.Instance.Config.Firmware.Images {
+	for _, f := range cfg.Firmware.Images {
 		switch f.VMType {
 		case "", limatype.VZ:
-			if f.Arch == *l.Instance.Config.Arch {
+			if f.Arch == *cfg.Arch {
 				return errors.New("`firmware.images` configuration is not supported for VZ driver")
 			}
 		}
 	}
-	if unknown := reflectutil.UnknownNonEmptyFields(l.Instance.Config, knownYamlProperties...); l.Instance.Config.VMType != nil && len(unknown) > 0 {
-		logrus.Warnf("vmType %s: ignoring %+v", *l.Instance.Config.VMType, unknown)
+	if unknown := reflectutil.UnknownNonEmptyFields(cfg, knownYamlProperties...); cfg.VMType != nil && len(unknown) > 0 {
+		logrus.Warnf("vmType %s: ignoring %+v", *cfg.VMType, unknown)
 	}
 
-	if !limayaml.IsNativeArch(*l.Instance.Config.Arch) {
-		return fmt.Errorf("unsupported arch: %q", *l.Instance.Config.Arch)
+	if !limayaml.IsNativeArch(*cfg.Arch) {
+		return fmt.Errorf("unsupported arch: %q", *cfg.Arch)
 	}
 
-	for i, image := range l.Instance.Config.Images {
+	for i, image := range cfg.Images {
 		if unknown := reflectutil.UnknownNonEmptyFields(image, "File", "Kernel", "Initrd"); len(unknown) > 0 {
-			logrus.Warnf("vmType %s: ignoring images[%d]: %+v", *l.Instance.Config.VMType, i, unknown)
+			logrus.Warnf("vmType %s: ignoring images[%d]: %+v", *cfg.VMType, i, unknown)
 		}
 	}
 
-	for i, mount := range l.Instance.Config.Mounts {
+	for i, mount := range cfg.Mounts {
 		if unknown := reflectutil.UnknownNonEmptyFields(mount, "Location",
 			"MountPoint",
 			"Writable",
 			"SSHFS",
 			"NineP",
 		); len(unknown) > 0 {
-			logrus.Warnf("vmType %s: ignoring mounts[%d]: %+v", *l.Instance.Config.VMType, i, unknown)
+			logrus.Warnf("vmType %s: ignoring mounts[%d]: %+v", *cfg.VMType, i, unknown)
 		}
 	}
 
-	for i, network := range l.Instance.Config.Networks {
-		if unknown := reflectutil.UnknownNonEmptyFields(network, "VZNAT",
+	for i, nw := range cfg.Networks {
+		if unknown := reflectutil.UnknownNonEmptyFields(nw, "VZNAT",
 			"Lima",
 			"Socket",
 			"MACAddress",
 			"Metric",
 			"Interface",
 		); len(unknown) > 0 {
-			logrus.Warnf("vmType %s: ignoring networks[%d]: %+v", *l.Instance.Config.VMType, i, unknown)
+			logrus.Warnf("vmType %s: ignoring networks[%d]: %+v", *cfg.VMType, i, unknown)
+		}
+
+		field := fmt.Sprintf("networks[%d]", i)
+		switch {
+		case nw.Lima != "":
+			if nw.VZNAT != nil && *nw.VZNAT {
+				return fmt.Errorf("field `%s.lima` and field `%s.vzNAT` are mutually exclusive", field, field)
+			}
+		case nw.Socket != "":
+			if nw.VZNAT != nil && *nw.VZNAT {
+				return fmt.Errorf("field `%s.socket` and field `%s.vzNAT` are mutually exclusive", field, field)
+			}
+		case nw.VZNAT != nil && *nw.VZNAT:
+			if nw.Lima != "" {
+				return fmt.Errorf("field `%s.vzNAT` and field `%s.lima` are mutually exclusive", field, field)
+			}
+			if nw.Socket != "" {
+				return fmt.Errorf("field `%s.vzNAT` and field `%s.socket` are mutually exclusive", field, field)
+			}
 		}
 	}
 
-	switch audioDevice := *l.Instance.Config.Audio.Device; audioDevice {
+	switch audioDevice := *cfg.Audio.Device; audioDevice {
 	case "":
 	case "vz", "default", "none":
 	default:
 		logrus.Warnf("field `audio.device` must be \"vz\", \"default\", or \"none\" for VZ driver, got %q", audioDevice)
 	}
 
-	switch videoDisplay := *l.Instance.Config.Video.Display; videoDisplay {
+	switch videoDisplay := *cfg.Video.Display; videoDisplay {
 	case "vz", "default", "none":
 	default:
 		logrus.Warnf("field `video.display` must be \"vz\", \"default\", or \"none\" for VZ driver , got %q", videoDisplay)
diff --git a/pkg/driver/wsl2/wsl_driver_windows.go b/pkg/driver/wsl2/wsl_driver_windows.go
index 01b21e4e116..17886de8863 100644
--- a/pkg/driver/wsl2/wsl_driver_windows.go
+++ b/pkg/driver/wsl2/wsl_driver_windows.go
@@ -6,6 +6,7 @@ package wsl2
 import (
 	"context"
 	"embed"
+	"errors"
 	"fmt"
 	"net"
 	"regexp"
@@ -79,80 +80,73 @@ func (l *LimaWslDriver) Configure(inst *limatype.Instance) *driver.ConfiguredDri
 	}
 }
 
-func (l *LimaWslDriver) AcceptConfig(cfg *limatype.LimaYAML, _ string) error {
-	if l.Instance == nil {
-		l.Instance = &limatype.Instance{}
-	}
-	l.Instance.Config = cfg
-
-	if err := l.Validate(context.Background()); err != nil {
-		return fmt.Errorf("config not supported by the WSL2 driver: %w", err)
-	}
-
-	return nil
-}
-
-func (l *LimaWslDriver) FillConfig(cfg *limatype.LimaYAML, _ string) error {
+func (l *LimaWslDriver) FillConfig(ctx context.Context, cfg *limatype.LimaYAML, _ string) error {
 	if cfg.VMType == nil {
 		cfg.VMType = ptr.Of(limatype.WSL2)
 	}
 	if cfg.MountType == nil {
 		cfg.MountType = ptr.Of(limatype.WSLMount)
 	}
+	return validateConfig(ctx, cfg)
+}
 
-	return nil
+func (l *LimaWslDriver) Validate(ctx context.Context) error {
+	return validateConfig(ctx, l.Instance.Config)
 }
 
-func (l *LimaWslDriver) Validate(_ context.Context) error {
-	if l.Instance.Config.MountType != nil && *l.Instance.Config.MountType != limatype.WSLMount {
-		return fmt.Errorf("field `mountType` must be %q for WSL2 driver, got %q", limatype.WSLMount, *l.Instance.Config.MountType)
+func validateConfig(_ context.Context, cfg *limatype.LimaYAML) error {
+	if cfg == nil {
+		return errors.New("configuration is nil")
+	}
+	if cfg.MountType != nil && *cfg.MountType != limatype.WSLMount {
+		return fmt.Errorf("field `mountType` must be %q for WSL2 driver, got %q", limatype.WSLMount, *cfg.MountType)
 	}
 	// TODO: revise this list for WSL2
-	if l.Instance.Config.VMType != nil {
-		if unknown := reflectutil.UnknownNonEmptyFields(l.Instance.Config, knownYamlProperties...); len(unknown) > 0 {
-			logrus.Warnf("Ignoring: vmType %s: %+v", *l.Instance.Config.VMType, unknown)
+	if cfg.VMType != nil {
+		if unknown := reflectutil.UnknownNonEmptyFields(cfg, knownYamlProperties...); len(unknown) > 0 {
+			logrus.Warnf("Ignoring: vmType %s: %+v", *cfg.VMType, unknown)
 		}
 	}
 
-	if !limayaml.IsNativeArch(*l.Instance.Config.Arch) {
-		return fmt.Errorf("unsupported arch: %q", *l.Instance.Config.Arch)
+	if !limayaml.IsNativeArch(*cfg.Arch) {
+		return fmt.Errorf("unsupported arch: %q", *cfg.Arch)
 	}
 
-	if l.Instance.Config.VMType != nil {
-		if l.Instance.Config.Images != nil && l.Instance.Config.Arch != nil {
+	if cfg.VMType != nil {
+		if cfg.Images != nil && cfg.Arch != nil {
 			// TODO: real filetype checks
 			tarFileRegex := regexp.MustCompile(`.*tar\.*`)
-			for i, image := range l.Instance.Config.Images {
+			for i, image := range cfg.Images {
 				if unknown := reflectutil.UnknownNonEmptyFields(image, "File"); len(unknown) > 0 {
-					logrus.Warnf("Ignoring: vmType %s: images[%d]: %+v", *l.Instance.Config.VMType, i, unknown)
+					logrus.Warnf("Ignoring: vmType %s: images[%d]: %+v", *cfg.VMType, i, unknown)
 				}
 				match := tarFileRegex.MatchString(image.Location)
-				if image.Arch == *l.Instance.Config.Arch && !match {
-					return fmt.Errorf("unsupported image type for vmType: %s, tarball root file system required: %q", *l.Instance.Config.VMType, image.Location)
+				if image.Arch == *cfg.Arch && !match {
+					return fmt.Errorf("unsupported image type for vmType: %s, tarball root file system required: %q", *cfg.VMType, image.Location)
 				}
 			}
 		}
 
-		if l.Instance.Config.Mounts != nil {
-			for i, mount := range l.Instance.Config.Mounts {
+		if cfg.Mounts != nil {
+			for i, mount := range cfg.Mounts {
 				if unknown := reflectutil.UnknownNonEmptyFields(mount); len(unknown) > 0 {
-					logrus.Warnf("Ignoring: vmType %s: mounts[%d]: %+v", *l.Instance.Config.VMType, i, unknown)
+					logrus.Warnf("Ignoring: vmType %s: mounts[%d]: %+v", *cfg.VMType, i, unknown)
 				}
 			}
 		}
 
-		if l.Instance.Config.Networks != nil {
-			for i, network := range l.Instance.Config.Networks {
+		if cfg.Networks != nil {
+			for i, network := range cfg.Networks {
 				if unknown := reflectutil.UnknownNonEmptyFields(network); len(unknown) > 0 {
-					logrus.Warnf("Ignoring: vmType %s: networks[%d]: %+v", *l.Instance.Config.VMType, i, unknown)
+					logrus.Warnf("Ignoring: vmType %s: networks[%d]: %+v", *cfg.VMType, i, unknown)
 				}
 			}
 		}
 
-		if l.Instance.Config.Audio.Device != nil {
-			audioDevice := *l.Instance.Config.Audio.Device
+		if cfg.Audio.Device != nil {
+			audioDevice := *cfg.Audio.Device
 			if audioDevice != "" {
-				logrus.Warnf("Ignoring: vmType %s: `audio.device`: %+v", *l.Instance.Config.VMType, audioDevice)
+				logrus.Warnf("Ignoring: vmType %s: `audio.device`: %+v", *cfg.VMType, audioDevice)
 			}
 		}
 	}
diff --git a/pkg/driverutil/vm.go b/pkg/driverutil/vm.go
index 4e54235505b..f6b3fbf3d0f 100644
--- a/pkg/driverutil/vm.go
+++ b/pkg/driverutil/vm.go
@@ -41,10 +41,7 @@ func validateConfigAgainstDriver(ctx context.Context, y *limatype.LimaYAML, file
 		return handlePreConfiguredDriverAction(ctx, y, extDriver.Path, filePath)
 	}
 
-	if err := intDriver.AcceptConfig(y, filePath); err != nil {
-		return err
-	}
-	if err := intDriver.FillConfig(y, filePath); err != nil {
+	if err := intDriver.FillConfig(ctx, y, filePath); err != nil {
 		return err
 	}
 


Test patch:
diff --git a/pkg/registry/registry_test.go b/pkg/registry/registry_test.go
index eccc5712e88..8e783f44994 100644
--- a/pkg/registry/registry_test.go
+++ b/pkg/registry/registry_test.go
@@ -47,12 +47,11 @@ func (m *mockDriver) GuestAgentConn(_ context.Context) (net.Conn, string, error)
 func (m *mockDriver) Info() driver.Info {
 	return driver.Info{Name: m.Name}
 }
-func (m *mockDriver) Configure(_ *limatype.Instance) *driver.ConfiguredDriver      { return nil }
-func (m *mockDriver) AcceptConfig(_ *limatype.LimaYAML, _ string) error            { return nil }
-func (m *mockDriver) FillConfig(_ *limatype.LimaYAML, _ string) error              { return nil }
-func (m *mockDriver) InspectStatus(_ context.Context, _ *limatype.Instance) string { return "" }
-func (m *mockDriver) SSHAddress(_ context.Context) (string, error)                 { return "", nil }
-func (m *mockDriver) BootScripts() (map[string][]byte, error)                      { return nil, nil }
+func (m *mockDriver) Configure(_ *limatype.Instance) *driver.ConfiguredDriver            { return nil }
+func (m *mockDriver) FillConfig(_ context.Context, _ *limatype.LimaYAML, _ string) error { return nil }
+func (m *mockDriver) InspectStatus(_ context.Context, _ *limatype.Instance) string       { return "" }
+func (m *mockDriver) SSHAddress(_ context.Context) (string, error)                       { return "", nil }
+func (m *mockDriver) BootScripts() (map[string][]byte, error)                            { return nil, nil }
 
 func TestRegister(t *testing.T) {
 	BackupRegistry(t)