Skip to content

Commit e1b3f85

Browse files
committed
decouple qemu internal from pkg/instance/start.go
Signed-off-by: Ansuman Sahoo <anshumansahoo500@gmail.com>
1 parent 0625d0b commit e1b3f85

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

pkg/instance/start.go

-23
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@ import (
1212
"os"
1313
"os/exec"
1414
"path/filepath"
15-
"runtime"
1615
"syscall"
1716
"text/template"
1817
"time"
1918

20-
"github.com/coreos/go-semver/semver"
2119
"github.com/lima-vm/lima/pkg/driver"
2220
"github.com/lima-vm/lima/pkg/driverutil"
2321
"github.com/lima-vm/lima/pkg/executil"
2422
"github.com/lima-vm/lima/pkg/osutil"
25-
"github.com/lima-vm/lima/pkg/qemu"
26-
"github.com/lima-vm/lima/pkg/qemu/entitlementutil"
2723
"github.com/mattn/go-isatty"
2824

2925
"github.com/lima-vm/lima/pkg/downloader"
@@ -134,25 +130,6 @@ func Start(ctx context.Context, inst *store.Instance, limactl string, launchHost
134130

135131
haSockPath := filepath.Join(inst.Dir, filenames.HostAgentSock)
136132

137-
// Ask the user to sign the qemu binary with the "com.apple.security.hypervisor" if needed.
138-
// Workaround for https://github.com/lima-vm/lima/issues/1742
139-
if runtime.GOOS == "darwin" && inst.VMType == limayaml.QEMU {
140-
macOSProductVersion, err := osutil.ProductVersion()
141-
if err != nil {
142-
return err
143-
}
144-
// The codesign --xml option is only available on macOS Monterey and later
145-
if !macOSProductVersion.LessThan(*semver.New("12.0.0")) {
146-
qExe, _, err := qemu.Exe(inst.Arch)
147-
if err != nil {
148-
return fmt.Errorf("failed to find the QEMU binary for the architecture %q: %w", inst.Arch, err)
149-
}
150-
if accel := qemu.Accel(inst.Arch); accel == "hvf" {
151-
entitlementutil.AskToSignIfNotSignedProperly(qExe)
152-
}
153-
}
154-
}
155-
156133
prepared, err := Prepare(ctx, inst)
157134
if err != nil {
158135
return err

pkg/qemu/qemu_driver.go

+28
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ import (
2121
"text/template"
2222
"time"
2323

24+
"github.com/coreos/go-semver/semver"
2425
"github.com/digitalocean/go-qemu/qmp"
2526
"github.com/digitalocean/go-qemu/qmp/raw"
2627
"github.com/lima-vm/lima/pkg/driver"
2728
"github.com/lima-vm/lima/pkg/executil"
2829
"github.com/lima-vm/lima/pkg/limayaml"
2930
"github.com/lima-vm/lima/pkg/networks/usernet"
31+
"github.com/lima-vm/lima/pkg/osutil"
32+
"github.com/lima-vm/lima/pkg/qemu/entitlementutil"
3033
"github.com/lima-vm/lima/pkg/store"
3134
"github.com/lima-vm/lima/pkg/store/filenames"
3235
"github.com/sirupsen/logrus"
@@ -47,6 +50,10 @@ func New(driver *driver.BaseDriver) *LimaQemuDriver {
4750
}
4851

4952
func (l *LimaQemuDriver) Validate() error {
53+
if runtime.GOOS == "darwin" {
54+
l.checkBinarySignature()
55+
}
56+
5057
if *l.Instance.Config.MountType == limayaml.VIRTIOFS && runtime.GOOS != "linux" {
5158
return fmt.Errorf("field `mountType` must be %q or %q for QEMU driver on non-Linux, got %q",
5259
limayaml.REVSSHFS, limayaml.NINEP, *l.Instance.Config.MountType)
@@ -233,6 +240,27 @@ func waitFileExists(path string, timeout time.Duration) error {
233240
return nil
234241
}
235242

243+
// Ask the user to sign the qemu binary with the "com.apple.security.hypervisor" if needed.
244+
// Workaround for https://github.com/lima-vm/lima/issues/1742
245+
func (l *LimaQemuDriver) checkBinarySignature() error {
246+
macOSProductVersion, err := osutil.ProductVersion()
247+
if err != nil {
248+
return err
249+
}
250+
// The codesign --xml option is only available on macOS Monterey and later
251+
if !macOSProductVersion.LessThan(*semver.New("12.0.0")) {
252+
qExe, _, err := Exe(l.BaseDriver.Instance.Arch)
253+
if err != nil {
254+
return fmt.Errorf("failed to find the QEMU binary for the architecture %q: %w", l.BaseDriver.Instance.Arch, err)
255+
}
256+
if accel := Accel(l.BaseDriver.Instance.Arch); accel == "hvf" {
257+
entitlementutil.AskToSignIfNotSignedProperly(qExe)
258+
}
259+
}
260+
261+
return nil
262+
}
263+
236264
func (l *LimaQemuDriver) changeVNCPassword(password string) error {
237265
qmpSockPath := filepath.Join(l.Instance.Dir, filenames.QMPSock)
238266
err := waitFileExists(qmpSockPath, 30*time.Second)

0 commit comments

Comments
 (0)