@@ -9,20 +9,20 @@ import (
99"path/filepath"
1010"runtime"
1111"strconv"
12+ "strings"
1213"text/template"
1314
1415"github.com/docker/go-units"
15- "github.com/lima-vm/lima/pkg/networks"
16- "github.com/lima-vm/lima/pkg/ptr"
1716"github.com/pbnjay/memory"
17+ "github.com/sirupsen/logrus"
18+ "golang.org/x/sys/cpu"
1819
1920"github.com/lima-vm/lima/pkg/guestagent/api"
21+ "github.com/lima-vm/lima/pkg/networks"
2022"github.com/lima-vm/lima/pkg/osutil"
23+ "github.com/lima-vm/lima/pkg/ptr"
2124"github.com/lima-vm/lima/pkg/store/dirnames"
2225"github.com/lima-vm/lima/pkg/store/filenames"
23- "github.com/sirupsen/logrus"
24-
25- "golang.org/x/sys/cpu"
2626)
2727
2828const (
@@ -83,6 +83,26 @@ func MACAddress(uniqueID string) string {
8383return hw .String ()
8484}
8585
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+
86106func defaultCPUs () int {
87107const x = 4
88108if hostCPUs := runtime .NumCPU (); hostCPUs < x {
@@ -325,6 +345,16 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
325345}
326346}
327347
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+
328358if y .SSH .LocalPort == nil {
329359y .SSH .LocalPort = d .SSH .LocalPort
330360}
@@ -731,6 +761,7 @@ func fixUpForPlainMode(y *LimaYAML) {
731761y .Containerd .User = ptr .Of (false )
732762y .Rosetta .BinFmt = ptr .Of (false )
733763y .Rosetta .Enabled = ptr .Of (false )
764+ y .TimeZone = ptr .Of ("" )
734765}
735766
736767func executeGuestTemplate (format string ) (bytes.Buffer , error ) {
0 commit comments