chore(scripts): probe a WSL2 NixOS VM for KVM, WSLg and RDP

The port can only be tried on a Windows machine, through a NixOS virtual machine
in WSL2, which the machines this history is built on do not have. What such a
machine can do for a Plasma guest is not known until something runs there, and
every guess about it is a risk for what comes next. wsl2-probe is that
something: one command, nix run .#wsl2-probe, that answers in about two minutes
what the guest needs to know and prints, for each answer that is not a yes, the
exact change: the .wslconfig lines, the NixOS option, the PowerShell command.

It checks the environment (WSL2, memory, disk, .wslconfig, Nix); KVM (/dev/kvm,
its group, and a tiny guest booted under KVM and under TCG, with the same loop
timed in both and on the machine itself, which must differ by several times);
the display (a QEMU GTK window through WSLg for a few seconds, and whether you
saw it); the GPU (/dev/dxg, the Windows driver libraries, the OpenGL renderer in
four environments, and virtio-vga-gl with gl=on); the Windows side (interop,
mstsc.exe, whether Windows reaches a port that WSL listens on); whether memory,
cores and disk are enough for the real guest; and virtiofs, which the real guest
uses for its /nix/store and every shared directory (/dev/fuse, virtiofsd as the
user with the options of nixpkgs' runner, and a guest that mounts the host's
/nix/store and a writable directory, reads, writes and compares). Each probe
runs apart from the others, so one that fails leaves the rest alone, and the
output ends in a block to paste back, which is also written to
wsl2-probe-report.txt.

The flake wraps the script with QEMU, virtiofsd, Mesa's eglinfo and glxinfo and
socat from nixpkgs, and builds the guest, a kernel from the binary cache, the
two modules of it that virtiofs needs and a static busybox initrd, as
wsl2-probe-guest, so nothing is compiled on the machine. Two checks keep the
script from rotting: wsl2-probe builds the wrapper, which runs ShellCheck over
the script and over the guest's init, and wsl2-probe-dry-run runs --dry-run in
the build sandbox, which has no KVM, no network and no display.
docs/dev/wsl2-probe.md says what each check means and how to read it.
This commit is contained in:
LGUG2Z committed 2026-10-28 13:27:11 -07:00
1 parent 1dde9fd257
commit 9b60a0020d
11 files changed
+2150 -3

No files matched your search

