The brain: a long-running Claude Code session, confined with bwrap to its workspace, that hears the box through a channel and works the TV with the box's ir and look capabilities. - brain/channel.js: MCP on stdio to the brain (reply, say, ir_listen, ir_send, look, report_problem), and the ask capability, behind a gate, to the box - brain/ask.js: the conversations between them; report.js: an issue on one repository, by a token that can do nothing else - brain/brain.service: the session in tmux, in bwrap: a read-only system, an empty home but for its workspace, keys, and claude - brain/instructions.md: how to work the TV; it imports household.md, who's who (an example, with no real people) - brain/Makefile: make install, attach, status - checks: brain-js (unit tests), brain (the package, put together) Generated-by: Claude Opus 5.5
80 lines
3.5 KiB
Nix
80 lines
3.5 KiB
Nix
{
|
|
description = "Peace and dignity at the TV: delegating the remotes to an agent";
|
|
|
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
|
|
|
|
outputs = { self, nixpkgs }:
|
|
let
|
|
systems = [ "x86_64-linux" "aarch64-linux" ];
|
|
forAll = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
|
|
python = pkgs: pkgs.python3.withPackages (ps: [ ps.pyserial ps.libgpiod ps.pyflakes ]);
|
|
# An example box, for nix flake check: does a box's system evaluate?
|
|
example = self.lib.mkBox {
|
|
name = "box"; server = "home"; wifi = "home"; admin = "admin"; sshKeys = [ ];
|
|
};
|
|
in
|
|
{
|
|
# The box's services, for a NixOS system of your own.
|
|
nixosModules.box = ./box/module.nix;
|
|
|
|
# A box: a Raspberry Pi 3B with the AIY Voice HAT, from a few names (box/system.nix says which).
|
|
# Its image: (mkBox { ... }).config.system.build.sdImage. The box's JavaScript and earcons are
|
|
# the same on every architecture, so they're built natively, on buildSystem, rather than under qemu.
|
|
lib.mkBox = { name, server, wifi, admin, sshKeys, modules ? [ ], buildSystem ? "x86_64-linux" }:
|
|
nixpkgs.lib.nixosSystem {
|
|
system = "aarch64-linux";
|
|
modules = [
|
|
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
|
|
self.nixosModules.box
|
|
./box/voicehat.nix
|
|
(import ./box/system.nix { inherit name server wifi admin sshKeys; })
|
|
{
|
|
pdtv26.box.packages = with self.packages.${buildSystem}; {
|
|
speechJs = speech-js; boxJs = box-js; inherit earcons;
|
|
};
|
|
}
|
|
] ++ modules;
|
|
};
|
|
|
|
packages = forAll (pkgs: {
|
|
speech = pkgs.callPackage ./speech/server.nix { };
|
|
speech-js = pkgs.callPackage ./speech/default.nix { };
|
|
box-js = pkgs.callPackage ./box/default.nix { };
|
|
earcons = pkgs.callPackage ./box/earcons.nix { };
|
|
brain = pkgs.callPackage ./brain/brain.nix { src = self; };
|
|
brain-js = pkgs.callPackage ./brain/default.nix { };
|
|
});
|
|
|
|
# nix develop --command make test
|
|
devShells = forAll (pkgs: {
|
|
default = pkgs.mkShellNoCC {
|
|
packages = [ (python pkgs) pkgs.gnumake pkgs.gawk pkgs.curl pkgs.picocom pkgs.nixos-rebuild pkgs.libsecret ];
|
|
};
|
|
});
|
|
|
|
checks = forAll (pkgs: {
|
|
ir-pico = pkgs.runCommand "ir-pico-doctests" { nativeBuildInputs = [ (python pkgs) ]; } ''
|
|
cd ${./ir-pico}
|
|
python3 -I -m doctest ir_commands.py pico_tty.py
|
|
touch $out
|
|
'';
|
|
speech = self.packages.${pkgs.stdenv.hostPlatform.system}.speech-js;
|
|
box-js = self.packages.${pkgs.stdenv.hostPlatform.system}.box-js;
|
|
brain-js = self.packages.${pkgs.stdenv.hostPlatform.system}.brain-js;
|
|
# The channel, its unit, and its instructions, put together.
|
|
brain = self.packages.${pkgs.stdenv.hostPlatform.system}.brain;
|
|
# Doctests, and pyflakes for the names doctests don't reach.
|
|
box-py = pkgs.runCommand "box-py-doctests" { nativeBuildInputs = [ (python pkgs) ]; } ''
|
|
cd ${./box/body}
|
|
python3 -I -m doctest *.py
|
|
pyflakes *.py ${./box/wifi_psk.py}
|
|
python3 -I -m doctest ${./box/wifi_psk.py}
|
|
touch $out
|
|
'';
|
|
# The example box's system evaluates; building it takes aarch64, and booting it, a Pi.
|
|
box-system = pkgs.writeText "box-system"
|
|
(builtins.unsafeDiscardStringContext example.config.system.build.toplevel.drvPath);
|
|
});
|
|
};
|
|
}
|