Files
komorebi/nix/tests/default.nix
T
LGUG2Z efcc90d279 feat(wm): workspace rules
A workspace rule sends the windows of an application to a workspace: an initial
rule once, when komorebi first sees the window, and a permanent rule every time,
so that a window the user takes away goes back. A rule is a rule on the window's
executable, class, title or path, with a monitor and a workspace index, or the
name of a workspace. It comes from komorebi.json (workspace_rules and
initial_workspace_rules of a workspace, made again from the file each time it is
read) or from komorebic (workspace-rule, initial-workspace-rule, their named
forms, and the commands that clear and enforce them).

The window manager looks at the rules before it handles each event about a
window it manages, and again when the configuration is loaded, so the windows
that were open when the daemon started are sent too. A window that leaves the
workspace in front is taken out of the layout and hidden, as the back of a stack
is, and it is put on the desktop of its new workspace, which is what it comes
back to and is tiled on when that workspace is shown. A window that moves
between workspaces that are not in front is put on the desktop of its new
workspace as well. A floating window that goes to another monitor is moved onto
it, and a workspace that does not exist yet is made.
2026-10-28 07:20:37 -07:00

61 lines
1.9 KiB
Nix

# `nix-options-validation`: the options `just nixgen` makes from `schema.json`, evaluated against
# the example configuration, whose JSON is checked against the schema, and against the example
# file of the docs. Run with `nix build -f nix/tests/default.nix`, or as a check of the flake.
{
pkgs ? import <nixpkgs> { },
}:
let
lib = pkgs.lib;
# the Nix module system uses null for an optional field that is not set, and the schema wants
# the field to be absent
filterNulls =
value:
if value == null then
null
else if builtins.isList value then
map filterNulls (builtins.filter (x: x != null) value)
else if builtins.isAttrs value then
lib.filterAttrs (_n: v: v != null) (builtins.mapAttrs (_n: v: filterNulls v) value)
else
value;
evaluated =
(lib.evalModules {
modules = [
(import ../komorebi-options.nix)
(import ./komorebi-example.nix)
];
}).config.komorebi;
evaluatedJson = pkgs.writeText "komorebi-example-from-nix.json" (
builtins.toJSON (filterNulls evaluated)
);
# the file has comment lines (komorebi reads them), which the schema checker does not
exampleJson = pkgs.runCommand "komorebi.example.json" { } ''
grep -v '^\s*//' ${../../docs/komorebi.example.json} > $out
'';
schema = ../../schema.json;
in
pkgs.runCommand "nix-options-validation"
{
nativeBuildInputs = [
pkgs.check-jsonschema
pkgs.jq
];
}
''
echo "Validating the example, written in Nix, against the schema..."
check-jsonschema --schemafile ${schema} ${evaluatedJson}
echo "Validating the example file of the docs against the schema..."
check-jsonschema --schemafile ${schema} ${exampleJson}
echo "Checking that the two examples say the same..."
jq -e --slurpfile example ${exampleJson} 'contains($example[0])' ${evaluatedJson} > /dev/null
echo "All validations passed!"
touch $out
''