Skip to content

Commit e0102ef

Browse files
committed
Add LIMA_CIDATA_HOME_MOUNTPOINT
This can be used by provisioning scripts to locate the mount point of the users home directory. We can't just use `/Users/$LIMA_CIDATA_USER` because we don't know if the host is Linux or macOS, so it could be `/home/$LIMA_CIDATA_USER` or something completely custom. Also `$LIMA_CIDATA_USER` is the username inside the guest and might be set to `lima` if the username on the macOS host is not a valid Linux username. Example usage to configure client certs for the docker daemon: ln -s $LIMA_CIDATA_HOME_MOUNTPOINT/.docker/certs.d /etc/docker/certs.d Signed-off-by: Jan Dubois <[email protected]>
1 parent 8af004c commit e0102ef

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

docs/internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ The volume label is "cidata", as defined by [cloud-init NoCloud](https://cloudin
118118
- `LIMA_CIDATA_MNT`: the mount point of the disk. `/mnt/lima-cidata`.
119119
- `LIMA_CIDATA_USER`: the user name string
120120
- `LIMA_CIDATA_UID`: the numeric UID
121+
- `LIMA_CIDATA_HOSTHOME_MOUNTPOINT`: the mount point of the host home directory, or empty if not mounted
121122
- `LIMA_CIDATA_MOUNTS`: the number of the Lima mounts
122123
- `LIMA_CIDATA_MOUNTS_%d_MOUNTPOINT`: the N-th mount point of Lima mounts (N=0, 1, ...)
123124
- `LIMA_CIDATA_MOUNTTYPE`: the type of the Lima mounts ("reverse-sshfs", "9p", ...)

pkg/cidata/cidata.TEMPLATE.d/lima.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
LIMA_CIDATA_NAME={{ .Name }}
22
LIMA_CIDATA_USER={{ .User }}
33
LIMA_CIDATA_UID={{ .UID }}
4+
LIMA_CIDATA_HOSTHOME_MOUNTPOINT={{ .HostHomeMountPoint }}
45
LIMA_CIDATA_MOUNTS={{ len .Mounts }}
56
{{- range $i, $val := .Mounts}}
67
LIMA_CIDATA_MOUNTS_{{$i}}_MOUNTPOINT={{$val.MountPoint}}

pkg/cidata/cidata.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
128128
case limayaml.NINEP:
129129
fstype = "9p"
130130
}
131+
hostHome, err := localpathutil.Expand("~")
132+
if err != nil {
133+
return err
134+
}
131135
for i, f := range y.Mounts {
132136
tag := fmt.Sprintf("mount%d", i)
133137
location, err := localpathutil.Expand(f.Location)
@@ -156,6 +160,9 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
156160
options += ",nofail"
157161
}
158162
args.Mounts = append(args.Mounts, Mount{Tag: tag, MountPoint: mountPoint, Type: fstype, Options: options})
163+
if location == hostHome {
164+
args.HostHomeMountPoint = mountPoint
165+
}
159166
}
160167

161168
switch *y.MountType {

pkg/cidata/template.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,25 @@ type Mount struct {
4343
Options string
4444
}
4545
type TemplateArgs struct {
46-
Name string // instance name
47-
IID string // instance id
48-
User string // user name
49-
UID int
50-
SSHPubKeys []string
51-
Mounts []Mount
52-
MountType string
53-
Containerd Containerd
54-
Networks []Network
55-
SlirpNICName string
56-
SlirpGateway string
57-
SlirpDNS string
58-
SlirpIPAddress string
59-
UDPDNSLocalPort int
60-
TCPDNSLocalPort int
61-
Env map[string]string
62-
DNSAddresses []string
63-
CACerts CACerts
46+
Name string // instance name
47+
IID string // instance id
48+
User string // user name
49+
UID int
50+
SSHPubKeys []string
51+
Mounts []Mount
52+
MountType string
53+
Containerd Containerd
54+
Networks []Network
55+
SlirpNICName string
56+
SlirpGateway string
57+
SlirpDNS string
58+
SlirpIPAddress string
59+
UDPDNSLocalPort int
60+
TCPDNSLocalPort int
61+
Env map[string]string
62+
DNSAddresses []string
63+
CACerts CACerts
64+
HostHomeMountPoint string
6465
}
6566

6667
func ValidateTemplateArgs(args TemplateArgs) error {

0 commit comments

Comments
 (0)