// PORTABILITY: WebKitGTK's DMABUF renderer cannot allocate GBM buffers on the // NVIDIA proprietary driver — the app window paints BLACK and stderr fills with // "Failed to create GBM buffer of size WxH: Invalid argument" (usually with an // "X11 Error: GLXBadWindow" alongside). Disabling that renderer path is the // standard upstream workaround. // // It has to be in the environment BEFORE the app process starts: WebKit reads // it when it forks its web process, and Bun's `process.env` writes do NOT // propagate to children (verified — a child sees the variable unset), so the // app cannot set this for itself from inside src/bun/. Only the dev launch // paths (`bun run dev` / `bun run start`) inject it; an installed build (the // official Linux Setup installer) needs the user to set // WEBKIT_DISABLE_DMABUF_RENDERER=1 themselves on NVIDIA. // // Scoped to NVIDIA so Intel/AMD keep hardware compositing, and an explicit // value from the user's environment always wins. import { existsSync } from "node:fs"; export function needsDmabufWorkaround(): boolean { return ( process.platform === "linux" && process.env.WEBKIT_DISABLE_DMABUF_RENDERER === undefined && existsSync("/proc/driver/nvidia") ); } /** `process.env` plus the workaround, ready to hand to Bun.spawn. */ export function launchEnv(extra: Record = {}): Record { return { ...process.env, ...(needsDmabufWorkaround() ? { WEBKIT_DISABLE_DMABUF_RENDERER: "1" } : {}), ...extra, }; }