Skip to content

Commit 592ca32

Browse files
committed
Search $LIMA_HOME/_templates before /usr/local/share/lima/templates
Signed-off-by: Jan Dubois <[email protected]>
1 parent 89e926a commit 592ca32

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

pkg/templatestore/templatestore.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"unicode"
1616

1717
securejoin "github.com/cyphar/filepath-securejoin"
18+
"github.com/lima-vm/lima/pkg/store/dirnames"
1819
"github.com/lima-vm/lima/pkg/usrlocalsharelima"
1920
)
2021

@@ -24,17 +25,21 @@ type Template struct {
2425
}
2526

2627
func TemplatesPaths() ([]string, error) {
27-
var paths []string
2828
if tmplPath := os.Getenv("LIMA_TEMPLATES_PATH"); tmplPath != "" {
29-
paths = strings.Split(tmplPath, string(filepath.ListSeparator))
30-
} else {
31-
dir, err := usrlocalsharelima.Dir()
32-
if err != nil {
33-
return nil, err
34-
}
35-
paths = []string{filepath.Join(dir, "templates")}
29+
return strings.Split(tmplPath, string(filepath.ListSeparator)), nil
30+
}
31+
limaDir, err := dirnames.LimaDir()
32+
if err != nil {
33+
return nil, err
3634
}
37-
return paths, nil
35+
shareDir, err := usrlocalsharelima.Dir()
36+
if err != nil {
37+
return nil, err
38+
}
39+
return []string{
40+
filepath.Join(limaDir, "_templates"),
41+
filepath.Join(shareDir, "templates"),
42+
}, nil
3843
}
3944

4045
func Read(name string) ([]byte, error) {
@@ -70,6 +75,9 @@ func Templates() ([]Template, error) {
7075

7176
templates := make(map[string]string)
7277
for _, templatesDir := range paths {
78+
if _, err := os.Stat(templatesDir); os.IsNotExist(err) {
79+
continue
80+
}
7381
walkDirFn := func(p string, _ fs.DirEntry, err error) error {
7482
if err != nil {
7583
return err

website/content/en/docs/config/environment-variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This page documents the environment variables used in Lima.
3030
### `LIMA_TEMPLATES_PATH`
3131

3232
- **Description**: Specifies the directories used to resolve `template://` URLs.
33-
- **Default**: `/usr/local/share/lima/templates`
33+
- **Default**: `$LIMA_HOME/_templates:/usr/local/share/lima/templates`
3434
- **Usage**:
3535
```sh
3636
export LIMA_TEMPLATES_PATH="$HOME/.config/lima/templates:/usr/local/share/lima/templates"

website/content/en/docs/dev/internals.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ When using `vmType: vz` (Virtualization.framework), on boot, any qcow2 (default)
107107

108108
`ls` will also only show the full/virtual size of the disks. To see the allocated space, `du -h disk_path` or `qemu-img info disk_path` can be used instead. See [#1405](https://github.com/lima-vm/lima/pull/1405) for more details.
109109

110+
## Templates directory (`${LIMA_HOME}/_templates`)
111+
112+
The templates directory can store additional template files that can be referenced with the `template://` schema.
113+
114+
If the template directory exists (and `$LIMA_TEMPLATES_PATH` is not set), then this directory will be searched before the `/usr/local/share/lima/templates` default directory that contains all the templates bundled with Lima itself.
115+
110116
## Lima cache directory (`~/Library/Caches/lima`)
111117

112118
Currently hard-coded to `~/Library/Caches/lima` on macOS.

0 commit comments

Comments
 (0)