@@ -9,20 +9,20 @@ import (
9
9
"path/filepath"
10
10
"runtime"
11
11
"strconv"
12
+ "strings"
12
13
"text/template"
13
14
14
15
"github.com/docker/go-units"
15
- "github.com/lima-vm/lima/pkg/networks"
16
- "github.com/lima-vm/lima/pkg/ptr"
17
16
"github.com/pbnjay/memory"
17
+ "github.com/sirupsen/logrus"
18
+ "golang.org/x/sys/cpu"
18
19
19
20
"github.com/lima-vm/lima/pkg/guestagent/api"
21
+ "github.com/lima-vm/lima/pkg/networks"
20
22
"github.com/lima-vm/lima/pkg/osutil"
23
+ "github.com/lima-vm/lima/pkg/ptr"
21
24
"github.com/lima-vm/lima/pkg/store/dirnames"
22
25
"github.com/lima-vm/lima/pkg/store/filenames"
23
- "github.com/sirupsen/logrus"
24
-
25
- "golang.org/x/sys/cpu"
26
26
)
27
27
28
28
const (
@@ -83,6 +83,26 @@ func MACAddress(uniqueID string) string {
83
83
return hw .String ()
84
84
}
85
85
86
+ func hostTimeZone () string {
87
+ // WSL2 will automatically set the timezone
88
+ if runtime .GOOS != "windows" {
89
+ tz , err := os .ReadFile ("/etc/timezone" )
90
+ if err == nil {
91
+ return strings .TrimSpace (string (tz ))
92
+ }
93
+ zoneinfoFile , err := filepath .EvalSymlinks ("/etc/localtime" )
94
+ if err == nil {
95
+ for baseDir := filepath .Dir (zoneinfoFile ); baseDir != "/" ; baseDir = filepath .Dir (baseDir ) {
96
+ if _ , err = os .Stat (filepath .Join (baseDir , "Etc/UTC" )); err == nil {
97
+ return strings .TrimPrefix (zoneinfoFile , baseDir + "/" )
98
+ }
99
+ }
100
+ logrus .Warnf ("could not locate zoneinfo directory from %q" , zoneinfoFile )
101
+ }
102
+ }
103
+ return ""
104
+ }
105
+
86
106
func defaultCPUs () int {
87
107
const x = 4
88
108
if hostCPUs := runtime .NumCPU (); hostCPUs < x {
@@ -325,6 +345,16 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
325
345
}
326
346
}
327
347
348
+ if y .TimeZone == nil {
349
+ y .TimeZone = d .TimeZone
350
+ }
351
+ if o .TimeZone != nil {
352
+ y .TimeZone = o .TimeZone
353
+ }
354
+ if y .TimeZone == nil {
355
+ y .TimeZone = ptr .Of (hostTimeZone ())
356
+ }
357
+
328
358
if y .SSH .LocalPort == nil {
329
359
y .SSH .LocalPort = d .SSH .LocalPort
330
360
}
@@ -731,6 +761,7 @@ func fixUpForPlainMode(y *LimaYAML) {
731
761
y .Containerd .User = ptr .Of (false )
732
762
y .Rosetta .BinFmt = ptr .Of (false )
733
763
y .Rosetta .Enabled = ptr .Of (false )
764
+ y .TimeZone = ptr .Of ("" )
734
765
}
735
766
736
767
func executeGuestTemplate (format string ) (bytes.Buffer , error ) {
0 commit comments