feat(box): the box's NixOS system as a module, and lib.mkBox from a few names
check / check (push) Canceled after 0s

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
This commit is contained in:
dckc committed 2026-12-02 16:18:17 -06:00
1 parent 2e7156dc36
commit 521998b666
35 files changed
+2165 -3

No files matched your search

+79
View File
@@ -0,0 +1,79 @@
# The Google AIY Voice Kit v1's HAT on a Raspberry Pi 3B: its speaker and mics, on one I2S bus:
# a MAX98357A amp (out, GPIO 21) and two ICS-43432 mics (in, GPIO 20). Mainline Linux has no
# googlevoicehat driver, but the codecs and simple-audio-card do the same; SD_MODE on GPIO 16, as in
# Google's overlay. simple-audio-card takes one codec per link, so the card gets two links on the
# same I2S: device 0 plays, device 1 records. The direction flags go on the codec nodes: simple-card
# reads them from the link, cpu, then codec, and the last one read wins.
{ ... }:
{
hardware.deviceTree.overlays = [{
name = "voicehat";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2837";
fragment@0 {
target = <&gpio>;
__overlay__ {
voicehat_i2s_pins: voicehat_i2s_pins { brcm,pins = <18 19 20 21>; brcm,function = <4>; }; /* ALT0 */
};
};
fragment@1 {
target = <&i2s>;
/* mainline's i2s node lacks #sound-dai-cells; without it simple-audio-card fails with -EINVAL */
__overlay__ { pinctrl-names = "default"; pinctrl-0 = <&voicehat_i2s_pins>; #sound-dai-cells = <0>; status = "okay"; };
};
fragment@2 {
target-path = "/";
__overlay__ {
voicehat_amp: voicehat-amp {
compatible = "maxim,max98357a";
#sound-dai-cells = <0>;
sdmode-gpios = <&gpio 16 0>;
};
voicehat_mic: voicehat-mic {
compatible = "invensense,ics43432";
#sound-dai-cells = <0>;
};
voicehat-sound {
compatible = "simple-audio-card";
simple-audio-card,name = "voicehat";
#address-cells = <1>;
#size-cells = <0>;
simple-audio-card,dai-link@0 {
reg = <0>;
format = "i2s";
cpu { sound-dai = <&i2s>; };
codec { sound-dai = <&voicehat_amp>; playback-only; };
};
simple-audio-card,dai-link@1 {
reg = <1>;
format = "i2s";
cpu { sound-dai = <&i2s>; };
codec { sound-dai = <&voicehat_mic>; capture-only; };
};
};
};
};
};
'';
}];
# The amp has no volume control of its own, so a softvol named speaker goes in front of it; everything
# plays through it. make volume VOL=30% sets the level; persistence keeps it across reboots.
hardware.alsa = {
enable = true;
enablePersistence = true;
# The card numbers its links in reverse of the overlay's order: device 0 is the mics, 1 the amp.
# The amp and mics share one I2S bus, so they run together only in one format: the mics'.
# Whichever opens first sets it; so the amp always asks for 32-bit stereo at 16 kHz.
config = ''
pcm.voicehat_out {
type plug
slave { pcm "hw:CARD=voicehat,DEV=1"; format S32_LE; rate 16000; channels 2; }
}
'';
controls.speaker = { device = "voicehat_out"; card = "voicehat"; };
};
}