Files
komorebi/nix/tests/vm/default.nix
T
LGUG2Z a86e2bdc63 build(nix): a NixOS module for komorebi
On NixOS, running komorebi should take one flake input and one module line. The
flake exports `services.komorebi` as nixosModules.default (and .komorebi). It
adds the flake's overlay, which gains komorebi-full, installs komorebi and
komorebic, and runs the daemon in every Plasma session as a systemd user unit,
wanted by plasma-workspace.target and ordered after plasma-core.target, which
Plasma orders after KWin. systemd starts a daemon that fails again; the exit
status of a SIGTERM (130) counts as success, so a stopped unit is not failed.
The unit's PATH is the one a terminal in the session has, instead of the few
store paths NixOS gives a unit.

The options are enable, package, logLevel and a read-only execStart, the command
line the unit runs. There is no configFile: the daemon reads no configuration
file yet, and an option that linked one would do nothing.

nixos-module-eval evaluates seven scenarios as real NixOS systems and checks
their assertions, the unit and execStart, with builtins.tryEval for the two that
must not evaluate. Nothing in it builds a Linux package, so it runs on a Mac as
well.

The VM nodes import the module, so every suite runs komorebi as the module
installs it. The headless node's komorebi@NAME runs execStart, which has
--log-level, so the nodes set logLevel to debug and the suites stop passing it;
latency, which times the daemon, keeps the default level. The session node
starts the module's unit at login; render-smoke turns it off, since a tiled
terminal would cover the desktop it looks at. A new fast suite, vm-module, logs
in to Plasma and checks that the unit runs the daemon with the module's log
level and PATH, that a window opened in the session is tiled, that a killed
daemon is started again, and that a stop is not a failure.

docs/installation.md covers NixOS first, and building from source on other
distributions. There is no binary cache: the Komorebi license does not allow
third parties to redistribute binaries.
2026-10-28 07:20:37 -07:00

111 lines
3.3 KiB
Nix

# The NixOS VM tests. Every directory under `suites/` is one test, `checks.<system>.vm-<name>`
# (Linux) and `legacyPackages.<system>.vm.<name>` (everywhere), so a new suite needs no edit to
# the flake. See docs/dev/vm-tests.md.
#
# `hostPkgs` is the pkgs of the machine that runs QEMU; the guests are always Linux.
# `komorebiModule` is the flake's NixOS module, `services.komorebi`, which every node imports: its
# overlay builds `komorebi` and `komorebic` for the guest's system. `scale` says how much slower
# than KVM that machine is (1 for KVM, 1.5 for HVF on a Mac, 8 for TCG), and every wait in the
# suites is multiplied by it.
{
hostPkgs,
komorebiModule,
scale ? 1,
}:
let
inherit (hostPkgs) lib;
# the library the suites import, built for the python of the test driver
komorebiVm =
ps:
ps.buildPythonPackage {
pname = "komorebi-vm";
version = "0.1.0";
pyproject = true;
src = lib.fileset.toSource {
root = ./lib;
fileset = ./lib;
};
build-system = [ ps.setuptools ];
dependencies = [ ps.pillow ];
doCheck = false;
};
# unit tests of the library against a fake machine, and the linters over it
libCheck =
let
python = hostPkgs.python3.withPackages (ps: [
ps.pytest
(komorebiVm ps)
]);
in
hostPkgs.runCommand "vm-lib"
{
nativeBuildInputs = [
python
hostPkgs.ruff
hostPkgs.ty
];
src = lib.fileset.toSource {
root = ./lib;
fileset = ./lib;
};
}
''
cp -r $src lib && chmod -R u+w lib && cd lib
ruff check .
ruff format --check .
ty check --python ${python} .
pytest -q -p no:cacheprovider
touch $out
'';
suiteNames = lib.attrNames (
lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./suites)
);
suiteDefs = lib.genAttrs suiteNames (name: import (./suites + "/${name}"));
mkSuite =
name:
let
dir = ./suites + "/${name}";
suite = suiteDefs.${name};
in
hostPkgs.testers.runNixOSTest {
name = "komorebi-${name}";
extraPythonPackages = ps: [ (komorebiVm ps) ];
globalTimeout = builtins.ceil (suite.timeoutMinutes * 60 * scale);
passthru.tier = suite.tier;
# the nodes import the module, `komorebiModule`, which adds its overlay to nixpkgs: the test
# framework's pkgs, which cannot be changed, would refuse it
node.specialArgs = { inherit komorebiModule; };
node.pkgsReadOnly = false;
nodes.machine = {
# a suite's `node`, if it has one, adds to the node of its kind
imports = [ (./nodes + "/${suite.kind}.nix") ] ++ lib.optional (suite ? node) suite.node;
};
testScript = ''
SCALE = ${toString scale}
''
+ builtins.readFile (dir + "/${suite.script or "test.py"}");
};
suites = lib.genAttrs suiteNames mkSuite;
in
{
inherit suites;
lib = libCheck;
# the suites of each tier, for the CI matrix: { fast = [ "kwin" ... ]; slow = [ ... ]; }
tiers = lib.groupBy (name: suiteDefs.${name}.tier) suiteNames;
# the guests of every suite, so that a Mac can build them on a Linux builder first
guests = lib.mapAttrs (
_: test: lib.mapAttrs (_: node: node.system.build.toplevel) test.nodes
) suites;
}