`packages.hhstream-mcp` (`nix/mcp.nix`), separate from `packages.hhstream` and the separation is the point: the frame socket, the CLI and the broker are stdlib-only by policy, the MCP SDK is a third-party dependency, and `packages.hhstream` runs as the compositor's own units. Verified: the hhstream closure gains no `mcp`, no `pydantic` and no `httpx`, and `hhstream_mcp` is not in its site-packages. The join to `hhstream` is a *library* one -- `toPythonModule`, because the tools call `hhstream.cli`'s handlers in process. `grim` and `ffmpeg` are prefixed onto the wrapper's PATH, because the CLI spawns them and the server is launched by an MCP client whose PATH is not ours to predict. The entry point is smoke-tested with `--list-tools` in a `postPhases` phase, not `postInstall`: the script is wrapped in `fixupPhase`, so any earlier and the check runs against a script with no PYTHONPATH and tests the wrong thing. (`installCheckPhase` is no use either -- `buildPythonPackage` does not include that phase at all.) `services.hyprland-headless-stream.mcp.enable` (default false) puts the binary on the system PATH, which is the whole of the option: the server is stdio and spawned per client, so there is no unit, no socket and no state directory. `mcp.package` defaults to this flake's build against `cfg.package`, so the server and the CLI it runs are one build. A warning, not an assertion, when it is enabled with `sessions.enable` off: 22 of the 26 tools then answer exit 5, but the four frame tools are genuinely useful alone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
83 lines
3.7 KiB
Nix
83 lines
3.7 KiB
Nix
{
|
|
description = "Stream a headless Hyprland session to a persistent Unix socket";
|
|
|
|
# Matches the nixpkgs this was developed against; consumers can override with
|
|
# inputs.nixpkgs.follows = "nixpkgs" and nothing breaks.
|
|
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
|
|
|
|
outputs = { self, nixpkgs, ... }: let
|
|
systems = [ "x86_64-linux" "aarch64-linux" ];
|
|
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f (import nixpkgs { inherit system; }));
|
|
# `checks` needs the system name as well as the package set, to reach
|
|
# self.packages.<system>; forAllSystems only hands over pkgs.
|
|
forAllSystems' = f: nixpkgs.lib.genAttrs systems (system:
|
|
f { inherit system; pkgs = import nixpkgs { inherit system; }; });
|
|
in {
|
|
packages = forAllSystems (pkgs: rec {
|
|
hhstream = pkgs.callPackage ./nix/package.nix {};
|
|
# The MCP server. Its own derivation, not another entry point on
|
|
# `hhstream`: it depends on the `mcp` SDK and `hhstream` is stdlib-only by
|
|
# policy (nix/mcp.nix says why at length). `packages.hhstream` therefore
|
|
# keeps the closure it had, which is the property `checks.unit` and
|
|
# `nix build .#hhstream` are expected to hold.
|
|
hhstream-mcp = pkgs.callPackage ./nix/mcp.nix {inherit hhstream;};
|
|
default = hhstream;
|
|
});
|
|
|
|
nixosModules = rec {
|
|
hyprland-headless-stream = import ./nix/module.nix;
|
|
default = hyprland-headless-stream;
|
|
};
|
|
|
|
# Unit tests + the two VM integration tests. See checks/default.nix and
|
|
# README.dev.md; the interface they assert is docs/CONTRACT.md.
|
|
checks = forAllSystems' ({ pkgs, system }:
|
|
import ./checks { inherit pkgs self system; });
|
|
|
|
devShells = forAllSystems (pkgs: let
|
|
hhstream = pkgs.callPackage ./nix/package.nix {};
|
|
in {
|
|
default = pkgs.mkShell {
|
|
packages = with pkgs; [
|
|
python3
|
|
python3.pkgs.pytest
|
|
git
|
|
tmux
|
|
jq
|
|
hyprland
|
|
grim
|
|
ffmpeg
|
|
# The client side of the contract (hhstream-client), so a shell can
|
|
# read the stream without a `nix build` first. It also brings
|
|
# pywayland and xkbcommon, which `tests/pointer` imports directly --
|
|
# `test_keymap.py` compiles a real `us` keymap rather than stubbing
|
|
# one, because a stub cannot tell you that `é` is unmappable.
|
|
hhstream
|
|
# The MCP server, so `hhstream-mcp` can be run (and handed to an MCP
|
|
# client) straight out of `nix develop`.
|
|
(callPackage ./nix/mcp.nix {inherit hhstream;})
|
|
# The SDK itself, because `tests/unit/test_mcp_server.py` imports it
|
|
# directly: the tool table is stdlib-only and testable without it, but
|
|
# the wiring that turns the table into `mcp.types.Tool` objects is not,
|
|
# and a suite that could skip that file would stop noticing a schema
|
|
# the SDK rejects.
|
|
python3.pkgs.mcp
|
|
# `websocket-client` drives Chromium over the DevTools protocol, which
|
|
# is how the demo types into the page and reads the result back.
|
|
python3.pkgs.websocket-client
|
|
# Something to *put on* the headless screen. Chromium is the only
|
|
# browser here that both runs on Wayland and can be driven over the
|
|
# DevTools protocol, which is how examples/agent-eyes-demo.py types
|
|
# into a page. Kept in the dev shell rather than installed globally.
|
|
chromium
|
|
];
|
|
shellHook = ''
|
|
export PYTHONPATH="$PWD/src''${PYTHONPATH:+:$PYTHONPATH}"
|
|
echo "hhstream dev shell -- python $(python3 --version 2>&1 | cut -d' ' -f2)"
|
|
'';
|
|
};
|
|
});
|
|
|
|
formatter = forAllSystems (pkgs: pkgs.alejandra);
|
|
};
|
|
} |