Skip to content

Commit ac9bedd

Browse files
authored
Merge pull request #2659 from jandubois/min-version
Add minimumLimaVersion and vmOpts.qemu.minimumVersion fields to lima.yaml
2 parents c761a97 + a35b5b0 commit ac9bedd

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

examples/default.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55
# Default values in this YAML file are specified by `null` instead of Lima's "builtin default" values,
66
# so they can be overridden by the $LIMA_HOME/_config/default.yaml mechanism documented at the end of this file.
77

8+
# A template should specify the minimum Lima version required to parse this template correctly.
9+
# It should not be set if the minimum version is less than 1.0.0
10+
# 🟢 Builtin default: not set
11+
minimumLimaVersion: null
12+
813
# VM type: "qemu", "vz" (on macOS 13 and later), or "default".
914
# The vmType can be specified only on creating the instance.
1015
# The vmType of existing instances cannot be changed.
1116
# 🟢 Builtin default: "vz" (on macOS 13.5 and later), "qemu" (on others)
1217
vmType: null
1318

19+
vmOpts:
20+
qemu:
21+
# Minimum version of QEMU required to create an instance of this template.
22+
# Will be ignored if the vmType is not "qemu"
23+
# 🟢 Builtin default: not set
24+
minimumVersion: null
25+
1426
# OS: "Linux".
1527
# 🟢 Builtin default: "Linux"
1628
os: null

pkg/limayaml/limayaml.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
)
88

99
type LimaYAML struct {
10+
MinimumLimaVersion *string `yaml:"minimumLimaVersion,omitempty" json:"minimumLimaVersion,omitempty"`
1011
VMType *VMType `yaml:"vmType,omitempty" json:"vmType,omitempty"`
12+
VMOpts VMOpts `yaml:"vmOpts,omitempty" json:"vmOpts,omitempty"`
1113
OS *OS `yaml:"os,omitempty" json:"os,omitempty"`
1214
Arch *Arch `yaml:"arch,omitempty" json:"arch,omitempty"`
1315
Images []Image `yaml:"images" json:"images"` // REQUIRED
@@ -72,6 +74,14 @@ const (
7274
WSL2 VMType = "wsl2"
7375
)
7476

77+
type VMOpts struct {
78+
QEMU QEMUOpts `yaml:"qemu,omitempty" json:"qemu,omitempty"`
79+
}
80+
81+
type QEMUOpts struct {
82+
MinimumVersion *string `yaml:"minimumVersion,omitempty" json:"minimumVersion,omitempty"`
83+
}
84+
7585
type Rosetta struct {
7686
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
7787
BinFmt *bool `yaml:"binfmt,omitempty" json:"binfmt,omitempty"`

pkg/limayaml/validate.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import (
1212
"strings"
1313
"unicode"
1414

15+
"github.com/coreos/go-semver/semver"
1516
"github.com/docker/go-units"
1617
"github.com/lima-vm/lima/pkg/localpathutil"
1718
"github.com/lima-vm/lima/pkg/networks"
1819
"github.com/lima-vm/lima/pkg/osutil"
20+
"github.com/lima-vm/lima/pkg/version"
21+
"github.com/lima-vm/lima/pkg/version/versionutil"
1922
"github.com/sirupsen/logrus"
2023
)
2124

@@ -43,6 +46,23 @@ func validateFileObject(f File, fieldName string) error {
4346
}
4447

4548
func Validate(y *LimaYAML, warn bool) error {
49+
if y.MinimumLimaVersion != nil {
50+
if _, err := versionutil.Parse(*y.MinimumLimaVersion); err != nil {
51+
return fmt.Errorf("field `minimumLimaVersion` must be a semvar value, got %q: %w", *y.MinimumLimaVersion, err)
52+
}
53+
limaVersion, err := versionutil.Parse(version.Version)
54+
if err != nil {
55+
return fmt.Errorf("can't parse builtin Lima version %q: %w", version.Version, err)
56+
}
57+
if versionutil.GreaterThan(*y.MinimumLimaVersion, limaVersion.String()) {
58+
return fmt.Errorf("template requires Lima version %q; this is only %q", *y.MinimumLimaVersion, limaVersion.String())
59+
}
60+
}
61+
if y.VMOpts.QEMU.MinimumVersion != nil {
62+
if _, err := semver.NewVersion(*y.VMOpts.QEMU.MinimumVersion); err != nil {
63+
return fmt.Errorf("field `vmOpts.qemu.minimumVersion` must be a semvar value, got %q: %w", *y.VMOpts.QEMU.MinimumVersion, err)
64+
}
65+
}
4666
switch *y.OS {
4767
case LINUX:
4868
default:

pkg/qemu/qemu.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
496496
if version.LessThan(*semver.New(MinimumQemuVersion)) {
497497
logrus.Fatalf("QEMU %v is too old, %v or later required", version, MinimumQemuVersion)
498498
}
499+
if y.VMOpts.QEMU.MinimumVersion != nil && version.LessThan(*semver.New(*y.VMOpts.QEMU.MinimumVersion)) {
500+
logrus.Fatalf("QEMU %v is too old, template requires %q or later", version, *y.VMOpts.QEMU.MinimumVersion)
501+
}
499502
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" && version.Equal(*semver.New("8.2.0")) {
500503
logrus.Fatal("QEMU 8.2.0 is no longer supported on ARM Mac due to <https://gitlab.com/qemu-project/qemu/-/issues/1990>. " +
501504
"Please upgrade QEMU to v8.2.1 (or downgrade to v8.1.x).")

0 commit comments

Comments
 (0)