Compare commits

...
3 Commits
Author SHA1 Message Date
dckc f35da9b883 fixup! feat(status): a status page, for the phone of whoever looks after the box
check / check (push) Canceled after 0s
booting: a ready counts unless it's from before the latest outage
the server saw. The box's services restart together, so the button's
ready can come before the next check sees the IR port up; comparing
ready with when the port came up read that as booting, until the next
ready. A server restarted while the box stayed up did the same.

Generated-by: Claude Opus 5.5
2026-12-02 18:23:54 -06:00
dckc c335935e2d fixup! feat: install on any Linux with Nix and systemd 2026-12-02 17:41:19 -06:00
dckc db174fc610 fixup! feat(box): the box's NixOS system as a module, and lib.mkBox from a few names 2026-12-02 17:41:19 -06:00
5 changed files with 45 additions and 32 deletions

No files matched your search

-1
View File
@@ -3,5 +3,4 @@ __pycache__/
ir-pico/cache/
speech/cache/
node_modules/
box/image
box/heard.wav
+11 -22
View File
@@ -1,21 +1,20 @@
# box: the part of the agent within reach of the couch: a Raspberry Pi 3B with the AIY Voice HAT.
# Tools come from the flake: nix develop --command make test
#
# A box's system comes from lib.mkBox in a flake of your own (FLAKE), as nixosConfigurations.BOX.
# Build its image, write it to a card, put the Wi-Fi secret on it, boot the Pi:
# make image FLAKE=... BOX=...
# make card DEV=/dev/sdX # look first
# make flash DEV=/dev/sdX CONFIRM=erase # then write
# A box's system, and so its image, come from lib.mkBox in your household's own flake: build the
# image there (nix build), and deploy changes from there (nixos-rebuild). Here, the tools that take
# no household details: write the image to a card, put the Wi-Fi secret on it, boot the Pi:
# make card DEV=/dev/sdX # look first
# make flash DEV=/dev/sdX IMG=.../sd-image/x.img CONFIRM=erase # then write
# make wifi-secret SSID=...
# After that, changes go over ssh: make deploy. Then, on the home server, as the brain's user,
# Then, on the home server, as the brain's user,
# with speech and the brain installed: make keys.
FLAKE = .
BOX = box
ADMIN = $(USER)
HOST = $(BOX).local
NIX = nix --option extra-platforms aarch64-linux
DEV =
IMG =
SSID =
MNT = /mnt/pdtv26-card
TEXT = Hello. Press my button and talk to me.
@@ -29,7 +28,7 @@ CAMERA_URL = $(HOME)/.config/pdtv26-camera/rtsp-url
SPEECH_KEY = /etc/pdtv26-speech/speech-key
ON_BOX = ssh $(ADMIN)@$(HOST)
.PHONY: help test image card flash wifi-secret deploy say volume record keys speech-key ask-key ir-key look-key rtsp-url
.PHONY: help test card flash wifi-secret say volume record keys speech-key ask-key ir-key look-key rtsp-url
## list targets
help:
@@ -39,31 +38,21 @@ help:
test:
nix build -L --no-link ..#checks.x86_64-linux.box-js ..#checks.x86_64-linux.box-py ..#checks.x86_64-linux.box-system
## BOX's SD card image (aarch64: under qemu, unless this is an aarch64 machine)
image:
$(NIX) build -L --out-link image '$(FLAKE)#nixosConfigurations.$(BOX).config.system.build.sdImage'
ls -l image/sd-image/
## show the card at DEV, and check it's removable, on USB, and under 128 GB
card:
./card-check.sh $(DEV)
## erase the card at DEV and write the image: make flash DEV=/dev/sdX CONFIRM=erase
# Not "flash: image": image links into the Nix store, where every mtime is 1970, so make would always rebuild.
## erase the card at DEV and write the image IMG to it: make flash DEV=/dev/sdX IMG=... CONFIRM=erase
flash: card
@test "$(CONFIRM)" = erase || { echo "this erases $(DEV); add CONFIRM=erase"; exit 1; }
@test -e image || { echo "no image yet: make image"; exit 1; }
./flash.sh image/sd-image/*.img $(DEV)
@test -f "$(IMG)" || { echo "which image? add IMG=.../sd-image/....img, from your household's nix build"; exit 1; }
./flash.sh '$(IMG)' $(DEV)
## put the Wi-Fi network's PSK on the card, from the passphrase in the desktop keyring: make wifi-secret SSID=...
wifi-secret:
@test -n "$(SSID)" || { echo "which network? add SSID=..."; exit 1; }
./wifi-secret.sh '$(SSID)' $(MNT)
## build BOX's system here and switch the Pi to it, over ssh: make deploy [HOST=...]
deploy:
nixos-rebuild switch --flake '$(FLAKE)#$(BOX)' --target-host $(ADMIN)@$(HOST) --sudo --option extra-platforms aarch64-linux
## speak TEXT through the box's speaker, with espeak-ng: make say [TEXT="..."] [AMP=0..200]
say:
printf '%s\n' "$(TEXT)" | ssh $(ADMIN)@$(HOST) 'espeak-ng -a $(AMP) --stdin --stdout | aplay -q -D speaker'
+9 -6
View File
@@ -13,7 +13,7 @@ A private git repository of your own holds what's yours: the names you choose, a
url = "git+https://git.inference.coop/dckc/pdtv26";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { pdtv26, ... }: {
outputs = { self, pdtv26, ... }: {
nixosConfigurations.pimote = pdtv26.lib.mkBox {
name = "pimote"; # the box's host name on your network
server = "den-pc"; # your home server's host name: speech and the brain
@@ -21,6 +21,8 @@ A private git repository of your own holds what's yours: the names you choose, a
admin = "pat"; # who looks after the box, and logs in to deploy
sshKeys = [ "ssh-ed25519 AAAA... pat@laptop" ];
};
# The box's SD card image, built on x86_64 Linux.
packages.x86_64-linux.sd-image = self.nixosConfigurations.pimote.config.system.build.sdImage;
};
}
```
@@ -38,13 +40,14 @@ The brain comes after the box, in step 5, since it needs the box's keys.
## 3. Make the box's SD card
On any Linux machine with Nix that can run ARM programs (on Debian or Ubuntu, `apt install qemu-user-static`), in pdtv26's `box/`:
The image carries your household's names, so it's built from your household repository, on any Linux machine with Nix that can run ARM programs (on Debian or Ubuntu, `apt install qemu-user-static`). The Wi-Fi passphrase and the keys stay out of it.
1. `make image FLAKE=path/to/household BOX=pimote`, then `make card DEV=/dev/sdX` to check you have the right device, and `make flash DEV=/dev/sdX CONFIRM=erase`.
2. `make wifi-secret SSID=MyNetwork`: it puts the network's PSK on the card from the passphrase in your desktop keyring, not in the image or the repository. Store the passphrase there once, with `secret-tool store --label="Wi-Fi MyNetwork" service wifi ssid MyNetwork`.
3. Put the card in the Pi, plug in the IR emitter's USB cord, and power it up.
1. In your household repository: `nix build --option extra-platforms aarch64-linux .#sd-image`.
2. In pdtv26's `box/`: `make card DEV=/dev/sdX` to check you have the right device, then `make flash DEV=/dev/sdX IMG=path/to/household/result/sd-image/*.img CONFIRM=erase`.
3. Also in `box/`: `make wifi-secret SSID=MyNetwork`: it puts the network's PSK on the card from the passphrase in your desktop keyring, not in the image or the repository. Store the passphrase there once, with `secret-tool store --label="Wi-Fi MyNetwork" service wifi ssid MyNetwork`.
4. Put the card in the Pi, plug in the IR emitter's USB cord, and power it up.
After this, changes to the box go over ssh: `make deploy FLAKE=path/to/household BOX=pimote`.
After this, changes to the box go over ssh, from your household repository: `nixos-rebuild switch --flake .#pimote --target-host pat@pimote.local --sudo --option extra-platforms aarch64-linux`.
## 4. Join the private network
+7 -3
View File
@@ -24,7 +24,7 @@ const fromButton = (source) => source.endsWith('-button');
/**
* @typedef {{ at: number, kind: string, source: string, reason?: string, code?: string, times?: number }} Event
* @typedef {{ name: string, up: boolean, at: number, since: number }} Check
* @typedef {{ name: string, up: boolean, at: number, since: number, outage?: number }} Check outage: when the latest outage we saw began
* @typedef {{ conversations: number, turns: number, huh: number, interrupts: number, irPresses: number, looks: number }} Tally
* @typedef {{ word: string, since?: number, why?: string }} State
* @typedef {{ state: State, heartbeat?: number, checks: (typeof CHECKS[number] & Partial<Check>)[], today: Tally, total: Tally, recent: Event[] }} Summary
@@ -82,7 +82,9 @@ export class Status {
/** @param {string} name @param {boolean} up @param {number} at */
check(name, up, at) {
const prev = this.#checks.get(name);
this.#checks.set(name, { name, up, at, since: prev && prev.up === up ? prev.since : at });
const since = prev && prev.up === up ? prev.since : at;
const outage = up ? prev?.outage : since;
this.#checks.set(name, { name, up, at, since, ...(outage === undefined ? {} : { outage }) });
}
size() { return this.#events.length; }
@@ -93,7 +95,9 @@ export class Status {
if (!up) return { word: 'not checked yet' };
if (!up.up) return { word: 'unreachable', since: up.since };
const ready = this.#events.findLast((e) => e.kind === 'ready');
if (!ready || ready.at < up.since) return { word: 'booting', since: up.since };
// Services restart together, so ready can come before the check sees the box up again: a ready
// counts unless it's from before the latest outage we saw.
if (!ready || ready.at < (up.outage ?? -Infinity)) return { word: 'booting', since: up.since };
const alive = Math.max(this.#heartbeat ?? 0, this.#events.findLast((e) => fromButton(e.source))?.at ?? 0);
if (now - alive > 3 * HEARTBEAT_MS) return { word: 'not responding', since: alive, why: 'no heartbeat from its button service' };
const last = this.#events.findLast((e) => e.kind === 'conversation' || e.kind === 'end');
+18
View File
@@ -41,6 +41,24 @@ test('a ready from before the box went away does not count: booting', () => {
assert.equal(s.summary(4 * MIN).state.word, 'booting');
});
test('a ready during the outage counts: services restart together, and the check sees the box up last', () => {
const s = new Status(dayOf);
s.check('box', true, 0);
s.record({ at: 1 * MIN, kind: 'ready', source: 'pdtv26-button' });
s.check('box', false, 2 * MIN);
s.record({ at: 2.5 * MIN, kind: 'ready', source: 'pdtv26-button' });
s.check('box', true, 3 * MIN);
assert.deepEqual(s.summary(4 * MIN).state, { word: 'ready for duty', since: 2.5 * MIN });
});
test('a ready from before the server started counts, if the server saw no outage', () => {
const s = new Status(dayOf);
s.record({ at: 1 * MIN, kind: 'ready', source: 'pdtv26-button' });
s.check('box', true, 10 * MIN);
s.beat(10.5 * MIN);
assert.deepEqual(s.summary(11 * MIN).state, { word: 'ready for duty', since: 1 * MIN });
});
test('checks keep when they last changed', () => {
const s = new Status(dayOf);
s.check('brain', true, 1 * MIN);