diff --git a/Sources/tart/Platform/Darwin.swift b/Sources/tart/Platform/Darwin.swift index 5e3c6b0..d603239 100644 --- a/Sources/tart/Platform/Darwin.swift +++ b/Sources/tart/Platform/Darwin.swift @@ -1,5 +1,11 @@ import Virtualization +struct UnsupportedHostOSError: Error, CustomStringConvertible { + var description: String { + "error: host macOS version is outdated to run this virtual machine" + } +} + struct Darwin: Platform { var ecid: VZMacMachineIdentifier var hardwareModel: VZMacHardwareModel @@ -50,11 +56,18 @@ struct Darwin: Platform { VZMacOSBootLoader() } - func platform(nvramURL: URL) -> VZPlatformConfiguration { + func platform(nvramURL: URL) throws -> VZPlatformConfiguration { let result = VZMacPlatformConfiguration() result.machineIdentifier = ecid result.auxiliaryStorage = VZMacAuxiliaryStorage(contentsOf: nvramURL) + + if !hardwareModel.isSupported { + // At the moment support of M1 chip is not yet dropped in any macOS version + // This mean that host software is not supporting this hardware model and should be updated + throw UnsupportedHostOSError() + } + result.hardwareModel = hardwareModel return result diff --git a/Sources/tart/Platform/Linux.swift b/Sources/tart/Platform/Linux.swift index 02ec60a..cd00177 100644 --- a/Sources/tart/Platform/Linux.swift +++ b/Sources/tart/Platform/Linux.swift @@ -14,7 +14,7 @@ struct Linux: Platform { return result } - func platform(nvramURL: URL) -> VZPlatformConfiguration { + func platform(nvramURL: URL) throws -> VZPlatformConfiguration { VZGenericPlatformConfiguration() } diff --git a/Sources/tart/Platform/Platform.swift b/Sources/tart/Platform/Platform.swift index 89eda6e..4249b02 100644 --- a/Sources/tart/Platform/Platform.swift +++ b/Sources/tart/Platform/Platform.swift @@ -3,7 +3,7 @@ import Virtualization protocol Platform: Codable { func os() -> OS func bootLoader(nvramURL: URL) throws -> VZBootLoader - func platform(nvramURL: URL) -> VZPlatformConfiguration + func platform(nvramURL: URL) throws -> VZPlatformConfiguration func graphicsDevice(vmConfig: VMConfig) -> VZGraphicsDeviceConfiguration func pointingDevices() -> [VZPointingDeviceConfiguration] } diff --git a/Sources/tart/VM.swift b/Sources/tart/VM.swift index 996c885..b0cefef 100644 --- a/Sources/tart/VM.swift +++ b/Sources/tart/VM.swift @@ -278,7 +278,7 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { configuration.memorySize = vmConfig.memorySize // Platform - configuration.platform = vmConfig.platform.platform(nvramURL: nvramURL) + configuration.platform = try vmConfig.platform.platform(nvramURL: nvramURL) // Display configuration.graphicsDevices = [vmConfig.platform.graphicsDevice(vmConfig: vmConfig)]