Adding a platform
A platform is a machine type: the value of platform: on a node. vz ships two, generic (Apple's generic Arm machine with UEFI) and apple (Apple's Mac machine for macOS). This page is for the rare case of a third.
Do you need one?
Probably not. Most new guests are an image, not a platform:
| The guest needs... | Add |
|---|---|
| a different download or preparation | an image maker in Sources/LabOS/Images/ |
| different first-boot setup | defaults in the guest's own user-data, not vz code |
| a device the machine does not have yet | a generic node key and a hardware part, usable on any platform: see Adding a lab file key |
| a machine type Virtualization offers besides the generic and Mac ones | a platform (this page) |
A platform is also the right place when a guest is the same machine with a different firmware, console or display, and that cannot be a node key. GenericUEFI in GenericPlatform.swift is a building block for exactly that: GenericUEFI.plan(for:console:) takes the console as a parameter.
What a platform owns
Everything that differs between machine types, and nothing else. The protocol is in Platform.swift:
public protocol Platform: Sendable {
var name: String { get } // the value of platform: in the lab file
var hostLimit: Int? { get } // nodes per Mac, if limited (default nil)
var resetFileNames: Set<String> { get } // its files in <state>/<node>/ that node reset deletes
func validate(_ node: Node, at path: String, in lab: LoadedLab) -> [ValidationIssue]
@MainActor func plan(for node: Node, in lab: LoadedLab) throws -> MachinePlan
}| Member | Meaning |
|---|---|
validate | What the lab file asks for that this machine cannot do. Report issues with path (for example nodes[2]) plus the key, like the other rules. Hardware parts are never removed for a platform; unusable keys are rejected here instead |
plan | Firmware, console, display, first-boot setup and an optional InstallStep. The engine adds the lab file's hardware itself |
resetFileNames | Files the platform keeps per node (firmware state, install markers). Disk layers and the seed are reset for every platform |
hostLimit | How many nodes of this platform one Mac may run, checked by PlatformTable.validate |
The table looks a node's platform up by name. No other code in vz may check which platform a node uses.
Steps
- Engine parts. If the machine needs firmware, console, display or install parts that do not exist yet, add them in
Sources/LabRuntime/Machine/, asMacOS.swiftdoes for Apple. Give per-node files aNodeStateDirectoryextension in the same file. - The adapter. Add
Sources/LabOS/Platforms/<Name>Platform.swiftimplementingPlatform. Model it onApplePlatform.swift. - Register it. Add it to
StandardPlatforms.allinPlatform.swift.PlatformTablefails a precondition if two platforms share a name. - Schema. Add the name to the
platformenum inschema/27.jsonand describe it. Runmake schema-check. - Images. If the machine boots something vz can fetch, add an image maker whose
labFileLinesprintplatform: <name>. - Tests. Add a suite to
Tests/LabOSTests/PlatformTests.swift: the plan's parts, every validation rule, reset files and the host limit.aPlatformCanBeAddedshows the smallest working platform. Runmake test-core. - Docs. The
platformsection of the lab file reference, the validation table, Files and environment for new state files, and a guide.
Nothing in the node model, the validator in LabCore, the commands or LabRunner should change. If one has to, the change is probably not platform-specific: make it a generic key or part instead.