ci(github): run the VM tests on KVM

`discover` asks the flake for the suites of each tier
(`legacyPackages.x86_64-linux.vmTiers`) and hands them to two matrices, so a new
directory under `nix/tests/vm/suites` is run without an edit to the workflow.
`vm-fast` runs the fast tier on every pull request, one machine per suite, as a
sandboxed `nix build` of the check. `vm-slow` runs on master, every week, and on
a pull request labeled `ci:vm-slow`; it builds the driver and runs it by hand,
outside the sandbox, so that the screenshots and journals of a failed run are
uploaded with `if: always()`.

A composite action installs nix with the store cached and, for the VM jobs,
frees disk space (a Plasma guest is a closure of about 10 GB), writes the udev
rule that makes /dev/kvm writable for the runner's user, checks it with `test
-w`, and adds `kvm` to nix's system features. KVM on hosted runners is
documented for public repositories only. Whether this private repository has it
is not known: the first run of these jobs says, and if it does not, they need a
different runner.

`lint` no longer runs `nix flake check`: on Linux that now boots every VM suite,
which a runner with no KVM cannot do. It builds the checks that need no virtual
machine, and `vm-lib`, the library's own tests.

CONTRIBUTING.md and docs/dev/vm-tests.md say what runs where.
This commit is contained in:
LGUG2Z committed 2026-10-27 14:06:52 -07:00
1 parent fec9c2773a
commit 0725705298
5 files changed
+136 -14

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
name: nix
description: Install nix on a hosted runner, with the store cached and, on request, KVM enabled
inputs:
kvm:
description: Make /dev/kvm usable and tell nix that this machine can run NixOS tests
default: "false"
runs:
using: composite
steps:
# A Plasma guest is a closure of about 10 GB, and a hosted runner has little free space on /
# until the toolchains it ships with are gone.
- name: Free disk space
if: inputs.kvm == 'true'
shell: bash
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL
df -h /
# The udev rule is what makes /dev/kvm writable for the runner's user. KVM on hosted runners
# is documented for public repositories; `test -w` is what says whether this one has it.
- name: Enable KVM
if: inputs.kvm == 'true'
shell: bash
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' |
sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
test -w /dev/kvm
# This action only installs nix. It does not use the Cachix service, and no Cachix cache, account
# or token is configured anywhere in this repository.
- uses: cachix/install-nix-action@v31
with:
extra_nix_config: |
system-features = nixos-test benchmark big-parallel ${{ inputs.kvm == 'true' && 'kvm' || '' }}
- uses: nix-community/cache-nix-action@v7
with:
primary-key: nix-${{ runner.os }}-${{ hashFiles('flake.lock', '**/Cargo.lock') }}
restore-prefixes-first-match: nix-${{ runner.os }}-
gc-max-store-size-linux: 8G
+75 -9
View File
@@ -27,8 +27,9 @@ jobs:
fetch-depth: 0
- uses: EmbarkStudios/cargo-deny-action@v2
# Everything that does not need a virtual machine: the formatting, clippy, rustdoc and the tests,
# as derivations. The jobs that boot KWin are separate.
# Everything that does not need a virtual machine: the formatting, clippy, rustdoc, the tests and
# the VM library's own tests, as derivations. The jobs that boot KWin are separate, and `nix flake
# check` is not used here because on Linux it would run those suites with no KVM.
lint:
if: github.repository == 'LGUG2Z/komorebi-for-kde'
runs-on: ubuntu-24.04
@@ -36,11 +37,76 @@ jobs:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: cachix/install-nix-action@v31
- uses: nix-community/cache-nix-action@v7
with:
primary-key: nix-${{ runner.os }}-${{ hashFiles('flake.lock', '**/Cargo.lock') }}
restore-prefixes-first-match: nix-${{ runner.os }}-
gc-max-store-size-linux: 8G
- run: nix flake check -L
- uses: ./.github/actions/nix
- name: Build every check that needs no virtual machine
run: |
nix eval --json .#checks.x86_64-linux --apply builtins.attrNames |
jq -r '(.[] | select(startswith("vm-") | not)), "vm-lib"' |
sed 's|^|.#checks.x86_64-linux.|' |
xargs nix build -L --no-link
- run: nix develop --command just lint
# The suites are found in the flake, so that a new directory under nix/tests/vm/suites is run
# without an edit here.
discover:
if: github.repository == 'LGUG2Z/komorebi-for-kde'
runs-on: ubuntu-24.04
outputs:
fast: ${{ steps.tiers.outputs.fast }}
slow: ${{ steps.tiers.outputs.slow }}
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/nix
- id: tiers
run: |
tiers=$(nix eval --json .#legacyPackages.x86_64-linux.vmTiers)
echo "fast=$(jq -c '.fast // []' <<<"$tiers")" >> "$GITHUB_OUTPUT"
echo "slow=$(jq -c '.slow // []' <<<"$tiers")" >> "$GITHUB_OUTPUT"
# The pull request gate: the suites that take minutes, each in its own machine, in a sandboxed
# `nix build` like any other check.
vm-fast:
needs: discover
if: github.repository == 'LGUG2Z/komorebi-for-kde' && needs.discover.outputs.fast != '[]'
runs-on: ubuntu-24.04
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
suite: ${{ fromJson(needs.discover.outputs.fast) }}
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/nix
with:
kvm: "true"
- run: nix build -L .#checks.x86_64-linux.vm-${{ matrix.suite }}
# The suites that draw and move a pointer. They run on master, every week, and on a pull
# request with the label `ci:vm-slow`. The driver is run by hand, outside the sandbox, so that
# the screenshots and the journals of a failed run can be uploaded.
vm-slow:
needs: discover
if: >-
github.repository == 'LGUG2Z/komorebi-for-kde' && needs.discover.outputs.slow != '[]' &&
(github.ref == 'refs/heads/master' || github.event_name == 'schedule' ||
github.event_name == 'workflow_dispatch' ||
contains(github.event.pull_request.labels.*.name, 'ci:vm-slow'))
runs-on: ubuntu-24.04
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
suite: ${{ fromJson(needs.discover.outputs.slow) }}
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/nix
with:
kvm: "true"
- run: nix build -L .#legacyPackages.x86_64-linux.vm.${{ matrix.suite }}.driver -o driver
- run: mkdir -p out && cd out && ../driver/bin/nixos-test-driver -o .
- if: always()
uses: actions/upload-artifact@v7
with:
name: vm-${{ matrix.suite }}-${{ github.sha }}
path: out/
retention-days: 7
+7 -4
View File
@@ -39,8 +39,9 @@ formatter is a nightly one.
`just check` runs everything a change has to pass before it is pushed: the
formatting check, clippy with warnings denied, the tests, and rustdoc with
warnings denied. `just fmt` formats the Rust sources, and `nix fmt` every file
type the repository has. `nix flake check` is what CI runs; it builds the same
checks, plus `cargo deny`, as derivations.
type the repository has. `nix flake check` builds the same checks, plus
`cargo deny`, as derivations; on Linux it also boots every VM test, which needs
KVM.
## VM tests
@@ -53,8 +54,10 @@ to run one (`just vm NAME`) and how to add one.
[`ci.yaml`](.github/workflows/ci.yaml) runs on every pull request and on every
push to `master`, `feature/*` and `hotfix/*`, in this repository only. The
`lint` job runs `nix flake check` and the repository's own lint rules, and
`cargo-deny` checks licenses and advisories. A weekly
`lint` job builds every check that needs no virtual machine and runs the
repository's own lint rules, `cargo-deny` checks licenses and advisories, and
the VM tests run on KVM in two jobs: `vm-fast` on every pull request and
`vm-slow` on `master`, every week, and on pull requests labeled `ci:vm-slow`. A weekly
[workflow](.github/workflows/update-flake-lock.yaml) opens a pull request that
moves `flake.lock`, and the same jobs run on it.
+2 -1
View File
@@ -29,7 +29,8 @@ without a checkout of the toolchain.
`just check` runs the formatting check, clippy with warnings denied, the tests
and rustdoc with warnings denied, inside `nix develop`. `nix flake check` runs
the same checks as derivations, plus `cargo deny`, the TOML and Nix formatting,
and the tests under `cargo nextest`, on Linux and on an Apple silicon Mac. A Mac
and the tests under `cargo nextest`, on Linux and on an Apple silicon Mac. On
Linux it also boots every VM test, which needs KVM. A Mac
runs the tests against the fake desktop, since KWin only exists on Linux.
`nix fmt` formats every file the checks look at.
+8
View File
@@ -14,6 +14,14 @@ they are laid out, how to run them, and how to add one.
| A Mac | `just vm NAME`, which runs `scripts/vm-mac` | HVF |
| A Linux machine with no KVM | `nix build -L .#legacyPackages.SYSTEM.vmTcg.NAME` | TCG |
CI runs the `fast` tier on every pull request and the `slow` tier on `master`,
every week, and on pull requests labeled `ci:vm-slow`
([`ci.yaml`](../../.github/workflows/ci.yaml)). The slow jobs run the driver
by hand instead of building the check, so that the screenshots and journals of a
failed run can be uploaded as an artifact. KVM on GitHub-hosted runners is
documented for public repositories; the first step of each VM job checks that
`/dev/kvm` is writable and fails there if it is not.
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.