Skip to content

Conversation

jandubois
Copy link
Member

Based on findings in #4042 (comment)

The template merge code already merged mounts correctly based on mountPoint, but FillDefault still merged based on location1.

Using master without this PR:

cat tmpl.yaml
base: template://default
mounts:
- location: /foo
  mountPoint: /foo
- location: /foo
  mountPoint: /bar
- location: /baz
  mountPoint: /barl create -y tmpl.yaml
...l yq .mounts ~/.lima/tmpl/lima.yaml
- location: /foo
  mountPoint: /foo
- location: /foo
  mountPoint: /bar
- location: "~"l ls tmpl --yq '.config.mounts[] | [.location, .mountPoint]'
[
    "/foo",
    "/bar"
]
[
    "/Users/jan",
    "/Users/jan"
]

So template merging has (correctly) dropped mounting the /baz location because the /bar mount point was already fully defined.

And then the /foo mount point has been incorrectly dropped because it shared a mount location with the /bar mount point.

This is fixed in this PR:

l yq .mounts ~/.lima/tmpl/lima.yaml
- location: /foo
  mountPoint: /foo
- location: /foo
  mountPoint: /bar
- location: "~"l ls tmpl --yq '.config.mounts[] | [.location, .mountPoint]'
[
    "/foo",
    "/foo"
]
[
    "/foo",
    "/bar"
]
[
    "/Users/jan",
    "/Users/jan"
]

So template merging is unchanged and has correctly removed the /baz location, but both the /foo and /bar mount points have been correctly preserved.

Footnotes

  1. The whole FillDefault() logic should be implemented via template merging, but that will be a bigger job.

@AkihiroSuda
Copy link
Member

base: template://default
mounts:
- location: /foo
  mountPoint: /foo
- location: /foo
  mountPoint: /bar
- location: /baz
  mountPoint: /bar

It seems invalid to have multiple mounts with the same mountPoint: /bar.
Why not just return an error?

@jandubois
Copy link
Member Author

jandubois commented Sep 19, 2025

It seems invalid to have multiple mounts with the same mountPoint: /bar.
Why not just return an error?

You could have the /bar mountpoint writable in a base template, but want to make it read-only in your instance:

base: template-with-bar.yaml
mounts:
- location: /bar
  writable: false

You could also override other mount options in your actual instance template.

There is special merging logic for additionalDisks, mounts, and networks. It comes from the handling of defaults.yaml and override.yaml in FillDefaults and has also been implemented in the template merging code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants