Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func setupEnv(instConfigEnv map[string]string, propagateProxyEnv bool, slirpGate
return env, nil
}

func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string, noCloudInit bool) (*TemplateArgs, error) {
func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string, noCloudInit, rosettaEnabled, rosettaBinFmt bool) (*TemplateArgs, error) {
if err := limayaml.Validate(instConfig, false); err != nil {
return nil, err
}
Expand All @@ -138,20 +138,15 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i
Containerd: Containerd{System: *instConfig.Containerd.System, User: *instConfig.Containerd.User, Archive: archive},
SlirpNICName: networks.SlirpNICName,

VMType: *instConfig.VMType,
VSockPort: vsockPort,
VirtioPort: virtioPort,
Plain: *instConfig.Plain,
TimeZone: *instConfig.TimeZone,
NoCloudInit: noCloudInit,
Param: instConfig.Param,
}

if instConfig.VMOpts.VZ.Rosetta.Enabled != nil {
args.RosettaEnabled = *instConfig.VMOpts.VZ.Rosetta.Enabled
}
if instConfig.VMOpts.VZ.Rosetta.BinFmt != nil {
args.RosettaBinFmt = *instConfig.VMOpts.VZ.Rosetta.BinFmt
VMType: *instConfig.VMType,
VSockPort: vsockPort,
VirtioPort: virtioPort,
RosettaEnabled: rosettaEnabled,
RosettaBinFmt: rosettaBinFmt,
Plain: *instConfig.Plain,
TimeZone: *instConfig.TimeZone,
NoCloudInit: noCloudInit,
Param: instConfig.Param,
}

firstUsernetIndex := limayaml.FirstUsernetIndex(instConfig)
Expand Down Expand Up @@ -351,7 +346,7 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i
}

func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig *limatype.LimaYAML) error {
args, err := templateArgs(ctx, false, instDir, name, instConfig, 0, 0, 0, "", false)
args, err := templateArgs(ctx, false, instDir, name, instConfig, 0, 0, 0, "", false, false, false)
if err != nil {
return err
}
Expand All @@ -373,8 +368,8 @@ func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig *
return os.WriteFile(filepath.Join(instDir, filenames.CloudConfig), config, 0o444)
}

func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, guestAgentBinary, nerdctlArchive string, vsockPort int, virtioPort string, noCloudInit bool) error {
args, err := templateArgs(ctx, true, instDir, name, instConfig, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort, noCloudInit)
func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, guestAgentBinary, nerdctlArchive string, vsockPort int, virtioPort string, noCloudInit, rosettaEnabled, rosettaBinFmt bool) error {
args, err := templateArgs(ctx, true, instDir, name, instConfig, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort, noCloudInit, rosettaEnabled, rosettaBinFmt)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,6 @@ type DriverFeatures struct {
DynamicSSHAddress bool `json:"dynamicSSHAddress"`
SkipSocketForwarding bool `json:"skipSocketForwarding"`
NoCloudInit bool `json:"noCloudInit"`
RosettaEnabled bool `json:"rosettaEnabled"`
RosettaBinFmt bool `json:"rosettaBinFmt"`
}
19 changes: 16 additions & 3 deletions pkg/driver/vz/vz_driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ const Enabled = true
type LimaVzDriver struct {
Instance *limatype.Instance

SSHLocalPort int
vSockPort int
virtioPort string
SSHLocalPort int
vSockPort int
virtioPort string
rosettaEnabled bool
rosettaBinFmt bool

machine *virtualMachineWrapper
}
Expand Down Expand Up @@ -106,6 +108,15 @@ func (l *LimaVzDriver) Configure(inst *limatype.Instance) *driver.ConfiguredDriv
}
}

if runtime.GOOS == "darwin" && limayaml.IsNativeArch(limatype.AARCH64) {
if l.Instance.Config.VMOpts.VZ.Rosetta.Enabled != nil {
l.rosettaEnabled = *l.Instance.Config.VMOpts.VZ.Rosetta.Enabled
}
}
if l.Instance.Config.VMOpts.VZ.Rosetta.BinFmt != nil {
l.rosettaBinFmt = *l.Instance.Config.VMOpts.VZ.Rosetta.BinFmt
}

return &driver.ConfiguredDriver{
Driver: l,
}
Expand Down Expand Up @@ -351,6 +362,8 @@ func (l *LimaVzDriver) Info() driver.Info {
DynamicSSHAddress: false,
SkipSocketForwarding: false,
CanRunGUI: guiFlag,
RosettaEnabled: l.rosettaEnabled,
RosettaBinFmt: l.rosettaBinFmt,
}
return info
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,19 @@ func New(ctx context.Context, instName string, stdout io.Writer, signalCh chan o
vSockPort := limaDriver.Info().VsockPort
virtioPort := limaDriver.Info().VirtioPort
noCloudInit := limaDriver.Info().Features.NoCloudInit
rosettaEnabled := limaDriver.Info().Features.RosettaEnabled
rosettaBinFmt := limaDriver.Info().Features.RosettaBinFmt

// Disable Rosetta in Plain mode
if *inst.Config.Plain {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the hostagent could query the plain mode config to the driver, wouldn't the hostagent be able to pass them to the functions that process the template without touching the contents of the config?

Copy link
Member Author

@afbjorklund afbjorklund Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be possible to move the logic from the hostagent to the guest and the boot scripts and have them read $LIMA_CIDATA_PLAIN instead (if one is willing to make them more "smart" like that)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should the hostagent be able to receive the template string used for lima.env from the driver?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lima.env is not handled by the driver, it is hostagent that creates the cidata (which includes lima.env)

rosettaEnabled = false
rosettaBinFmt = false
}

if err := cidata.GenerateCloudConfig(ctx, inst.Dir, instName, inst.Config); err != nil {
return nil, err
}
if err := cidata.GenerateISO9660(ctx, limaDriver, inst.Dir, instName, inst.Config, udpDNSLocalPort, tcpDNSLocalPort, o.guestAgentBinary, o.nerdctlArchive, vSockPort, virtioPort, noCloudInit); err != nil {
if err := cidata.GenerateISO9660(ctx, limaDriver, inst.Dir, instName, inst.Config, udpDNSLocalPort, tcpDNSLocalPort, o.guestAgentBinary, o.nerdctlArchive, vSockPort, virtioPort, noCloudInit, rosettaEnabled, rosettaBinFmt); err != nil {
return nil, err
}

Expand Down
18 changes: 0 additions & 18 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,22 +768,6 @@ func FillDefault(ctx context.Context, y, d, o *limatype.LimaYAML, filePath strin
y.CACertificates.Files = unique(slices.Concat(d.CACertificates.Files, y.CACertificates.Files, o.CACertificates.Files))
y.CACertificates.Certs = unique(slices.Concat(d.CACertificates.Certs, y.CACertificates.Certs, o.CACertificates.Certs))

if runtime.GOOS == "darwin" && IsNativeArch(limatype.AARCH64) {
if y.VMOpts.VZ.Rosetta.Enabled == nil {
y.VMOpts.VZ.Rosetta.Enabled = d.VMOpts.VZ.Rosetta.Enabled
}
if o.VMOpts.VZ.Rosetta.Enabled != nil {
y.VMOpts.VZ.Rosetta.Enabled = o.VMOpts.VZ.Rosetta.Enabled
}
}

if y.VMOpts.VZ.Rosetta.BinFmt == nil {
y.VMOpts.VZ.Rosetta.BinFmt = d.VMOpts.VZ.Rosetta.BinFmt
}
if o.VMOpts.VZ.Rosetta.BinFmt != nil {
y.VMOpts.VZ.Rosetta.BinFmt = o.VMOpts.VZ.Rosetta.BinFmt
}

if y.NestedVirtualization == nil {
y.NestedVirtualization = d.NestedVirtualization
}
Expand Down Expand Up @@ -831,8 +815,6 @@ func fixUpForPlainMode(y *limatype.LimaYAML) {
y.Mounts = nil
y.Containerd.System = ptr.Of(false)
y.Containerd.User = ptr.Of(false)
y.VMOpts.VZ.Rosetta.BinFmt = ptr.Of(false)
y.VMOpts.VZ.Rosetta.Enabled = ptr.Of(false)
y.TimeZone = ptr.Of("")
}

Expand Down