Skip to content

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 preparationan image maker in Sources/LabOS/Images/
different first-boot setupdefaults in the guest's own user-data, not vz code
a device the machine does not have yeta 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 onesa 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:

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
}
MemberMeaning
validateWhat 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
planFirmware, console, display, first-boot setup and an optional InstallStep. The engine adds the lab file's hardware itself
resetFileNamesFiles the platform keeps per node (firmware state, install markers). Disk layers and the seed are reset for every platform
hostLimitHow 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 ​

  1. Engine parts. If the machine needs firmware, console, display or install parts that do not exist yet, add them in Sources/LabRuntime/Machine/, as MacOS.swift does for Apple. Give per-node files a NodeStateDirectory extension in the same file.
  2. The adapter. Add Sources/LabOS/Platforms/<Name>Platform.swift implementing Platform. Model it on ApplePlatform.swift.
  3. Register it. Add it to StandardPlatforms.all in Platform.swift. PlatformTable fails a precondition if two platforms share a name.
  4. Schema. Add the name to the platform enum in schema/27.json and describe it. Run make schema-check.
  5. Images. If the machine boots something vz can fetch, add an image maker whose labFileLines print platform: <name>.
  6. Tests. Add a suite to Tests/LabOSTests/PlatformTests.swift: the plan's parts, every validation rule, reset files and the host limit. aPlatformCanBeAdded shows the smallest working platform. Run make test-core.
  7. Docs. The platform section 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.

See also ​