Skip to content

jukebox: a Kodi appliance distro, and pizzie to run it - #20

Open
gotha wants to merge 17 commits into
mainfrom
jukebox-kodi-appliance
Open

gotha wants to merge 17 commits into
mainfrom
jukebox-kodi-appliance

Conversation

@gotha

@gotha gotha commented Oct 3, 2026

Copy link
Copy Markdown
Owner

A media box for the TV, in two parts: a jukebox distro that is nothing
but Kodi, and pizzie, a Raspberry Pi 3 Model B that boots it off an SD
card.

The session

Kodi is the session. kodi-gbm renders straight onto KMS through GBM,
started by systemd on tty1 — no X server, no Wayland compositor, no
display manager. nixpkgs only offers
services.xserver.desktopManager.kodi, which is an X11 session, so
distros/jukebox/kodi.nix stands in for that module rather than
configuring it.

The load-bearing line is PAMName = "login". It opens a real logind
session on the seat that owns tty1, and only a session leader gets DRM
master plus the uaccess ACLs on /dev/dri/*, /dev/input/* and
/dev/cec0. Without it Kodi starts, finds no GPU it may drive, and
exits.

HDMI-CEC

The point of the exercise: the TV remote drives Kodi. vc4 registers the
adapter as /dev/cec0 once config.txt loads vc4-kms-v3d, and a udev
rule tags it uaccess so the session can open it. libcec and
v4l-utils ride along for cec-client and cec-ctl, which is how you
tell "no adapter" from "adapter, uncooperative TV".

Why nixos-hardware is a new input

nixpkgs removed the linux_rpi* kernels in September 2026 — "linux-rpi
series has been removed, please change to use nixos-hardware"
. It brings
the vendor kernel, the config.txt generator and the firmware-partition
installer.

Vendor kernel rather than mainline because bcm2835-codec, the V4L2
interface to the Pi 3's hardware H.264 decoder, exists only in the
Raspberry Pi fork. Mainline drives HDMI and CEC perfectly well through
vc4 but leaves decoding to four A53 cores.

The first image build compiles that kernel under emulation and takes
hours.
Nothing public caches it. Build it on lucie and that also
publishes it, since cachix.hgeorgiev.com serves lucie's store.

Deliberately split

distros/jukebox knows nothing about a Raspberry Pi — it should take an
x86 HTPC just as well, so the board profile, device tree, config.txt
and SD layout all live in hosts/pizzie.

Two corrections worth flagging

  • sd-image.nix declares sdImage.populateRootCommands with no default
    and the raspberry-pi-3 profile fills in only the firmware half, so an
    image build dies on the missing value. hosts/pizzie supplies the same
    two lines sd-image-aarch64.nix uses. That file is deliberately not
    imported whole: it also pulls in profiles/base.nix and writes its own
    populateFirmwareCommands, which nixos-hardware then mkForces away.
  • sd-image.nix mounts the firmware partition noauto. The firmware
    activation script checks mountpoint and otherwise skips with a
    warning — so left alone it would quietly never update config.txt.

Verified

  • pizzie evaluates, both system.build.toplevel and the SD image.
  • Kernel resolves to linux-rpi-6.18.50-stable_20260911.
  • Generated config.txt carries kernel=u-boot.bin, arm_64bit=1,
    dtoverlay=vc4-kms-v3d, cec_osd_name=Jukebox.
  • Kodi unit: User=gotha, wrapped env, getty@tty1 off,
    /boot/firmware mounting nofail.
  • All nine addons resolve with their transitive deps; every one has a
    cached aarch64-linux build.
  • deadnix, statix, nixfmt pass. bae, bastion, devbox,
    lucie and the Mac all still evaluate.

Not done

  • No deploy.nodes.pizzie entry — the Pi has no address until it boots.
  • CMA left at its default. If video stutters that is the first knob, and
    README-jukebox.md gives the by-hand config.txt edit.
  • Kodi runs as gotha, by choice. os/linux/user.nix puts gotha in
    wheel under wheelNeedsPassword = false, so Kodi, its addons and
    anyone with a USB keyboard at the TV are one sudo from root.

gotha added 12 commits October 3, 2026 13:43
nixpkgs moves 2026-09-03 -> 2026-09-30, with home-manager, sops-nix,
deploy-rs, hunk, llm-agents, nix-index-database and nix-vscode-extensions
alongside it. One consequence had to be handled before anything would
evaluate at all.

links2 is marked broken upstream as of nixpkgs 6d1f6ca22. links 2.30
fails to compile under current gcc on a discarded-qualifiers error that
-Wno-error= cannot suppress, and the maintainer declined to patch it
since upstream publishes from no forge. The flag is unconditional, so
every configuration importing config/packages.nix refuses to evaluate -
darwin included, even though clang builds it here without complaint.

Drop it rather than unmark it. The list is shared by platypus and the
NixOS distros, so waving the flag away for darwin would only defer the
failure to the next Linux deploy, and nothing is in the binary cache for
any system because Hydra skips broken packages. platypus and devbox keep
w3m from the aerc module, which covers mucie, devbox, devbox-arm and
lucie; bae and bastion are left with no text browser.

All five configurations evaluate against the new lock.
A media box for the TV. Kodi is the whole session - kodi-gbm renders
straight onto KMS through GBM, started by systemd on tty1, with no X
server, no Wayland compositor and no display manager underneath. nixpkgs
offers services.xserver.desktopManager.kodi, which is an X11 session, so
distros/jukebox/kodi.nix stands in for that module rather than
configuring it.

The load-bearing line is PAMName = "login". It opens a real logind
session on the seat that owns tty1, and only a session leader gets DRM
master and the uaccess ACLs on /dev/dri/*, /dev/input/* and /dev/cec0.
Without it Kodi starts, finds no GPU it is allowed to drive, and exits.
getty@tty1 and autovt@tty1 are disabled so nothing else claims the VT.

HDMI-CEC is the point of the exercise - the TV remote drives Kodi. The
vc4 driver registers the adapter as /dev/cec0 once config.txt loads
vc4-kms-v3d, and a udev rule tags it uaccess so the session above can
open it. libcec and v4l-utils come along for cec-client and cec-ctl,
which is how you tell "no adapter" apart from "adapter, uncooperative
TV".

The distro knows nothing about a Raspberry Pi: it is meant to take an x86
home theatre PC just as well, so the board profile, the device tree,
config.txt and the SD layout all live in hosts/pizzie instead.

pizzie is a Raspberry Pi 3 Model B. nixpkgs removed the linux_rpi*
kernels in September 2026 ("linux-rpi series has been removed, please
change to use nixos-hardware"), so nixos-hardware becomes an input and
brings three things: the vendor kernel, the config.txt generator and the
firmware-partition installer. The vendor kernel rather than mainline
because bcm2835-codec - the V4L2 interface to the Pi 3's hardware H.264
decoder - exists only in the Raspberry Pi fork. Mainline drives HDMI and
CEC perfectly well through vc4 but leaves decoding to four A53 cores.
Nothing in any public cache has that kernel, so the first image build
compiles it under emulation and takes hours. Once.

Two details that are not obvious from the modules they correct:

sd-image.nix declares sdImage.populateRootCommands with no default, and
the raspberry-pi-3 profile fills in only the firmware half, so an image
build dies on the missing value. hosts/pizzie supplies the same two lines
sd-image-aarch64.nix uses. That file is deliberately not imported whole -
it also drags in profiles/base.nix and writes its own
populateFirmwareCommands, which nixos-hardware then has to mkForce back
out of the way.

sd-image.nix also mounts the firmware partition noauto, on the grounds
that nothing needs it after boot. The firmware activation script does:
it checks mountpoint first and otherwise skips with a warning, so left as
noauto it would quietly never update config.txt.

nix build .#packages.aarch64-linux.pizzie-sd produces pizzie-sd.img,
uncompressed so flashing is dd with no zstd in the pipe.

Kodi runs as gotha rather than a dedicated service user, by choice.
os/linux/user.nix puts gotha in wheel under wheelNeedsPassword = false,
so Kodi, its addons and anyone with a USB keyboard at the TV are one
sudo from root. Fine on a home LAN; worth knowing before this box goes
anywhere else.
Covers what the other READMEs do not: that the first image build
compiles a kernel under emulation and why, that building it on lucie is
also what publishes it to cachix.hgeorgiev.com, and how to flash and
first-boot the card.

The CEC section is the one worth having written down. Three checks,
narrowest first - cec-ctl for whether the kernel registered an adapter,
cec-client for whether anything answers on the bus, the Kodi log for
whether Kodi is using it - because the usual answer is that CEC is
switched off in the TV's own menu under whatever that manufacturer
decided to call it.
Two unrelated breakages, both of which made `nix flake show` and
`nix flake check` fail outright.

deployChecks mapped over every system deploy-rs.lib exposes, which
includes x86_64-darwin. nixpkgs 26.11 dropped that platform and throws
on evaluation, and mapAttrs forces every attribute, so the throw was
unavoidable. The `systems` list above is not consulted here, which is
why trimming that would not have helped.

image/repart.nix moved behind a new image.repart.enable that defaults
off, so importing the module no longer defines system.build.image. The
error's "did you mean images?" is a red herring: system.build.images.qemu
is the make-disk-image/cptofs path this module exists to avoid.
A build with no progress bar is the normal state of this repo - the
first pizzie image spent twelve hours in a single kernel derivation with
nothing on screen but the drv name. nom draws the dependency tree as it
goes, and `nix build -L |& nom --json` is the version worth reaching for
when a build is going to take a while.

In config/packages-user.nix rather than config/packages.nix, which
distros/jukebox imports as systemPackages: the Pi has no business
carrying a build monitor.
The SSID and the PSK live in secrets/appliance/home-wifi.enc.env and
reach NetworkManager through ensureProfiles, whose generated keyfile
carries $HOME_WIFI_SSID and $HOME_WIFI_PSK rather than their values.
envsubst fills those in at boot from the decrypted secret, so the
world-readable store copy of the profile holds neither; the rendered one
lands in /run/NetworkManager, tmpfs and mode 0600.

Decryption is the part that needed deciding. Every other host here
decrypts with an age key derived from its ssh host key, which a freshly
written card does not have - sshd-keygen.service runs when sshd first
starts, long after sops-install-secrets has run during activation - and
which would change on every reflash. So pizzie reads a key minted ahead
of time, written to /var/lib/sops-nix/key.txt on the card by hand.
sops.age.keyFile is typed pathNotInStore, which is what stops that key
from arriving through the image and into the binary cache.

The key is shared across appliances rather than per-host, so a second
box joins the wifi without touching .sops.yaml at all. The cost is that
many machines hold the same copy and any one card gives it up, so its
reach is fenced to a directory: *appliance is a recipient on
secrets/appliance/ and nothing outside it. secrets/keys/ excludes it on
purpose - that directory is where per-host keys go, and one lost card
must not open those.

Its own private half is secrets/keys/appliance.agekey.enc, readable by
the two workstations and breakglass, so a card can be seeded from any
checkout rather than from a single file on lucie. README-jukebox.md has
the procedure for both, and no longer claims the first boot must be
wired.
Same shape as bastion, so `deploy .#pizzie` replaces copying a closure
over by hand. remoteBuild is false for a stronger reason than it is on
bastion: the alternative is compiling aarch64 on four 1.2 GHz A53 cores
with an SD card underneath, where lucie reaches that platform through
boot.binfmt.emulatedSystems and sends the result over.

The hostname is the address the router handed it, which is a lease
rather than a reservation - hence the todo to move it onto wireguard,
where bastion already has an address that holds still.

cfg is imported beside wireguard so sshUser comes from
config/default.nix instead of being spelled out a second time.
A Mac-formatted 1 TB USB disk, pinned by filesystem UUID so it does not
care which port it lands in or what /dev/sd* name it gets. noauto plus
x-systemd.automount has systemd mount it on first access to /media/bkp
and never at boot, so Kodi comes up with or without the disk attached,
and device-timeout fails an access with nothing there in 10s rather than
the default 90.

Ownership is handed out at mount time because HFS+ carries none this
driver will trust: root:users with a group-writable umask, since the user
Kodi runs as has users as its primary group, and that group's gid is
declared where its uid is allocated dynamically and so cannot be named.

noCheck because hfsplus is not in nixpkgs' fsToSkipCheck, so the default
passno would pull in a systemd-fsck@ for an fsck.hfsplus this machine
does not ship - and that unit failing takes the mount down with it.

force is the part worth being unhappy about, and it is the only way to
get read-write out of a journaled HFS+ volume: the kernel driver can
neither replay nor maintain the journal. Checked on a throwaway
`mkfs.hfsplus -J` image rather than on the disk itself - without force it
mounts ro, with it an unprivileged member of users can write a file. An
unclean unplug will leave a volume only a Mac can repair, so disabling
the journal or reformatting exFAT both retire the flag later.
An agent wrote twelve lines of comment for a one-line config change, so
AGENT.md says what the house style already was: a one-line change gets
at most a one-line comment and usually none, comment only what the code
cannot say, and put the reasoning in the commit message - read once by
someone asking why, rather than in the file, read every time by someone
trying to see the code.

Then the same rule applied backwards over this branch. 42 comment lines
out of hosts/pizzie/default.nix for 18 in: the three short ones are
inline now, and `force` on the HFS+ mount keeps three because losing a
volume to it is still worth a warning. .sops.yaml only needed its header
paragraph trimmed to the width of the two above it, and the count fixed
- there have been three kinds of recipient in that file since the
appliance key landed.

No behaviour change: config.system.build.toplevel is still
ns3w4ip6jfwn8fkvq4ypc0dr7dqwql1i, byte for byte what it was before.
Kodi had sound all along, playing into an unplugged 3.5 mm jack. ALSA's
default is card 0, the bcm2835 analog device held card 0 with vc4hdmi
second, and audiooutput.audiodevice had never been moved off "Default".
card0/pcm0p/sub0 was RUNNING under Kodi's pid while card1 sat closed.

snd_bcm2835.enable_headphones=0 takes that card away and leaves vc4hdmi
as card 0, so a freshly written card has sound without anyone picking a
sink in the GUI. The alternative lives in guisettings.xml, mutable state
that a reflash throws away.

dtparam=audio=off is the obvious thing to reach for and it does not work.
It does remove the audio node from the device tree - confirmed on the
running machine, where no node matching *audio* was left - and the card
turns up anyway, as a child of the VC4 mailbox: snd_bcm2835 is built into
the vendor kernel and never consults that node. Hence a kernel parameter
instead, and hence the boot.* assignments merged into one block, since
three of them trip statix's repeated-keys lint and nix flake check is
what deploy-rs runs before it will deploy anything.
@gotha
gotha force-pushed the jukebox-kodi-appliance branch from 7bbe12a to b422d03 Compare October 4, 2026 20:43
gotha added 5 commits October 5, 2026 12:33
With the disk attached at power-on, the Pi intermittently came up on the
wrong device: U-Boot reported trying to boot the USB disk rather than the
card. boot_targets is "mmc usb pxe dhcp", so the SD card is already
first - it only reaches usb when the mmc scan comes back empty, and the
kernel log says why. "Undervoltage detected!" lands two seconds into
every boot, and the drive declares bMaxPower 500mA against a budget of
600mA shared across all four ports. The platters pull well past that for
the first second, the 5 V rail sags, the SD read fails, and U-Boot walks
down its list.

max_usb_current=1 raises that budget to 1.2 A, which the official 2.5 A
supply can feed. Nothing in U-Boot was worth changing: it never
enumerates USB before reading the card (preboot is just "pci"), and the
drive spins up when the board powers on whatever the bootloader does, so
reordering boot_targets would only have reworded the failure - U-Boot
cannot read HFS+ either way.

Whether 1.2 A actually covers the surge is still unproven; it wants a
few cold boots with the drive attached. If the undervoltage line
survives, the answer is external power for the drive rather than another
line here.
kodi.bin was shot by the OOM killer holding 563 MB of anon-rss on a board
with 889 MB usable and no swap at all - the sd-image carries a firmware
partition and a root, nothing else.

zram compresses to RAM rather than to the card, whose write endurance is
why journald is already capped in distros/jukebox; a swapfile there would
be both slow and corrosive. lz4 rather than the NixOS default zstd
because the same four 1.2 GHz A53 cores are decoding video, and lz4 costs
far less per page for a ratio that is good enough on anonymous memory.

Headroom, not a higher ceiling: at 563 MB Kodi already wanted most of the
machine, so if it is leaking rather than caching this delays the next OOM
instead of preventing it.
Kodi files an addon it has not seen before as disabled and asks about it
at startup, so a freshly written card wanted a dozen yes-clicks on a TV
remote before anything worked. The state lives in
~/.kodi/userdata/Database/Addons*.db, table installed; of 72 rows on
pizzie, 17 were disabled and they were exactly the ones from
withPackages plus their python dependencies.

Kodi's own bundled addons avoid this by appearing in
system/addon-manifest.xml, which marks them as always-on - inputstream.adaptive
is listed there and was the single withPackages addon already enabled.
That file is upstream's, inside the kodi package, so editing it means
rebuilding Kodi under emulation. The database is the cheaper lever.

An ExecStartPre takes the ids from the env the unit is about to run, so
the withPackages list stays the only switch. It reads each id out of
addon.xml rather than trusting the directory name: script.plex holds
script.plexmod, and taking the name left plex disabled.

Checked under binfmt against a copy of pizzie's database - 17 disabled
to 0, idempotent on a second run, and exit 0 with no database at all,
which matters because a failing ExecStartPre would stop Kodi booting.
The first start of a brand-new card still prompts: the database does not
exist yet when the pre-start runs, so there is nothing to update.
pvr.iptvsimple reads one playlist and cannot filter, so the filtering
happens here: a timer fetches iptv-org's 11138-entry index and keeps
every channel with a .bg tvg-id - 65 of them, so BNT, bTV and Nova need
no curation - plus six global news ids named in full. CNN and Eurosport
are absent from the index; both are pay-TV and a free-to-air list does
not carry them.

The filter reads ids out of tvg-id and carries EXTVLCOPT and KODIPROP
lines with their entry, because several streams 403 without the user
agent they specify. It also strips the CR from the source's CRLF, which
otherwise rides along on every URL.

Fetched at runtime rather than pinned in the store: these URLs rot
constantly, and a fixed-output hash would break the build every time
upstream edits the list.

iptvsimple keeps its config in mutable addon_data, so a tmpfiles C+ rule
stamps settings.xml from the store on every boot - the playlist here wins
over whatever the GUI last saved.

OnBootSec is what gives a new card its first playlist. Persistent only
replays an elapse it can prove it missed, and with no stamp file there is
nothing to miss, so the first version of this sat at 0% until midnight.

Verified on pizzie: 71 channels and 19 groups loaded, 2.7s and 14.6 MB
peak for the fetch. 23 of the 71 streams answer today; the big Bulgarian
broadcasters 404 or time out upstream, which the daily refresh will pick
up if they come back.
script.plexmod aborted at startup with

  ibis.errors.TemplateSyntaxError: Template 'script-plex-playlist.xml.tpl',
  line 169: Unparsable expression '132+63'.

which is three bugs deep. The template does arithmetic in an include;
ibis evaluates it through ast; its Constant branch reads
getattr(node, 'value', getattr(node, 'n')) and Python computes that
default eagerly, so node.n is touched for every constant. ast.Constant.n
was deprecated in 3.8 and removed in 3.14, which is what Kodi 21 links
against here, so the read raises AttributeError - and a bare `except:
pass` in _parse_primary_expr swallows it, leaving the parser to report the
expression as unparsable. Kodi's own builds ship Python 3.8 to 3.11,
which is why upstream has not seen it.

Reproduced on 3.14.7 directly: getattr(node, 'value', getattr(node, 'n'))
raises where node.value returns 132. Verified with the patch applied, the
same expressions evaluate - 132+63 to 195, 132+63*2 to 258.

A patch file rather than substituteInPlace, so the reasoning sits next to
the change and a nixpkgs bump that moves those lines fails the build
instead of quietly shipping the bug back. The hunk applies to 1.0.6 as
well, checked with a dry run, which is what an src override to that
release would need.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant