Skip to content

Commit 5762a8a

Browse files
committed
Add OS to lima.yaml for future guests
Avoid hardcoding "linux" everywhere, use OS instead (like Arch). TODO: Add proper cidata template parameter for LIMA_CIDATA_HOME Signed-off-by: Anders F Björklund <[email protected]>
1 parent 31d6828 commit 5762a8a

File tree

8 files changed

+52
-13
lines changed

8 files changed

+52
-13
lines changed

cmd/limactl/hostagent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func newHostagentCommand() *cobra.Command {
2929
hostagentCommand.Flags().StringP("pidfile", "p", "", "write pid to file")
3030
hostagentCommand.Flags().String("socket", "", "hostagent socket")
3131
hostagentCommand.Flags().Bool("run-gui", false, "run gui synchronously within hostagent")
32-
hostagentCommand.Flags().String("nerdctl-archive", "", "local file path (not URL) of nerdctl-full-VERSION-linux-GOARCH.tar.gz")
32+
hostagentCommand.Flags().String("nerdctl-archive", "", "local file path (not URL) of nerdctl-full-VERSION-GOOS-GOARCH.tar.gz")
3333
return hostagentCommand
3434
}
3535

examples/default.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
# 🟢 Builtin default: "qemu"
1212
vmType: null
1313

14+
# OS: "Linux".
15+
# 🟢 Builtin default: "Linux"
16+
os: null
17+
1418
# Arch: "default", "x86_64", "aarch64".
1519
# 🟢 Builtin default: "default" (corresponds to the host architecture)
1620
arch: null

pkg/cidata/cidata.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
303303
}
304304
}
305305

306-
guestAgentBinary, err := GuestAgentBinary(*y.Arch)
306+
guestAgentBinary, err := GuestAgentBinary(*y.OS, *y.Arch)
307307
if err != nil {
308308
return err
309309
}
@@ -329,15 +329,18 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
329329
return iso9660util.Write(filepath.Join(instDir, filenames.CIDataISO), "cidata", layout)
330330
}
331331

