Files
komorebi/nix/tests/nixos-module.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

216 lines
6.5 KiB
Nix

# `nixos-module-eval`: `services.komorebi` in real NixOS systems, evaluated and never built. Each
# scenario is a `nixosSystem` with the module, and the checks read what it evaluates to: the
# assertions, the unit the module defines, and its read-only `execStart`. A scenario that must
# not evaluate is caught with `builtins.tryEval`. Nothing here builds a Linux package (the
# derivation below gets only check names and booleans), so a Mac runs it too.
{
pkgs,
# nixpkgs' `lib.nixosSystem`
nixosSystem,
# the module, as the flake exports it, with its overlay
module,
# the flake's komorebi-full for a system, which the overlay has to provide
komorebiFor,
}:
let
inherit (pkgs) lib;
# the systems are of the host's architecture
system = "${pkgs.stdenv.hostPlatform.parsed.cpu.name}-linux";
# enough of a machine for every NixOS assertion to hold, since no scenario is ever built
machine = {
nixpkgs.hostPlatform = system;
boot.loader.grub.enable = false;
fileSystems."/" = {
device = "/dev/vda";
fsType = "ext4";
};
system.stateVersion = lib.trivial.release;
};
plasma = {
services.desktopManager.plasma6.enable = true;
};
eval =
scenario:
(nixosSystem {
modules = [
module
machine
scenario
];
}).config;
enabled = eval {
imports = [ plasma ];
services.komorebi.enable = true;
};
disabled = eval plasma;
withoutPlasma = eval { services.komorebi.enable = true; };
debug = eval {
imports = [ plasma ];
services.komorebi = {
enable = true;
logLevel = "debug";
};
};
# a package that is not the overlay's: any package will do, since nothing is built
otherPackage = eval (
{ pkgs, ... }:
{
imports = [ plasma ];
services.komorebi = {
enable = true;
package = pkgs.hello;
};
}
);
unknownLevel = eval {
imports = [ plasma ];
services.komorebi = {
enable = true;
logLevel = "verbose";
};
};
execStartSet = eval {
imports = [ plasma ];
services.komorebi = {
enable = true;
execStart = "/bin/true";
};
};
failed = config: map (a: a.message) (lib.filter (a: !a.assertion) config.assertions);
unit = config: config.systemd.user.services.komorebi;
evaluates = value: (builtins.tryEval value).success;
checks = [
{
name = "enabled with Plasma 6, every assertion holds";
ok = failed enabled == [ ];
got = failed enabled;
}
{
name = "the unit is started by plasma-workspace.target";
ok = (unit enabled).wantedBy == [ "plasma-workspace.target" ];
got = (unit enabled).wantedBy;
}
{
name = "the unit starts after plasma-core.target";
ok = lib.elem "plasma-core.target" (unit enabled).after;
got = (unit enabled).after;
}
{
name = "the unit is restarted when it fails";
ok = (unit enabled).serviceConfig.Restart == "on-failure";
}
{
name = "the unit counts the exit status of a SIGTERM (130) as success";
ok = (unit enabled).serviceConfig.SuccessExitStatus == 130;
}
{
name = "the unit runs execStart";
ok = (unit enabled).serviceConfig.ExecStart == enabled.services.komorebi.execStart;
got = (unit enabled).serviceConfig.ExecStart;
}
{
name = "execStart is bin/komorebi of the package, at the info level";
ok =
enabled.services.komorebi.execStart
== "${enabled.services.komorebi.package}/bin/komorebi --log-level info";
got = enabled.services.komorebi.execStart;
}
{
name = "the default package is the flake's komorebi-full, from the overlay";
ok = enabled.services.komorebi.package.outPath == (komorebiFor system).outPath;
}
{
name = "the unit has the PATH of the user's session";
ok =
(unit enabled).environment.PATH
== "/run/wrappers/bin:/etc/profiles/per-user/%u/bin:/run/current-system/sw/bin";
got = (unit enabled).environment.PATH;
}
{
name = "the package is installed in the system profile";
ok = lib.elem enabled.services.komorebi.package enabled.environment.systemPackages;
}
{
name = "disabled, every assertion holds";
ok = failed disabled == [ ];
got = failed disabled;
}
{
name = "disabled, there is no unit";
ok = !(disabled.systemd.user.services ? komorebi);
}
{
name = "disabled, nothing is installed";
ok = !(lib.elem disabled.services.komorebi.package disabled.environment.systemPackages);
}
{
name = "without Plasma 6, an assertion fails and names the option to set";
ok = lib.any (lib.hasInfix "services.desktopManager.plasma6.enable = true") (failed withoutPlasma);
got = failed withoutPlasma;
}
{
name = "logLevel reaches execStart and the unit";
ok =
debug.services.komorebi.execStart
== "${debug.services.komorebi.package}/bin/komorebi --log-level debug"
&& (unit debug).serviceConfig.ExecStart == debug.services.komorebi.execStart;
got = (unit debug).serviceConfig.ExecStart;
}
{
name = "another package is the one the unit runs and the one installed";
ok =
(unit otherPackage).serviceConfig.ExecStart
== "${otherPackage.services.komorebi.package}/bin/komorebi --log-level info"
&& lib.elem otherPackage.services.komorebi.package otherPackage.environment.systemPackages;
got = (unit otherPackage).serviceConfig.ExecStart;
}
{
name = "a log level the daemon does not have does not evaluate";
ok = !(evaluates unknownLevel.services.komorebi.logLevel);
}
{
name = "execStart cannot be set";
ok = !(evaluates execStartSet.services.komorebi.execStart);
}
];
failures = lib.filter (check: !check.ok) checks;
# what a failed check got, without the store paths' context: this derivation must not depend on
# a Linux package
show =
check:
check.name
+ lib.optionalString (check ? got) (
": got " + builtins.unsafeDiscardStringContext (builtins.toJSON check.got)
);
in
pkgs.runCommand "nixos-module-eval" { } (
if failures == [ ] then
''
${lib.concatMapStringsSep "\n" (check: "echo ${lib.escapeShellArg "ok: ${check.name}"}") checks}
echo "${toString (lib.length checks)} checks of services.komorebi passed"
touch $out
''
else
''
${lib.concatMapStringsSep "\n" (
check: "echo ${lib.escapeShellArg "FAILED: ${show check}"}"
) failures}
exit 1
''
)