The box within reach of the couch: a Raspberry Pi 3B with the AIY Voice HAT, from the first household's configuration, made generic. - box/body: the button service, in Python: press and talk, turns by voice, a press interrupts; the look signal - box/*.js: the ir and look capabilities, behind gates, for the brain; the ask client, the box's side of a conversation - box/module.nix: the services, each confined to the devices and addresses it needs; the private network as an option (a tailnet by default); the Pico found by its USB IDs, as /dev/pdtv26-ir - box/voicehat.nix: the Voice HAT's device tree overlay and ALSA setup - lib.mkBox: a box's whole system from its name, the home server's, the Wi-Fi network's, and who looks after it - checks: box-js, box-py (doctests and pyflakes), and box-system (an example box's system evaluates) Generated-by: Claude Opus 5.5
75 lines
3.2 KiB
Nix
75 lines
3.2 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 { };
|
|
});
|
|
|
|
# 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;
|
|
# 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);
|
|
});
|
|
};
|
|
}
|