|
| 1 | +--- |
| 2 | +title: Virtual Machine Drivers |
| 3 | +weight: 15 |
| 4 | +--- |
| 5 | + |
| 6 | + | ⚡ Requirement | Lima >= 0.16.0 | |
| 7 | + |-------------------|----------------| |
| 8 | + |
| 9 | +Lima supports two types of drivers: **internal** and **external**. This architecture allows for extensibility and platform-specific implementations. Drivers are unware whether they are internal or external. |
| 10 | + |
| 11 | +> **💡 See also**: [VM Types](../../config/vmtype) for user configuration of different virtualization backends. |
| 12 | +
|
| 13 | + |
| 14 | +## Internal vs External Drivers |
| 15 | + |
| 16 | +**Internal Drivers** are compiled directly into the `limactl` binary and are registered automatically at startup by passing the driver object into `registry.Register()` function and importing the package in the main limactl code using Go's blank import `_`. For example: |
| 17 | +- **qemu:** [registration file](https://github.com/lima-vm/lima/blob/master/pkg/driver/qemu/register.go) & [import file](https://github.com/lima-vm/lima/blob/master/cmd/limactl/main_qemu.go) |
| 18 | + |
| 19 | +Build tags control which drivers are compiled as internal vs external (e.g., `external_qemu`, `external_vz`, `external_wsl2`). |
| 20 | + |
| 21 | +**External Drivers** are separate executables that communicate with Lima via gRPC. They are discovered at runtime from configured directories. |
| 22 | + |
| 23 | +> **⚠️ Note**: External drivers are experimental and the API may change in future releases. |
| 24 | +
|
| 25 | +## Building Drivers as External |
| 26 | + |
| 27 | +You can build existing internal drivers as external drivers using the `ADDITIONAL_DRIVERS` Makefile variable: |
| 28 | + |
| 29 | +```bash |
| 30 | +# Build QEMU as external driver |
| 31 | +make ADDITIONAL_DRIVERS=qemu limactl additional-drivers |
| 32 | + |
| 33 | +# Build multiple drivers as external |
| 34 | +make ADDITIONAL_DRIVERS="qemu vz wsl2" limactl additional-drivers |
| 35 | +``` |
| 36 | + |
| 37 | +This creates external driver binaries in `_output/libexec/lima/` with the naming pattern `lima-driver-<name>` (or `lima-driver-<name>.exe` on Windows). |
| 38 | + |
| 39 | +## Driver Discovery |
| 40 | + |
| 41 | +Lima discovers external drivers from these locations: |
| 42 | + |
| 43 | +1. **Standard directory**: `<LIMA-PREFIX>/libexec/lima/`, where `<LIMA_PREFIX>` is the location path where the Lima binary is present |
| 44 | +2. **Custom directories**: Set path to the external driver's directory via `LIMA_DRIVERS_PATH` environment variable |
| 45 | + |
| 46 | +The discovery process is handled by [`pkg/registry/registry.go`.](https://github.com/lima-vm/lima/blob/master/pkg/registry/registry.go) |
| 47 | + |
| 48 | +## Creating Custom External Drivers |
| 49 | + |
| 50 | +To create a new external driver: |
| 51 | + |
| 52 | +1. **Implement the interface**: Your driver must implement the [`driver.Driver`](https://pkg.go.dev/github.com/lima-vm/lima/v2/pkg/driver#Driver) interface: |
| 53 | + |
| 54 | +```go |
| 55 | +type Driver interface { |
| 56 | + Lifecycle |
| 57 | + GUI |
| 58 | + SnapshotManager |
| 59 | + GuestAgent |
| 60 | + |
| 61 | + Info() Info |
| 62 | + Configure(inst *limatype.Instance) *ConfiguredDriver |
| 63 | + FillConfig(ctx context.Context, cfg *limatype.LimaYAML, filePath string) error |
| 64 | + SSHAddress(ctx context.Context) (string, error) |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +2. **Create main.go**: Use [`server.Serve()`](https://pkg.go.dev/github.com/lima-vm/lima/v2/pkg/driver/external/server#Serve) to expose your driver: |
| 69 | + |
| 70 | +```go |
| 71 | +package main |
| 72 | + |
| 73 | +import ( |
| 74 | + "context" |
| 75 | + "github.com/lima-vm/lima/v2/pkg/driver/external/server" |
| 76 | +) |
| 77 | + |
| 78 | +func main() { |
| 79 | + driver := &MyDriver{} |
| 80 | + server.Serve(context.Background(), driver) |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +3. **Build and deploy**: |
| 85 | + - Build your driver: `go build -o lima-driver-mydriver main.go` |
| 86 | + - Place the binary in a directory accessible via `LIMA_DRIVERS_PATH` |
| 87 | + - Ensure the binary is executable |
| 88 | + |
| 89 | +4. **Use the driver**: Explicitly specify the driver when creating instances: |
| 90 | + |
| 91 | +```bash |
| 92 | +limactl create myinstance --vm-type=mydriver template://default |
| 93 | +``` |
| 94 | + |
| 95 | +## Examples |
| 96 | + |
| 97 | +See existing external driver implementations: |
| 98 | +- [`cmd/lima-driver-qemu/main.go`](https://github.com/lima-vm/lima/blob/master/cmd/lima-driver-qemu/main.go) |
| 99 | +- [`cmd/lima-driver-vz/main_darwin.go`](https://github.com/lima-vm/lima/blob/master/cmd/lima-driver-vz/main_darwin.go) |
| 100 | +- [`cmd/lima-driver-wsl2/main_windows.go`](https://github.com/lima-vm/lima/blob/master/cmd/lima-driver-wsl2/main_windows.go) |
0 commit comments