Skip to content

NixOS support - #379

Open
mrosseel wants to merge 532 commits into
brickbots:mainfrom
mrosseel:nixos
Open

mrosseel wants to merge 532 commits into
brickbots:mainfrom
mrosseel:nixos

Conversation

@mrosseel

Copy link
Copy Markdown
Collaborator

Summary

  • Full NixOS-based system for PiFinder (replaces Raspbian)
  • Declarative system configuration via Nix flake
  • SD card image, netboot, and migration bootstrap tarball builds
  • Software update via nixos-rebuild with GitHub release/PR channels

Test plan

  • Flash SD image and verify boot
  • Test WiFi AP and client mode switching
  • Test software update UI channels
  • Test hostname rename via web UI

🤖 Generated with Claude Code

@mrosseel mrosseel added the testable Ready for testing via PiFinder software update label Feb 12, 2026
@mrosseel mrosseel added testable Ready for testing via PiFinder software update and removed testable Ready for testing via PiFinder software update labels Feb 14, 2026
@mrosseel
mrosseel force-pushed the nixos branch 6 times, most recently from 485daaa to d021534 Compare May 28, 2026 12:22
mrosseel added a commit to mrosseel/PiFinder that referenced this pull request May 28, 2026
…cceed)

Brickbots/PiFinder runs the workflow on pull_request:synchronize from
PR brickbots#379 (mrosseel:nixos -> brickbots:main). With ATTIC_TOKEN now also
set on brickbots, build-emulated's 'Push to Attic' step succeeds — the
last failing step. But stamp-build then tries to checkout the PR head
ref (mrosseel:nixos) and 'git push' a pifinder-build.json commit there,
which can't work from brickbots' Actions runner (no write access to the
fork). The PR run therefore failed at the stamp step even after attic
was wired correctly.

Gating stamp-build on github.event_name == 'push' keeps the canonical
stamp on the mrosseel:nixos push run (where it works) and skips it on
brickbots PR runs (which only need to verify the build).

Net effect: both repos' CI runs in parallel without stomping —
- Both build and push the same closure to cache.pifinder.eu (attic
  FastCDC-dedups, so the second push is a no-op),
- Only mrosseel stamps pifinder-build.json,
- build-migration-tarball already gates on github.ref == refs/heads/nixos
  so it only runs on mrosseel push.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mrosseel mrosseel changed the title [WIP] NixOS support NixOS support Jun 23, 2026
