Skip to content

Commit 753bf0a

Browse files
authored
Merge pull request #3931 from unsuman/website/drivers-section
docs: internal and external drivers
2 parents a89ce4c + 338fcb7 commit 753bf0a

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

website/content/en/docs/config/vmtype.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Lima supports two ways of running guest machines:
1010
The vmType can be specified only on creating the instance.
1111
The vmType of existing instances cannot be changed.
1212

13+
> **💡 For developers**: See [Virtual Machine Drivers](../../dev/drivers) for technical details about driver architecture and creating custom drivers.
14+
15+
1316
See the following flowchart to choose the best vmType for you:
1417
```mermaid
1518
flowchart
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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)

website/content/en/docs/installation/source.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ make PREFIX=$HOME/.local install
3333
export PATH=$HOME/.local/bin:$PATH
3434
```
3535

36+
### Building External Drivers
37+
38+
> **⚠️ Building drivers as external mode is experimental**
39+
40+
Lima supports building drivers as external executables. For detailed information on creating and building external drivers, see the [Virtual Machine Drivers](../../dev/drivers) guide.
41+
3642
## Packaging Lima for Distribution
3743
After building Lima from source, you may want to package it for installation on other machines:
3844

website/content/en/docs/releases/experimental.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The following features are experimental and subject to change:
1212
- `video.display: vnc` and relevant configuration (`video.vnc.display`)
1313
- `audio.device`
1414
- `mountInotify: true`
15+
- `External drivers`: building and using drivers as separate executables (see [Virtual Machine Drivers](../dev/drivers))
1516

1617
The following commands are experimental and subject to change:
1718

0 commit comments

Comments
 (0)