Skip to content

Commit bc39aed

Browse files
committed
vz: add support for nested virtualization
Signed-off-by: Abiola Ibrahim <[email protected]>
1 parent 133979a commit bc39aed

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

pkg/limayaml/defaults.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,16 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
735735
y.Rosetta.BinFmt = ptr.Of(false)
736736
}
737737

738+
if y.NestedVirtualization == nil {
739+
y.NestedVirtualization = d.NestedVirtualization
740+
}
741+
if o.NestedVirtualization != nil {
742+
y.NestedVirtualization = o.NestedVirtualization
743+
}
744+
if y.NestedVirtualization == nil {
745+
y.NestedVirtualization = ptr.Of(false)
746+
}
747+
738748
if y.Plain == nil {
739749
y.Plain = d.Plain
740750
}

pkg/limayaml/defaults_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ func TestFillDefault(t *testing.T) {
106106
CACertificates: CACertificates{
107107
RemoveDefaults: ptr.Of(false),
108108
},
109-
Plain: ptr.Of(false),
109+
NestedVirtualization: ptr.Of(false),
110+
Plain: ptr.Of(false),
110111
}
111112

112113
defaultPortForward := PortForward{
@@ -293,6 +294,8 @@ func TestFillDefault(t *testing.T) {
293294
BinFmt: ptr.Of(false),
294295
}
295296

297+
expect.NestedVirtualization = ptr.Of(false)
298+
296299
FillDefault(&y, &LimaYAML{}, &LimaYAML{}, filePath)
297300
assert.DeepEqual(t, &y, &expect, opts...)
298301

@@ -420,6 +423,7 @@ func TestFillDefault(t *testing.T) {
420423
Enabled: ptr.Of(true),
421424
BinFmt: ptr.Of(true),
422425
},
426+
NestedVirtualization: ptr.Of(true),
423427
}
424428

425429
expect = d
@@ -634,6 +638,7 @@ func TestFillDefault(t *testing.T) {
634638
Enabled: ptr.Of(false),
635639
BinFmt: ptr.Of(false),
636640
},
641+
NestedVirtualization: ptr.Of(false),
637642
}
638643

639644
y = filledDefaults
@@ -690,6 +695,8 @@ func TestFillDefault(t *testing.T) {
690695
}
691696
expect.Plain = ptr.Of(false)
692697

698+
expect.NestedVirtualization = ptr.Of(false)
699+
693700
FillDefault(&y, &d, &o, filePath)
694701
assert.DeepEqual(t, &y, &expect, opts...)
695702
}

pkg/limayaml/limayaml.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ type LimaYAML struct {
3838
DNS []net.IP `yaml:"dns,omitempty" json:"dns,omitempty"`
3939
HostResolver HostResolver `yaml:"hostResolver,omitempty" json:"hostResolver,omitempty"`
4040
// `useHostResolver` was deprecated in Lima v0.8.1, removed in Lima v0.14.0. Use `hostResolver.enabled` instead.
41-
PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty"`
42-
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
43-
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
44-
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty"`
45-
TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty"`
41+
PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty"`
42+
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
43+
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
44+
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty"`
45+
TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty"`
46+
NestedVirtualization *bool `yaml:"nestedVirtualization,omitempty" json:"nestedVirtualization,omitempty"`
4647
}
4748

4849
type (

pkg/vz/vm_darwin.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"syscall"
1616

1717
"github.com/Code-Hex/vz/v3"
18+
"github.com/coreos/go-semver/semver"
1819
"github.com/docker/go-units"
1920
"github.com/lima-vm/go-qcow2reader"
2021
"github.com/lima-vm/go-qcow2reader/image/raw"
@@ -25,6 +26,7 @@ import (
2526
"github.com/lima-vm/lima/pkg/nativeimgutil"
2627
"github.com/lima-vm/lima/pkg/networks"
2728
"github.com/lima-vm/lima/pkg/networks/usernet"
29+
"github.com/lima-vm/lima/pkg/osutil"
2830
"github.com/lima-vm/lima/pkg/store"
2931
"github.com/lima-vm/lima/pkg/store/filenames"
3032
"github.com/sirupsen/logrus"
@@ -239,6 +241,21 @@ func attachPlatformConfig(driver *driver.BaseDriver, vmConfig *vz.VirtualMachine
239241
if err != nil {
240242
return err
241243
}
244+
245+
// nested virt
246+
if *driver.Yaml.NestedVirtualization {
247+
macOSProductVersion, err := osutil.ProductVersion()
248+
if err != nil {
249+
return fmt.Errorf("failed to get macOS product version: %w", err)
250+
}
251+
252+
if macOSProductVersion.LessThan(*semver.New("15.0.0")) {
253+
return fmt.Errorf("nested virtualization requires macOS 15 or newer")
254+
}
255+
256+
platformConfig.SetNestedVirtualizationEnabled(true)
257+
}
258+
242259
vmConfig.SetPlatformVirtualMachineConfiguration(platformConfig)
243260
return nil
244261
}

pkg/vz/vz_driver_darwin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var knownYamlProperties = []string{
4040
"Mounts",
4141
"MountType",
4242
"MountInotify",
43+
"NestedVirtualization",
4344
"Networks",
4445
"OS",
4546
"Param",

0 commit comments

Comments
 (0)