github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/pkg/dockerutil/wsl.go (about)

     1  package dockerutil
     2  
     3  import (
     4  	"github.com/drud/ddev/pkg/fileutil"
     5  	"os"
     6  	"runtime"
     7  )
     8  
     9  // IsWSL2 returns true if running WSL2
    10  func IsWSL2() bool {
    11  	if runtime.GOOS == "linux" {
    12  		// First, try checking env variable
    13  		if os.Getenv(`WSL_INTEROP`) != "" {
    14  			return true
    15  		}
    16  		// But that doesn't always work, so check for existence of wsl.exe
    17  		if isWSL2, _ := fileutil.FgrepStringInFile("/proc/version", "-microsoft"); isWSL2 {
    18  			return true
    19  		}
    20  	}
    21  	return false
    22  }