+3 -1
View File
@@ -377,7 +377,9 @@ and [`docs/cli`](docs/cli) has a page for every `komorebic` subcommand, which
[`docs/dev/COMPARE.md`](docs/dev/COMPARE.md) what is the same and what is different in
komorebi for Windows and komorebi for Mac,
[`docs/dev/vm-tests.md`](docs/dev/vm-tests.md) how the VM tests work, and
[`docs/dev/utm.md`](docs/dev/utm.md) how to develop in a Plasma guest.
[`docs/dev/utm.md`](docs/dev/utm.md) how to develop in a Plasma guest, and
[`docs/dev/wsl2-probe.md`](docs/dev/wsl2-probe.md) how to find out whether a
NixOS-WSL2 machine can run one (`nix run .#wsl2-probe`).
## License
+5
View File
@@ -1979,6 +1979,11 @@ plan needs no engine. A failure to start is logged, and the window manager runs
[COMPARE.md](COMPARE.md) from this checkout and from checkouts of komorebi for Windows and
komorebi for Mac, and checks them. Continuous integration has neither checkout and does not run
it.
- [`scripts/wsl2-probe.sh`](../../scripts/wsl2-probe.sh), wrapped by
[`nix/dev/wsl2-probe.nix`](../../nix/dev/wsl2-probe.nix): probes a NixOS-WSL2 machine for KVM,
WSLg, a GPU and RDP ([wsl2-probe.md](wsl2-probe.md)). The flake checks `wsl2-probe` (ShellCheck
over the script and over the guest's init) and `wsl2-probe-dry-run` (the script's `--dry-run` in
the build sandbox) keep it building.
[`nixos-module.nix`]: ../../nix/nixos-module.nix
[`supported-kwin.nix`]: ../../nix/supported-kwin.nix
+3
View File
@@ -862,6 +862,9 @@ they work or that they do not.
the curve gives about 60 % ([KWin effects](#kwin-effects)). The log evidence and the comparison
with animation off do not depend on it.
- Graphics other than llvmpipe: every render measured was in software.
- WSL2: KVM, a QEMU window through WSLg, the Windows GPU as OpenGL in WSL, a port that
Windows reaches in WSL, and `virtiofsd` serving a guest's `/nix/store`. The probe that measures
them ([wsl2-probe.md](wsl2-probe.md)) has not run on WSL2.
- The scrolling layout on a monitor that has another beside it. A strip spills onto the
neighbor when that monitor shows the same workspace number, and a window whose middle is on a
monitor that shows another desktop is not drawn. This is read from KWin's sources, not
+4
View File
@@ -34,6 +34,10 @@ it.
TCG is software emulation. It is slow enough that only short suites are worth
running that way, and the library's `scale` argument (below) is 8 for it.
Whether a machine has working KVM is not always obvious, and under WSL2 it
depends on settings of Windows. `nix run .#wsl2-probe` boots a tiny guest with
and without KVM and times both ([wsl2-probe.md](wsl2-probe.md)).
The suites are what `testedMax` in
[`nix/supported-kwin.nix`](../../nix/supported-kwin.nix) means: the newest KWin
every suite has passed against. When the weekly canary job, which runs every
+278
View File
@@ -0,0 +1,278 @@
# Probing a NixOS-WSL2 machine
A Plasma guest that runs komorebi can be started on a Windows machine from a
NixOS virtual machine in WSL2: QEMU with KVM boots the guest, and its window is
shown through WSLg. Whether a given machine can do that depends on five things
that nothing but that machine can answer: whether WSL2 passes KVM through,
whether WSLg opens a QEMU window, whether the Windows GPU reaches OpenGL in
WSL, whether Windows can reach a port that the guest listens on, and whether the
guest can mount the host's `/nix/store` by virtiofs. The probe answers them in
about two minutes, and prints what to change for each answer that is not a yes.
It changes nothing on the machine. It reads files and system settings, boots a
tiny guest under QEMU that powers itself off, opens two windows for a few
seconds each, starts `virtiofsd` for a few seconds, and listens on two local
ports until it ends.
## Running it
From a checkout of this repository, in the NixOS-WSL2 shell, with flakes
enabled:
```sh
nix run .#wsl2-probe
```
`just wsl2-probe` runs the same command, and arguments for the script go after
it (`just wsl2-probe --hold 15`). Nix brings QEMU, `virtiofsd`, Mesa's
`eglinfo` and `glxinfo`, `socat` and the guest, about 1.6 GiB in the Nix store
as of 2026-10-28, most of it QEMU's and Mesa's dependencies. The guest is a
kernel and a static busybox from the binary cache, and the two kernel modules
that virtiofs needs, so nothing is compiled; building the module closure also
downloads the kernel's module tree (about 150 MB), which the probe does not keep.
While it runs, look at the Windows desktop: a QEMU window opens twice for 8
seconds (P2, then P3), and after each the script asks whether it appeared. The
answer is one of the things the script cannot find out itself.
| Option | Effect |
|---|---|
| `--only P1,P3` | runs only those probes (P0 always runs: the others read what it found) |
| `--hold SECONDS` | how long a window stays open (default 8) |
| `--yes` | answers yes to "did a window appear?" without asking |
| `--no-prompt` | asks nothing; this is also the case when stdin is not a terminal |
| `--dry-run` | runs P0 and P5, which only read, and prints what the others would start |
| `--report FILE` | where to write the report (default `wsl2-probe-report.txt` in the current directory) |
The exit status is 0 when the probes ran, whatever they found, and 2 for a
mistake in the options.
## Reading the output
Every line that carries a result starts with one of these:
| Tag | Meaning |
|---|---|
| `[PASS]` | the check passed |
| `[WARN]` | it works, but not as it should, or the check cannot say |
| `[FAIL]` | the thing the real guest needs is missing |
| `[SKIP]` | the check did not run, and the line says why |
| `[INFO]` | a value that was read or measured; the summary repeats it |
A `WARN` or a `FAIL` is followed by a `fix:` block with the exact change: the
lines for `%USERPROFILE%\.wslconfig`, an option of the NixOS configuration, or a
command for PowerShell. The checks have numbers (`P1.2`), and the fix of a
check often names another (`see P1.1`).
The output ends with a block between two lines of equals signs, headed
`PASTE THIS`: one verdict per probe, one line per check, and every fact the
probes read or measured. That block is what to send back. The whole output is in
`wsl2-probe-report.txt`, without colors.
## The probes
### P0: the environment
| Check | What it looks at | Verdict |
|---|---|---|
| P0.1 | `WSL_DISTRO_NAME`, `/run/WSL` and `/proc/version` | `PASS` on WSL2; `WARN` on WSL1 or when this is not WSL at all, where the probes can only report what they find |
| P0.2 | `nix config show experimental-features` | `PASS` when flakes are on; `WARN` with the NixOS option when not |
| P0.3 | `trusted-users` against the user and its groups | `PASS` when the user is trusted; `WARN` with the NixOS option when not |
The facts are the kernel, PID 1, `/etc/os-release` and `nixos-version`, the
`nixos-wsl` input of `/etc/nixos/flake.lock` if there is one, memory, the number
of processors, the free disk in `/nix`, the home directory, the directory the
real guest would keep its state in, the current directory and `/mnt/c`, the CPU
vendor, model and virtualization flag, the Nix version and substituters, and,
through interop, the Windows build, `wsl.exe --version` and the `.wslconfig` of
the Windows user. When interop is off, the Windows facts are missing and P4.1
says how to turn it on.
### P1: KVM
| Check | What it looks at | Verdict |
|---|---|---|
| P1.1 | the `svm` (AMD) or `vmx` (Intel) flag of `/proc/cpuinfo` | `FAIL` with the `.wslconfig` lines for nested virtualization when neither is there; `INFO` on a CPU that has neither flag by design |
| P1.2 | `/dev/kvm` exists and the user can open it read-write | `FAIL` when it is missing (nested virtualization) or closed to the user (the `kvm` group, with the exact `extraGroups` line) |
| P1.3 | a guest booted under `-accel kvm -cpu host` and the loop it ran | `PASS` with the loop time and the time of the whole boot; `FAIL` with QEMU's error and a fix chosen from it |
| P1.4 | the same guest under `-accel tcg`, software emulation | `PASS` with the times; `FAIL` means QEMU does not work here at all |
| P1.5 | TCG's loop time divided by KVM's | `PASS` at 3 or more, `WARN` from 1.5, `FAIL` below |
The facts are the nested-virtualization setting of `kvm_amd` or `kvm_intel`, the
QEMU version, the guest's CPU model, memory and flags (whether it sees `svm` or
`vmx` itself, and `hypervisor`, `avx`, `avx2`, `aes`), and the loop timed on the
machine itself with the same busybox.
The loop is 600000 iterations of an `ash` counting loop, timed from
`/proc/uptime` (a resolution of 10 ms, so the loop has to take about a second).
KVM runs the guest's instructions on the CPU, so its time is about that of the
machine itself; TCG translates them, and is several times slower. On a Xeon
6975P with KVM, at time of writing (2026-10-28), the loop took 970 ms on the
machine, 980 ms in a KVM guest and 11370 ms under TCG, 11.6 times as long. A
ratio under 3 means the acceleration is partial or absent, and the figure to
paste is `kvm_vs_tcg`.
### P2: display
| Check | What it looks at | Verdict |
|---|---|---|
| P2.1 | `WAYLAND_DISPLAY`, `DISPLAY`, `XDG_RUNTIME_DIR`, `/mnt/wslg` and the sockets in them | `PASS` when the shell can reach a display; `WARN` when only WSLg's defaults (`/mnt/wslg/runtime-dir/wayland-0`, `:0`) can, which the probe then uses for its windows; `FAIL` on WSL with none (`WARN` elsewhere) |
| P2.2 | `-display gtk -device virtio-vga` for `--hold` seconds, with the guest printing a line a second | `PASS` when QEMU started, the guest ran to its end with the window up, and QEMU exited 0; `FAIL` with QEMU's error otherwise. When the window system the toolkit picked fails and both are available, each is tried by name (`GDK_BACKEND`) |
| P2.3 | your answer to "did a window appear?" | `PASS` for yes; `FAIL` for no; `INFO` when it was not asked (`--no-prompt`, no terminal) or `--yes` answered it |
A line says when the framebuffer's frame rate was not measured: the guest is a
text console, so there is no moving picture to count frames of.
### P3: GPU
| Check | What it looks at | Verdict |
|---|---|---|
| P3.1 | `/dev/dxg`, the device through which WSL2 passes the Windows GPU | `FAIL` on WSL when it is missing: the Windows driver needs WSL support |
| P3.2 | `libd3d12.so`, `libd3d12core.so` and `libdxcore.so` in `/usr/lib/wsl/lib`, where WSL mounts the Windows driver's libraries | `WARN` when they are missing |
| P3.3 | the same libraries linked into `/run/opengl-driver/lib`, which is what `wsl.useWindowsDriver = true` does on NixOS-WSL | `WARN` with the options when they are not |
| P3.4 | the OpenGL renderer that `eglinfo -B` and `glxinfo -B` report on the machine, in four environments: as it is, with `LD_LIBRARY_PATH=/usr/lib/wsl/lib`, with `GALLIUM_DRIVER=d3d12`, and with both | `PASS` when one of them reports a hardware renderer (`d3d12` or other), naming the environment that does; `WARN` when all report `llvmpipe` or none works |
| P3.5 | `qemu -device help` and `-display help` list `virtio-vga-gl` (`virtio-gpu-gl-pci` on aarch64) and `gtk` | `FAIL` when not: the QEMU of nixpkgs lacks it |
| P3.6 | `-display gtk,gl=on -device virtio-vga-gl` for `--hold` seconds | the same as P2.2, with the environment of P3.4's variant tried when the default one fails; QEMU's refusal is printed |
| P3.7 | your answer to "did the VirGL window appear too?" | as P2.3 |
The facts include the contents of `/usr/lib/wsl/lib` and `/usr/lib/wsl/drivers`,
the Windows GPU name and driver version from `Win32_VideoController`, and each
renderer line per variant (`host_gl[default]`, `host_gl[d3d12]`, ...), which names
the renderer that each platform of `eglinfo` (X11, Wayland, GBM, surfaceless)
reports. A renderer string that names `d3d12` is Mesa's Direct3D 12 driver,
which draws on the Windows GPU; `llvmpipe` is Mesa's software rasterizer.
What happens inside the guest is not checked: the guest of this probe has no
graphics stack, so the renderer that a Plasma session in it gets (VirGL on the
host's renderer, or `llvmpipe`) is for the real guest to report.
### P4: the Windows side
| Check | What it looks at | Verdict |
|---|---|---|
| P4.1 | `cmd.exe /c ver` through interop | `FAIL` with the NixOS-WSL interop options when Windows programs do not run from WSL |
| P4.2 | `mstsc.exe`, Windows' RDP client, on `PATH` or in `System32` | `PASS` when found; `WARN` with the `includePath` option when not |
| P4.3 | two `socat` listeners on free ports above 20000, one on `127.0.0.1` and one on `0.0.0.0`, and a TCP connection to each from `powershell.exe`, as `127.0.0.1` and as `localhost` | `PASS` when Windows reaches the loopback listener both ways; `WARN` when only `127.0.0.1` works, or only the `0.0.0.0` listener is reachable; `FAIL` when nothing is, with the `.wslconfig` lines for `localhostForwarding` and `networkingMode` |
The facts are the path of `cmdkey.exe` (which a later step would use to hand
Windows the RDP credentials), the networking mode (`wslinfo --networking-mode`,
or `networkingMode` of `.wslconfig`: NAT by default, or mirrored), the
`localhostForwarding` setting, the WSL machine's addresses, and the four
connection results.
Outside WSL, P4 says so and checks nothing.
### P5: resources
The real guest wants 8 GiB of memory, 4 or more cores, and about 25 GiB of disk,
plus the space the Nix build takes.
| Check | What it looks at | Verdict |
|---|---|---|
| P5.1 | `MemTotal` of the WSL machine | `PASS` from 10 GiB (8 for the guest, 2 for WSL and Nix next to it); `WARN` from 6 GiB, where the guest would run with `--memory 6144`; `FAIL` below, each with the `memory=` and `swap=` lines for `.wslconfig` |
| P5.2 | `nproc` | `PASS` from 4; `WARN` below, with the `processors=` line |
| P5.3 | the free space under `/nix`, or on the Windows drive under the virtual disk when that is less | `PASS` from 40 GiB (25 for the closure and the guest's disk, 10 for the build); `WARN` from 25; `FAIL` below |
On WSL the virtual disk looks like a terabyte; what limits it is the Windows
drive it lives on, so the probe reads `/mnt/c` as well and takes the smaller of
the two.
### P6: virtiofs
The real guest does not copy the host's `/nix/store`: it mounts it. On a Linux
host nixpkgs' QEMU runner starts one `virtiofsd` per shared directory (the
store, the repository, the directory of the credentials), and QEMU joins the
guest's virtio-fs device to each daemon's socket, with the guest's memory in a
shared `memfd`. This probe builds the same chain, with the same options as the
runner, for the host's `/nix/store` (read-only) and a temporary directory
(writable), and a guest whose kernel is the one the real guest boots.
| Check | What it looks at | Verdict |
|---|---|---|
| P6.1 | `/dev/fuse` exists and the user can open it read-write | `PASS`; `WARN` with the NixOS lines when it is missing or closed: `virtiofsd` does not open it (see below), so the guest can still start |
| P6.2 | `virtiofsd` (the one of nixpkgs, as the runner uses) starts as the user, with `--sandbox=none --seccomp=none --translate-uid ...`, and makes its socket, for `/nix/store` read-only and a temporary directory writable | `FAIL` with the daemon's output when a socket does not appear; `SKIP` when the program is not there |
| P6.3 | QEMU boots the guest with `-object memory-backend-memfd,share=on`, `-machine memory-backend=` and two `vhost-user-fs-pci` devices, under KVM when `/dev/kvm` opens and under TCG otherwise | `FAIL` with QEMU's error, or when the guest does not run to its end |
| P6.4 | the guest loads `virtio_pci` and `virtiofs`, mounts `/nix/store` read-only, and its checksum of the busybox it came with equals the host's; a write is refused | `FAIL` with the guest's error and, when the module did not load, that; `WARN` when the share could be written |
| P6.5 | the guest mounts the writable directory, reads a random token the host wrote, and writes a file that the host reads | `FAIL` when any of the three does not work |
The facts are the path and version of `virtiofsd`, the warnings it printed, how
each module loaded in the guest (`built in` for a kernel that has the transport
in its image), the file systems the guest lists, what the guest saw (the
checksum, the owner and mode of the host user's file, of the file it wrote) and
the owner of the file it wrote as the host sees it.
What is known of `virtiofsd` before WSL2 (read at time of writing, 2026-10-28,
from `virtiofsd` 1.14.0 and nixpkgs' runner on Linux machines that are not WSL2):
- it runs as an ordinary user with the runner's options, and prints two
warnings, that it could not raise the limit of open files above the hard limit,
and that it cannot use file handles for the root node (`Operation not
permitted`) and falls back to `O_PATH` descriptors; both are harmless;
- it never opens `/dev/fuse`: a `strace` of its start shows no such open. It
speaks FUSE to the guest's kernel through the vhost-user socket, so the
daemon needs the socket, a shared `memfd` in QEMU, and the directory;
- a file that the host user owns appears in the guest owned by the same numeric
uid and gid (`--translate-uid host:65534:0:1` maps only the host's 65534),
which is why the guest user of the demo cannot read a directory of a host
user whose uid is not 1000 when its mode is 0700;
- the kernel configuration of WSL2 (`linux-msft-wsl-6.6.y`, `config-wsl` for
`x86_64`, read from its repository, not measured on a machine) has
`CONFIG_FUSE_FS=y`, `CONFIG_MEMFD_CREATE=y`, `CONFIG_USER_NS=y`,
`CONFIG_UNIX=y`, `CONFIG_DEVTMPFS=y` and `CONFIG_KVM_AMD=m`: nothing the
chain needs is missing from it. `/dev/fuse` is a device node that the kernel's
devtmpfs makes closed to ordinary users, and udev's default rules open it, so
where udev's rules do not apply it can be closed, which `virtiofsd` does not
mind.
On WSL2 itself the chain is not measured at time of writing: the paste of the
first run is the first fact.
## The NixOS-WSL option names
The fixes name these options of NixOS-WSL: `wsl.useWindowsDriver`,
`wsl.interop.includePath`, `wsl.interop.register` and `wsl.wslConf.interop.enabled`,
and of NixOS itself `users.users.<name>.extraGroups`, `nix.settings.trusted-users`
and `nix.settings.experimental-features`. NixOS-WSL renames options now and then;
when `nixos-rebuild` rejects one, its options page has the current name.
## How the script is checked
The script is `scripts/wsl2-probe.sh` and the flake wraps it
([`nix/dev/wsl2-probe.nix`](../../nix/dev/wsl2-probe.nix)): `packages.<system>.wsl2-probe`
and the app of the same name, and `wsl2-probe-guest`, the kernel and the initrd
(with the modules of virtio's PCI transport and of virtiofs).
The initrd's init and the loop are `nix/dev/wsl2-probe-init.sh` and
`nix/dev/wsl2-probe-loop.sh`; the same loop file is what the script times on the
machine.
Two checks of the flake keep the script from rotting between the times someone
runs it. `wsl2-probe` builds the wrapper, which runs ShellCheck over the script
and over the guest's init, so neither can have a warning. `wsl2-probe-dry-run`
runs `wsl2-probe --dry-run` in the build sandbox, which has no KVM, no network
and no display, and expects a line for every probe, the paste block, and a
refusal of an unknown option. `just lint` runs ShellCheck on the script as well.
The script was exercised, at time of writing (2026-10-28), on machines that
are not WSL2:
- an `x86_64` NixOS machine with KVM: P1 passes with the ratio above; P2 passes
under `xvfb-run` and reports "no display" without one; P3 reports the missing
OpenGL driver and QEMU's refusal of `gl=on`;
- an `aarch64` NixOS machine without KVM: P1 reports the missing `/dev/kvm` and
boots the guest under TCG alone;
- the `x86_64` machine again with stand-ins for Windows' `cmd.exe`,
`powershell.exe` (PowerShell 7, running the script's PowerShell), `wsl.exe`
and `wslpath` on `PATH` and `WSL_DISTRO_NAME` set, for the paths that need
interop, and with `/dev/kvm`, `/proc/cpuinfo` and `/proc/meminfo` replaced
inside a user namespace for the failing and short-of-resources verdicts;
- P6 on the `x86_64` machine with KVM (the whole chain passes; the guest boots
in 1.2 s), on the `aarch64` machine under TCG (passes; 3.7 s), under TCG on
the `x86_64` machine with `/dev/kvm` closed in a user namespace (passes;
4 s), with `/dev/fuse` closed in a user namespace (`WARN`, and the rest
passes), with `virtiofsd` off `PATH` (`SKIP`), with a `virtiofsd` that exits
(`FAIL` with its output), and with a stand-in for QEMU that refuses the shared
memory, or prints what a guest would after each way the mounts can fail (the
verdicts of P6.3 to P6.5 for each).
Nothing in the script has run on WSL2 itself at time of writing, so the paste of
its first run there is the first measurement of any of this on WSL2.
+40
View File
@@ -150,6 +150,16 @@
inherit komorebiModule;
scale = if isLinux then 1 else 1.5;
};
# the probe of a NixOS-WSL2 machine (docs/dev/wsl2-probe.md); the checks use a constant
# revision, so that they are the same derivations for every commit
wsl2Probe = import ./nix/dev/wsl2-probe.nix {
inherit pkgs;
rev = self.rev or self.dirtyRev or "unknown";
};
wsl2ProbeForChecks = import ./nix/dev/wsl2-probe.nix {
inherit pkgs;
rev = "nix-check";
};
nightlyRustfmt = pkgs.rust-bin.nightly.latest.rustfmt;
nightlyToolchain = pkgs.rust-bin.nightly.latest.default;
rustToolchainWithNightlyRustfmt = pkgs.symlinkJoin {
@@ -298,6 +308,29 @@
touch $out
'';
}
# The probe builds (shellcheck runs over the script and over the guest's init as it
# does) and its dry run works without a machine to probe, so that it cannot rot between
# the times somebody runs it.
// lib.optionalAttrs isLinux {
wsl2-probe = wsl2ProbeForChecks.probe;
wsl2-probe-dry-run =
pkgs.runCommand "wsl2-probe-dry-run" { nativeBuildInputs = [ wsl2ProbeForChecks.probe ]; }
''
wsl2-probe --dry-run --no-prompt --report report.txt > out.txt
cat out.txt
for probe in P0 P1 P2 P3 P4 P5 P6; do
grep -q "^$probe " out.txt || { echo "no verdict line for $probe"; exit 1; }
done
grep -q "PASTE THIS" out.txt
grep -q "would run" out.txt
# the report file has what the screen has
grep -q "PASTE THIS" report.txt
# a mistake in the options is refused
if wsl2-probe --nonsense 2> err.txt; then exit 1; fi
grep -q "unknown option" err.txt
touch $out
'';
}
# The VM tests need QEMU with KVM, so only Linux checks them. A Mac runs the same tests
# through legacyPackages.<system>.vm, see docs/dev/vm-tests.md.
// lib.optionalAttrs isLinux (
@@ -335,6 +368,8 @@
default = build.fullBuild;
kde-rounded-corners-komorebi = pkgs.callPackage ./nix/kde-rounded-corners.nix { };
kwin-effect-geometry-change-komorebi = pkgs.callPackage ./nix/kwin-effect-geometry-change.nix { };
wsl2-probe = wsl2Probe.probe;
wsl2-probe-guest = wsl2Probe.guest;
};
apps = lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
@@ -348,6 +383,11 @@
program = "${build.komorebic}/bin/komorebic";
meta.description = "The command line interface of komorebi";
};
wsl2-probe = {
type = "app";
program = lib.getExe wsl2Probe.probe;
meta.description = "Probes a NixOS-WSL2 machine for KVM, WSLg, a GPU and RDP";
};
default = config.apps.komorebi;
};
+7 -2
View File
@@ -17,13 +17,14 @@ check-js:
cd komorebi/src/kwin && tsc -p tsconfig.json
node --test komorebi/src/kwin/bridge.test.js
# the macros the codebase has agreed not to use, and the workflows, which actionlint checks (with
# shellcheck over their scripts), both from the nixpkgs flake.lock pins
# the macros the codebase has agreed not to use, the workflows, which actionlint checks (with
# shellcheck over their scripts), and the probe script, all with the tools of the nixpkgs flake.lock pins
lint:
test -z "$(rg 'eyre!' --type rust .)" || (echo "eyre! macro not allowed"; false)
test -z "$(rg 'dbg!' --type rust .)" || (echo "dbg! macro not allowed"; false)
test -z "$(rg 'println!' --type rust ./komorebi/src)" || (echo "println! macro not allowed"; false)
nix shell --inputs-from . nixpkgs#actionlint nixpkgs#shellcheck --command actionlint .github/workflows/*.yaml
nix shell --inputs-from . nixpkgs#shellcheck --command shellcheck scripts/wsl2-probe.sh
# the JSON Schemas of komorebi.json and of applications.json, from the Rust types
jsonschema:
@@ -40,6 +41,10 @@ nixgen:
nix fmt nix/komorebi-options.nix
nix build -L --no-link ".#checks.$(nix eval --raw --impure --expr builtins.currentSystem).nix-options-validation"
# probe a NixOS-WSL2 machine for KVM, WSLg, a GPU and RDP (docs/dev/wsl2-probe.md): `just wsl2-probe --dry-run`
wsl2-probe *args:
nix run .#wsl2-probe -- {{ args }}
# one VM test, on this machine: `just vm kwin`. Linux boots the guest under KVM through the
# flake check; a Mac builds the guest on a builder and runs the driver (see docs/dev/vm-tests.md)
vm name:
+114
View File
@@ -0,0 +1,114 @@
# The init of the guest that scripts/wsl2-probe.sh boots (nix/dev/wsl2-probe.nix puts the
# interpreter, PATH and `probe_loop` in front of this text). The kernel command line chooses what
# it does:
#
# probe.mode=bench runs the CPU loop, prints the CPU, and powers off (the default)
# probe.mode=hold prints a line every second for probe.hold seconds, then powers off: it
# keeps a window open long enough to be seen
# probe.mode=virtiofs loads the kernel's virtio and virtiofs modules, mounts the share that
# the host serves with virtiofsd (tag probe.fstag, default probe), reads
# probe.token's file and writes one, then powers off
# probe.loops=N the number of iterations of the loop (default 600000)
# probe.hold=N the number of seconds of the hold mode (default 8)
# probe.serial=DEV a serial device the lines are copied to, for a run whose console is the
# screen (default none: the console is the serial port)
#
# Every line that matters starts with `PROBE:` so that the host can find it in the console.
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs devtmpfs /dev
exec </dev/console >/dev/console 2>&1
# param NAME DEFAULT: the value NAME has on the kernel command line
param() {
value=$(tr ' ' '\n' </proc/cmdline | sed -n "s/^$1=//p" | tail -n 1)
echo "${value:-$2}"
}
mode=$(param probe.mode bench)
hold=$(param probe.hold 8)
loops=$(param probe.loops 600000)
serial=$(param probe.serial none)
fstag=$(param probe.fstag probe)
token=$(param probe.token none)
# to the console, and to the serial port that the host reads when the console is the screen
say() {
echo "PROBE:$*"
[ -c "/dev/$serial" ] && echo "PROBE:$*" >"/dev/$serial"
}
say "START kernel=$(uname -r) machine=$(uname -m) mode=$mode"
say "CPU_MODEL=$(grep -m1 -E '^(model name|Processor|CPU part)' /proc/cpuinfo | cut -d: -f2- | sed 's/^ *//')"
say "CPU_FLAGS=$(grep -m1 -E '^(flags|Features)' /proc/cpuinfo | cut -d: -f2- | sed 's/^ *//')"
say "CPU_COUNT=$(grep -c '^processor' /proc/cpuinfo)"
say "MEM_KB=$(grep -m1 '^MemTotal' /proc/meminfo | tr -s ' ' | cut -d' ' -f2)"
if [ "$mode" = bench ]; then
say "LOOP_ITERATIONS=$loops"
say "LOOP_MS=$(probe_loop "$loops")"
fi
if [ "$mode" = virtiofs ]; then
# virtio's PCI transport, FUSE and virtiofs are modules in this kernel, as they are in the real
# guest's, whose initrd loads them before it mounts /nix/store
for module in virtio_pci virtiofs; do
if text=$(modprobe "$module" 2>&1); then
say "MODULE_$module=loaded"
elif [ "$module" = virtio_pci ] && [ -d /sys/bus/pci/drivers/virtio-pci ]; then
# a kernel that has the transport built in (the aarch64 one) has no module of it
say "MODULE_$module=built in"
else
say "MODULE_$module=failed: $text"
fi
done
say "FILESYSTEMS=$(grep -E 'virtiofs|fuse' /proc/filesystems | tr -s '\t\n' ' ')"
mkdir -p /store /share
# the host's /nix/store, read-only: the guest's busybox is read through it and checksummed
if text=$(mount -t virtiofs -o ro probestore /store 2>&1); then
say "STORE_MOUNT=ok"
say "STORE_SHA256=$(sha256sum "/store/$(param probe.storefile none)" 2>&1 | cut -d' ' -f1)"
if echo x >/store/probe-write 2>/dev/null; then
say "STORE_WRITE=allowed"
else
say "STORE_WRITE=refused"
fi
else
say "STORE_MOUNT=failed: $text"
say "DEVICES=$(cd /sys/bus/virtio/devices 2>&1 && echo *)"
fi
# a writable directory: the guest reads the file the host made and writes one of its own
if text=$(mount -t virtiofs "$fstag" /share 2>&1); then
say "SHARE_MOUNT=ok"
say "SHARE_LISTING=$(cd /share && echo *)"
say "SHARE_READ=$(cat /share/token 2>&1)"
say "SHARE_READ_OWNER=$(stat -c '%u:%g %a' /share/token 2>&1)"
if text=$({ echo "$token" >/share/from-guest; } 2>&1); then
say "SHARE_WRITE=ok"
else
say "SHARE_WRITE=failed: $text"
fi
say "SHARE_WRITE_OWNER=$(stat -c '%u:%g %a' /share/from-guest 2>&1)"
else
say "SHARE_MOUNT=failed: $text"
fi
sync
fi
if [ "$mode" = hold ]; then
n=0
while [ "$n" -lt "$hold" ]; do
say "ALIVE $n of $hold seconds: this window is the guest of wsl2-probe, it closes by itself"
sleep 1
n=$((n + 1))
done
fi
say "DONE"
sync
poweroff -f
# a kernel that does not power off on request is stopped by the host's timeout
sleep 600
+22
View File
@@ -0,0 +1,22 @@
# A CPU loop that scripts/wsl2-probe.sh times in three places: on the host, in a guest under
# KVM and in a guest under TCG. busybox's ash runs it, so the same interpreter runs the same
# instructions everywhere and only the way the CPU is provided differs.
#
# `probe_loop N` counts to N and prints the milliseconds it took, read from /proc/uptime, whose
# resolution is 10 ms: a loop shorter than about a second says little.
# the uptime in centiseconds; the 1 in front of the fraction keeps ash from reading 08 as octal
probe_centis() {
read -r up _ </proc/uptime
echo $((${up%.*} * 100 + 1${up#*.} - 100))
}
probe_loop() {
start=$(probe_centis)
i=0
while [ "$i" -lt "$1" ]; do
i=$((i + 1))
done
end=$(probe_centis)
echo $(((end - start) * 10))
}
+117
View File
@@ -0,0 +1,117 @@
{
pkgs,
# the revision the probe says it came from; the checks pass a constant, so that they are the
# same derivations for every commit
rev,
}:
# scripts/wsl2-probe.sh, with the tools it uses from nixpkgs, and the tiny guest it boots.
#
# The guest is a kernel from the binary cache and an initrd made here of a static busybox, the
# kernel modules that virtiofs needs, and the init in wsl2-probe-init.sh: nothing in it is built
# from source, so the first run is a download. docs/dev/wsl2-probe.md says what the probe does.
let
inherit (pkgs) lib;
busybox = pkgs.pkgsStatic.busybox;
# the kernel is the one the real guest boots (the default of NixOS), so that what the probe's
# guest can do with virtiofs is what the real guest's kernel can do
kernel = pkgs.linuxPackages.kernel;
# the file of the kernel package that QEMU boots
kernelImage = if pkgs.stdenv.hostPlatform.isAarch64 then "Image" else "bzImage";
# virtio's PCI transport, FUSE and virtiofs are modules of that kernel, not built in; this is
# the closure of them in the shape the NixOS initrd uses (modules.dep included, for modprobe)
modules = pkgs.makeModulesClosure {
kernel = pkgs.aggregateModules [ (lib.getOutput "modules" kernel) ];
firmware = pkgs.runCommand "wsl2-probe-no-firmware" { } "mkdir -p $out";
rootModules = [
"virtio_pci"
"virtiofs"
];
};
# the loop that the host and the guest both time, which busybox's ash runs in both
loop = pkgs.writeTextFile {
name = "wsl2-probe-loop.sh";
text = builtins.readFile ./wsl2-probe-loop.sh;
checkPhase = ''
${lib.getExe pkgs.shellcheck} --shell=sh "$target"
'';
};
init = pkgs.writeTextFile {
name = "wsl2-probe-init";
executable = true;
text = ''
#!${busybox}/bin/sh
PATH=${busybox}/bin
# shellcheck source=/dev/null
. ${loop}
${builtins.readFile ./wsl2-probe-init.sh}
'';
checkPhase = ''
${lib.getExe pkgs.shellcheck} --shell=sh "$target"
'';
};
initrd = pkgs.makeInitrd {
contents = [
{
object = init;
symlink = "/init";
}
{
object = "${modules}/lib/modules";
symlink = "/lib/modules";
}
];
};
guest = pkgs.runCommand "wsl2-probe-guest" { } ''
mkdir -p $out
ln -s ${kernel}/${kernelImage} $out/kernel
ln -s ${initrd}/initrd $out/initrd
ln -s ${busybox}/bin/busybox $out/busybox
ln -s ${loop} $out/loop.sh
'';
probe = pkgs.writeShellApplication {
name = "wsl2-probe";
runtimeInputs = with pkgs; [
# QEMU with GTK and VirGL, which the real guest uses, and the daemon that serves the guest's
# /nix/store and shared directories
qemu_kvm
virtiofsd
# eglinfo and glxinfo
mesa-demos
socat
# what the script needs of a system, the same on every distribution
coreutils
findutils
gawk
gnugrep
gnused
iproute2
jq
procps
util-linux
];
# the script sets its own options: a probe that stops at the first failure answers nothing
bashOptions = [ ];
text = ''
export WSL2_PROBE_GUEST=${guest}
export WSL2_PROBE_REV=${rev}
${builtins.readFile ../../scripts/wsl2-probe.sh}
'';
meta = {
description = "Probes a NixOS-WSL2 machine for KVM, WSLg, a GPU and RDP, for a Plasma guest";
mainProgram = "wsl2-probe";
};
};
in
{
inherit guest probe;
}
File diff suppressed because it is too large. Load diff