@mrosseel
mrosseel force-pushed the nixos branch 9 times, most recently from 33f9794 to a4f8db2 Compare June 25, 2026 13:27
@mrosseel mrosseel added testable Ready for testing via PiFinder software update and removed testable Ready for testing via PiFinder software update labels Jun 25, 2026
mrosseel and others added 9 commits November 6, 2026 04:16
…rver (#117)

The brickbots DNS now points cache.pifinder.io and deltas.pifinder.io at
the same server as the .eu names. The devices, the CI and the docs use
the .io names from this change on.

The server keeps the .eu names as aliases. Devices that run an older
build still use them.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
On rev 4, GPIO14 is the LTC2954 power-off kill line (ADR 0007). The
config.txt sets enable_uart=1, which makes GPIO14 the mini UART TXD. The
first byte that U-Boot prints cuts the power, so a migrated CM4 switches
itself off at each power-on.

- config.txt: a [cm4] section after [all] sets gpio=14=ip,pu. The
  firmware sets the pin back to an input with a pull-up before U-Boot
  starts. U-Boot needs enable_uart=1, and its serial drivers check only
  GPIO15, so it keeps its console. Brickbots tested this on a rev 4 unit:
  a cold boot stays on, reboot comes back, poweroff cuts the power.
- CM4 device tree: the gpio-poweroff overlay disables uart1. The kernel
  tree marked it okay with stdout-path on it, so the kernel registered
  ttyS0 on GPIO14 as its default console.
- SD images: nixos/sd-image.nix now holds the settings of nixpkgs'
  sd-image-aarch64.nix without its console=ttyS0 and console=ttyAMA0
  kernel parameters. A list option merges, so a later module cannot
  remove them. The image derivation diff shows only that change.

Already migrated rev 4 cards keep their old config.txt, because an
upgrade does not write the FAT partition.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…igration guide (#119)

A release builds a migration tarball only when new_migration_tarball is
set. The tarball installs the newest release at first boot, so one tarball
serves many releases. Without a new tarball, update_manifest.py
--migration-from-manifest gives the entry the migration_v2 keys of the
newest release that has them. With no such release it stops with an error.

nixos/RELEASE.md now covers where each part is, the release rules, the
migration steps, the fixed contract with Pi OS 2.6.4, when a new tarball is
needed, and the known faults. ADR 0039 names migration_v2_url and the
shared tarball.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* chore(nixos): kernel 6.18.60 (Raspberry Pi stable_20261103), update nixpkgs and nixos-hardware

The kernel tag and hash are fixed in nixos/pkgs/pifinder-kernel.nix, so
the kernel changes only when that file changes. nixos-hardware now
follows our nixpkgs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(nixos): btrfs checksum modules in the initrd for kernel 6.18

The forced initrd module list also removes the modules that the NixOS
btrfs module adds. Kernel 6.12 had crc32c built in. In 6.18 it is the
module crc32c-cryptoapi, so stage 1 could not mount the btrfs root.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* docs(nixos): kernel update steps and the initrd module fault

* docs(nixos): use git commands in the release guide

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…122)

nixos-hardware now sets sdImage.populateFirmwareCommands with mkForce.
Our value had the same priority, so both scripts ran. Its read-only
copies made our copy fail with Permission denied. mkOverride 40 keeps
only firmwareCommands.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Brings in 24 commits of brickbots main: the catalog import fixes
(brickbots#671 to brickbots#694), the Named Stars catalog (brickbots#695), the names view of the
object list (brickbots#696), the Pi OS side of the migration (brickbots#657), the release
workflow (brickbots#658), the OLED SPI clock (brickbots#701) and CI changes.

Conflicts and their resolution:
- Pi OS migration files (migration_gate.json, migration_progress,
  migration_progress.c, nixos_migration_calc.py): nixos keeps them
  deleted. They belong to the Pi OS line.
- noxfile.py, requirements_dev.txt: nixos keeps them deleted. The flake
  dev shell and uv2nix replace them.
- ui/software.py, tests/test_software.py, sys_utils.py, main.py: nixos
  keeps its own software screen. Its keep_awake and on_battery are the
  same feature as upstream's. The migration UI stays out of nixos.
- catalog_imports: upstream's code. The parser moved to designations.py,
  so the local copy of parse_designation goes. The Perek-Kohoutek loader
  stays and runs before the Named Stars loader.
- catalogs.py: upstream's NAME_MODE_CATALOGS. The T9 tables stay in
  catalog_arrays.py.
- object_details.py: upstream's listing index (brickbots#678), with a search on
  the listing_key column for an ObjectSequence.
- obslist.py and its tests: the name index of nixos (resolvers) with
  upstream's ambiguous designation check.
- tests/test_ui_modules.py: upstream's comet retry stub, the catalog
  build of nixos (no background loader).
- docs/ax/catalog.md, CONTEXT.md: text of both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The three commits of brickbots release that main lacks: the back piece
with edge inserts, the BOM warning about the Adafruit 2472 BNO055 board
(brickbots#641) and the 2.6.2 pause of version.txt. The tree of main has the
same content already. version.txt stays 2.6.3.

Fixes for the merge of upstream main:
- object_details.py: the listing index in the format of ruff 0.4.8.
- star_identity.py: load_hipparcos copies the position columns. With
  copy-on-write, pandas gives a read-only array, and the fill of the
  unsolved positions failed.
- test_obslist_designations.py: the fake catalogs give iter_names, as
  the name index of nixos reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fixes

The committed database was built before the catalog import changes of
upstream main. It now holds the Named Stars catalog (578 stars) and the
import fixes (brickbots#681, brickbots#683, brickbots#685, brickbots#691, brickbots#692, brickbots#694, brickbots#695). EGC has 102
objects (was 91) and SaM 2157 (was 2162). IC 1805 is now one object with
Sh2 190 and Lyn 77, of type cluster with nebula. The catalog data test
has the new values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mrosseel and others added 12 commits November 18, 2026 04:58
The Harris and Lynga loaders parsed their float columns as float32, and
arp.sqlite stores its magnitudes as float32 values, so the database held
values such as 6.46999979019165 for M 2. The Harris and Lynga loaders now
parse float64, and the Arp loader rounds to two decimals. The database is
rebuilt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The boot splash drove both panels at 40 MHz. Newer 1.5" SSD1351 panels
stay blank at 40 MHz, which is about twice the datasheet clock. brickbots#701 set
the app to 20 MHz for this panel.

The splash now uses the clock of the detected panel: 20 MHz for the
SSD1351 and 40 MHz for the SSD1333, the same as displays.py.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…se guide (#132)

- release.yml: for a fork source, create the release tag on the built commit through the GitHub API. If the API refuses, warn and continue.
- nixos/RELEASE.md: point to release_notes/RELEASE-PLAYBOOK.md, start releases from brickbots main, add a beta example, the 90-day rule and a tag check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings brickbots#697 (rebuilt catalog database), brickbots#703 (an alignment point for each
telescope), brickbots#704 (Obs Lists picker layout) and brickbots#706 (migration progress
panel type).

- main.py: the reload_config handler sets the target pixel of the active
  telescope. nixos has no catalogs_fully_loaded handler.
- text_menu.py: _draw_item_text draws with draw_text_cached.
- pifinder_objects.db: rebuilt from a fresh file with
  python -m PiFinder.catalog_imports.main. Two builds with different
  PYTHONHASHSEED values are byte-identical. 23 catalogs (main's 22 and PK).
- test_obs_list_layout.py: records the draw_text_cached rows.
- test_target_pixel_wiring.py: stubs the lazy timezonefinder module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Hold SQUARE at power-on: pifinder-recovery-hold.service scans the keypad and starts the app with only the Software screen (Rollback first).
- A rollback pick becomes the boot default. A recovery app that fails its health check rolls back to the newest confirmed generation.
- The trial rollback finds a confirmed camera specialisation (#136).
- ADR 0038, troubleshooting and user guide describe recovery mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- user guide: Update Software describes the NixOS Software screen, with three rev4 screenshots
- docs/source/nixos_migration.rst: the move to PiFinder software 3
- ADR 0022 §4.3: the per-frame optical-black pedestal; the separate ADR is removed
- ADR 0039 and 0041: status lines describe what is built
- delete version.txt and docs/ax/nixos/HANDOVER.md
- the API reports the version from utils.get_version()
- pf_remote.py finds cedar-detect-server on the PATH of the dev shell

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e failure (#139)

A tester's update failed with "Update failed!". After the restart the
old build did not start, and the update log was lost. A full SD card can
cause both faults, and the device did not report it.

- The upgrade compares the free space with the download before it starts.
  When the space is too small, it deletes the unused store paths, then the
  old generations except the two newest (not in recovery mode). If the
  space stays too small, the status is "nospace <needed> <free>" and the
  Software screen shows "SD card full" with both sizes.
- A "No space left on device" from the build or a later step gives the
  same status. The upgrade then deletes what the failed download left.
- The upgrade keeps the status, the error and the nix log tail of a
  failure in /var/lib/pifinder/last-upgrade-failure.json. The log download
  of the web interface contains it.
- pifinder-space-guard runs before pifinder.service. Below 256 MiB free it
  deletes the unused store paths, so that the app and recovery mode can
  start. VM test: nixos/tests/space-guard.
- The watchdog advisory adds "SD CARD FULL" when the card is full.
- Recovery mode: the Software screen reads the WiFi mode from
  NetworkManager (the wifi_status.txt in the store is always "Client"),
  and the Rollback list shows the generation that boots now with ">".

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The device listed each directory in /nix/store as a possible base. A
directory that the nix database does not list is a partial copy, for
example after a power loss during a download. The delta server makes
the patch against the cache copy of that path, so the patch does not
apply to the partial copy: zstd stops with "Data corruption detected"
and the path downloads in full.

The prefetch now asks nix-store --check-validity for the candidate
bases, in one call, and offers only the valid ones. When the check
cannot run, no base is offered and all paths download in full.

delta-e2e, bb6d2cf to f3104f0, with a test store that has partial
paths: the old code failed on 15 of 50 patches, this code on none.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…t the app (#140)

* feat(nixos): one diagnostics record for each failure, readable without the app

A tester's PiFinder did not start after a failed update. The web log
download runs in the app, the journal is in RAM, and for a confirmed
generation the watchdog wrote nothing. So no log was left.

pifinder-diagnostics (nixos/pkgs/diagnostics.nix) writes one text record:
the event, the generation, the free space, the state of pifinder.service,
an attachment and the end of the journal. Each failure path calls it:

- an update failure and a full card (nixos_upgrade, with the error and
  the nix log tail); a missing build or cache writes no record
- a trial rollback and a recovery failure (watchdog)
- a confirmed generation whose app does not start (watchdog)
- a boot counter fallback (watchdog)
- the space guard, when it freed space

The record goes to /var/lib/pifinder/diagnostics, to PiFinder_data/
diagnostics on the Samba share (as the pifinder user), and as
PIFINDER-DIAG.TXT to the FAT partition, which any PC with a card reader
shows. Each place keeps the 5 newest. A record is at most 1 MiB, and the
script always exits 0. Recovery mode shows the newest record as
"Last fault", and the web log download contains the records.

This replaces the failed-boot logs of the watchdog and the
last-upgrade-failure.json of #139. VM test: nixos/tests/diagnostics.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: tidy the diagnostics review faults and name the NixOS SMB share

- software.py: the attribute that holds the recovery fault line is
  _last_fault. It had the same name as the function _fault_line.
- test_recovery.py: the imports are at the top of the file. The test of
  recovery mode now checks the fault line that active() sets.
- The NixOS Samba share is PiFinder_data, not shared. connectivity.rst
  names both: software 2.x uses shared. The migration page keeps shared,
  because the backup is made on 2.x.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(nixos): harden diagnostics on full card, keep FAT history, filter nix progress

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
mrosseel and others added 2 commits December 5, 2026 19:11
The weekly nix-gc timer can start the garbage collection during an
observation and slow the app. The full system has no timer now. The
upgrade service collects garbage after each update and when it needs
space. pifinder-space-guard collects garbage at boot when the card is
almost full.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…B1) (#145)

* docs(adr): revise ADR 0040 data packs: differ shards, pinned pack list, adoption by reflink

ADR 0040 was decided on 2026-09-26 and not built. This rewrite keeps the
packs outside the system closure and changes how they work:

- Each system build pins its pack versions in /etc/pifinder/packs.json.
- The differ (ADR 0036) patches a changed shard. The Attic chunk helper
  is dropped.
- The catalog image pack is POSS only: 40 shards of about 102 MiB.
- A migrated card adopts its kept images by reflink copies.
- A lean card downloads a pack only after "Get".
- "Off" deletes only the paths of the pack.

ADR 0036, 0037 and 0039, the NixOS glossary and Part B of the plan follow.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(nixos): catalog image shards and pack (ADR 0040, B1)

Generic data pack tooling, with one PackSpec per pack:

- python/PiFinder/data_packs.py: the shard rule. A top-level folder is a
  group, and a file goes to a shard by the sha256 of its path in the
  group. The catalog images use 10 folders, 4 shards each, POSS only.
- python/scripts/make_pack_shards.py: writes the shard tarballs and the
  JSON list with the NAR hash of each shard.
- nixos/pkgs/data-pack.nix: fixed-output shards and the joined pack. The
  flake output dataPacks has one entry per JSON file in nixos/pkgs/packs.
- .github/scripts/push_packs.sh: builds and pushes a pack only when no
  cache has it. Releases push to pifinder-release, PR builds to pifinder.

The 40 catalog image shards (4.0 GB, 17,614 files) are on
files.pifinder.eu/catalog-images. No device reads the pack yet.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(adr): ADR 0040 gives the reason for no full collection without a time

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testable Ready for testing via PiFinder software update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants