mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 13:51:19 +01:00
The daemon answers on its socket, but a person has no way to write a message on it. komorebic is that way: each subcommand that asks something of the daemon is one message, sent with komorebi-client, and a question's answer is printed. komorebic is a separate program because the daemon takes no input but its socket, so a key binding, a script and a terminal all drive it the same way. It has what the daemon can answer so far: state, monitor-information, query, retile and stop. Around them, start runs the komorebi on the PATH in the background and passes it what follows a --, such as --fake-backend to try it without a compositor; log follows the daemon's log, which the daemon now writes to a file a day in LOG_DIR as well as to stdout; data-directory shows where the socket is; completions prints a shell completion script. The hidden docgen writes each subcommand's help to docs/cli, in fences that name their language and wrapped at 100 columns whatever the width of the terminal, so that the pages are the same wherever they are generated; just docgen runs it. The user guide starts here: docs/index.md for KDE Plasma, and a page on running komorebi. tests/cli.rs runs each subcommand against a socket the test serves in place of the daemon. In the VM tests the guests get komorebic next to the daemon, and vm-core-e2e reads the daemon's state with it (the windows it manages, the one it focuses, after KWin restarts too) and stops it with komorebic stop, which unloads the bridge and removes the socket. In the VM test library, Kde.state asks again, a second (times the scale) after an empty answer or a failed command, up to 10 times. The daemon drops a query when it cannot take hold of the window manager within a second, and komorebic then prints an empty line and succeeds; komorebic itself gives the daemon a second to answer and fails when that is not enough. A daemon busy with the first windows does either on a machine that is loaded or slow, and a suite that polled the state died on JSONDecodeError. An answer that is not JSON still fails at once.
308 lines
10 KiB
Nix
308 lines
10 KiB
Nix
{
|
|
description = "komorebi for KDE Plasma";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
crane.url = "github:ipetkov/crane";
|
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
|
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
|
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
|
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
|
|
git-hooks-nix.url = "github:cachix/git-hooks.nix";
|
|
git-hooks-nix.inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
outputs =
|
|
inputs@{
|
|
self,
|
|
nixpkgs,
|
|
flake-parts,
|
|
crane,
|
|
rust-overlay,
|
|
...
|
|
}:
|
|
let
|
|
mkPkgs =
|
|
system:
|
|
import nixpkgs {
|
|
inherit system;
|
|
overlays = [ (import rust-overlay) ];
|
|
};
|
|
|
|
mkKomorebiPackages =
|
|
{ pkgs }:
|
|
let
|
|
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
|
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
|
|
# rustfmt.toml uses options only a nightly rustfmt knows
|
|
craneLibFmt = (crane.mkLib pkgs).overrideToolchain (
|
|
pkgs.rust-bin.nightly.latest.minimal.override { extensions = [ "rustfmt" ]; }
|
|
);
|
|
|
|
src = pkgs.lib.cleanSourceWith {
|
|
src = ./.;
|
|
filter =
|
|
path: type:
|
|
(craneLib.filterCargoSources path type)
|
|
# the script komorebi loads into KWin, which the daemon includes
|
|
|| (pkgs.lib.hasSuffix ".js" path)
|
|
# the messages the tests of the bridge and of the daemon share
|
|
|| (pkgs.lib.hasSuffix ".json" path);
|
|
};
|
|
|
|
commonArgs = {
|
|
inherit src;
|
|
pname = "komorebi-workspace";
|
|
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
|
|
strictDeps = true;
|
|
# The version crate wants a commit at compile time. It is a constant here, so that the
|
|
# dependencies and every check are the same derivations for every commit; only the final
|
|
# build below knows the real one.
|
|
COMMIT_HASH = "nix-check";
|
|
};
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
|
|
|
individualCrateArgs = commonArgs // {
|
|
inherit cargoArtifacts;
|
|
doCheck = false;
|
|
doDoc = false;
|
|
};
|
|
|
|
fullBuild = craneLib.buildPackage (
|
|
individualCrateArgs
|
|
// {
|
|
COMMIT_HASH = self.rev or (pkgs.lib.removeSuffix "-dirty" self.dirtyRev);
|
|
}
|
|
);
|
|
|
|
extractBinary =
|
|
binaryName:
|
|
pkgs.runCommand "komorebi-${binaryName}" { meta = fullBuild.meta // { }; } ''
|
|
mkdir -p $out/bin
|
|
cp ${fullBuild}/bin/${binaryName} $out/bin/
|
|
'';
|
|
in
|
|
{
|
|
inherit
|
|
craneLib
|
|
craneLibFmt
|
|
src
|
|
commonArgs
|
|
individualCrateArgs
|
|
fullBuild
|
|
;
|
|
komorebi = extractBinary "komorebi";
|
|
komorebic = extractBinary "komorebic";
|
|
};
|
|
in
|
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
|
# Linux is what komorebi runs on. An Apple silicon Mac gets the dev shell, the formatter and the
|
|
# checks, which run the same tests against the fake desktop. nixpkgs dropped x86_64-darwin in
|
|
# 26.11.
|
|
systems = [
|
|
"aarch64-linux"
|
|
"x86_64-linux"
|
|
"aarch64-darwin"
|
|
];
|
|
|
|
imports = [
|
|
inputs.treefmt-nix.flakeModule
|
|
inputs.git-hooks-nix.flakeModule
|
|
];
|
|
|
|
perSystem =
|
|
{
|
|
config,
|
|
lib,
|
|
system,
|
|
...
|
|
}:
|
|
let
|
|
pkgs = mkPkgs system;
|
|
build = mkKomorebiPackages { inherit pkgs; };
|
|
isLinux = pkgs.stdenv.hostPlatform.isLinux;
|
|
# the daemon and komorebic each guest runs, built for the guest's system
|
|
komorebiFor = guestSystem: self.packages.${guestSystem}.komorebi-full;
|
|
# a Mac runs the guests under HVF, which is slower than KVM
|
|
vm = import ./nix/tests/vm {
|
|
hostPkgs = pkgs;
|
|
inherit komorebiFor;
|
|
scale = if isLinux then 1 else 1.5;
|
|
};
|
|
nightlyRustfmt = pkgs.rust-bin.nightly.latest.rustfmt;
|
|
nightlyToolchain = pkgs.rust-bin.nightly.latest.default;
|
|
rustToolchainWithNightlyRustfmt = pkgs.symlinkJoin {
|
|
name = "rust-toolchain-with-nightly-rustfmt";
|
|
paths = [
|
|
nightlyRustfmt
|
|
(pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml)
|
|
];
|
|
};
|
|
# cargo-udeps needs a nightly compiler
|
|
cargo-udeps = pkgs.writeShellScriptBin "cargo-udeps" ''
|
|
export PATH="${nightlyToolchain}/bin:$PATH"
|
|
exec ${pkgs.cargo-udeps}/bin/cargo-udeps "$@"
|
|
'';
|
|
in
|
|
{
|
|
treefmt = {
|
|
projectRootFile = "flake.nix";
|
|
programs = {
|
|
deadnix.enable = true;
|
|
just.enable = true;
|
|
nixfmt.enable = true;
|
|
taplo.enable = true;
|
|
rustfmt = {
|
|
enable = true;
|
|
package = nightlyRustfmt;
|
|
};
|
|
};
|
|
};
|
|
|
|
checks = {
|
|
komorebi-workspace-fmt = build.craneLibFmt.cargoFmt { inherit (build) src; };
|
|
|
|
komorebi-workspace-clippy = build.craneLib.cargoClippy (
|
|
build.individualCrateArgs
|
|
// {
|
|
cargoClippyExtraArgs = "--workspace --all-targets -- -D warnings";
|
|
}
|
|
);
|
|
|
|
komorebi-workspace-doc = build.craneLib.cargoDoc (
|
|
build.individualCrateArgs
|
|
// {
|
|
cargoDocExtraArgs = "--workspace --no-deps";
|
|
env.RUSTDOCFLAGS = "-D warnings";
|
|
}
|
|
);
|
|
|
|
komorebi-workspace-toml-fmt = build.craneLib.taploFmt {
|
|
src = lib.sources.sourceFilesBySuffices build.src [ ".toml" ];
|
|
};
|
|
|
|
komorebi-workspace-deny = build.craneLib.cargoDeny { inherit (build) src; };
|
|
|
|
komorebi-workspace-nextest = build.craneLib.cargoNextest (
|
|
build.individualCrateArgs // { doCheck = true; }
|
|
);
|
|
|
|
# The bridge is not Rust: tsc checks its types from its JSDoc comments, and node runs
|
|
# its tests against a fake KWin. No package.json and no build step.
|
|
komorebi-bridge-js =
|
|
pkgs.runCommand "komorebi-bridge-js"
|
|
{
|
|
nativeBuildInputs = [
|
|
pkgs.nodejs
|
|
pkgs.typescript
|
|
];
|
|
src = lib.fileset.toSource {
|
|
root = ./komorebi/src/kwin;
|
|
fileset = lib.fileset.fileFilter (file: !file.hasExt "rs") ./komorebi/src/kwin;
|
|
};
|
|
}
|
|
''
|
|
cd $src
|
|
tsc -p tsconfig.json
|
|
node --test bridge.test.js
|
|
touch $out
|
|
'';
|
|
|
|
vm-lib = vm.lib;
|
|
}
|
|
# 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 (
|
|
lib.mapAttrs' (name: test: lib.nameValuePair "vm-${name}" test) vm.suites
|
|
);
|
|
|
|
legacyPackages = {
|
|
# every suite, as a test with a `driver`, on every system
|
|
vm = vm.suites;
|
|
# the suites of each tier, for the CI matrix
|
|
vmTiers = vm.tiers;
|
|
# the guests of every suite, to build on a Linux builder when the host is a Mac
|
|
vmGuests = vm.guests;
|
|
}
|
|
// lib.optionalAttrs isLinux {
|
|
# the same suites on a machine with no KVM, which is slow but works anywhere
|
|
vmTcg =
|
|
(import ./nix/tests/vm {
|
|
hostPkgs = pkgs;
|
|
inherit komorebiFor;
|
|
scale = 8;
|
|
}).suites;
|
|
};
|
|
|
|
packages = lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
|
inherit (build) komorebi komorebic;
|
|
komorebi-full = build.fullBuild;
|
|
default = build.fullBuild;
|
|
};
|
|
|
|
apps = lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
|
komorebi = {
|
|
type = "app";
|
|
program = "${build.komorebi}/bin/komorebi";
|
|
meta.description = "The komorebi daemon";
|
|
};
|
|
komorebic = {
|
|
type = "app";
|
|
program = "${build.komorebic}/bin/komorebic";
|
|
meta.description = "The command line interface of komorebi";
|
|
};
|
|
default = config.apps.komorebi;
|
|
};
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
name = "komorebi";
|
|
|
|
RUST_BACKTRACE = "full";
|
|
|
|
inputsFrom = [ build.fullBuild ];
|
|
|
|
packages = [
|
|
rustToolchainWithNightlyRustfmt
|
|
cargo-udeps
|
|
|
|
pkgs.cargo-deny
|
|
pkgs.cargo-nextest
|
|
pkgs.jq
|
|
pkgs.just
|
|
pkgs.ripgrep
|
|
|
|
# the bridge's type check and tests (`just check-js`)
|
|
pkgs.nodejs
|
|
pkgs.typescript
|
|
|
|
# the VM test library
|
|
pkgs.ruff
|
|
pkgs.ty
|
|
(pkgs.python3.withPackages (ps: [ ps.pytest ]))
|
|
];
|
|
};
|
|
|
|
pre-commit = {
|
|
check.enable = true;
|
|
settings.hooks.treefmt = {
|
|
enable = true;
|
|
package = config.treefmt.build.wrapper;
|
|
pass_filenames = false;
|
|
};
|
|
};
|
|
};
|
|
|
|
flake = {
|
|
overlays.default = final: _: {
|
|
inherit ((mkKomorebiPackages { pkgs = mkPkgs final.stdenv.hostPlatform.system; }))
|
|
komorebi
|
|
komorebic
|
|
;
|
|
};
|
|
overlays.komorebi = self.overlays.default;
|
|
};
|
|
};
|
|
}
|