@@ -8,14 +8,17 @@ import (
88 "fmt"
99 "net"
1010 "path/filepath"
11+ "runtime"
1112 "time"
1213
1314 "github.com/Code-Hex/vz/v3"
15+ "github.com/mitchellh/mapstructure"
1416
1517 "github.com/sirupsen/logrus"
1618
1719 "github.com/lima-vm/lima/pkg/driver"
1820 "github.com/lima-vm/lima/pkg/limayaml"
21+ "github.com/lima-vm/lima/pkg/osutil"
1922 "github.com/lima-vm/lima/pkg/reflectutil"
2023 "github.com/lima-vm/lima/pkg/store/filenames"
2124)
@@ -204,6 +207,34 @@ func (l *LimaVzDriver) RunGUI() error {
204207 return fmt .Errorf ("RunGUI is not supported for the given driver '%s' and display '%s'" , "vz" , * l .Instance .Config .Video .Display )
205208}
206209
210+ func (l * LimaVzDriver ) RuntimeConfig (_ context.Context , config interface {}) (interface {}, error ) {
211+ if config == nil {
212+ return l .config , nil
213+ }
214+ var newConfig LimaVzDriverRuntimeConfig
215+ err := mapstructure .Decode (config , & newConfig )
216+ if err != nil {
217+ return nil , err
218+ }
219+ if newConfig .SaveOnStop {
220+ if runtime .GOARCH != "arm64" {
221+ return nil , fmt .Errorf ("saveOnStop is not supported on %s" , runtime .GOARCH )
222+ } else if runtime .GOOS != "darwin" {
223+ return nil , fmt .Errorf ("saveOnStop is not supported on %s" , runtime .GOOS )
224+ } else if macOSProductVersion , err := osutil .ProductVersion (); err != nil {
225+ return nil , fmt .Errorf ("failed to get macOS product version: %w" , err )
226+ } else if macOSProductVersion .Major < 14 {
227+ return nil , fmt .Errorf ("saveOnStop is not supported on macOS %d" , macOSProductVersion .Major )
228+ }
229+ logrus .Info ("VZ RuntimeConfiguration changed: SaveOnStop is enabled" )
230+ l .config .SaveOnStop = true
231+ } else {
232+ logrus .Info ("VZ RuntimeConfiguration changed: SaveOnStop is disabled" )
233+ l .config .SaveOnStop = false
234+ }
235+ return l .config , nil
236+ }
237+
207238func (l * LimaVzDriver ) Stop (_ context.Context ) error {
208239 if l .config .SaveOnStop {
209240 machineStatePath := filepath .Join (l .Instance .Dir , filenames .VzMachineState )
0 commit comments