Skip to content

Commit 7ab02dc

Browse files
authored
Merge pull request #2530 from abiosoft/vz-nested-virtualization
vz: add support for nested virtualization
2 parents 2ea780e + 10a60fe commit 7ab02dc

File tree

7 files changed

+54
-8
lines changed

7 files changed

+54
-8
lines changed

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,7 @@ require (
139139
// We can't just `require` github.com/inetaf/tcpproxy, as gvisor-tap-vsock
140140
// still imports inet.af/tcpproxy: https://github.com/containers/gvisor-tap-vsock/pull/399
141141
replace inet.af/tcpproxy => github.com/inetaf/tcpproxy v0.0.0-20240214030015-3ce58045626c
142+
143+
// Nested virtualization support is yet to be merged into VZ https://github.com/Code-Hex/vz/pull/159.
144+
// We use our (temporary) fork to add the feature.
145+
replace github.com/Code-Hex/vz/v3 => github.com/lima-vm/vz/v3 v3.0.0-20241008080607-2a22b5e278ee

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkk
44
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
55
github.com/Code-Hex/go-infinity-channel v1.0.0 h1:M8BWlfDOxq9or9yvF9+YkceoTkDI1pFAqvnP87Zh0Nw=
66
github.com/Code-Hex/go-infinity-channel v1.0.0/go.mod h1:5yUVg/Fqao9dAjcpzoQ33WwfdMWmISOrQloDRn3bsvY=
7-
github.com/Code-Hex/vz/v3 v3.1.0 h1:rcMIbZwPYwf78yXOhK68DZgYMdzxlrdmpDuM+NnGf1I=
8-
github.com/Code-Hex/vz/v3 v3.1.0/go.mod h1:xUfvg1VJ5A6ZQNuzQERwXJ7l2ZdTnY6eCy9CIS6/DYQ=
97
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
108
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
119
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
@@ -171,6 +169,8 @@ github.com/lima-vm/go-qcow2reader v0.1.2 h1:A9+h9Yg2oWDxmMlE2oJsdd+djaKk+Ge4hawv
171169
github.com/lima-vm/go-qcow2reader v0.1.2/go.mod h1:e3p29BzLT8hNh4jbLezdFAHU4eBijf0bm5GilStCRKE=
172170
github.com/lima-vm/sshocker v0.3.4 h1:5rn6vMkfqwZSZiBW+Udo505OIRhPB4xbLUDdEnFgWwI=
173171
github.com/lima-vm/sshocker v0.3.4/go.mod h1:QT4c7XNmeQTv79h5/8EgiS7U51B9BLenlXV7idCY0tE=
172+
github.com/lima-vm/vz/v3 v3.0.0-20241008080607-2a22b5e278ee h1:USiLYd9WbmtU1mPM0egUMrz9QVpMkblMyKioC2EsWCA=
173+
github.com/lima-vm/vz/v3 v3.0.0-20241008080607-2a22b5e278ee/go.mod h1:WqWQuBbT4SbjO4C4GHG9m9HO8j5jecAmMh4eyVSEbEg=
174174
github.com/linuxkit/virtsock v0.0.0-20220523201153-1a23e78aa7a2 h1:DZMFueDbfz6PNc1GwDRA8+6lBx1TB9UnxDQliCqR73Y=
175175
github.com/linuxkit/virtsock v0.0.0-20220523201153-1a23e78aa7a2/go.mod h1:SWzULI85WerrFt3u+nIm5F9l7EvxZTKQvd0InF3nmgM=
176176
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=

pkg/limayaml/defaults.go

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

770+
if y.NestedVirtualization == nil {
771+
y.NestedVirtualization = d.NestedVirtualization
772+
}
773+
if o.NestedVirtualization != nil {
774+
y.NestedVirtualization = o.NestedVirtualization
775+
}
776+
if y.NestedVirtualization == nil {
777+
y.NestedVirtualization = ptr.Of(false)
778+
}
779+
770780
if y.Plain == nil {
771781
y.Plain = d.Plain
772782
}

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
@@ -41,11 +41,12 @@ type LimaYAML struct {
4141
DNS []net.IP `yaml:"dns,omitempty" json:"dns,omitempty"`
4242
HostResolver HostResolver `yaml:"hostResolver,omitempty" json:"hostResolver,omitempty"`
4343
// `useHostResolver` was deprecated in Lima v0.8.1, removed in Lima v0.14.0. Use `hostResolver.enabled` instead.
44-
PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty"`
45-
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
46-
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
47-
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty"`
48-
TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty"`
44+
PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty"`
45+
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
46+
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
47+
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty"`
48+
TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty"`
49+
NestedVirtualization *bool `yaml:"nestedVirtualization,omitempty" json:"nestedVirtualization,omitempty"`
4950
}
5051

5152
type (

pkg/vz/vm_darwin.go

Lines changed: 23 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"
@@ -234,6 +236,27 @@ func attachPlatformConfig(driver *driver.BaseDriver, vmConfig *vz.VirtualMachine
234236
if err != nil {
235237
return err
236238
}
239+
240+
// nested virt
241+
if *driver.Instance.Config.NestedVirtualization {
242+
macOSProductVersion, err := osutil.ProductVersion()
243+
if err != nil {
244+
return fmt.Errorf("failed to get macOS product version: %w", err)
245+
}
246+
247+
if macOSProductVersion.LessThan(*semver.New("15.0.0")) {
248+
return errors.New("nested virtualization requires macOS 15 or newer")
249+
}
250+
251+
if !vz.IsNestedVirtualizationSupported() {
252+
return errors.New("nested virtualization is not supported on this device")
253+
}
254+
255+
if err := platformConfig.SetNestedVirtualizationEnabled(true); err != nil {
256+
return fmt.Errorf("cannot enable nested virtualization: %w", err)
257+
}
258+
}
259+
237260
vmConfig.SetPlatformVirtualMachineConfiguration(platformConfig)
238261
return nil
239262
}

pkg/vz/vz_driver_darwin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var knownYamlProperties = []string{
4141
"MountType",
4242
"MountTypesUnsupported",
4343
"MountInotify",
44+
"NestedVirtualization",
4445
"Networks",
4546
"OS",
4647
"Param",

0 commit comments

Comments
 (0)