Skip to content

Add minimumLimaVersion and vmOpts.qemu.minimumVersion fields to lima.yaml #2659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@
# Default values in this YAML file are specified by `null` instead of Lima's "builtin default" values,
# so they can be overridden by the $LIMA_HOME/_config/default.yaml mechanism documented at the end of this file.

# A template should specify the minimum Lima version required to parse this template correctly.
# It should not be set if the minimum version is less than 1.0.0
# 🟢 Builtin default: not set
minimumLimaVersion: null

# VM type: "qemu", "vz" (on macOS 13 and later), or "default".
# The vmType can be specified only on creating the instance.
# The vmType of existing instances cannot be changed.
# 🟢 Builtin default: "vz" (on macOS 13.5 and later), "qemu" (on others)
vmType: null

vmOpts:
qemu:
# Minimum version of QEMU required to create an instance of this template.
# Will be ignored if the vmType is not "qemu"
# 🟢 Builtin default: not set
minimumVersion: null

# OS: "Linux".
# 🟢 Builtin default: "Linux"
os: null
Expand Down
10 changes: 10 additions & 0 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
)

type LimaYAML struct {
MinimumLimaVersion *string `yaml:"minimumLimaVersion,omitempty" json:"minimumLimaVersion,omitempty"`
VMType *VMType `yaml:"vmType,omitempty" json:"vmType,omitempty"`
VMOpts VMOpts `yaml:"vmOpts,omitempty" json:"vmOpts,omitempty"`
OS *OS `yaml:"os,omitempty" json:"os,omitempty"`
Arch *Arch `yaml:"arch,omitempty" json:"arch,omitempty"`
Images []Image `yaml:"images" json:"images"` // REQUIRED
Expand Down Expand Up @@ -72,6 +74,14 @@ const (
WSL2 VMType = "wsl2"
)

type VMOpts struct {
QEMU QEMUOpts `yaml:"qemu,omitempty" json:"qemu,omitempty"`
}

type QEMUOpts struct {
MinimumVersion *string `yaml:"minimumVersion,omitempty" json:"minimumVersion,omitempty"`
}

type Rosetta struct {
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
BinFmt *bool `yaml:"binfmt,omitempty" json:"binfmt,omitempty"`
Expand Down
20 changes: 20 additions & 0 deletions pkg/limayaml/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import (
"strings"
"unicode"

"github.com/coreos/go-semver/semver"
"github.com/docker/go-units"
"github.com/lima-vm/lima/pkg/localpathutil"
"github.com/lima-vm/lima/pkg/networks"
"github.com/lima-vm/lima/pkg/osutil"
"github.com/lima-vm/lima/pkg/version"
"github.com/lima-vm/lima/pkg/version/versionutil"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -43,6 +46,23 @@ func validateFileObject(f File, fieldName string) error {
}

func Validate(y *LimaYAML, warn bool) error {
if y.MinimumLimaVersion != nil {
if _, err := versionutil.Parse(*y.MinimumLimaVersion); err != nil {
return fmt.Errorf("field `minimumLimaVersion` must be a semvar value, got %q: %w", *y.MinimumLimaVersion, err)
}
limaVersion, err := versionutil.Parse(version.Version)
if err != nil {
return fmt.Errorf("can't parse builtin Lima version %q: %w", version.Version, err)
}
if versionutil.GreaterThan(*y.MinimumLimaVersion, limaVersion.String()) {
return fmt.Errorf("template requires Lima version %q; this is only %q", *y.MinimumLimaVersion, limaVersion.String())
}
}
if y.VMOpts.QEMU.MinimumVersion != nil {
if _, err := semver.NewVersion(*y.VMOpts.QEMU.MinimumVersion); err != nil {
return fmt.Errorf("field `vmOpts.qemu.minimumVersion` must be a semvar value, got %q: %w", *y.VMOpts.QEMU.MinimumVersion, err)
}
}
switch *y.OS {
case LINUX:
default:
Expand Down
3 changes: 3 additions & 0 deletions pkg/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
if version.LessThan(*semver.New(MinimumQemuVersion)) {
logrus.Fatalf("QEMU %v is too old, %v or later required", version, MinimumQemuVersion)
}
if y.VMOpts.QEMU.MinimumVersion != nil && version.LessThan(*semver.New(*y.VMOpts.QEMU.MinimumVersion)) {
logrus.Fatalf("QEMU %v is too old, template requires %q or later", version, *y.VMOpts.QEMU.MinimumVersion)
}
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" && version.Equal(*semver.New("8.2.0")) {
logrus.Fatal("QEMU 8.2.0 is no longer supported on ARM Mac due to <https://gitlab.com/qemu-project/qemu/-/issues/1990>. " +
"Please upgrade QEMU to v8.2.1 (or downgrade to v8.1.x).")
Expand Down
Loading