332-
func GuestAgentBinary(arch string) (io.ReadCloser, error) {
332+
func GuestAgentBinary(ostype limayaml.OS, arch limayaml.Arch) (io.ReadCloser, error) {
333+
if ostype == "" {
334+
return nil, errors.New("os must be set")
335+
}
333336
if arch == "" {
334337
return nil, errors.New("arch must be set")
335338
}
336339
dir, err := usrlocalsharelima.Dir()
337340
if err != nil {
338341
return nil, err
339342
}
340-
gaPath := filepath.Join(dir, "lima-guestagent.Linux-"+arch)
343+
gaPath := filepath.Join(dir, "lima-guestagent."+ostype+"-"+arch)
341344
return os.Open(gaPath)
342345
}
343346

pkg/limayaml/defaults.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ const (
3939

4040
func defaultContainerdArchives() []File {
4141
const nerdctlVersion = "1.5.0"
42-
location := func(goarch string) string {
43-
return "https://github.com/containerd/nerdctl/releases/download/v" + nerdctlVersion + "/nerdctl-full-" + nerdctlVersion + "-linux-" + goarch + ".tar.gz"
42+
location := func(goos string, goarch string) string {
43+
return "https://github.com/containerd/nerdctl/releases/download/v" + nerdctlVersion + "/nerdctl-full-" + nerdctlVersion + "-" + goos + "-" + goarch + ".tar.gz"
4444
}
4545
return []File{
4646
{
47-
Location: location("amd64"),
47+
Location: location("linux", "amd64"),
4848
Arch: X8664,
4949
Digest: "sha256:3f8c494e3c6a265fe2a3c41ef9d6bc859eeeb22095b3353d3558d8120833a23a",
5050
},
5151
{
52-
Location: location("arm64"),
52+
Location: location("linux", "arm64"),
5353
Arch: AARCH64,
5454
Digest: "sha256:32a2537e0a80e1493b5934ca56c3e237466606a1b720aef23b9c0a7fc3303bdb",
5555
},
@@ -134,6 +134,13 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
134134
y.VMType = o.VMType
135135
}
136136
y.VMType = pointer.String(ResolveVMType(y.VMType))
137+
if y.OS == nil {
138+
y.OS = d.OS
139+
}
140+
if o.OS != nil {
141+
y.OS = o.OS
142+
}
143+
y.OS = pointer.String(ResolveOS(y.OS))
137144
if y.Arch == nil {
138145
y.Arch = d.Arch
139146
}
@@ -768,6 +775,16 @@ func FillCopyToHostDefaults(rule *CopyToHost, instDir string) {
768775
}
769776
}
770777

778+
func NewOS(osname string) OS {
779+
switch osname {
780+
case "linux":
781+
return LINUX
782+
default:
783+
logrus.Warnf("Unknown os: %s", osname)
784+
return osname
785+
}
786+
}
787+
771788
func goarm() int {
772789
if runtime.GOOS != "linux" {
773790
return 0
@@ -824,6 +841,13 @@ func ResolveVMType(s *string) VMType {
824841
return NewVMType(*s)
825842
}
826843

844+
func ResolveOS(s *string) OS {
845+
if s == nil || *s == "" || *s == "default" {
846+
return NewOS("linux")
847+
}
848+
return *s
849+
}
850+
827851
func ResolveArch(s *string) Arch {
828852
if s == nil || *s == "" || *s == "default" {
829853
return NewArch(runtime.GOARCH)

pkg/limayaml/defaults_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func TestFillDefault(t *testing.T) {
6161
// Builtin default values
6262
builtin := LimaYAML{
6363
VMType: pointer.String("qemu"),
64+
OS: pointer.String(LINUX),
6465
Arch: pointer.String(arch),
6566
CPUType: map[Arch]string{
6667
AARCH64: "cortex-a72",
@@ -266,6 +267,7 @@ func TestFillDefault(t *testing.T) {
266267
// Choose values that are different from the "builtin" defaults
267268
d = LimaYAML{
268269
VMType: pointer.String("vz"),
270+
OS: pointer.String("unknown"),
269271
Arch: pointer.String("unknown"),
270272
CPUType: map[Arch]string{
271273
AARCH64: "arm64",
@@ -443,6 +445,7 @@ func TestFillDefault(t *testing.T) {
443445

444446
o = LimaYAML{
445447
VMType: pointer.String("qemu"),
448+
OS: pointer.String(LINUX),
446449
Arch: pointer.String(arch),
447450
CPUType: map[Arch]string{
448451
AARCH64: "uber-arm",

pkg/limayaml/limayaml.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
type LimaYAML struct {
1010
VMType *VMType `yaml:"vmType,omitempty" json:"vmType,omitempty"`
11+
OS *OS `yaml:"os,omitempty" json:"os,omitempty"`
1112
Arch *Arch `yaml:"arch,omitempty" json:"arch,omitempty"`
1213
Images []Image `yaml:"images" json:"images"` // REQUIRED
1314
CPUType map[Arch]string `yaml:"cpuType,omitempty" json:"cpuType,omitempty"`
@@ -39,11 +40,14 @@ type LimaYAML struct {
3940
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
4041
}
4142

43+
type OS = string
4244
type Arch = string
4345
type MountType = string
4446
type VMType = string
4547

4648
const (
49+
LINUX OS = "Linux"
50+
4751
X8664 Arch = "x86_64"
4852
AARCH64 Arch = "aarch64"
4953
ARMV7L Arch = "armv7l"

pkg/start/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
// to be running before timing out.
2929
const DefaultWatchHostAgentEventsTimeout = 10 * time.Minute
3030

31-
// ensureNerdctlArchiveCache prefetches the nerdctl-full-VERSION-linux-GOARCH.tar.gz archive
31+
// ensureNerdctlArchiveCache prefetches the nerdctl-full-VERSION-GOOS-GOARCH.tar.gz archive
3232
// into the cache before launching the hostagent process, so that we can show the progress in tty.
3333
// https://github.com/lima-vm/lima/issues/326
3434
func ensureNerdctlArchiveCache(y *limayaml.LimaYAML) (string, error) {

pkg/usrlocalsharelima/usrlocalsharelima.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func Dir() (string, error) {
2727
}
2828
}
2929

30+
ostype := limayaml.NewOS("linux")
3031
arch := limayaml.NewArch(runtime.GOARCH)
3132
if arch == "" {
3233
return "", fmt.Errorf("failed to get arch for %q", runtime.GOARCH)
@@ -40,12 +41,12 @@ func Dir() (string, error) {
4041
// - self: /Applications/Lima.app/Contents/MacOS/limactl
4142
// - agent: /Applications/Lima.app/Contents/MacOS/lima-guestagent.Linux-x86_64
4243
// - dir: /Applications/Lima.app/Contents/MacOS
43-
filepath.Join(selfDir, "lima-guestagent.Linux-"+arch),
44+
filepath.Join(selfDir, "lima-guestagent."+ostype+"-"+arch),
4445
// candidate 1:
4546
// - self: /usr/local/bin/limactl
4647
// - agent: /usr/local/share/lima/lima-guestagent.Linux-x86_64
4748
// - dir: /usr/local/share/lima
48-
filepath.Join(selfDirDir, "share/lima/lima-guestagent.Linux-"+arch),
49+
filepath.Join(selfDirDir, "share/lima/lima-guestagent."+ostype+"-"+arch),
4950
// TODO: support custom path
5051
}
5152
for _, gaCandidate := range gaCandidates {
@@ -56,6 +57,6 @@ func Dir() (string, error) {
5657
}
5758
}
5859

59-
return "", fmt.Errorf("failed to find \"lima-guestagent.Linux-%s\" binary for %q, attempted %v",
60-
arch, self, gaCandidates)
60+
return "", fmt.Errorf("failed to find \"lima-guestagent.%s-%s\" binary for %q, attempted %v",
61+
ostype, arch, self, gaCandidates)
6162
}

0 commit comments

Comments
 (0)