Skip to content

Commit 936abd3

Browse files
authored
Merge pull request #59 from rancher-sandbox/lima-home
Implement LIMA_HOME to override ~/.lima location
2 parents 958c8bf + 2b6f3a0 commit 936abd3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cmd/limactl/start.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ func loadOrCreateInstance(clicontext *cli.Context) (*store.Instance, error) {
8282
return nil, err
8383
}
8484

85+
// all socket names should be 6 characters or less
86+
maxSockName := filepath.Join(instDir, "serial.sock")
87+
if len(maxSockName) >= 104 {
88+
return nil, errors.Errorf("Instance name %q too long: %q must be less than 104 characers, but is %d",
89+
instName, maxSockName, len(maxSockName))
90+
}
8591
if _, err := os.Stat(instDir); !errors.Is(err, os.ErrNotExist) {
8692
return nil, errors.Errorf("instance %q already exists (%q)", instName, instDir)
8793
}

pkg/store/store.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ import (
1212
// DotLima is a directory that appears under the home directory.
1313
const DotLima = ".lima"
1414

15-
// LimaDir returns the abstract path of `~/.lima`.
15+
// LimaDir returns the abstract path of `~/.lima` (or $LIMA_HOME, if set).
1616
//
1717
// NOTE: We do not use `~/Library/Application Support/Lima` on macOS.
1818
// We use `~/.lima` so that we can have enough space for the length of the socket path,
1919
// which can be only 104 characters on macOS.
2020
func LimaDir() (string, error) {
21-
homeDir, err := os.UserHomeDir()
22-
if err != nil {
23-
return "", err
21+
dir := os.Getenv("LIMA_HOME")
22+
if dir == "" {
23+
homeDir, err := os.UserHomeDir()
24+
if err != nil {
25+
return "", err
26+
}
27+
dir = filepath.Join(homeDir, DotLima)
2428
}
25-
dir := filepath.Join(homeDir, DotLima)
2629
return dir, nil
2730
}
2831

0 commit comments

Comments
 (0)