diff --git a/docs/content/docs/backends/lima.md b/docs/content/docs/backends/lima.md index 899cfa7c..e5663ff0 100644 --- a/docs/content/docs/backends/lima.md +++ b/docs/content/docs/backends/lima.md @@ -68,7 +68,7 @@ Set the variables in the VM's shell or in your project's scripts, before the too ## Limits -- **Folder names in VM names are cut short.** Lima keeps each VM's ssh socket in the VM's folder in its home, and a socket path has at most 104 characters. A long Lima home leaves less room for the name, so set `DEVVM_LIMA_HOME` to a shorter folder if devvm says the home is too long, or that a VM's name leaves no room for the folder's name ([VM names](../internals/backends.md#vm-names)). +- **Folder names in VM names are cut short.** Lima keeps each VM's ssh socket in the VM's folder in its home, and a socket path has fewer than 104 characters. A long Lima home leaves less room for the name, so set `DEVVM_LIMA_HOME` to a shorter folder if devvm says the home is too long, or that a VM's name leaves no room for the folder's name ([VM names](../internals/backends.md#vm-names)). - **Paths can't contain commas.** Lima and QEMU split mount options on commas, so devvm refuses to mount a project folder whose path has one, and it leaves out an agent's folder whose path has one, with a warning. - **Disks can grow but not shrink.** - **Mounts on Linux are 9p.** A 9p share mounts once per guest, and file watchers in the VM miss changes in its subfolders ([file watchers](#file-watchers)). diff --git a/internal/backend/lima/lima.go b/internal/backend/lima/lima.go index 67595594..6b3439d0 100644 --- a/internal/backend/lima/lima.go +++ b/internal/backend/lima/lima.go @@ -323,17 +323,14 @@ func (l *Lima) Caps() backend.Caps { } } -// socketMax is the longest unix socket path macOS takes (Linux takes 108). // sshSocketExtra is what OpenSSH adds to the socket's name while making it. -const ( - socketMax = 104 - sshSocketExtra = 17 -) +const sshSocketExtra = 17 // NameMax is the longest VM name whose ssh socket fits: Lima keeps it in -// the VM's folder (//ssh.sock). +// the VM's folder (//ssh.sock) and refuses a path of +// paths.SocketMax characters or more, as the last byte is the NUL. func (l *host) NameMax() int { - return max(0, socketMax-sshSocketExtra-len(l.Dirs.Lima)-len("/")-len("/ssh.sock")) + return max(0, paths.SocketMax-1-sshSocketExtra-len(l.Dirs.Lima)-len("/")-len("/ssh.sock")) } // imageKey returns the key of an image's instance, and whether it is one. diff --git a/internal/backend/lima/lima_test.go b/internal/backend/lima/lima_test.go index 21e42f62..d293adb0 100644 --- a/internal/backend/lima/lima_test.go +++ b/internal/backend/lima/lima_test.go @@ -336,13 +336,13 @@ func TestStartRefusesGlobalConfigsAndNetworks(t *testing.T) { } // Lima keeps a VM's ssh socket in its folder, OpenSSH adds 17 characters -// while making it, and a socket path has at most 104: the name gets what's -// left. +// while making it, and Lima refuses a socket path of paths.SocketMax +// characters or more: the name gets what's left. func TestNameMax(t *testing.T) { l, f, _ := testLima(t, "darwin") n := l.NameMax() - if len(l.Dirs.Lima)+1+n+len("/ssh.sock")+17 != 104 { - t.Errorf("NameMax %d for a Lima home of %d characters", n, len(l.Dirs.Lima)) + if sock := len(l.Dirs.Lima) + 1 + n + len("/ssh.sock") + 17; sock != paths.SocketMax-1 { + t.Errorf("NameMax %d gives a socket path of %d characters for a Lima home of %d", n, sock, len(l.Dirs.Lima)) } long := "devvm-" + strings.Repeat("x", n) + "-0123456789abcd" err := l.CreateVM(t.Context(), "k", backend.VMSpec{Name: long})