utmapp / utmapp/UTM

scripting: cannot create macOS VM

Open
#6,982 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Swift
Stars
35.5k
Forks
1.8k
Avg merge
5d 5h
Merged PRs (30d)
7

Description

Creating VM using Apple backend , will result in Linux (operating system) VM by default, which is fine.
However, the field Boot->Operating System is not exposed to config , which means we cannot update the the OS field in Boot section to macOS and hence we will not be able to create a macOS VM via script.

Default VM creation issue
```Swift
let config = UTMAppleConfiguration()
// Creates Linux VM by default
config.system.boot = try UTMAppleConfigurationBoot(for: .linux)

// But the config.system.boot is not exposed in config to be updated, Hence you cannot create macOS VM via script
```

Originally requested in https://github.com/naveenrajm7/packer-plugin-utm/issues/12

Suggested Fix:

```swift
// Get os via config record
guard let osString = record["operatingSystem"] as? String else {
throw ScriptingError.osNotSpecified
}
let config = UTMAppleConfiguration()
// validate os. Creating MacOS requires you to have a valid ipsw file, so enforce it
switch osString {
case "macos":
guard let ipswURL = record["ipsw"] as? URL else {
throw ScriptingError.ipswNotSpecified
}
let image = try await VZMacOSRestoreImage.image(from: ipswURL)
guard let model = image.mostFeaturefulSupportedConfiguration?.hardwareModel else {
throw ScriptingError.ipswNotSupported
}
config.system.macPlatform = UTMAppleConfigurationMacPlatform(newHardware: model)
config.system.boot = try UTMAppleConfigurationBoot(for: .macOS)
config.system.boot.macRecoveryIpswURL = ipswURL
case "linux":
config.system.boot = try UTMAppleConfigurationBoot(for: .linux)
default:
throw ScriptingError.osNotSupported
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.