Documentation
¶
Overview ¶
Package wsl lets a Windows-native `dejima` client drive a `dejimad` running inside a WSL2 distro.
Windows can't host Dejima: dejimad needs a Unix host with Docker (see scripts/setup.sh, which exits on anything but Darwin/Linux, and internal/service, which only knows launchd + systemd). WSL2 *is* such a host — a real Linux kernel with a real Docker — so a Windows user can run the whole stack locally after all, with the daemon one virtualization boundary away.
The transport is deliberately the cheapest thing that preserves the security model: we shell out to `wsl.exe -d <distro> -- socat STDIO UNIX-CONNECT:…` and wrap that process's stdio as a net.Conn. dejimad needs no new listener, no TCP bind, and no relaxation of the tailnet pin; its 0600 Unix socket remains the only operator surface, reachable exactly by whoever can already run commands as that user inside the distro.
A connection target for this path is spelled `wsl://<distro>` and is stored in a client profile like any other host.
Index ¶
- Constants
- Variables
- func Available() bool
- func Dial(ctx context.Context, distro string) (net.Conn, error)
- func DialTimeout() time.Duration
- func Distro(host string) string
- func Host(distro string) string
- func IsHost(host string) bool
- func Run(ctx context.Context, distro, script string) (string, error)
- func RunExe(ctx context.Context, args ...string) (string, error)
- func Supported() bool
- type Distribution
- type Report
Constants ¶
const DefaultDistro = "dejima"
DefaultDistro is the distro name `dejima wsl setup` creates and that the first-run flow offers. Named for the project so it's obvious in `wsl -l -v` and can't be confused with a distro the user keeps for other work.
const Scheme = "wsl://"
Scheme prefixes a WSL connection target: "wsl://dejima".
Variables ¶
var ErrUnsupported = errors.New("wsl:// targets work only on Windows (WSL interop); use a host:port address here")
ErrUnsupported is returned when a `wsl://` target is used off Windows.
Functions ¶
func Available ¶
func Available() bool
Available reports whether WSL interop is usable at all: Windows, with wsl.exe on PATH.
func Dial ¶
Dial opens a connection to dejimad's Unix socket inside distro by piping through `wsl.exe … socat`. The returned conn owns the subprocess and kills it on Close.
ctx bounds the *handshake* (spawning wsl.exe), not the connection's lifetime: http.Transport pools connections past the request whose context triggered the dial, so binding the process to that context would kill live pooled conns.
func DialTimeout ¶
DialTimeout is the handshake budget callers should use when building a transport for this path.
func Distro ¶
Distro extracts the distro name from a `wsl://<distro>` host, or "" if host isn't a WSL target. A bare "wsl://" yields DefaultDistro so the shorthand works.
func IsHost ¶
IsHost reports whether a connection host names a WSL distro rather than a TCP address.
func Run ¶
Run is run() exported for the setup flow, which needs to execute provisioning steps inside the distro and show their output.
func RunExe ¶
RunExe invokes wsl.exe with *management* arguments (--install, --set-version, …) rather than a command inside a distro. It returns the combined output even on failure so callers can classify the error (e.g. an old wsl.exe that lacks a flag), and streams nothing — these operations are slow but quiet.
Types ¶
type Distribution ¶
type Distribution struct {
Name string
State string // "Running" / "Stopped"
Version int // 1 or 2; only 2 has a real kernel + Docker
Default bool
}
Distribution is one entry from `wsl.exe -l -v`.
type Report ¶
type Report struct {
Distro string
Exists bool
Version int
Running bool
HasSocat bool
HasDocker bool // docker CLI present AND the engine answers
HasDejima bool // dejimad binary installed
SocketUp bool // ~/.dejima/dejimad.sock exists
}
Report is a health read of one distro as a Dejima host.