fix(postinstall): repair reviewed source builds and kernel choices
Some checks are pending
ci / test (push) Waiting to run

This commit is contained in:
Phoebus 2026-10-09 05:24:39 -07:00
parent 00df467a41
commit a6ccae21ef
19 changed files with 2238 additions and 107 deletions

View file

@ -5,6 +5,45 @@ this file is the curated, human-readable summary.
## Unreleased — Fast defaults with user-controlled source builds ## Unreleased — Fast defaults with user-controlled source builds
- **Mozilla source-codec build fix (2026-10-08).**
Firefox ESR 153.4.0 failed after 7852 seconds: libgkcodecs exported missing
system-libaom symbols (Mozilla bug 2063808, fixed upstream in branch 156).
The working firefox-bin remained installed. Source-policy USE settings now
select the supported bundled AV1 codec only for Firefox/Thunderbird below
version 156; binary bootstrap policy stays separate. The clean Firefox conversion passed in 9674 seconds with data/default/fallback
preservation; the native browser rendered JavaScript and decoded AV1 video.
Thunderbird conversion also passed in 8710 seconds; LibreOffice passed in
15005 seconds. Both native normal-user windows and clean exits passed on
October 9; Writer accepted an edit and undo. Calibre remains compiling.
All 961 Rust tests, fmt/Clippy and
static/dynamic release builds pass. The rebuilt local ISO includes this fix
and passed two no-target-disk UEFI boots using read-only virtio-SCSI CD.
- **VM harness recovery:** Serial Ctrl+C now reaches the guest through an
explicit QEMU stdio chardev with signal handling disabled, preventing timeout
recovery from terminating QEMU. The 22 harness tests and recovered generic
boot pass; the monitor's reserved Zsh variable was also corrected.
- **Post-install chooser fixes and acceptance (2026-10-07/08, in progress).**
Welcome buttons now respond to Enter/Return and scroll with keyboard focus.
Source/kernel choices prepare a deterministic review and require explicit
approval. Exact source builds install dependencies first while retaining the
original application during compilation. Fixed scoped dependency USE flags
and normal-user snapshot history access. GIMP conversion and native graphical
launch passed in the freshly installed encrypted VM. The actual balanced
build exposed private kernel fragment permissions; fixed those modes and
completed the corrected build, balanced source boot, live-kernel guard and
generic fallback boot. Measured scratch exceeded the original estimate, so
kernel reviews now recommend 25 GiB. Kernel switching now
requires the generic running kernel, pins its default before hooks, and
removes stale named source aliases. Remaining compilation/boot acceptance
and the final ISO are pending; no completed release is claimed. Hidden native
desktop compatibility entries preserve existing binary/Flatpak/versioned
Office IDs without editing user preferences. Original binary Writer failed
to map a window with automatic backend selection; GTK3 rendered correctly,
so the session now selects GTK3 and publishes it to user services. A fresh
session subsequently opened Writer through its normal desktop entry.
- **Fresh live ISO and VM cleanup (2026-10-06).** Removed 33 disposable qcow2 - **Fresh live ISO and VM cleanup (2026-10-06).** Removed 33 disposable qcow2
images, freeing about 80 GiB. Rebuilt the live root filesystem and static images, freeing about 80 GiB. Rebuilt the live root filesystem and static
binaries so the ISO includes the latest package list, desktop, and `sys` binaries so the ISO includes the latest package list, desktop, and `sys`

View file

@ -3,6 +3,99 @@
Rolling note between work sessions. **Update this file before you finish**, then Rolling note between work sessions. **Update this file before you finish**, then
commit it. It should be short and current; use `git log` for detail. commit it. It should be short and current; use `git log` for detail.
- **Post-install acceptance in progress (2026-10-09 12:11 UTC):** Finish all
five real application conversions/native windows and both source-kernel
compile/install/boot/fallback tests, then deliver the updated local ISO,
remove the disposable VM after exporting evidence, commit and push.
**Verified:** fresh encrypted install/generic boots; welcome Enter/Return,
keyboard scroll, all seven real bridge reviews and cancelled-review safety;
GIMP source 3.2.4 conversion/native window; balanced 6.18.54 GUI-approved
compile in 18584 seconds, correct suffix/config/modules, source boot,
source-running build refusal and persistent generic fallback. Balanced scratch
peaked at 19.6 GiB; reviews now recommend 25 GiB. Firefox clean conversion
passed in 9674 seconds with source VDB, old binary removal, user-data/default
preservation and generic image preservation. Native normal-user launch through
the preserved desktop ID shows JavaScript and bundled AV1 video PASS in
run 141501Z, `shots/05-05-native-firefox-js-av1-rendered.png`; closed normally.
**Active:** generic GUI run `gui-desktop-20261008T194155Z-5c8973ad` passes
kernel/systemd/Wayland. Persistent controller user unit
`phoebus-postinstall-controller-recovery2`, log
`/var/tmp/phoebus-postinstall-controller-recovery.log`. Guest unit
`phoebus-postinstall-apps-recovery2` runs Thunderbird, then LibreOffice and
Calibre, stopping on first failure. Guest state/logs:
`/var/tmp/phoebus-app-sequence.status`, `/var/tmp/source-build-APP.{log,rc}`.
Do not start tuned or replace binaries during that worker. Guest 12 GiB/12
CPU; QtWebEngine capped at two jobs, later tuned at ten. Thunderbird conversion
passed in 8710 seconds, LibreOffice in 15005; both native normal-user windows
and clean exits passed October 9. Writer edit/undo passed. Calibre QtWebEngine
is at ~15942/23519 after ~35336 seconds; guest 27 GiB/host 31 GiB free.
Original Thunderbird
profile is in `.config/thunderbird`; Calibre's real guide/library is in
`~/Calibre Library`. Calibre must open that existing EPUB after conversion.
Controller `/var/tmp/phoebus-postinstall-control.py` uses request/result JSON
in `/var/tmp/phoebus-postinstall-control`; latest manual ID 527, monitor IDs
use nanoseconds. Helper `/var/tmp/phoebus-postinstall-request.py` reads JSON
stdin. Shell markers must split their echo: `echo MARKER-$(printf DONE)`.
Auth/UI-auth use internal fixtures; never print credentials. Compact host
monitor `/var/tmp/phoebus-postinstall-monitor-apps.py` runs in exec session
92167; poll with write_stdin up to 45 seconds. Restart it if the backend loses
that session. Variables must be task-specific: Zsh `status` is read-only.
**Current payload deployed during idle recovery:** sys SHA-256
`73c2bf6132eb7e69a7984c7470f61fa73ad67072a7655ef560720ce7e5047173`,
installer `2cd3cb6c14f6f2900979727c02ac5382555da60054a473991d96951f0cc5bfa5`,
transition bundle `20208cc5689aa8a778b0d6db752946737e32d4825e95aeb0fb8c11d3d855a876`.
Fmt/Clippy/all 961 tests/static/dynamic releases pass, logs
`/var/tmp/phoebus-postinstall-codec-*.log`; VM harness 22 tests/ShellCheck pass.
The source-only codec fix scopes -system-av1 to Firefox/Thunderbird below 156
(Mozilla bug 2063808); both fresh .mozconfig files confirm without-system-av1.
Temporary keepwork was removed after a stale-config retry; do not restore it.
**Latest ISO:** `installer/live/phoebus-installer-amd64-postinstall.iso`,
SHA-256 `b0e63a8d3ed9b82fab08a561522cb9b7b36ddad24ef61bb8493641cf5523a92a`.
Exact embedded binaries/QML/GTK3 setting pass, as do two fresh-vars,
no-target-disk UEFI boots through a read-only virtio-SCSI CD (173910Z,
174001Z), reaching graphical.target/live login after normal menu selection.
AHCI CD attempts failed/stalled in firmware; baseline control also stalled;
EFI files match byte-for-byte. Do not claim the AHCI cause or physical tests.
Packing scratch removed; rootfs tar retained. Two obsolete generated ISO
copies removed, freeing 3289325568 bytes; host free ~36 GiB. Older verified
ISO retained. No formal tag/latest.iso publication: CI gate remains NotRun.
**Interrupted evidence:** old generic run 074853Z was externally killed
during Firefox. Run 141501Z ends PASS=12/FAIL=2 after the new monitor used
reserved `status`, preventing its marker; Ctrl+C recovery killed QEMU.
Its earlier Firefox acceptance remains valid, no clean poweroff claimed.
gui-driver now uses stdio chardev signal=off. Read-only ISO run 194424Z
confirms Ctrl+C no longer terminates QEMU, but left Utilities selected and
did not finish live boot; not another ISO boot pass. Thunderbird interrupted
log was preserved, its exact work directory cleaned and remaining worker
restarted. Firefox source VDB persists, original Thunderbird binary intact.
**Next:** finish remaining conversions and native windows; approve tuned
through actual GUI/polkit, compile/verify configuration and actual modules,
one-shot boot tuned and verify generic default fallback. Kernel boot script
now includes source .config/module checks. Balanced config/module manifests
saved in /var/tmp for export. Reboot helper
`/var/tmp/phoebus-postinstall-reboot-service.py CHOICE` requires current clean
poweroff, preserves stopped OVMF_VARS and starts a persistent controller.
Set the tuned one-shot entry before invoking it. Keep generic persistent.
HTTP user unit `phoebus-postinstall-http`, port 8000, serves
`/var/tmp/phoebus-postinstall-serve`. Native launcher in guest is
`/var/tmp/launch-native-app-codec-fixture.py`; HTML/AV1 files already copied.
Export fixture `export-source-evidence.sh` uploads only logs/atoms/boot
entries/aliases/config manifests to port 8001; persistent receiver user unit
`phoebus-postinstall-evidence-receiver` writes
`/var/tmp/phoebus-vm/postinstall-source-acceptance-evidence/postinstall-evidence.tar.gz`.
Export/verify before deleting the sole qcow2
`/var/tmp/phoebus-vm/disks/postinstall-choices.qcow2`. Finalize ISO/checksum,
docs/status/changelog, conventional commit and push. Rebuild ISO only if
further production code changes; the serial-harness fix is outside its payload.
- **Fresh ISO and VM cleanup (2026-10-06):** Cleared all 33 disposable qcow2 - **Fresh ISO and VM cleanup (2026-10-06):** Cleared all 33 disposable qcow2
images from `/var/tmp/phoebus-vm/disks` (about 80 GiB freed), retaining the images from `/var/tmp/phoebus-vm/disks` (about 80 GiB freed), retaining the
small test evidence files. `make doctor` and `make check` pass. The live small test evidence files. `make doctor` and `make check` pass. The live

View file

@ -8,6 +8,29 @@ Truthful implementation/verification matrix. Vocabulary:
- **Hardware verified** — exercised on real hardware. - **Hardware verified** — exercised on real hardware.
- **Not verified** — do not claim it works. - **Not verified** — do not claim it works.
## Post-install source choices — acceptance in progress (2026-10-09)
- **VM verified:** fresh encrypted installation and generic kernel boots;
welcome keyboard navigation; all five application and two kernel reviews;
cancelled-review safety; GIMP/Firefox/Thunderbird/LibreOffice source
conversions with data/default/fallback preservation and native normal-user
launches. Firefox JavaScript and bundled AV1 playback pass; Writer edit/undo
and clean exits pass. Preserved binary/versioned Office desktop IDs launch
the native replacements. Balanced source compile/install, source boot,
source-running build refusal without mutation, and generic fallback boot pass.
- **Fixed and unit tested:** history metadata permissions, scoped source-build
dependencies and Mozilla codec policy, exact source selection, separate kernel
names, Portage-readable fragments, generic pinning before hooks and obsolete
named source-alias removal. Tuned replacement still needs actual coverage.
- **Local ISO verified:** current postinstall ISO includes all product changes,
passes embedded binary/QML/settings checks and two fresh-vars, no-target-disk
UEFI boots using read-only virtio-SCSI CD. AHCI firmware attempts failed or
stalled; physical boot remains unverified. Formal release CI gate is NotRun.
- **Pending:** Calibre conversion/library/viewer (QtWebEngine compiling), tuned
compile/replacement/source/fallback boots, final evidence export and VM
removal, canonical ISO delivery, commit and push. The marked disposable VM
remains active for these tests.
## Proven baseline (do not regress) ## Proven baseline (do not regress)
A complete installation in a disposable UEFI VM, booted with the ISO detached: A complete installation in a disposable UEFI VM, booted with the ISO detached:
@ -445,9 +468,9 @@ A fresh install with these defaults is not yet verified.
| Fast-default Flatpaks (Calibre/GIMP/Flatseal, system-wide, target-only) | yes | yes (install/verify/provisioning; fail-closed on missing app) | yes (installed in target root, verified in `/var/lib/flatpak/app/` and `/var/lib/phoebus/flatpaks-installed`) | no | | Fast-default Flatpaks (Calibre/GIMP/Flatseal, system-wide, target-only) | yes | yes (install/verify/provisioning; fail-closed on missing app) | yes (installed in target root, verified in `/var/lib/flatpak/app/` and `/var/lib/phoebus/flatpaks-installed`) | no |
| Fast `-bin` defaults (firefox-bin/libreoffice-bin/thunderbird-bin, fail-closed) | yes | yes (atoms, policy, binary-capability refusal) | yes (installed identities verified in Gentoo VDB on detached boot) | no | | Fast `-bin` defaults (firefox-bin/libreoffice-bin/thunderbird-bin, fail-closed) | yes | yes (atoms, policy, binary-capability refusal) | yes (installed identities verified in Gentoo VDB on detached boot) | no |
| Single generic kernel default (no second generic kernel) | yes | yes (guard + tuned path keeps the fallback) | yes (existing boot path unchanged) | no | | Single generic kernel default (no second generic kernel) | yes | yes (guard + tuned path keeps the fallback) | yes (existing boot path unchanged) | no |
| User-initiated source builds (`convert_to_source`) | yes | yes (table incl. thunderbird, review, build-before-remove, Brave/unknown refusals) | no (no conversion journey run in a VM) | no | | User-initiated source builds (`convert_to_source`) | yes | yes (table incl. thunderbird, review, build-before-remove, Brave/unknown refusals) | partial (GIMP/Firefox/Thunderbird/LibreOffice real source conversions, data/default/fallback preservation and native windows pass; Firefox JavaScript/AV1 playback and Writer edit/undo pass; Calibre pending) | no |
| Tuned-kernel build (`build_tuned_kernel`, separate BLS, fallback kept) | yes | yes (refusal without fallback, entry creation, default never blind-switched) | no (same long build; VM attempt recorded under the balanced row) | no | | Tuned-kernel build (`build_tuned_kernel`, separate BLS, fallback kept) | yes | yes (refusal without fallback, entry creation, default never blind-switched) | pending (real reviews pass; tuned compile/install/source boot still required) | no |
| Balanced source kernel (`build_balanced_kernel`, broad hardware, bin fallback) | yes | yes (plan/fragment/review, refusal without fallback, separate `phoebus-balanced.conf`, default untouched; two VM-found bugs fixed: exact VDB match, `loader/entries` path) | **started, not completed** (disposable VM 2026-09-29: full distribution-config kernel build exceeded 3 h with 10 jobs, `RC=124`, no system change; needs a multi-hour window) | no | | Balanced source kernel (`build_balanced_kernel`, broad hardware, bin fallback) | yes | yes (plan/fragment/review, refusal without fallback, separate `phoebus-balanced.conf`, default untouched; two VM-found bugs fixed: exact VDB match, `loader/entries` path) | yes (2026-10-08 real GUI-approved build in 18584 seconds; correct 6.18.54 balanced suffix/config/modules, source boot, running-source build refusal and persistent generic fallback pass) | no |
| Installed first-login welcome (once per user, reopenable, non-blocking) | yes | yes (assets, explicit Mango session launch, QML actions, DMS seed) | fresh candidate installed desktop 30/30; screenshot inspected, Escape creates seen marker | no | | Installed first-login welcome (once per user, reopenable, non-blocking) | yes | yes (assets, explicit Mango session launch, QML actions, DMS seed) | fresh candidate installed desktop 30/30; screenshot inspected, Escape creates seen marker | no |
| Install metrics (time, download, peak disk, installed size) | yes | yes (report rendering; orchestration hooks) | yes (Run 13 recorded 588 compile times into target metrics) | no | | Install metrics (time, download, peak disk, installed size) | yes | yes (report rendering; orchestration hooks) | yes (Run 13 recorded 588 compile times into target metrics) | no |
| XWayland / polkit agent / kitty / wofi | yes | no | polkit agent and kitty launched in visible VM; XWayland and wofi not separately verified | no | | XWayland / polkit agent / kitty / wofi | yes | no | polkit agent and kitty launched in visible VM; XWayland and wofi not separately verified | no |
@ -823,3 +846,26 @@ A fresh install with these defaults is not yet verified.
A tampered-*signature* VM case is not feasible without a network MITM (the A tampered-*signature* VM case is not feasible without a network MITM (the
key is fixed and Gentoo serves authentic DIGESTS); the bad-signature key is fixed and Gentoo serves authentic DIGESTS); the bad-signature
branch is unit-tested. branch is unit-tested.
### 2026-10-08 Mozilla conversion failure and scoped codec fix
Firefox ESR 153.4.0's real source build failed after 7852 seconds with undefined
libgkcodecs libaom exports; the original firefox-bin stayed installed. This
matches [Mozilla bug 2063808](https://bugzilla.mozilla.org/show_bug.cgi?id=2063808),
fixed in branch 156. Source-only USE settings choose bundled AV1 on affected
Firefox/Thunderbird versions below 156. Portage's real pretend output confirms
-system-av1 on ESR 153.4.0. The clean Firefox conversion retest passed in 9674 seconds: ESR 153.4.0 source
VDB, old binary removal, preserved user-data hashes/default desktop IDs and
unchanged generic kernel images. Its native normal-user launch through the
preserved desktop entry rendered the local JavaScript and bundled AV1 video
tests as PASS (GUI run 141501Z, shot 05-native-firefox-js-av1-rendered).
Thunderbird conversion passed in 8710 seconds and LibreOffice in 15005 seconds.
Both native normal-user launches through the preserved desktop entries passed
in generic GUI run 194155Z on October 9; Writer accepted an edit and undo.
Both applications closed normally, with no remaining application process.
Calibre is still compiling QtWebEngine. Fmt, Clippy,
all 961 workspace tests and static/dynamic release builds pass. The updated local
ISO includes the fix (SHA-256
`b0e63a8d3ed9b82fab08a561522cb9b7b36ddad24ef61bb8493641cf5523a92a`)
and passed two no-target-disk UEFI boots with a read-only virtio-SCSI CD. AHCI
CD attempts failed or stalled in firmware; physical firmware remains unverified.

View file

@ -3,6 +3,83 @@
This records the first successful end-to-end install and boot of Phoebus OS This records the first successful end-to-end install and boot of Phoebus OS
against a disposable qcow2 disk. No physical disk was ever touched. against a disposable qcow2 disk. No physical disk was ever touched.
## 2026-10-07/08 Installed post-install acceptance — ongoing
Fresh encrypted Gentoo installation `serial-install-20261007T122805Z-da765f3d`
passed five checks; detached installed generic boot
`serial-boot-20261007T155220Z-1d9415a3` passed four. Installed GUI run
`gui-desktop-20261007T155403Z-dc002f64` verified both welcome actions and all
seven real bridge reviews after scoped dependency fixes. History metadata
permissions were fixed and retested as the installation user.
GIMP's approved source build completed in
`gui-desktop-20261007T162413Z-516c7589`: 13 signed binary dependencies, then
local GIMP 3.2.4 compilation. The original Flatpak stayed installed and opened
while compilation ran. Verification passed source VDB, original Flatpak
removal, unchanged generic images, preserved data and native desktop default.
The subsequent serial native launch timed out, so that driver overall recorded
22 passes and two harness failures. A fresh graphical boot
`gui-desktop-20261007T171009Z-a8188ad4` successfully opened native GIMP 3.2.4
from DMS spotlight (`05-05-native-gimp-ready.png`).
The first balanced compilation generated an unbranded release: Portage could
not read root-only `/etc/kernel/config.d`. Cancelled that build before install,
verified generic images/boot, repaired configuration modes, and repeated GUI
review/approval. The corrected build began around 2026-10-08 02:38 UTC; actual
build/modprep configurations include `-gentoo-dist-phoebus-balanced` and the
build log confirms the fragment was merged. Original
Firefox/Thunderbird 157.0.1 graphical launches also passed and seeded real
profiles for later conversion checks. The corrected balanced build completed
in 18584 seconds: source VDB, preserved generic image digests and all boot-entry
files pass. Build scratch reached 19.6 GiB; the kernel review now recommends
25 GiB. Source boot `gui-desktop-20261008T074624Z-5e1b43be` passes; its running-
kernel guard refused another build without VDB/config/default changes. Clean
poweroff and persistent generic fallback in
`gui-desktop-20261008T074853Z-fd35d9f2` pass. Four application conversions are
now running sequentially, starting with Firefox. Tuned build/boots and final
ISO acceptance remain pending. In the fresh generic session, original Writer
opened through its desktop entry without a per-launch GTK override; user
systemd environment includes SAL_USE_VCLPLUGIN=gtk3. Screenshot
`04-writer-fresh-session-ready.png` records its window.
## 2026-10-07 post-install build chooser — UI smoke test, installation in progress
- A read-only live VM (`gui-gui-20261007T130820Z-cfc6e979`, no writable
disk) loaded the installed welcome QML and the updated Assistant chooser.
Its Debian live environment is **not** evidence of Gentoo compilation or
installed-system execution. The separate encrypted Gentoo installation is
still running in `serial-install-20261007T122805Z-da765f3d`.
- Found and fixed a real keyboard defect: the welcome advertised Enter, but
Qt's Button did not activate on Return. Explicit Return/Enter handlers now
open both application and kernel choosers. Keyboard focus also scrolls the
kernel button into view on the 600-pixel welcome window.
- Inspected screenshots `07-source-welcome-enter-settled`,
`08-kernel-button-keyboard-scroll`, `09-kernel-welcome-enter-fixed`,
`10-keep-prebuilt-kernel`, `12-balanced-kernel-selection` and
`13-tuned-kernel-selection` under that run's `shots/` directory. Application
selection reached GIMP, the kernel popup listed prebuilt/balanced/tuned, and
keeping the prebuilt kernel started no package action. The preview VM was
stopped after these checks.
- Actual Gentoo review/approval, conversion, compiled-kernel boot and fallback
tests remain pending. Do not treat this smoke test as completed acceptance.
## 2026-10-08 Updated post-install ISO smoke test
The local candidate `installer/live/phoebus-installer-amd64-postinstall.iso`
contains the latest static installer and `sys`, both Assistant QML files, and
GTK3 LibreOffice session setting. Extraction verified exact binary hashes:
`sys` `cc850ef20737275942c90281e01bd2c4f26b0e1d6197713146d4ecb9f746d1f8`,
installer `184ba0ee912e240fe80d39abd3b7294550a2a879c83a502ed886ee158bbc9695`.
ISO SHA-256:
`377c5fa376ac96a9169f101b32a2a20808350ea3dc3282597765860deba6004c`.
xorriso reports BIOS and UEFI entries. Disposable no-target-disk UEFI run
`postinstall-iso-smoke-20261008T045549Z` reached the normal live menu; selecting
its highlighted normal entry with Enter reached `graphical.target` and
`phoebus-live login:`. This verifies selected-entry boot, not automatic menu
countdown timing. An earlier smoke attempt was interrupted at the menu to
add screen capture; it is not a passing run. Installed source conversions and
kernel acceptance are still running; this candidate is not a formal release.
## 2026-10-06 Fresh ISO UEFI boot smoke test ## 2026-10-06 Fresh ISO UEFI boot smoke test
After removing 33 disposable qcow2 images, the live rootfs was rebuilt with After removing 33 disposable qcow2 images, the live rootfs was rebuilt with
@ -1464,3 +1541,135 @@ Disposable 80 GiB qcow2 `phoebus-headless-80g.qcow2`, 8 vCPU/8 GiB, headless
the verified gate. The tunnel needed `settimeout(None)`: `create_connection` the verified gate. The tunnel needed `settimeout(None)`: `create_connection`
leaves its timeout on the socket and killed replies slower than 30 s leaves its timeout on the socket and killed replies slower than 30 s
(curl exit 52). (curl exit 52).
## 2026-10-08: interrupted application build recovery and updated local ISO
The generic GUI run `gui-desktop-20261008T074853Z-fd35d9f2` was externally
interrupted during Firefox source compilation at 08:43 UTC. Its individual
boot checks passed, but it has no final clean-poweroff manifest. Recovery run
`gui-desktop-20261008T141501Z-d370eb0e` passed generic boot/systemd and reached
Mango/DMS. Original firefox-bin remained installed. Controller/HTTP and guest
sequential conversion worker now use persistent systemd transient services.
Firefox work recovery uses a temporary, scoped Portage keepwork environment;
remaining conversions/native GUI/tuned acceptance are still pending.
Latest code passed fmt, Clippy, all 961 workspace tests and static/dynamic
release builds. Local ISO SHA-256:
`0e2329b24b94f7db356525b672bbaecbcb03d5c2e41750448e1714c7f0b0988b`.
Extracted sys/installer/QML bytes match the latest build/source files, and
GTK3 Mango session setting plus BIOS/UEFI boot entries pass inspection.
No-target-disk UEFI run `postinstall-iso-smoke-20261008T142940Z` passed
`graphical.target` and live serial login after Return on the normal live entry.
Earlier smoke retries exited during firmware startup with QEMU -no-reboot;
allowing startup resets passed. This is not automatic-countdown verification.
Verified ISO packing scratch was cleared; cached rootfs tar retained.
### Firefox source-codec failure and retest
Recovery source build failed after 7852 seconds at libgkcodecs linking with
undefined libaom version-script exports. Original firefox-bin was retained,
and the sequential worker stopped before Thunderbird. Failed log is kept in
`/var/tmp/source-build-firefox-system-av1-failed.log` inside the VM. This matches
[Mozilla bug 2063808](https://bugzilla.mozilla.org/show_bug.cgi?id=2063808).
Scoped source USE entries `<www-client/firefox-156 -system-av1` and
`<mail-client/thunderbird-156 -system-av1` select Mozilla's supported bundled
codec on affected branches. Actual Portage pretend confirms -system-av1 on
Firefox 153.4.0. Guest retest unit `phoebus-postinstall-apps-codec-retest` is
running; its complete conversion/native launch results are still pending.
The first codec retry failed in 146 seconds because the temporary keepwork
recovery kept the old .configured state and --with-system-av1 mozconfig. After
capturing that stale setting, removed the test-only recovery env/map, ran
Portage ebuild clean for exactly Firefox 153.4.0, confirmed WORK-CLEAN and
recovery env removed, and restarted the sequence in
`phoebus-postinstall-apps-codec-clean`. This fresh retest is still pending.
### Updated codec-fix ISO — 2026-10-08
Local candidate `installer/live/phoebus-installer-amd64-postinstall.iso`,
SHA-256 `b0e63a8d3ed9b82fab08a561522cb9b7b36ddad24ef61bb8493641cf5523a92a`,
contains the exact statically built installer/sys, current assistant QML and
GTK3 session setting (host evidence
`/var/tmp/phoebus-postinstall-codec-iso-embedded.txt`). Fresh OVMF variables,
KVM/q35, 3 GiB/2 CPUs, virtio graphics/RNG and a **read-only virtio-SCSI CD with no
target disk** booted twice: `postinstall-iso-smoke-20261008T173910Z` and
`postinstall-iso-smoke-20261008T174001Z`. Both selected the normal menu entry
with Return and reached `graphical.target` plus the live serial login. Their
`result.txt`, `serial.log`, `action.txt` and menu screenshot retain evidence.
Earlier AHCI CD attempts failed in firmware loading grubx64.efi with Device
Error or stalled before the menu (171117Z, 171724Z, 173020Z). The older verified
ISO control also stalled before the menu (172322Z). Both images' EFI image,
bootx64.efi and grubx64.efi are byte-identical. The successful SCSI tests verify
this candidate's UEFI boot; they do not establish the cause of the AHCI failure
or verify physical firmware/controllers.
### Firefox clean codec retest and native playback — 2026-10-08
The clean retest finished with `CASE source-build-firefox PASS`, rc 0,
`BUILD_SECONDS=9674` in generic GUI run
`gui-desktop-20261008T141501Z-d370eb0e`. Source Firefox 153.4.0 ESR is installed,
firefox-bin removed, profile/settings hashes and explicit desktop defaults
preserved, and generic fallback images unchanged. Scratch peaked at 8.3 GiB;
the staged application was 333.5 MiB. Both bundled libaom and dav1d compiled.
`gtk-launch firefox-bin.desktop` (preserved native compatibility entry) opened
`/usr/lib64/firefox/firefox` as user phoebus. Screenshot
`shots/05-05-native-firefox-js-av1-rendered.png` shows the local fixture's
JavaScript PASS and bundled AV1 decode PASS with the playing AV1 clip. A later
quit-dialog screenshot shows a changed video frame/time. No browser sandbox
flags were disabled. Closed normally through Ctrl+Q and its confirmation.
User-data preservation is verified before launching; this does not claim
migration of a newer binary profile into the older ESR profile. Thunderbird
started automatically after all Firefox acceptance checks passed.
### Harness serial Ctrl+C recovery — 2026-10-08
A new host progress monitor assigned Zsh's read-only `status` variable; the
command aborted before its marker. The temporary controller's timeout recovery
sent Ctrl+C over QEMU stdio, which terminated QEMU with SIGINT and interrupted
Thunderbird before installation. Run `gui-desktop-20261008T141501Z-d370eb0e`
therefore ends with PASS=12/FAIL=2; its earlier Firefox conversion/native AV1
and balanced evidence remains valid, but no clean poweroff is claimed.
The monitor now uses task-specific variables. The graphical harness configures
`-chardev stdio,id=serial0,signal=off -serial chardev:serial0`, matching
[QEMU's documented signal behavior](https://www.qemu.org/docs/master/system/qemu-manpage.html).
All 22 VM-harness tests pass. A read-only, no-target-disk ISO test
`postinstall-iso-smoke-20261008T194424Z` injected terminal Ctrl+C and confirmed
QEMU remained alive (`serial-interrupt.txt`). That extra test did not finish
normal live boot: Ctrl+C left Utilities selected. It is not a third ISO boot
pass. The earlier two complete SCSI ISO boots remain the candidate boot proof.
Recovery generic boot `gui-desktop-20261008T194155Z-5c8973ad` passes kernel,
systemd and Wayland checks. Firefox source VDB persists, firefox-bin remains
absent, and the original Thunderbird binary is intact. With all compilers idle,
the final codec-fix payload was deployed; guest sys/installer hashes now match
the updated ISO. The interrupted Thunderbird log is preserved, its exact
Portage work directory cleaned, and the remaining three-app sequence restarted
in guest unit `phoebus-postinstall-apps-recovery2`.
### Thunderbird and LibreOffice source/native retests — 2026-10-09
The persistent guest sequence survived overnight in generic GUI run
`gui-desktop-20261008T194155Z-5c8973ad`: Thunderbird source conversion passed
with rc 0, `BUILD_SECONDS=8710`; LibreOffice passed with rc 0,
`BUILD_SECONDS=15005`. Each acceptance script verified the source VDB, old
binary removal, original user-data/default preservation, native compatibility
desktop entry and generic kernel image preservation.
Launching the preserved `thunderbird-bin.desktop` entry opened the welcome
window (shot `03-native-thunderbird-source.png`) as user phoebus with executable
`/usr/lib64/thunderbird/thunderbird`. No email account was configured or mail
sent. Ctrl+Q closed it and the process count became zero.
Launching the preserved `libreoffice25.8-writer.desktop` entry opened native
Writer as user phoebus with executable
`/usr/lib64/libreoffice/program/soffice.bin`. The tip dialog dismissed normally;
a keyboard edit appeared in the document (`05-native-libreoffice-source-edit.png`),
Ctrl+Z undid it and Ctrl+Q closed Writer. No document was saved; process count
became zero. The underlying desktop is visible in shot
`06-native-libreoffice-source-quit.png`.
Calibre remains building QtWebEngine; no success is claimed yet. At 12:11 UTC
it had reached 15942/23519 Ninja steps, with guest 27 GiB and host 31 GiB free.

View file

@ -152,8 +152,8 @@ pub const SOURCE_CONVERSIONS: &[SourceConversion] = &[
app: "calibre", app: "calibre",
installed_from: "com.calibre_ebook.calibre (Flatpak)", installed_from: "com.calibre_ebook.calibre (Flatpak)",
source_atom: "app-text/calibre", source_atom: "app-text/calibre",
expected_time: "typically 10–30 min on 8 vCPUs (measured history varies)", expected_time: "Calibre itself typically 10–30 min; source dependencies such as QtWebEngine can add several hours",
temp_disk: "needs ~8 GiB temporary build space", temp_disk: "allow ~30 GiB temporary build space when QtWebEngine needs compiling",
}, },
SourceConversion { SourceConversion {
app: "gimp", app: "gimp",
@ -347,9 +347,10 @@ pub fn kernel_build_review(plan: &KernelBuildPlan) -> String {
o.push_str( o.push_str(
" Expected work : the full distribution configuration compiles for a long\n\ " Expected work : the full distribution configuration compiles for a long\n\
\x20 time — allow several hours (measured >3 h with 10 build\n\ \x20 time — allow several hours (measured >3 h with 10 build\n\
\x20 jobs on a 10-vCPU VM); >=15 GiB temporary space; keep AC\n\ \x20 jobs on a 10-vCPU VM); >=25 GiB temporary space; keep AC\n\
\x20 power connected. Start it only when the machine can stay\n\ \x20 power connected. Start it only when the machine can stay\n\
\x20 powered: an interrupted build changes nothing.\n", \x20 powered: interrupted compilation keeps the working kernel\n\
\x20 and boot selection. Build dependencies may be installed.\n",
); );
o.push_str(&format!( o.push_str(&format!(
" Boot entry : {} (separate entry; boot-tested first)\n", " Boot entry : {} (separate entry; boot-tested first)\n",
@ -360,8 +361,12 @@ pub fn kernel_build_review(plan: &KernelBuildPlan) -> String {
plan.fallback_atom plan.fallback_atom
)); ));
o.push_str( o.push_str(
" Safety : a failed build or failed boot never replaces the working\n\ " Safety : boot the prebuilt generic kernel before starting a build.\n\
\x20 default; a clear route back to the generic kernel remains.\n\ \x20 The generic entry is pinned as default before compilation.\n\
\x20 A failed build never replaces the working generic default.\n\
\x20 Another source variant can replace an earlier variant's\n\
\x20 modules; obsolete Phoebus test entries are removed.\n\
\x20 A clear route back to the generic kernel remains.\n\
\x20Approval : explicit approval is required before the broker runs.\n", \x20Approval : explicit approval is required before the broker runs.\n",
); );
o o

View file

@ -1014,6 +1014,12 @@ pub fn binrepos_conf(config: &InstallConfig) -> String {
o o
} }
/// Enabled after the desktop dependencies exist, so Pillow's bootstrap
/// freetype/documentation cycle remains broken during the base installation.
/// Mozilla bug 2063808 breaks system-AV1 linking before the 156 branch.
/// Use the supported bundled codec for those versions, including ESR 153.
pub const SOURCE_BUILD_USE: &str = "# Optional native source-build dependencies (after desktop bootstrap)\n# Mozilla bug 2063808: use the bundled AV1 codec on affected branches.\n<www-client/firefox-156 -system-av1\n<mail-client/thunderbird-156 -system-av1\nmedia-libs/libvpx postproc\ndev-python/pillow truetype\ndev-python/pyqt6 quick webchannel\napp-office/libreoffice gtk3\n";
pub fn package_use(config: &InstallConfig, hardware: &HardwareReport) -> String { pub fn package_use(config: &InstallConfig, hardware: &HardwareReport) -> String {
let mut o = String::new(); let mut o = String::new();
o.push_str(&format!( o.push_str(&format!(
@ -1296,6 +1302,7 @@ pub fn balanced_kernel_config() -> String {
o.push_str("# Phoebus balanced-kernel fragment (broad hardware coverage).\n"); o.push_str("# Phoebus balanced-kernel fragment (broad hardware coverage).\n");
o.push_str("# Applied on top of the Gentoo distribution-kernel configuration.\n"); o.push_str("# Applied on top of the Gentoo distribution-kernel configuration.\n");
o.push_str("# Modules (not built-in) so hot-plugged hardware loads on demand.\n"); o.push_str("# Modules (not built-in) so hot-plugged hardware loads on demand.\n");
o.push_str("CONFIG_LOCALVERSION=\"-gentoo-dist-phoebus-balanced\"\n");
o.push_str("\n# USB Ethernet adapters (common chipsets)\n"); o.push_str("\n# USB Ethernet adapters (common chipsets)\n");
for line in [ for line in [
@ -1359,7 +1366,7 @@ pub fn balanced_kernel_config() -> String {
/// single supported, measurable optimization. Required drivers are never /// single supported, measurable optimization. Required drivers are never
/// disabled, so a tuned kernel remains as hardware-tolerant as the balanced one. /// disabled, so a tuned kernel remains as hardware-tolerant as the balanced one.
pub fn tuned_kernel_config() -> String { pub fn tuned_kernel_config() -> String {
let mut o = balanced_kernel_config(); let mut o = balanced_kernel_config().replace("-phoebus-balanced", "-phoebus-tuned");
o.push_str("\n# Tuning (conservative, portable; no -march=native)\n"); o.push_str("\n# Tuning (conservative, portable; no -march=native)\n");
o.push_str("CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y\n"); o.push_str("CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y\n");
o o
@ -1412,6 +1419,9 @@ export QT_QPA_PLATFORM=wayland
export QT_QPA_PLATFORMTHEME=gtk3 export QT_QPA_PLATFORMTHEME=gtk3
export QT_QPA_PLATFORMTHEME_QT6=gtk3 export QT_QPA_PLATFORMTHEME_QT6=gtk3
export GDK_BACKEND=wayland,x11 export GDK_BACKEND=wayland,x11
# LibreOffice's generic X11 backend can fail to map a window under Mango.
# Its GTK backend supports the native Wayland session in both package lanes.
export SAL_USE_VCLPLUGIN=gtk3
export ELECTRON_OZONE_PLATFORM_HINT=auto export ELECTRON_OZONE_PLATFORM_HINT=auto
export _JAVA_AWT_WM_NONREPARENTING=1 export _JAVA_AWT_WM_NONREPARENTING=1
@ -1708,7 +1718,7 @@ fi
if command -v dbus-update-activation-environment >/dev/null 2>&1; then if command -v dbus-update-activation-environment >/dev/null 2>&1; then
dbus-update-activation-environment --systemd \ dbus-update-activation-environment --systemd \
WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_TYPE XDG_RUNTIME_DIR \ WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_TYPE XDG_RUNTIME_DIR \
QT_QPA_PLATFORM PATH >/dev/null 2>&1 || true QT_QPA_PLATFORM SAL_USE_VCLPLUGIN PATH >/dev/null 2>&1 || true
fi fi
# Exactly one shell: DMS, bound to mango-session.target. Verify it actually # Exactly one shell: DMS, bound to mango-session.target. Verify it actually
@ -1953,9 +1963,12 @@ pub const PHOEBUS_ASSISTANT_SCRIPT: &str = r#"#!/bin/bash
# shellcheck disable=SC2016 # shellcheck disable=SC2016
set -u set -u
updates=false updates=false
builds=""
case "${1:-}" in case "${1:-}" in
"") ;; "") ;;
--updates) updates=true ;; --updates) updates=true ;;
--source-builds) builds=source ;;
--kernel-builds) builds=kernel ;;
--apply-updates) --apply-updates)
if ! command -v kitty >/dev/null 2>&1; then if ! command -v kitty >/dev/null 2>&1; then
echo "phoebus-assistant: Kitty is required to show update progress" >&2 echo "phoebus-assistant: Kitty is required to show update progress" >&2
@ -1969,11 +1982,17 @@ case "${1:-}" in
exit "$result" exit "$result"
' '
;; ;;
*) echo "Usage: phoebus-assistant [--updates|--apply-updates]" >&2; exit 2 ;; *) echo "Usage: phoebus-assistant [--updates|--apply-updates|--source-builds|--kernel-builds]" >&2; exit 2 ;;
esac esac
if [ -n "${WAYLAND_DISPLAY:-}" ] || [ -n "${DISPLAY:-}" ]; then if [ -n "${WAYLAND_DISPLAY:-}" ] || [ -n "${DISPLAY:-}" ]; then
if command -v quickshell >/dev/null 2>&1 \ if command -v quickshell >/dev/null 2>&1 \
&& [ -f /etc/xdg/quickshell/phoebus-assistant/shell.qml ]; then && [ -f /etc/xdg/quickshell/phoebus-assistant/shell.qml ]; then
if [ -n "$builds" ]; then
if quickshell ipc -c phoebus-assistant call panel builds "$builds" >/dev/null 2>&1; then
exit 0
fi
PHOEBUS_ASSISTANT_START_TAB=builds PHOEBUS_ASSISTANT_BUILD_KIND="$builds" exec quickshell --no-duplicate -c phoebus-assistant
fi
if "$updates"; then if "$updates"; then
if quickshell ipc -c phoebus-assistant call panel updates >/dev/null 2>&1; then if quickshell ipc -c phoebus-assistant call panel updates >/dev/null 2>&1; then
exit 0 exit 0
@ -2205,9 +2224,9 @@ ApplicationWindow {
Quickshell.execDetached(["/usr/local/bin/phoebus-welcome", "--mark-seen"]) Quickshell.execDetached(["/usr/local/bin/phoebus-welcome", "--mark-seen"])
} }
function openAssistant() { function openAssistant(choice) {
markSeen() markSeen()
Quickshell.execDetached(["/usr/local/bin/phoebus-assistant"]) Quickshell.execDetached(["/usr/local/bin/phoebus-assistant", choice])
root.close() root.close()
} }
@ -2223,6 +2242,17 @@ ApplicationWindow {
implicitWidth: Math.max(implicitContentWidth + 24, 100) implicitWidth: Math.max(implicitContentWidth + 24, 100)
implicitHeight: 36 implicitHeight: 36
padding: 8 padding: 8
Keys.onReturnPressed: event => { event.accepted = true; control.clicked() }
Keys.onEnterPressed: event => { event.accepted = true; control.clicked() }
onActiveFocusChanged: {
if (activeFocus) {
const position = control.mapToItem(welcomeScroll.contentItem, 0, 0);
if (position.y < welcomeScroll.contentY)
welcomeScroll.contentY = Math.max(0, position.y - 12);
else if (position.y + height > welcomeScroll.contentY + welcomeScroll.height)
welcomeScroll.contentY = Math.min(welcomeScroll.contentHeight - welcomeScroll.height, position.y + height - welcomeScroll.height + 12);
}
}
contentItem: Text { contentItem: Text {
text: control.text text: control.text
font.pixelSize: 14 font.pixelSize: 14
@ -2239,6 +2269,7 @@ ApplicationWindow {
} }
Flickable { Flickable {
id: welcomeScroll
anchors.fill: parent anchors.fill: parent
contentWidth: parent.width contentWidth: parent.width
contentHeight: column.implicitHeight + 48 contentHeight: column.implicitHeight + 48
@ -2366,7 +2397,7 @@ ApplicationWindow {
WelcomeButton { WelcomeButton {
id: srcButton id: srcButton
text: "Open assistant to review source builds" text: "Open assistant to review source builds"
onClicked: root.openAssistant() onClicked: root.openAssistant("--source-builds")
KeyNavigation.tab: kernelButton KeyNavigation.tab: kernelButton
} }
} }
@ -2384,7 +2415,7 @@ ApplicationWindow {
spacing: 10 spacing: 10
Text { Text {
width: parent.width width: parent.width
text: "Optional: build a kernel tuned for this machine" text: "Optional: build a balanced or tuned kernel"
font.bold: true font.bold: true
color: "#f5b942" color: "#f5b942"
} }
@ -2396,8 +2427,8 @@ ApplicationWindow {
} }
WelcomeButton { WelcomeButton {
id: kernelButton id: kernelButton
text: "Open assistant to review tuned kernel" text: "Open assistant to review kernel choices"
onClicked: root.openAssistant() onClicked: root.openAssistant("--kernel-builds")
KeyNavigation.tab: keepButton KeyNavigation.tab: keepButton
} }
} }
@ -3309,6 +3340,8 @@ mod tests {
assert!(script.contains(".phoebus-cursor-include-v1")); assert!(script.contains(".phoebus-cursor-include-v1"));
assert!(script.contains("for f in colors layout outputs cursor; do")); assert!(script.contains("for f in colors layout outputs cursor; do"));
assert!(script.contains("dbus-update-activation-environment --systemd")); assert!(script.contains("dbus-update-activation-environment --systemd"));
assert!(script.contains("export SAL_USE_VCLPLUGIN=gtk3"));
assert!(script.contains("QT_QPA_PLATFORM SAL_USE_VCLPLUGIN PATH"));
assert!(script.contains("wait \"$MANGO_PID\"")); assert!(script.contains("wait \"$MANGO_PID\""));
// WAYLAND_DISPLAY must not be set before the compositor starts, or // WAYLAND_DISPLAY must not be set before the compositor starts, or
// wlroots selects its nested Wayland backend instead of DRM. // wlroots selects its nested Wayland backend instead of DRM.

View file

@ -125,6 +125,13 @@ impl TargetRoot {
std::fs::read_to_string(&path).map_err(|e| CoreError::io(path, e)) std::fs::read_to_string(&path).map_err(|e| CoreError::io(path, e))
} }
/// Remove a target file without following symlink components.
pub fn remove_file(&self, relative: &str) -> Result<()> {
self.reject_symlink_components(relative)?;
let path = self.resolve(relative)?;
std::fs::remove_file(&path).map_err(|e| CoreError::io(path, e))
}
pub fn copy_file(&self, relative: &str, src: &Path, mode: u32) -> Result<PathBuf> { pub fn copy_file(&self, relative: &str, src: &Path, mode: u32) -> Result<PathBuf> {
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
self.reject_symlink_components(relative)?; self.reject_symlink_components(relative)?;
@ -182,6 +189,22 @@ mod tests {
assert_eq!(t.read_to_string("etc/fstab").unwrap(), "hello"); assert_eq!(t.read_to_string("etc/fstab").unwrap(), "hello");
} }
#[test]
fn removal_stays_inside_root_and_rejects_symlinks() {
let dir = tempfile::tempdir().unwrap();
let outside = tempfile::tempdir().unwrap();
let t = TargetRoot::new(dir.path());
let path = t.write("etc/obsolete.conf", "old").unwrap();
t.remove_file("etc/obsolete.conf").unwrap();
assert!(!path.exists());
let protected = outside.path().join("keep");
std::fs::write(&protected, "keep").unwrap();
std::os::unix::fs::symlink(&protected, dir.path().join("etc/link")).unwrap();
assert!(t.remove_file("etc/link").is_err());
assert!(t.remove_file("../keep").is_err());
assert_eq!(std::fs::read_to_string(&protected).unwrap(), "keep");
}
#[test] #[test]
fn refuses_to_write_through_an_escaping_symlink() { fn refuses_to_write_through_an_escaping_symlink() {
let dir = tempfile::tempdir().unwrap(); let dir = tempfile::tempdir().unwrap();

View file

@ -229,6 +229,9 @@ fn pretend_args(action: &SystemAction) -> Option<Vec<String>> {
Some(vec![ Some(vec![
"--pretend".into(), "--pretend".into(),
"--color=n".into(), "--color=n".into(),
"--usepkg=y".into(),
"--getbinpkg=y".into(),
format!("--usepkg-exclude={}", conv.source_atom),
"--".into(), "--".into(),
conv.source_atom.to_string(), conv.source_atom.to_string(),
]) ])
@ -236,12 +239,18 @@ fn pretend_args(action: &SystemAction) -> Option<Vec<String>> {
SystemAction::BuildTunedKernel { .. } => Some(vec![ SystemAction::BuildTunedKernel { .. } => Some(vec![
"--pretend".into(), "--pretend".into(),
"--color=n".into(), "--color=n".into(),
"--usepkg=y".into(),
"--getbinpkg=y".into(),
"--usepkg-exclude=sys-kernel/gentoo-kernel".into(),
"--".into(), "--".into(),
"sys-kernel/gentoo-kernel".into(), "sys-kernel/gentoo-kernel".into(),
]), ]),
SystemAction::BuildBalancedKernel { .. } => Some(vec![ SystemAction::BuildBalancedKernel { .. } => Some(vec![
"--pretend".into(), "--pretend".into(),
"--color=n".into(), "--color=n".into(),
"--usepkg=y".into(),
"--getbinpkg=y".into(),
"--usepkg-exclude=sys-kernel/gentoo-kernel".into(),
"--".into(), "--".into(),
"sys-kernel/gentoo-kernel".into(), "sys-kernel/gentoo-kernel".into(),
]), ]),
@ -249,6 +258,27 @@ fn pretend_args(action: &SystemAction) -> Option<Vec<String>> {
} }
} }
/// Pin the locally built artifact to the exact source version in the review.
/// A later repository sync must not turn the merge into another package.
pub(crate) fn reviewed_source_atom(plan: &ResolvedPlan, atom: &str) -> Result<String> {
let targets: Vec<_> = plan
.effects
.iter()
.filter(|effect| {
effect.source == phoebus_core::effects::EffectSource::Source
&& portage::normalize_dep_atom(&effect.target) == atom
})
.collect();
if targets.len() != 1 || targets[0].target == atom {
return Err(ExecError::operation(
"sys",
"source build",
"no unique exact source version in the reviewed plan",
));
}
Ok(format!("={}", targets[0].target.trim_start_matches('=')))
}
/// Whether a Portage atom has a VDB record under `root` (installed). /// Whether a Portage atom has a VDB record under `root` (installed).
fn vdb_has_atom(root: &Path, atom: &str) -> bool { fn vdb_has_atom(root: &Path, atom: &str) -> bool {
// Normalize first: a versioned/slotted atom (`=app-editors/vim-9.0.2167`, // Normalize first: a versioned/slotted atom (`=app-editors/vim-9.0.2167`,
@ -326,11 +356,11 @@ fn convert_to_source(exec: &Exec, root: &Path, app: &str) -> Result<String> {
) )
} }
})?; })?;
let desktop_ids = replaced_desktop_ids(root, conv.app)?;
// 1. Blockers and dependencies first: the pretend plan is the reviewed // 1. Blockers and dependencies first: the pretend plan is the reviewed
// evidence; an unresolvable plan aborts before anything is built. // evidence; an unresolvable plan aborts before anything is built.
let pretend = SystemAction::InstallPackage { let pretend = SystemAction::ConvertToSource {
atom: conv.source_atom.to_string(), app: app.to_string(),
binary: None,
}; };
let plan = resolve_effects(exec, &pretend, root)?; let plan = resolve_effects(exec, &pretend, root)?;
if !plan.established { if !plan.established {
@ -343,6 +373,25 @@ fn convert_to_source(exec: &Exec, root: &Path, app: &str) -> Result<String> {
), ),
)); ));
} }
let source_atom = reviewed_source_atom(&plan, conv.source_atom)?;
// Build dependencies are part of the reviewed effects. Merge them first:
// Portage cannot build a binary package while dependencies are missing.
run_in_target(
exec,
root,
"sys",
"prepare source build dependencies",
"emerge",
&[
"--ask=n".into(),
"--onlydeps".into(),
"--usepkg=y".into(),
"--getbinpkg=y".into(),
format!("--usepkg-exclude={}", conv.source_atom),
"--".into(),
source_atom.clone(),
],
)?;
// 2. Build without installing. A failure here leaves the working // 2. Build without installing. A failure here leaves the working
// application exactly as it was. // application exactly as it was.
run_in_target( run_in_target(
@ -354,8 +403,10 @@ fn convert_to_source(exec: &Exec, root: &Path, app: &str) -> Result<String> {
&[ &[
"--ask=n".into(), "--ask=n".into(),
"--buildpkgonly".into(), "--buildpkgonly".into(),
"--usepkg=n".into(),
"--getbinpkg=n".into(),
"--".into(), "--".into(),
conv.source_atom.to_string(), source_atom.clone(),
], ],
) )
.map_err(|e| { .map_err(|e| {
@ -417,9 +468,10 @@ fn convert_to_source(exec: &Exec, root: &Path, app: &str) -> Result<String> {
"emerge", "emerge",
&[ &[
"--ask=n".into(), "--ask=n".into(),
"--usepkg=y".into(), "--usepkgonly".into(),
"--getbinpkg=n".into(),
"--".into(), "--".into(),
conv.source_atom.to_string(), source_atom.clone(),
], ],
)?; )?;
if !vdb_has_atom(root, conv.source_atom) { if !vdb_has_atom(root, conv.source_atom) {
@ -433,11 +485,182 @@ fn convert_to_source(exec: &Exec, root: &Path, app: &str) -> Result<String> {
), ),
)); ));
} }
preserve_source_desktop_ids(exec, root, conv.app, &desktop_ids)?;
Ok(format!( Ok(format!(
"built {} from source ({}) and verified the installation; user data preserved", "built {} from source ({}) and verified the installation; user data preserved",
conv.app, conv.source_atom conv.app, conv.source_atom
)) ))
} }
const SOURCE_DESKTOP_ALIAS: &str = "# Phoebus source-conversion compatibility alias";
/// Preserve desktop IDs referenced by existing preferences without rewriting
/// users' mimeapps.list or adding duplicate launcher items.
fn replaced_desktop_ids(root: &Path, app: &str) -> Result<Vec<String>> {
let fixed = match app {
"firefox" => Some("firefox-bin.desktop"),
"thunderbird" => Some("thunderbird-bin.desktop"),
"calibre" => Some("com.calibre_ebook.calibre.desktop"),
"gimp" => Some("org.gimp.GIMP.desktop"),
_ => None,
};
if let Some(id) = fixed {
return Ok(vec![id.into()]);
}
let directory = root.join("var/db/pkg/app-office");
if !directory.is_dir() {
return Ok(Vec::new());
}
let mut ids = std::collections::BTreeSet::new();
for entry in std::fs::read_dir(&directory).map_err(|e| ExecError::io(directory, e))? {
let entry = entry.map_err(|e| ExecError::io(root, e))?;
let name = entry.file_name().to_string_lossy().into_owned();
if !name
.strip_prefix("libreoffice-bin-")
.is_some_and(|v| v.starts_with(|c: char| c.is_ascii_digit()))
{
continue;
}
let path = entry.path().join("CONTENTS");
let contents = std::fs::read_to_string(&path).map_err(|e| ExecError::io(path, e))?;
for line in contents.lines() {
let words: Vec<_> = line.split_whitespace().collect();
if words.len() < 2 || !matches!(words[0], "obj" | "sym") {
continue;
}
let file = Path::new(words[1]);
if file.parent() == Some(Path::new("/usr/share/applications")) {
if let Some(id) = file
.file_name()
.and_then(|n| n.to_str())
.filter(|n| n.starts_with("libreoffice") && n.ends_with(".desktop"))
{
ids.insert(id.to_string());
}
}
}
}
Ok(ids.into_iter().collect())
}
fn preserve_source_desktop_ids(exec: &Exec, root: &Path, app: &str, ids: &[String]) -> Result<()> {
use std::os::unix::fs::PermissionsExt;
let native = root.join("usr/share/applications");
for id in ids {
let replacement = match app {
"firefox" | "thunderbird" => {
let candidates: Vec<_> = [format!("{app}.desktop"), format!("{app}-esr.desktop")]
.into_iter()
.filter(|name| native.join(name).is_file())
.collect();
if candidates.len() != 1 {
return Err(ExecError::operation(
"sys",
"preserve desktop defaults",
format!("no unique native replacement for {id}"),
));
}
candidates[0].clone()
}
"calibre" => "calibre-gui.desktop".to_string(),
"gimp" => "org.gimp.GIMP.desktop".to_string(),
"libreoffice" => {
let suffix = id
.rsplit_once('-')
.map(|(_, suffix)| suffix)
.ok_or_else(|| {
ExecError::operation(
"sys",
"preserve desktop defaults",
"unrecognized LibreOffice desktop ID",
)
})?;
let candidates: Vec<_> = std::fs::read_dir(&native)
.map_err(|e| ExecError::io(&native, e))?
.flatten()
.filter_map(|entry| {
let name = entry.file_name().to_str()?.to_string();
(name.starts_with("libreoffice") && name.ends_with(&format!("-{suffix}")))
.then_some(name)
})
.collect();
if candidates.len() != 1 {
return Err(ExecError::operation(
"sys",
"preserve desktop defaults",
format!("no unique native replacement for {id}"),
));
}
candidates[0].clone()
}
_ => {
return Err(ExecError::operation(
"sys",
"preserve desktop defaults",
"unsupported source application",
))
}
};
if *id == replacement {
continue;
}
let source = native.join(&replacement);
let canonical = source
.canonicalize()
.map_err(|e| ExecError::io(&source, e))?;
let canonical_root = root.canonicalize().map_err(|e| ExecError::io(root, e))?;
if !canonical.starts_with(canonical_root) {
return Err(ExecError::operation(
"sys",
"preserve desktop defaults",
"native desktop entry escapes target root",
));
}
let text = std::fs::read_to_string(&canonical).map_err(|e| ExecError::io(canonical, e))?;
if !text.lines().any(|line| line == "[Desktop Entry]")
|| !text.lines().any(|line| line.starts_with("Exec="))
{
return Err(ExecError::operation(
"sys",
"preserve desktop defaults",
format!("invalid native desktop entry {replacement}"),
));
}
let relative = format!("usr/local/share/applications/{id}");
let target = exec.target();
if target.resolve(&relative)?.exists()
&& !target
.read_to_string(&relative)?
.contains(SOURCE_DESKTOP_ALIAS)
{
return Err(ExecError::operation(
"sys",
"preserve desktop defaults",
format!("refusing to overwrite customized desktop entry {id}"),
));
}
let mut main = false;
let mut alias = format!("{SOURCE_DESKTOP_ALIAS}\n");
for line in text.lines() {
if line.starts_with('[') {
main = line == "[Desktop Entry]";
}
if main && line.starts_with("NoDisplay=") {
continue;
}
alias.push_str(line);
alias.push('\n');
if line == "[Desktop Entry]" {
alias.push_str("NoDisplay=true\n");
}
}
target.ensure_dir_mode("usr/local/share/applications", 0o755)?;
let path = target.write(&relative, alias)?;
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o644))
.map_err(|e| ExecError::io(path, e))?;
}
Ok(())
}
/// ///
/// Portage transactions resolve from `emerge --pretend`; the maintenance /// Portage transactions resolve from `emerge --pretend`; the maintenance
/// actions (depclean, per-source updates, cache cleanup) resolve a structured, /// actions (depclean, per-source updates, cache cleanup) resolve a structured,
@ -2316,10 +2539,28 @@ Total: 1 package (1 new), Size of downloads: 512 KiB
assert!(runner.recorded().is_empty()); assert!(runner.recorded().is_empty());
} }
#[test]
fn source_build_requires_one_exact_source_version() {
let source = phoebus_core::effects::parse_emerge_pretend(
"[ebuild N ] www-client/firefox-128.0:0::gentoo\n",
);
assert_eq!(
reviewed_source_atom(&source, "www-client/firefox").unwrap(),
"=www-client/firefox-128.0:0::gentoo"
);
let binary =
phoebus_core::effects::parse_emerge_pretend("[binary N ] www-client/firefox-128.0\n");
assert!(reviewed_source_atom(&binary, "www-client/firefox").is_err());
assert!(reviewed_source_atom(&ResolvedPlan::default(), "www-client/firefox").is_err());
}
#[test] #[test]
fn source_conversion_builds_before_removing_and_verifies() { fn source_conversion_builds_before_removing_and_verifies() {
let runner = RecordingRunner::new(); let runner = RecordingRunner::new();
runner.set_response("chroot", response(PRETEND_VIM)); runner.set_response(
"chroot",
response(&PRETEND_VIM.replace("app-editors/vim-9.1.0", "www-client/firefox-128.0")),
);
let exec = make_exec(runner.clone()); let exec = make_exec(runner.clone());
let root = exec.root.clone(); let root = exec.root.clone();
// Fixture VDB: the fast-default binary copy and (simulating a // Fixture VDB: the fast-default binary copy and (simulating a
@ -2330,6 +2571,12 @@ Total: 1 package (1 new), Size of downloads: 512 KiB
] { ] {
std::fs::create_dir_all(root.join(dir)).unwrap(); std::fs::create_dir_all(root.join(dir)).unwrap();
} }
std::fs::create_dir_all(root.join("usr/share/applications")).unwrap();
std::fs::write(
root.join("usr/share/applications/firefox.desktop"),
"[Desktop Entry]\nName=Firefox\nExec=firefox %u\n",
)
.unwrap();
let action = SystemAction::ConvertToSource { let action = SystemAction::ConvertToSource {
app: "firefox".into(), app: "firefox".into(),
}; };
@ -2360,7 +2607,175 @@ Total: 1 package (1 new), Size of downloads: 512 KiB
.iter() .iter()
.position(|a| a == "--unmerge") .position(|a| a == "--unmerge")
.expect("old copy removed"); .expect("old copy removed");
assert!(pretend < build && build < unmerge, "{args:?}"); let dependencies = args
.iter()
.position(|a| a == "--onlydeps")
.expect("dependencies prepared");
assert!(
pretend < dependencies && dependencies < build && build < unmerge,
"{args:?}"
);
let commands = runner.recorded();
let build_command = commands
.iter()
.find(|s| s.args.iter().any(|a| a == "--buildpkgonly"))
.unwrap();
assert!(build_command
.args
.iter()
.any(|a| a == "=www-client/firefox-128.0"));
assert!(build_command.args.iter().any(|a| a == "--usepkg=n"));
assert!(build_command.args.iter().any(|a| a == "--getbinpkg=n"));
assert!(commands
.iter()
.any(|s| s.args.iter().any(|a| a == "--usepkgonly")
&& s.args.iter().any(|a| a == "--getbinpkg=n")));
}
#[test]
fn source_desktop_alias_preserves_actions_and_does_not_override_custom_entries() {
use std::os::unix::fs::PermissionsExt;
let exec = make_exec(RecordingRunner::new());
let root = &exec.root;
let native = root.join("usr/share/applications");
std::fs::create_dir_all(&native).unwrap();
std::fs::write(native.join("firefox.desktop"), "[Desktop Entry]\nName=Firefox\nExec=firefox %u\nNoDisplay=false\nActions=new-window;\n[Desktop Action new-window]\nExec=firefox --new-window %u\n").unwrap();
let ids = replaced_desktop_ids(root, "firefox").unwrap();
preserve_source_desktop_ids(&exec, root, "firefox", &ids).unwrap();
let path = root.join("usr/local/share/applications/firefox-bin.desktop");
let alias = std::fs::read_to_string(&path).unwrap();
assert!(alias.contains("NoDisplay=true\n"));
assert!(!alias.contains("NoDisplay=false"));
assert!(alias.contains("Exec=firefox %u"));
assert!(alias.contains("Exec=firefox --new-window %u"));
assert_eq!(
std::fs::metadata(&path).unwrap().permissions().mode() & 0o777,
0o644
);
// Our aliases can be refreshed; independently customized ones cannot.
preserve_source_desktop_ids(&exec, root, "firefox", &ids).unwrap();
std::fs::write(&path, "[Desktop Entry]\nExec=custom-browser\n").unwrap();
assert!(preserve_source_desktop_ids(&exec, root, "firefox", &ids).is_err());
assert!(std::fs::read_to_string(path)
.unwrap()
.contains("custom-browser"));
}
#[test]
fn stable_esr_desktop_ids_preserve_binary_browser_preferences() {
let exec = make_exec(RecordingRunner::new());
let root = &exec.root;
std::fs::create_dir_all(root.join("usr/share/applications")).unwrap();
for app in ["firefox", "thunderbird"] {
std::fs::write(
root.join(format!("usr/share/applications/{app}-esr.desktop")),
format!("[Desktop Entry]\nName={app} ESR\nExec={app} %u\n"),
)
.unwrap();
preserve_source_desktop_ids(
&exec,
root,
app,
&replaced_desktop_ids(root, app).unwrap(),
)
.unwrap();
let text = std::fs::read_to_string(
root.join(format!("usr/local/share/applications/{app}-bin.desktop")),
)
.unwrap();
assert!(text.contains(&format!("Exec={app} %u")));
assert!(text.contains("NoDisplay=true"));
}
}
#[test]
fn versioned_office_desktop_ids_are_preserved_using_native_components() {
let exec = make_exec(RecordingRunner::new());
let root = &exec.root;
let vdb = root.join("var/db/pkg/app-office/libreoffice-bin-25.8.4");
std::fs::create_dir_all(&vdb).unwrap();
std::fs::write(vdb.join("CONTENTS"), "obj /usr/share/applications/libreoffice25.8-writer.desktop hash 0\nobj /usr/share/applications/libreoffice25.8-calc.desktop hash 0\nobj /usr/share/unrelated.desktop hash 0\n").unwrap();
std::fs::create_dir_all(root.join("usr/share/applications")).unwrap();
for component in ["writer", "calc"] {
std::fs::write(
root.join(format!(
"usr/share/applications/libreoffice-{component}.desktop"
)),
format!("[Desktop Entry]\nExec=libreoffice --{component} %U\n"),
)
.unwrap();
}
let ids = replaced_desktop_ids(root, "libreoffice").unwrap();
assert_eq!(ids.len(), 2);
preserve_source_desktop_ids(&exec, root, "libreoffice", &ids).unwrap();
for component in ["writer", "calc"] {
let alias = std::fs::read_to_string(root.join(format!(
"usr/local/share/applications/libreoffice25.8-{component}.desktop"
)))
.unwrap();
assert!(alias.contains(&format!("Exec=libreoffice --{component} %U")));
}
}
#[test]
fn native_desktop_alias_refuses_an_escaping_source_symlink() {
let exec = make_exec(RecordingRunner::new());
let root = &exec.root;
let outside = tempfile::tempdir().unwrap();
let source = outside.path().join("firefox.desktop");
std::fs::write(&source, "[Desktop Entry]\nExec=firefox\n").unwrap();
std::fs::create_dir_all(root.join("usr/share/applications")).unwrap();
std::os::unix::fs::symlink(source, root.join("usr/share/applications/firefox.desktop"))
.unwrap();
let ids = replaced_desktop_ids(root, "firefox").unwrap();
assert!(preserve_source_desktop_ids(&exec, root, "firefox", &ids).is_err());
assert!(!root
.join("usr/local/share/applications/firefox-bin.desktop")
.exists());
}
#[test]
fn failed_source_compilation_keeps_the_binary_application() {
struct FailedBuild(RecordingRunner);
impl crate::command::ProcessRunner for FailedBuild {
fn execute(
&self,
spec: &crate::command::CommandSpec,
) -> Result<crate::command::CommandOutput> {
let mut output = crate::command::ProcessRunner::execute(&self.0, spec)?;
if spec.args.iter().any(|arg| arg == "--buildpkgonly") {
output.success = false;
output.status = 1;
output.stderr = b"test compiler failure".to_vec();
}
Ok(output)
}
}
let runner = RecordingRunner::new();
runner.set_response(
"chroot",
response(&PRETEND_VIM.replace("app-editors/vim-9.1.0", "www-client/firefox-128.0")),
);
let temp = tempfile::tempdir().unwrap();
let root = temp.path().join("root");
std::fs::create_dir_all(root.join("var/db/pkg/www-client/firefox-bin-128.0")).unwrap();
let logger = Logger::open(temp.path().join("test.log"), Redactor::new(), false);
let exec = Exec::new(
Box::new(FailedBuild(runner.clone())),
logger,
false,
root.clone(),
temp.path().to_path_buf(),
);
let err = convert_to_source(&exec, &root, "firefox").unwrap_err();
assert!(err.to_string().contains("still installed"), "{err}");
assert!(root
.join("var/db/pkg/www-client/firefox-bin-128.0")
.is_dir());
assert!(!runner.recorded().iter().any(|s| s
.args
.iter()
.any(|a| a == "--unmerge" || a == "--usepkgonly")));
} }
#[test] #[test]

View file

@ -85,6 +85,15 @@ pub fn write_session_script(exec: &Exec, config: &InstallConfig) -> Result<()> {
} }
let target = exec.target(); let target = exec.target();
// The bootstrap policy disables Pillow truetype to avoid a dependency
// cycle. Desktop libraries now exist; enable the scoped flags needed by
// the optional native application builds before showing their chooser.
write_public(
&target,
"etc/portage/package.use/phoebus-source-builds",
sysgen::SOURCE_BUILD_USE,
)?;
// A launcher for the installed assistant. It opens `sys ask`, which keeps // A launcher for the installed assistant. It opens `sys ask`, which keeps
// privilege and approval in the deterministic broker. // privilege and approval in the deterministic broker.
write_script( write_script(
@ -719,6 +728,22 @@ mod tests {
let xdg = exec.target().ensure_dir("etc/xdg").unwrap(); let xdg = exec.target().ensure_dir("etc/xdg").unwrap();
std::fs::set_permissions(&xdg, std::fs::Permissions::from_mode(0o700)).unwrap(); std::fs::set_permissions(&xdg, std::fs::Permissions::from_mode(0o700)).unwrap();
write_session_script(&exec, &cfg).unwrap(); write_session_script(&exec, &cfg).unwrap();
assert_eq!(
std::fs::read_to_string(
exec.root
.join("etc/portage/package.use/phoebus-source-builds")
)
.unwrap(),
sysgen::SOURCE_BUILD_USE
);
assert!(sysgen::package_use(&cfg, &HardwareReport::default())
.contains("dev-python/pillow -truetype"));
// ESR 153's system-AV1 link fails (Mozilla bug 2063808). Keep the
// workaround on source packages and affected branches only; the
// ordinary binary bootstrap policy must not inherit it.
assert!(sysgen::SOURCE_BUILD_USE.contains("<www-client/firefox-156 -system-av1\n"));
assert!(sysgen::SOURCE_BUILD_USE.contains("<mail-client/thunderbird-156 -system-av1\n"));
assert!(!sysgen::package_use(&cfg, &HardwareReport::default()).contains("system-av1"));
for rel in ["etc/xdg", "etc/xdg/mango"] { for rel in ["etc/xdg", "etc/xdg/mango"] {
let mode = std::fs::metadata(exec.root.join(rel)) let mode = std::fs::metadata(exec.root.join(rel))
.unwrap() .unwrap()

View file

@ -14,9 +14,23 @@ use crate::error::{ExecError, Result};
use crate::exec::Exec; use crate::exec::Exec;
use crate::portage; use crate::portage;
// Portage builds as its unprivileged build user. Kernel fragments contain
// public configuration, so both the directory and files must be readable.
fn write_fragment(exec: &Exec, name: &str, contents: impl AsRef<[u8]>) -> Result<()> {
use std::os::unix::fs::PermissionsExt;
let target = exec.target();
target.ensure_dir_mode("etc/kernel", 0o755)?;
target.ensure_dir_mode("etc/kernel/config.d", 0o755)?;
let path = target.write(&format!("etc/kernel/config.d/{name}"), contents)?;
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o644))
.map_err(|error| ExecError::io(path, error))?;
Ok(())
}
pub fn write_profile(exec: &Exec, config: &InstallConfig) -> Result<()> { pub fn write_profile(exec: &Exec, config: &InstallConfig) -> Result<()> {
exec.target().write( write_fragment(
"etc/kernel/config.d/00-phoebus-profile.config", exec,
"00-phoebus-profile.config",
sysgen::kernel_profile_config(config), sysgen::kernel_profile_config(config),
)?; )?;
exec.logger.info("wrote kernel profile fragment"); exec.logger.info("wrote kernel profile fragment");
@ -115,6 +129,42 @@ fn build_source_kernel(
), ),
)); ));
} }
if make_default {
if let Some(release) = running_source_kernel(root, choice)? {
let entry = source_kernel_bls_entry_for_versions(exec, root, choice, &[release])?;
set_default_entry(exec, root, &entry)?;
return Ok(format!(
"test boot confirmed; {} is now the default; {} remains available as fallback",
choice.label(),
plan.fallback_atom
));
}
}
// Variants of the same kernel PV share a Portage slot. Installing one
// can remove the other's modules; never do that to the running kernel.
if root == Path::new("/") {
let running = std::fs::read_to_string("/proc/sys/kernel/osrelease")
.map_err(|e| ExecError::io("/proc/sys/kernel/osrelease", e))?;
require_generic_build_boot(running.trim())?;
}
let action = if choice == KernelChoice::Balanced {
phoebus_core::action::SystemAction::BuildBalancedKernel { make_default }
} else {
phoebus_core::action::SystemAction::BuildTunedKernel { make_default }
};
let effects = crate::actions::resolve_effects(exec, &action, root)?;
let source_atom = crate::actions::reviewed_source_atom(&effects, plan.source_atom)?;
// Capture the working selection before dependencies can install another
// distribution kernel. Restore it even if dependency setup/build fails.
let loader_path = if root.join("efi/loader/loader.conf").is_file() {
"efi/loader/loader.conf"
} else {
"boot/loader/loader.conf"
};
let loader_before = pin_wildcard_default(root, &exec.target().read_to_string(loader_path)?)?;
// Pin before package hooks run, including the interval before a failure
// or power loss could interrupt restoration of the working selection.
exec.target().write(loader_path, &loader_before)?;
// 2. The choice's fragment, on top of the proven profile fragment. // 2. The choice's fragment, on top of the proven profile fragment.
let fragment = match choice { let fragment = match choice {
KernelChoice::Balanced => sysgen::balanced_kernel_config(), KernelChoice::Balanced => sysgen::balanced_kernel_config(),
@ -127,18 +177,49 @@ fn build_source_kernel(
)) ))
} }
}; };
exec.target().write( // Repair older installers' private modes without changing user edits.
&format!("etc/kernel/config.d/{}", plan.fragment_file), let profile_path = "etc/kernel/config.d/00-phoebus-profile.config";
fragment, if exec.target().resolve(profile_path)?.is_file() {
)?; let profile = exec.target().read_to_string(profile_path)?;
write_fragment(exec, "00-phoebus-profile.config", profile)?;
}
write_fragment(exec, plan.fragment_file, fragment)?;
let inactive = if choice == KernelChoice::Balanced {
"10-phoebus-tuned.config"
} else {
"10-phoebus-balanced.config"
};
write_fragment(exec, inactive, "# Inactive Phoebus kernel choice\n")?;
exec.logger exec.logger
.info(format!("wrote {} fragment", choice.label())); .info(format!("wrote {} fragment", choice.label()));
// 3. Build only; a failure here leaves boot untouched. let install_result = (|| -> Result<()> {
portage::chroot( portage::chroot(
exec, exec,
root, root,
"emerge", "emerge",
&["--ask=n", "--buildpkgonly", "--", plan.source_atom], &[
"--ask=n",
"--onlydeps",
"--usepkg=y",
"--getbinpkg=y",
"--usepkg-exclude=sys-kernel/gentoo-kernel",
"--",
&source_atom,
],
)?;
// 3. Force a local source build; a cached generic binpkg cannot satisfy it.
portage::chroot(
exec,
root,
"emerge",
&[
"--ask=n",
"--buildpkgonly",
"--usepkg=n",
"--getbinpkg=n",
"--",
&source_atom,
],
) )
.map_err(|e| { .map_err(|e| {
ExecError::operation( ExecError::operation(
@ -152,38 +233,120 @@ fn build_source_kernel(
exec, exec,
root, root,
"emerge", "emerge",
&["--ask=n", "--usepkg=y", "--", plan.source_atom], &[
"--ask=n",
"--usepkgonly",
"--getbinpkg=n",
"--",
&source_atom,
],
) )
.map_err(|e| ExecError::operation("sys", choice.label(), e.to_string()))?; .map_err(|e| ExecError::operation("sys", choice.label(), e.to_string()))
if !vdb_has_atom(root, plan.source_atom) { })();
exec.target().write(loader_path, loader_before)?;
install_result?;
if !vdb_has_atom(root, plan.source_atom) || !vdb_has_atom(root, plan.fallback_atom) {
return Err(ExecError::operation( return Err(ExecError::operation(
"sys", "sys",
choice.label(), choice.label(),
"the source kernel did not verify in the package database; the working default is unchanged", "the source kernel did not verify in the package database; the working default is unchanged",
)); ));
} }
let entry = source_kernel_bls_entry(root, choice)?; let versions = installed_source_versions(root, &source_atom, choice)?;
let entry = source_kernel_bls_entry_for_versions(exec, root, choice, &versions)?;
let mut out = format!( let mut out = format!(
"{} built and verified; separate boot entry `{entry}` created; {} stays the default", "{} built and verified; separate boot entry `{entry}` created; {} stays the default",
choice.label(), choice.label(),
plan.fallback_atom plan.fallback_atom
); );
if make_default { if make_default {
if tuned_kernel_is_running(root)? {
set_default_entry(exec, root, &entry)?;
out.push_str("; test boot confirmed, the source kernel is now the default");
} else {
out.push_str( out.push_str(
"; not made default yet: boot the new entry once for a test boot, \ "; not made default yet: boot the new entry once for a test boot, \
then re-run with approval to make it the default", then re-run with approval to make it the default",
); );
}
} else { } else {
out.push_str("; boot the new entry to test it before making it default"); out.push_str("; boot the new entry to test it before making it default");
} }
Ok(out) Ok(out)
} }
/// A wildcard may select an untested kernel, and a source default may lose its
/// modules when another variant replaces its package. Pin the generic fallback.
fn pin_wildcard_default(root: &Path, loader: &str) -> Result<String> {
let needs_pin = |line: &str| {
let words: Vec<_> = line.split_whitespace().collect();
words.len() == 2
&& words[0] == "default"
&& (words[1] == "*"
|| words[1].contains("-phoebus-")
|| matches!(words[1], "phoebus-balanced.conf" | "phoebus-tuned.conf"))
};
if !loader.lines().any(needs_pin) {
return Ok(loader.to_string());
}
let entries = if root.join("efi/loader/entries").is_dir() {
root.join("efi/loader/entries")
} else {
root.join("boot/loader/entries")
};
let candidates: Vec<_> = std::fs::read_dir(&entries)
.map_err(|e| ExecError::io(entries.clone(), e))?
.flatten()
.filter_map(|item| {
let name = item.file_name().to_str()?.to_string();
let text = std::fs::read_to_string(item.path()).ok()?;
let entry = phoebus_core::boot::BlsEntry::parse(&name, &text)?;
let version = entry.kernel_version()?;
if !version.ends_with("-gentoo-dist-bin")
|| entry.title.to_ascii_lowercase().contains("recovery")
|| entry.options.contains("systemd.unit=")
|| entry.options.contains("subvol=@snapshots")
{
return None;
}
Some((version, name))
})
.collect();
let (_, name) = candidates
.iter()
.max_by_key(|(version, _)| phoebus_core::boot::version_key(version))
.ok_or_else(|| {
ExecError::operation(
"sys",
"preserve kernel default",
"no existing generic boot entry",
)
})?;
let (stem, count) = phoebus_core::boot::parse_bls_filename(name);
let selected = if count.is_some() {
// systemd-boot strips boot counters from the entry ID. This also
// continues matching after a successful boot blesses the filename.
format!("{stem}.conf")
} else {
name.clone()
};
Ok(loader
.lines()
.map(|line| {
if needs_pin(line) {
format!("default {selected}\n")
} else {
format!("{line}\n")
}
})
.collect())
}
fn require_generic_build_boot(release: &str) -> Result<()> {
if !release.ends_with("-gentoo-dist-bin") {
return Err(ExecError::operation(
"sys", "build source kernel",
"boot the prebuilt generic kernel before building a source kernel; replacing a source-kernel package can remove its running modules",
));
}
Ok(())
}
/// Whether a VDB record exists for `atom` under `root`. /// Whether a VDB record exists for `atom` under `root`.
fn vdb_has_atom(root: &Path, atom: &str) -> bool { fn vdb_has_atom(root: &Path, atom: &str) -> bool {
// Normalize versioned/slotted atoms to `category/name` before the lookup. // Normalize versioned/slotted atoms to `category/name` before the lookup.
@ -211,10 +374,16 @@ fn vdb_has_atom(root: &Path, atom: &str) -> bool {
}) })
} }
/// Copy the default BLS entry to a separate source-kernel entry (balanced or /// Copy the verified source BLS entry to a separate named entry (balanced or
/// tuned). Returns the new entry file name. Never rewrites the default loader /// tuned). Returns the new entry file name. Never rewrites the default loader
/// selection. /// selection.
fn source_kernel_bls_entry(root: &Path, choice: KernelChoice) -> Result<String> { fn source_kernel_bls_entry_for_versions(
exec: &Exec,
root: &Path,
choice: KernelChoice,
versions: &[String],
) -> Result<String> {
prune_obsolete_source_aliases(exec, root)?;
// systemd-boot BLS entries live in `$ESP/loader/entries/*.conf` (the same // systemd-boot BLS entries live in `$ESP/loader/entries/*.conf` (the same
// directory `boot.rs` writes). `EFI/Linux` is for UKIs, which are deferred. // directory `boot.rs` writes). `EFI/Linux` is for UKIs, which are deferred.
let entries = root.join("efi/loader/entries"); let entries = root.join("efi/loader/entries");
@ -236,59 +405,218 @@ fn source_kernel_bls_entry(root: &Path, choice: KernelChoice) -> Result<String>
.filter(|p| p.extension().is_some_and(|x| x == "conf")) .filter(|p| p.extension().is_some_and(|x| x == "conf"))
.collect(); .collect();
current.sort(); current.sort();
let Some(src) = current.first().cloned() else { let parsed: Vec<_> = current
.iter()
.filter_map(|path| {
let text = std::fs::read_to_string(path).ok()?;
let name = path.file_name()?.to_str()?;
let entry = phoebus_core::boot::BlsEntry::parse(name, &text)?;
if entry.title.to_ascii_lowercase().contains("recovery")
|| entry.options.contains("systemd.unit=")
|| entry.options.contains("subvol=@snapshots")
{
return None;
}
Some(entry)
})
.collect();
let Some(src) = phoebus_core::boot::choose_entry_for_versions(&parsed, versions) else {
return Err(ExecError::operation( return Err(ExecError::operation(
"sys", "sys",
choice.label(), choice.label(),
"no existing BLS entry to derive the separate entry from", "no BLS entry with matching built source-kernel modules; refusing to copy a generic or recovery entry",
)); ));
}; };
let text = std::fs::read_to_string(&src).map_err(|e| ExecError::io(src.clone(), e))?; let esp = entries
let entry = format!( .parent()
"{}\n# Phoebus {} kernel (test entry; generic fallback stays default)\n", .and_then(Path::parent)
text.trim_end(), .ok_or_else(|| ExecError::operation("sys", "kernel entry", "invalid ESP layout"))?;
choice.as_str() if src.initrds.is_empty()
); || std::iter::once(&src.linux)
.chain(src.initrds.iter())
.any(|image| {
let path = Path::new(image.trim_start_matches('/'));
path.components()
.any(|c| !matches!(c, std::path::Component::Normal(_)))
|| !esp.join(path).is_file()
})
{
return Err(ExecError::operation(
"sys",
choice.label(),
"source kernel entry has missing kernel or initramfs images",
));
}
let entry = src
.with_title(&format!("Phoebus {} kernel (test boot)", choice.as_str()))
.render();
let name = match choice { let name = match choice {
KernelChoice::Balanced => "phoebus-balanced.conf", KernelChoice::Balanced => "phoebus-balanced.conf",
KernelChoice::Tuned => "phoebus-tuned.conf", KernelChoice::Tuned => "phoebus-tuned.conf",
KernelChoice::Bin => "phoebus-bin.conf", KernelChoice::Bin => "phoebus-bin.conf",
}; };
let dest = entries.join(name); let relative = entries
std::fs::write(&dest, entry).map_err(|e| ExecError::io(dest.clone(), e))?; .strip_prefix(root)
.map_err(|e| ExecError::operation("sys", "kernel entry", e.to_string()))?
.join(name);
exec.target().write(&relative.to_string_lossy(), entry)?;
Ok(name.to_string()) Ok(name.to_string())
} }
/// Whether the tuned kernel is the running kernel: only on the host root, /// Our named aliases outlive Portage's automatic removal of an older variant.
/// the running release must match an installed `sys-kernel/gentoo-kernel` /// Keep valid aliases and leave all recovery and user-created entries alone.
/// VDB version. For an alternate root (or when the release cannot be fn prune_obsolete_source_aliases(exec: &Exec, root: &Path) -> Result<()> {
/// established) this reports false, so the default is never switched let relative_dir = if root.join("efi/loader/entries").is_dir() {
/// blindly — the user test-boots the new entry first, then re-runs. "efi/loader/entries"
fn tuned_kernel_is_running(root: &Path) -> Result<bool> { } else {
"boot/loader/entries"
};
let esp = if relative_dir.starts_with("efi/") {
"efi"
} else {
"boot"
};
for choice in [KernelChoice::Balanced, KernelChoice::Tuned] {
let name = format!("phoebus-{}.conf", choice.as_str());
let relative = format!("{relative_dir}/{name}");
if !exec.target().resolve(&relative)?.is_file() {
continue;
}
let text = exec.target().read_to_string(&relative)?;
let valid = phoebus_core::boot::BlsEntry::parse(&name, &text).is_some_and(|entry| {
entry
.kernel_version()
.is_some_and(|release| source_kernel_versions(root, choice).contains(&release))
&& !entry.initrds.is_empty()
&& std::iter::once(&entry.linux)
.chain(entry.initrds.iter())
.all(|image| {
let path = Path::new(image.trim_start_matches('/'));
path.components()
.all(|c| matches!(c, std::path::Component::Normal(_)))
&& root.join(esp).join(path).is_file()
})
});
if !valid {
exec.target().remove_file(&relative)?;
exec.logger
.info(format!("removed obsolete source kernel alias {name}"));
}
}
Ok(())
}
/// Bind the boot entry to the exact package that was built and installed,
/// even when modules from another source-kernel version remain available.
fn installed_source_versions(root: &Path, atom: &str, choice: KernelChoice) -> Result<Vec<String>> {
let package = atom
.trim_start_matches('=')
.split(':')
.next()
.unwrap_or_default();
let path = root.join("var/db/pkg").join(package).join("CONTENTS");
let contents = std::fs::read_to_string(&path).map_err(|e| ExecError::io(path, e))?;
Ok(source_kernel_versions(root, choice)
.into_iter()
.filter(|release| contents.contains(&format!("/lib/modules/{release}/")))
.collect())
}
/// Confirm the exact running source release and that its package was installed
/// before this boot. Rebuilding the same release after boot is not a test boot.
fn running_source_kernel(root: &Path, choice: KernelChoice) -> Result<Option<String>> {
if root != Path::new("/") { if root != Path::new("/") {
return Ok(false); return Ok(None);
} }
let release = std::fs::read_to_string("/proc/sys/kernel/osrelease") let release = std::fs::read_to_string("/proc/sys/kernel/osrelease")
.map(|s| s.trim().to_string()) .map(|s| s.trim().to_string())
.unwrap_or_default(); .unwrap_or_default();
let boot_time = std::fs::read_to_string("/proc/stat").ok().and_then(|text| {
text.lines()
.find_map(|line| line.strip_prefix("btime ")?.trim().parse::<u64>().ok())
});
let tested = boot_time.is_some_and(|boot| {
source_kernel_versions(root, choice).contains(&release)
&& installed_source_predates_boot(root, &release, boot)
});
Ok(tested.then_some(release))
}
fn installed_source_predates_boot(root: &Path, release: &str, boot_time: u64) -> bool {
if release.is_empty() { if release.is_empty() {
return Ok(false); return false;
} }
let dir = root.join("var/db/pkg/sys-kernel/gentoo-kernel"); let Ok(entries) = std::fs::read_dir(root.join("var/db/pkg/sys-kernel")) else {
let Ok(entries) = std::fs::read_dir(&dir) else { return false;
return Ok(false);
}; };
// VDB dirs are `gentoo-kernel-<version>`; the release contains the entries.flatten().any(|entry| {
// version plus localversion suffixes. let name = entry.file_name().to_string_lossy().to_string();
for e in entries.flatten() { if !name
let name = e.file_name().to_string_lossy().to_string(); .strip_prefix("gentoo-kernel-")
if let Some(ver) = name.strip_prefix("gentoo-kernel-") { .is_some_and(|tail| tail.starts_with(|c: char| c.is_ascii_digit()))
if release.starts_with(ver) || release.contains(ver) { {
return Ok(true); return false;
}
let contents = std::fs::read_to_string(entry.path().join("CONTENTS")).unwrap_or_default();
if !contents.contains(&format!("/lib/modules/{release}/")) {
return false;
}
let installed = std::fs::metadata(entry.path().join("COUNTER"))
.ok()
.and_then(|metadata| metadata.modified().ok())
.and_then(|time| time.duration_since(std::time::UNIX_EPOCH).ok());
installed.is_some_and(|time| time.as_secs() < boot_time)
})
}
fn source_kernel_versions(root: &Path, choice: KernelChoice) -> Vec<String> {
let suffix = format!("-phoebus-{}", choice.as_str());
let mut versions = Vec::new();
for relative in ["lib/modules", "usr/lib/modules"] {
if let Ok(entries) = std::fs::read_dir(root.join(relative)) {
for entry in entries.flatten() {
let name = entry.file_name().to_string_lossy().to_string();
if name.ends_with(&suffix)
&& entry.path().join("modules.dep").is_file()
&& has_kernel_modules(&entry.path().join("kernel"))
{
versions.push(name);
} }
} }
} }
Ok(false) }
versions.sort();
versions.dedup();
versions
}
/// Dependency metadata can remain after module removal. Require a module
/// tree before offering or retaining an installed source-kernel boot entry.
fn has_kernel_modules(directory: &Path) -> bool {
let mut pending = vec![directory.to_path_buf()];
while let Some(path) = pending.pop() {
let Ok(entries) = std::fs::read_dir(path) else {
continue;
};
for entry in entries.flatten() {
let Ok(kind) = entry.file_type() else {
continue;
};
if kind.is_dir() {
pending.push(entry.path());
} else if kind.is_file() {
let name = entry.file_name();
let name = name.to_string_lossy();
if [".ko", ".ko.xz", ".ko.zst", ".ko.gz"]
.iter()
.any(|suffix| name.ends_with(suffix))
{
return true;
}
}
}
}
false
} }
/// Point the loader default at `entry`. /// Point the loader default at `entry`.
@ -314,7 +642,10 @@ fn set_default_entry(exec: &Exec, root: &Path, entry: &str) -> Result<()> {
if !set { if !set {
out.push_str(&format!("default {entry}\n")); out.push_str(&format!("default {entry}\n"));
} }
std::fs::write(&loader, out).map_err(|e| ExecError::io(loader.clone(), e))?; let relative = loader
.strip_prefix(root)
.map_err(|e| ExecError::operation("sys", "kernel default", e.to_string()))?;
exec.target().write(&relative.to_string_lossy(), out)?;
exec.logger.info(format!("loader default set to {entry}")); exec.logger.info(format!("loader default set to {entry}"));
Ok(()) Ok(())
} }
@ -327,11 +658,112 @@ mod tests {
use phoebus_core::Redactor; use phoebus_core::Redactor;
fn make_exec(runner: RecordingRunner) -> Exec { fn make_exec(runner: RecordingRunner) -> Exec {
runner.set_response(
"chroot",
crate::command::CommandOutput {
status: 0,
success: true,
stdout: b"[ebuild N ] sys-kernel/gentoo-kernel-6.12.32\n".to_vec(),
stderr: vec![],
duration: std::time::Duration::ZERO,
},
);
let path = tempfile::tempdir().unwrap().keep(); let path = tempfile::tempdir().unwrap().keep();
let logger = Logger::open(path.join("l.log"), Redactor::new(), false); let logger = Logger::open(path.join("l.log"), Redactor::new(), false);
Exec::new(Box::new(runner), logger, false, path.join("root"), path) Exec::new(Box::new(runner), logger, false, path.join("root"), path)
} }
fn source_entry_fixture(root: &Path, choice: &str) {
let version = format!("6.12.32-gentoo-dist-phoebus-{choice}");
std::fs::create_dir_all(root.join(format!("lib/modules/{version}"))).unwrap();
std::fs::write(root.join(format!("lib/modules/{version}/modules.dep")), "").unwrap();
std::fs::create_dir_all(root.join(format!("lib/modules/{version}/kernel/drivers")))
.unwrap();
std::fs::write(
root.join(format!("lib/modules/{version}/kernel/drivers/test.ko.zst")),
"module",
)
.unwrap();
std::fs::create_dir_all(root.join(format!("efi/machine/{version}"))).unwrap();
for image in ["linux", "initrd"] {
std::fs::write(root.join(format!("efi/machine/{version}/{image}")), "image").unwrap();
}
let vdb = root.join("var/db/pkg/sys-kernel/gentoo-kernel-6.12.32");
std::fs::create_dir_all(&vdb).unwrap();
std::fs::write(
vdb.join("CONTENTS"),
format!("obj /usr/lib/modules/{version}/modules.dep hash 0\n"),
)
.unwrap();
let entry = format!("title Source kernel\nlinux /machine/{version}/linux\ninitrd /machine/{version}/initrd\noptions root=/dev/mapper/cryptroot rootflags=subvol=@\n");
std::fs::write(root.join("efi/loader/entries/zz-source.conf"), &entry).unwrap();
std::fs::write(
root.join("efi/loader/entries/00-recovery.conf"),
entry
.replace("title Source kernel", "title Recovery")
.replace("subvol=@", "subvol=@snapshots/recovery"),
)
.unwrap();
}
#[test]
fn kernel_fragments_repair_private_installer_permissions() {
use std::os::unix::fs::PermissionsExt;
let exec = make_exec(RecordingRunner::new());
let target = exec.target();
target.ensure_dir_mode("etc/kernel", 0o700).unwrap();
target
.ensure_dir_mode("etc/kernel/config.d", 0o700)
.unwrap();
let path = target
.write(
"etc/kernel/config.d/00-phoebus-profile.config",
"custom profile\n",
)
.unwrap();
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600)).unwrap();
let original = target
.read_to_string("etc/kernel/config.d/00-phoebus-profile.config")
.unwrap();
write_fragment(&exec, "00-phoebus-profile.config", &original).unwrap();
write_fragment(
&exec,
"10-phoebus-balanced.config",
sysgen::balanced_kernel_config(),
)
.unwrap();
for relative in ["etc/kernel", "etc/kernel/config.d"] {
assert_eq!(
std::fs::metadata(target.resolve(relative).unwrap())
.unwrap()
.permissions()
.mode()
& 0o777,
0o755
);
}
for name in ["00-phoebus-profile.config", "10-phoebus-balanced.config"] {
assert_eq!(
std::fs::metadata(
target
.resolve(&format!("etc/kernel/config.d/{name}"))
.unwrap()
)
.unwrap()
.permissions()
.mode()
& 0o777,
0o644
);
}
assert_eq!(
target
.read_to_string("etc/kernel/config.d/00-phoebus-profile.config")
.unwrap(),
original
);
}
#[test] #[test]
fn cmdline_written_with_rd_luks_name() { fn cmdline_written_with_rd_luks_name() {
let runner = RecordingRunner::new(); let runner = RecordingRunner::new();
@ -379,13 +811,18 @@ mod tests {
"default phoebus.conf\n", "default phoebus.conf\n",
) )
.unwrap(); .unwrap();
source_entry_fixture(root, "tuned");
// chroot build/install succeed (recording runner). // chroot build/install succeed (recording runner).
let out = build_tuned_kernel(&exec, root, true).unwrap(); let out = build_tuned_kernel(&exec, root, true).unwrap();
assert!(out.contains("separate boot entry"), "{out}"); assert!(out.contains("separate boot entry"), "{out}");
// The new entry exists and derives from the current one. // The new entry exists and derives from the current one.
let tuned = let tuned =
std::fs::read_to_string(root.join("efi/loader/entries/phoebus-tuned.conf")).unwrap(); std::fs::read_to_string(root.join("efi/loader/entries/phoebus-tuned.conf")).unwrap();
assert!(tuned.contains("linux /vmlinuz-6.12.32"), "{tuned}"); assert!(
tuned.contains("/6.12.32-gentoo-dist-phoebus-tuned/linux"),
"{tuned}"
);
assert!(!tuned.contains("@snapshots"));
// The default was NOT switched: no test boot happened in this // The default was NOT switched: no test boot happened in this
// context, so the generic kernel stays the default. // context, so the generic kernel stays the default.
let loader = std::fs::read_to_string(root.join("efi/loader/loader.conf")).unwrap(); let loader = std::fs::read_to_string(root.join("efi/loader/loader.conf")).unwrap();
@ -451,11 +888,16 @@ mod tests {
) )
.unwrap(); .unwrap();
source_entry_fixture(root, "balanced");
let out = build_balanced_kernel(&exec, root, false).unwrap(); let out = build_balanced_kernel(&exec, root, false).unwrap();
assert!(out.contains("balanced source kernel"), "{out}"); assert!(out.contains("balanced source kernel"), "{out}");
let entry = let entry =
std::fs::read_to_string(root.join("efi/loader/entries/phoebus-balanced.conf")).unwrap(); std::fs::read_to_string(root.join("efi/loader/entries/phoebus-balanced.conf")).unwrap();
assert!(entry.contains("linux /vmlinuz-6.12.32"), "{entry}"); assert!(
entry.contains("/6.12.32-gentoo-dist-phoebus-balanced/linux"),
"{entry}"
);
assert!(!entry.contains("@snapshots"));
assert!(entry.contains("balanced"), "{entry}"); assert!(entry.contains("balanced"), "{entry}");
// The balanced fragment carries broad hot-plug coverage, not tuning. // The balanced fragment carries broad hot-plug coverage, not tuning.
let frag = let frag =
@ -473,4 +915,225 @@ mod tests {
assert!(loader.contains("default phoebus.conf"), "{loader}"); assert!(loader.contains("default phoebus.conf"), "{loader}");
assert!(!loader.contains("phoebus-balanced"), "{loader}"); assert!(!loader.contains("phoebus-balanced"), "{loader}");
} }
#[test]
fn source_entry_refuses_generic_and_missing_initramfs() {
let exec = make_exec(RecordingRunner::new());
let root = &exec.root;
std::fs::create_dir_all(root.join("efi/loader/entries")).unwrap();
std::fs::write(
root.join("efi/loader/entries/generic.conf"),
"title Generic\nlinux /machine/6.12.32/linux\n",
)
.unwrap();
assert!(source_kernel_bls_entry_for_versions(
&exec,
root,
KernelChoice::Balanced,
&source_kernel_versions(root, KernelChoice::Balanced)
)
.is_err());
source_entry_fixture(root, "balanced");
std::fs::remove_file(root.join("efi/machine/6.12.32-gentoo-dist-phoebus-balanced/initrd"))
.unwrap();
assert!(source_kernel_bls_entry_for_versions(
&exec,
root,
KernelChoice::Balanced,
&source_kernel_versions(root, KernelChoice::Balanced)
)
.is_err());
assert!(!root
.join("efi/loader/entries/phoebus-balanced.conf")
.exists());
}
#[test]
fn wildcard_default_is_pinned_to_the_existing_generic_entry() {
let exec = make_exec(RecordingRunner::new());
let root = &exec.root;
std::fs::create_dir_all(root.join("efi/loader/entries")).unwrap();
std::fs::write(
root.join("efi/loader/entries/generic.conf"),
"title Generic\nlinux /machine/6.12.32-gentoo-dist-bin/linux\n",
)
.unwrap();
source_entry_fixture(root, "balanced");
let pinned = pin_wildcard_default(root, "default *\ntimeout 5\n").unwrap();
assert_eq!(pinned, "default generic.conf\ntimeout 5\n");
for selected in [
"phoebus-balanced.conf",
"phoebus-tuned.conf",
"machine-6.12.32-gentoo-dist-phoebus-balanced.conf",
] {
assert_eq!(
pin_wildcard_default(root, &format!("default {selected}\n")).unwrap(),
"default generic.conf\n"
);
}
std::fs::rename(
root.join("efi/loader/entries/generic.conf"),
root.join("efi/loader/entries/generic+3-0.conf"),
)
.unwrap();
assert!(pin_wildcard_default(root, "default *\n")
.unwrap()
.contains("default generic.conf"));
}
#[test]
fn source_build_requires_running_the_generic_fallback() {
assert!(require_generic_build_boot("6.12.32-gentoo-dist-bin").is_ok());
for release in [
"6.12.32-gentoo-dist",
"6.12.32-gentoo-dist-phoebus-balanced",
"6.12.32-gentoo-dist-phoebus-tuned",
] {
assert!(require_generic_build_boot(release)
.unwrap_err()
.to_string()
.contains("boot the prebuilt generic kernel"));
}
}
#[test]
fn obsolete_source_alias_is_removed_without_touching_other_entries() {
let exec = make_exec(RecordingRunner::new());
let root = &exec.root;
std::fs::create_dir_all(root.join("efi/loader/entries")).unwrap();
source_entry_fixture(root, "balanced");
std::fs::copy(
root.join("efi/loader/entries/zz-source.conf"),
root.join("efi/loader/entries/phoebus-balanced.conf"),
)
.unwrap();
std::fs::copy(
root.join("efi/loader/entries/zz-source.conf"),
root.join("efi/loader/entries/user.conf"),
)
.unwrap();
std::fs::remove_dir_all(
root.join("lib/modules/6.12.32-gentoo-dist-phoebus-balanced/kernel"),
)
.unwrap();
source_entry_fixture(root, "tuned");
std::fs::copy(
root.join("efi/loader/entries/zz-source.conf"),
root.join("efi/loader/entries/phoebus-tuned.conf"),
)
.unwrap();
let recovery = std::fs::read(root.join("efi/loader/entries/00-recovery.conf")).unwrap();
let user = std::fs::read(root.join("efi/loader/entries/user.conf")).unwrap();
prune_obsolete_source_aliases(&exec, root).unwrap();
assert!(!root
.join("efi/loader/entries/phoebus-balanced.conf")
.exists());
assert!(root.join("efi/loader/entries/phoebus-tuned.conf").exists());
assert_eq!(
std::fs::read(root.join("efi/loader/entries/00-recovery.conf")).unwrap(),
recovery
);
assert_eq!(
std::fs::read(root.join("efi/loader/entries/user.conf")).unwrap(),
user
);
}
#[test]
fn failed_build_restores_default_changed_by_dependency_hooks() {
struct DependencyHooks {
runner: RecordingRunner,
loader: std::path::PathBuf,
}
impl crate::command::ProcessRunner for DependencyHooks {
fn execute(
&self,
spec: &crate::command::CommandSpec,
) -> Result<crate::command::CommandOutput> {
let mut output = crate::command::ProcessRunner::execute(&self.runner, spec)?;
if spec.args.iter().any(|arg| arg == "--onlydeps") {
assert_eq!(
std::fs::read_to_string(&self.loader).unwrap(),
"default generic.conf\ntimeout 5\n"
);
std::fs::write(&self.loader, "default untested-new-kernel.conf\n").unwrap();
}
if spec.args.iter().any(|arg| arg == "--buildpkgonly") {
output.success = false;
output.status = 1;
}
Ok(output)
}
}
let temp = tempfile::tempdir().unwrap();
let root = temp.path().join("root");
std::fs::create_dir_all(root.join("var/db/pkg/sys-kernel/gentoo-kernel-bin-6.12.32"))
.unwrap();
std::fs::create_dir_all(root.join("efi/loader/entries")).unwrap();
std::fs::write(
root.join("efi/loader/entries/generic.conf"),
"title Generic\nlinux /machine/6.12.32-gentoo-dist-bin/linux\n",
)
.unwrap();
let loader = root.join("efi/loader/loader.conf");
std::fs::write(&loader, "default *\ntimeout 5\n").unwrap();
let runner = RecordingRunner::new();
runner.set_response(
"chroot",
crate::command::CommandOutput {
status: 0,
success: true,
stdout: b"[ebuild N ] sys-kernel/gentoo-kernel-6.12.32\n".to_vec(),
stderr: vec![],
duration: std::time::Duration::ZERO,
},
);
let logger = Logger::open(temp.path().join("test.log"), Redactor::new(), false);
let exec = Exec::new(
Box::new(DependencyHooks {
runner: runner.clone(),
loader: loader.clone(),
}),
logger,
false,
root.clone(),
temp.path().to_path_buf(),
);
let error = build_balanced_kernel(&exec, &root, false).unwrap_err();
assert!(error.to_string().contains("build failed"), "{error}");
assert_eq!(
std::fs::read_to_string(&loader).unwrap(),
"default generic.conf\ntimeout 5\n"
);
assert!(!runner
.recorded()
.iter()
.any(|s| s.args.iter().any(|a| a == "--usepkgonly")));
}
#[test]
fn rebuilt_release_is_not_promoted_until_a_later_boot() {
let temp = tempfile::tempdir().unwrap();
let vdb = temp
.path()
.join("var/db/pkg/sys-kernel/gentoo-kernel-6.12.32");
std::fs::create_dir_all(&vdb).unwrap();
let release = "6.12.32-gentoo-dist-phoebus-balanced";
std::fs::write(
vdb.join("CONTENTS"),
format!("obj /usr/lib/modules/{release}/modules.dep hash 0\n"),
)
.unwrap();
std::fs::write(vdb.join("COUNTER"), "1\n").unwrap();
assert!(!installed_source_predates_boot(temp.path(), release, 0));
let later_boot = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs()
+ 1;
assert!(installed_source_predates_boot(
temp.path(),
release,
later_boot
));
assert!(!installed_source_predates_boot(
temp.path(),
"different-release",
later_boot
));
}
} }

View file

@ -57,7 +57,20 @@ pub fn read_history_lossy(exec: &Exec, root: &Path) -> SnapshotHistory {
} }
pub fn write_history(root: &Path, history: &SnapshotHistory) -> Result<()> { pub fn write_history(root: &Path, history: &SnapshotHistory) -> Result<()> {
history.save(&history_path(root)).map_err(ExecError::Core) use std::os::unix::fs::PermissionsExt;
let target = phoebus_core::TargetRoot::new(root);
let text = toml::to_string_pretty(history)
.map_err(|e| ExecError::operation("snapshot", "serialize history", e.to_string()))?;
let path = target.write(HISTORY_REL, text)?;
// This contains snapshot identifiers/status, not credentials. `sys history`
// is a normal-user query; keep its metadata readable and root writable.
if let Some(parent) = path.parent() {
std::fs::set_permissions(parent, std::fs::Permissions::from_mode(0o755))
.map_err(|e| ExecError::io(parent.to_path_buf(), e))?;
}
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o644))
.map_err(|e| ExecError::io(path, e))?;
Ok(())
} }
fn now_unix() -> u64 { fn now_unix() -> u64 {
@ -376,6 +389,35 @@ mod tests {
Exec::new(Box::new(runner), logger, false, path.join("root"), path) Exec::new(Box::new(runner), logger, false, path.join("root"), path)
} }
#[test]
fn snapshot_metadata_remains_readable_after_private_bootstrap() {
use std::os::unix::fs::PermissionsExt;
let exec = make_exec(RecordingRunner::new());
let path = history_path(&exec.root);
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
std::fs::write(&path, "").unwrap();
std::fs::set_permissions(
path.parent().unwrap(),
std::fs::Permissions::from_mode(0o700),
)
.unwrap();
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600)).unwrap();
write_history(&exec.root, &SnapshotHistory::default()).unwrap();
assert_eq!(
std::fs::metadata(&path).unwrap().permissions().mode() & 0o777,
0o644
);
assert_eq!(
std::fs::metadata(path.parent().unwrap())
.unwrap()
.permissions()
.mode()
& 0o777,
0o755
);
assert!(read_history(&exec.root).unwrap().records.is_empty());
}
#[test] #[test]
fn create_uses_readonly_btrfs_snapshot() { fn create_uses_readonly_btrfs_snapshot() {
let runner = RecordingRunner::new(); let runner = RecordingRunner::new();

View file

@ -431,6 +431,24 @@ pub fn handle_request(
// so the CLI and GUI see the same preferences. // so the CLI and GUI see the same preferences.
let storage = UserStorage::for_initiating_user(); let storage = UserStorage::for_initiating_user();
match req.op.as_str() { match req.op.as_str() {
"prepare_build" => {
let Some(value) = req.action else {
return BridgeResponse::err(id, "select a source application or kernel build");
};
let action = match phoebus_core::action::parse_action(&value.to_string()) {
Ok(
action @ (SystemAction::ConvertToSource { .. }
| SystemAction::BuildBalancedKernel {
make_default: false,
}
| SystemAction::BuildTunedKernel {
make_default: false,
}),
) => action,
_ => return BridgeResponse::err(id, "unsupported post-install build choice"),
};
execute_action_helper(exec, root, plans, id, action, false, true)
}
"overlay_prepare" => { "overlay_prepare" => {
let atom = req.application.unwrap_or_default(); let atom = req.application.unwrap_or_default();
let repository = req.repository.unwrap_or_default(); let repository = req.repository.unwrap_or_default();
@ -529,7 +547,15 @@ pub fn handle_request(
let action = SystemAction::Undo { let action = SystemAction::Undo {
snapshot: req.snapshot, snapshot: req.snapshot,
}; };
execute_action_helper(exec, root, plans, id, action, req.yes.unwrap_or(false)) execute_action_helper(
exec,
root,
plans,
id,
action,
req.yes.unwrap_or(false),
false,
)
} }
"legacy_install" => { "legacy_install" => {
let app = match req.application { let app = match req.application {
@ -590,7 +616,15 @@ pub fn handle_request(
} else { } else {
return BridgeResponse::err(id, "missing action or phrase parameter"); return BridgeResponse::err(id, "missing action or phrase parameter");
}; };
execute_action_helper(exec, root, plans, id, action, req.yes.unwrap_or(false)) execute_action_helper(
exec,
root,
plans,
id,
action,
req.yes.unwrap_or(false),
false,
)
} }
"ask" => { "ask" => {
let query = req.request.unwrap_or_default(); let query = req.request.unwrap_or_default();
@ -1028,6 +1062,7 @@ fn execute_action_helper(
id: u64, id: u64,
action: SystemAction, action: SystemAction,
assume_yes: bool, assume_yes: bool,
prepare_only: bool,
) -> BridgeResponse { ) -> BridgeResponse {
let mut effects = match actions::resolve_effects(exec, &action, root) { let mut effects = match actions::resolve_effects(exec, &action, root) {
Ok(plan) => plan, Ok(plan) => plan,
@ -1045,7 +1080,11 @@ fn execute_action_helper(
expires_unix: now + service::DEFAULT_PLAN_TTL_SECONDS, expires_unix: now + service::DEFAULT_PLAN_TTL_SECONDS,
kind: service::PlanKind::General, kind: service::PlanKind::General,
summary: action.describe(), summary: action.describe(),
recommendation: action.describe(), recommendation: if prepare_only {
actions::preview(&action)
} else {
action.describe()
},
application: None, application: None,
candidate: None, candidate: None,
alternatives: Vec::new(), alternatives: Vec::new(),
@ -1067,6 +1106,10 @@ fn execute_action_helper(
return BridgeResponse::err(id, format!("could not stage plan: {e}")); return BridgeResponse::err(id, format!("could not stage plan: {e}"));
} }
if prepare_only {
return plan_response(id, "plan", &plan);
}
match service::execute_plan(exec, root, plans, &plan.id, &digest, assume_yes) { match service::execute_plan(exec, root, plans, &plan.id, &digest, assume_yes) {
Ok(outcome) => BridgeResponse::ok( Ok(outcome) => BridgeResponse::ok(
id, id,
@ -1277,6 +1320,66 @@ mod tests {
} }
} }
#[test]
fn build_choice_stages_review_without_installing_or_requiring_ai() {
let temp = tempdir().unwrap();
let runner = RecordingRunner::new();
runner.set_response(
"chroot",
phoebus_executor::command::CommandOutput {
status: 0,
success: true,
stdout: b"[ebuild N ] sys-kernel/gentoo-kernel-6.12.32\n".to_vec(),
stderr: vec![],
duration: std::time::Duration::ZERO,
},
);
let logger = Logger::open(temp.path().join("test.log"), Redactor::new(), false);
let root = temp.path().join("root");
std::fs::create_dir_all(&root).unwrap();
let exec = Exec::new(
Box::new(runner.clone()),
logger,
false,
root.clone(),
temp.path().to_path_buf(),
);
let plans = PlanStore::with_dir(temp.path().join("plans"));
let mut req = request("prepare_build");
req.action = Some(json!({"action":"build_balanced_kernel","make_default":false}));
let response = handle_request(&exec, &root, &plans, req);
assert!(response.ok, "{response:?}");
let result = response.result.unwrap();
assert_eq!(result["state"], "prepared");
assert!(result["recommendation"]
.as_str()
.unwrap()
.contains("gentoo-kernel-bin"));
assert!(!runner.recorded().is_empty());
assert!(runner
.recorded()
.iter()
.all(|spec| spec.args.iter().any(|arg| arg == "--pretend")));
assert!(!root.join("etc/kernel/config.d").exists());
}
#[test]
fn build_choice_rejects_other_actions_and_default_changes() {
let temp = tempdir().unwrap();
let exec = make_test_exec(temp.path());
let plans = PlanStore::with_dir(temp.path().join("plans"));
for action in [
json!({"action":"build_tuned_kernel","make_default":true}),
json!({"action":"remove_package","atom":"sys-kernel/gentoo-kernel-bin"}),
] {
let mut req = request("prepare_build");
req.action = Some(action);
let response = handle_request(&exec, temp.path(), &plans, req);
assert!(!response.ok);
}
assert!(!temp.path().join("plans").exists());
}
/// Serializes tests that redirect personal storage through the process /// Serializes tests that redirect personal storage through the process
/// environment. /// environment.
static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());

View file

@ -117,6 +117,10 @@ Singleton {
call("legacy_execute", { phrase: phrase, action: action, yes: yes }, cb); call("legacy_execute", { phrase: phrase, action: action, yes: yes }, cb);
} }
function prepareBuild(action, cb, onProgress) {
call("prepare_build", { action: action }, cb, onProgress);
}
function getUpdates(cb) { function getUpdates(cb) {
call("updates", {}, cb); call("updates", {}, cb);
} }

View file

@ -11,7 +11,8 @@ ShellRoot {
// Keep the broker and conversation alive while the scratchpad is hidden. // Keep the broker and conversation alive while the scratchpad is hidden.
property bool panelOpen: true property bool panelOpen: true
property string currentTab: Quickshell.env("PHOEBUS_ASSISTANT_START_TAB") === "updates" ? "updates" : "assistant" property string currentTab: ["updates", "builds"].indexOf(Quickshell.env("PHOEBUS_ASSISTANT_START_TAB")) >= 0 ? Quickshell.env("PHOEBUS_ASSISTANT_START_TAB") : "assistant"
property string buildKind: Quickshell.env("PHOEBUS_ASSISTANT_BUILD_KIND") === "kernel" ? "kernel" : "source"
property var conversation: [] property var conversation: []
signal activityEvent(int messageIndex, int position, var entry) signal activityEvent(int messageIndex, int position, var entry)
property bool busy: false property bool busy: false
@ -400,6 +401,23 @@ ShellRoot {
focusTimer.start(); focusTimer.start();
} }
function prepareBuild(action) {
shell.busy = true;
shell.statusText = "Checking the source build and its dependencies…";
const index = addMessage("assistant", "Preparing the selected build for review…", { state: "investigating", activity: [] });
shell.currentTab = "assistant";
AssistantBridge.prepareBuild(action, reply => {
shell.busy = false;
if (reply.ok) {
finishMessage(index, reply.result.recommendation, reply.result);
shell.statusText = "Build plan ready for approval";
} else {
finishMessage(index, reply.error || "Build review failed.", { state: "failed" });
shell.statusText = "Build could not be prepared";
}
}, progress => shell.recordActivity(index, progress));
}
IpcHandler { IpcHandler {
target: "panel" target: "panel"
@ -423,6 +441,13 @@ ShellRoot {
shell.checkUpdates(); shell.checkUpdates();
return "shown"; return "shown";
} }
function builds(kind: string): string {
shell.buildKind = kind === "kernel" ? "kernel" : "source";
shell.currentTab = "builds";
shell.showPanel();
return "shown";
}
} }
Timer { Timer {
@ -430,10 +455,17 @@ ShellRoot {
interval: 120 interval: 120
onTriggered: { onTriggered: {
if (shell.panelOpen) { if (shell.panelOpen) {
if (shell.currentTab === "builds") {
if (shell.buildKind === "kernel")
kernelBuildChoice.forceActiveFocus();
else
sourceBuildChoice.forceActiveFocus();
} else {
promptField.forceActiveFocus(); promptField.forceActiveFocus();
} }
} }
} }
}
FloatingWindow { FloatingWindow {
id: window id: window
@ -492,11 +524,11 @@ ShellRoot {
Layout.preferredWidth: 8 Layout.preferredWidth: 8
Layout.preferredHeight: 8 Layout.preferredHeight: 8
radius: 4 radius: 4
color: (shell.currentTab === "updates" ? AssistantBridge.ready : shell.assistantConnected) ? Theme.primary : Theme.warning color: (["updates", "builds"].indexOf(shell.currentTab) >= 0 ? AssistantBridge.ready : shell.assistantConnected) ? Theme.primary : Theme.warning
} }
Label { Label {
text: shell.currentTab === "updates" ? (AssistantBridge.ready ? "System broker ready" : "Connecting…") : (shell.assistantConnected ? "Connected (" + shell.aiBackend + ")" : (shell.bridgeConnecting ? "Connecting…" : (AssistantBridge.ready ? "Setup required" : "Offline"))) text: ["updates", "builds"].indexOf(shell.currentTab) >= 0 ? (AssistantBridge.ready ? "System broker ready" : "Connecting…") : (shell.assistantConnected ? "Connected (" + shell.aiBackend + ")" : (shell.bridgeConnecting ? "Connecting…" : (AssistantBridge.ready ? "Setup required" : "Offline")))
color: Theme.muted color: Theme.muted
font.pixelSize: 12 font.pixelSize: 12
} }
@ -544,6 +576,11 @@ ShellRoot {
primary: shell.currentTab === "legacy" primary: shell.currentTab === "legacy"
onClicked: shell.currentTab = "legacy" onClicked: shell.currentTab = "legacy"
} }
PhoebusButton {
label: "Source builds"
primary: shell.currentTab === "builds"
onClicked: shell.currentTab = "builds"
}
PhoebusButton { PhoebusButton {
label: "Alerts" + (shell.activeAlerts.length > 0 ? " (" + shell.activeAlerts.length + ")" : "") label: "Alerts" + (shell.activeAlerts.length > 0 ? " (" + shell.activeAlerts.length + ")" : "")
@ -627,6 +664,13 @@ ShellRoot {
property int messageIndex: index property int messageIndex: index
width: chatList.width width: chatList.width
height: msgCol.height + 16 height: msgCol.height + 16
// Keep the running action visible when its activity
// expands below a long approval summary.
onHeightChanged: {
if (messageIndex === chatList.count - 1 && modelData.data
&& ["executing", "completed", "error"].includes(modelData.data.state))
Qt.callLater(() => chatList.positionViewAtEnd());
}
radius: 8 radius: 8
color: modelData.sender === "user" ? Theme.cardHover : Theme.card color: modelData.sender === "user" ? Theme.cardHover : Theme.card
border.color: Theme.border border.color: Theme.border
@ -1159,6 +1203,58 @@ ShellRoot {
} }
} }
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
visible: shell.currentTab === "builds"
spacing: 16
Label { text: "Optional source builds"; color: Theme.text; font.pixelSize: 22 }
Label {
text: "Choose an application or kernel, then review its packages, build time and disk needs. Nothing starts until you approve the plan. Builds need network access and may take hours."
wrapMode: Text.WordWrap
Layout.fillWidth: true
color: Theme.muted
}
RowLayout {
PhoebusButton { label: "Applications"; primary: shell.buildKind === "source"; onClicked: shell.buildKind = "source" }
PhoebusButton { label: "Kernel"; primary: shell.buildKind === "kernel"; onClicked: shell.buildKind = "kernel" }
}
ComboBox {
id: sourceBuildChoice
visible: shell.buildKind === "source"
Layout.fillWidth: true
model: ["Firefox", "LibreOffice", "Thunderbird", "Calibre", "GIMP"]
}
ComboBox {
id: kernelBuildChoice
visible: shell.buildKind === "kernel"
Layout.fillWidth: true
model: ["Keep the prebuilt generic kernel", "Build a balanced source kernel", "Build a tuned source kernel"]
}
Label {
text: shell.buildKind === "kernel" ? "Boot the generic kernel before starting a source build. It stays the default and fallback. A source kernel gets a separate test boot entry; test it before changing your default. Building another variant can replace an earlier source kernel." : "The current application stays installed during compilation. Your data and desktop defaults are preserved. A protective snapshot supports recovery after installation."
wrapMode: Text.WordWrap
Layout.fillWidth: true
color: Theme.muted
}
PhoebusButton {
label: shell.buildKind === "kernel" && kernelBuildChoice.currentIndex === 0 ? "Keep current kernel" : "Review selected build"
actionEnabled: AssistantBridge.ready && !shell.busy
onClicked: {
if (shell.buildKind === "kernel") {
if (kernelBuildChoice.currentIndex === 0) {
shell.statusText = "Keeping the current prebuilt kernel";
return;
}
shell.prepareBuild({ action: kernelBuildChoice.currentIndex === 1 ? "build_balanced_kernel" : "build_tuned_kernel", make_default: false });
} else {
shell.prepareBuild({ action: "convert_to_source", app: sourceBuildChoice.currentText.toLowerCase() });
}
}
}
Item { Layout.fillHeight: true }
}
// TAB 3: Legacy Admin // TAB 3: Legacy Admin
ColumnLayout { ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true

View file

@ -152,7 +152,9 @@ class Driver:
args += [ args += [
"-boot", "order=c" if boot_disk else "order=d", "-boot", "order=c" if boot_disk else "order=d",
"-vga", "none", "-display", "none", "-vga", "none", "-display", "none",
"-serial", "stdio", # Recovery Ctrl+C belongs to the guest, not the QEMU host process.
"-chardev", "stdio,id=serial0,signal=off",
"-serial", "chardev:serial0",
"-qmp", f"unix:{self.paths.monitor_sock},server,nowait", "-qmp", f"unix:{self.paths.monitor_sock},server,nowait",
"-no-reboot", "-no-reboot",
] ]

View file

@ -0,0 +1,187 @@
#!/bin/bash
# Real compilation/installation acceptance, ONLY inside the disposable guest.
# The host driver provisions the marker after checking its qcow2 boundary.
set -euo pipefail
choice=${1:?choose firefox/libreoffice/thunderbird/calibre/gimp/balanced/tuned}
phase=${2:-execute}
case "$phase" in prepare|verify|execute) ;; *) echo "unsupported phase" >&2; exit 2 ;; esac
case "$choice" in
firefox) atom=www-client/firefox; old=www-client/firefox-bin; program=firefox ;;
libreoffice) atom=app-office/libreoffice; old=app-office/libreoffice-bin; program=libreoffice ;;
thunderbird) atom=mail-client/thunderbird; old=mail-client/thunderbird-bin; program=thunderbird ;;
calibre) atom=app-text/calibre; old=com.calibre_ebook.calibre; program=calibre ;;
gimp) atom=media-gfx/gimp; old=org.gimp.GIMP; program=gimp ;;
balanced|tuned) atom=sys-kernel/gentoo-kernel; old=''; program='' ;;
*) echo 'unsupported test choice' >&2; exit 2 ;;
esac
if [[ $EUID != 0 || ! -f /var/lib/phoebus/postinstall-test-vm ]]; then
echo 'This acceptance test requires the marked disposable VM and root.' >&2
exit 2
fi
manufacturer=$(cat /sys/class/dmi/id/sys_vendor)
case "$manufacturer" in QEMU|KVM) ;; *) echo 'refusing a non-QEMU guest' >&2; exit 2 ;; esac
trap 'echo "CASE source-build-$choice FAIL"' ERR
if [[ $phase != verify ]]; then
started=$(date +%s)
echo "$started" > /tmp/phoebus-build-started
if [[ -n $program ]]; then
runuser -u phoebus -- python3 - "$choice" <<'PY'
import hashlib
import json
import sys
from pathlib import Path
directories = {'firefox': ['.mozilla', '.config/mozilla'],
'thunderbird': ['.thunderbird', '.config/thunderbird'],
'libreoffice': ['.config/libreoffice'],
'calibre': ['.var/app/com.calibre_ebook.calibre', 'Calibre Library'],
'gimp': ['.var/app/org.gimp.GIMP']}
preserved = {}
for relative in directories[sys.argv[1]]:
directory = Path.home() / relative
directory.mkdir(parents=True, exist_ok=True)
sentinel = directory / '.phoebus-preservation-test'
sentinel.write_text('Phoebus post-install data preservation acceptance\n')
files = [sentinel]
for name in ['profiles.ini', 'compatibility.ini', 'prefs.js', 'gui.json',
'gimprc', 'registrymodifications.xcu', 'metadata.db', '*.epub']:
files.extend(directory.rglob(name))
for file in files:
preserved[str(file)] = hashlib.sha256(file.read_bytes()).hexdigest()
Path('/tmp/phoebus-build-user-data.json').write_text(json.dumps(preserved))
PY
fi
if [[ -n $program ]]; then
runuser -u phoebus -- python3 - "$choice" <<'PY'
import json
import subprocess
import sys
from pathlib import Path
types = {'firefox': ['text/html', 'x-scheme-handler/https'],
'thunderbird': ['x-scheme-handler/mailto'],
'libreoffice': ['application/vnd.oasis.opendocument.text'],
'calibre': ['application/epub+zip'], 'gimp': ['image/png']}
defaults = {mime: subprocess.check_output(['xdg-mime', 'query', 'default', mime],
text=True).strip()
for mime in types[sys.argv[1]]}
if sys.argv[1] == 'libreoffice':
writers = list(Path('/usr/share/applications').glob('libreoffice*-writer.desktop'))
assert len(writers) == 1, 'no unique original binary Writer desktop entry'
defaults[types['libreoffice'][0]] = writers[0].name
assert all(defaults.values()), 'initial desktop default is missing'
# Pin these as explicit fixture preferences. An inferred fallback can change
# when a new MIME provider appears even though no preference file was touched.
for mime, desktop_id in defaults.items():
subprocess.run(['xdg-mime', 'default', desktop_id, mime], check=True)
Path('/tmp/phoebus-build-desktop-defaults.json').write_text(json.dumps(defaults))
PY
fi
portageq match / sys-kernel/gentoo-kernel-bin > /tmp/phoebus-fallback-before
[[ -s /tmp/phoebus-fallback-before ]]
# Keep a digest of the existing generic kernel and initramfs images, so a
# successful source build cannot hide a overwritten fallback.
python3 - <<'PY'
import hashlib
import json
from pathlib import Path
images = {}
for path in Path('/efi/loader/entries').glob('*.conf'):
text = path.read_text()
if 'recovery' in text.lower() or '-phoebus-' in text:
continue
for line in text.splitlines():
words = line.split()
if len(words) == 2 and words[0] in ['linux', 'initrd']:
image = Path('/efi') / words[1].lstrip('/')
images[str(image)] = hashlib.sha256(image.read_bytes()).hexdigest()
assert len(images) >= 2, 'no complete generic kernel entry'
Path('/tmp/phoebus-fallback-images.json').write_text(json.dumps(images))
PY
fi
if [[ $phase == prepare ]]; then
echo "CASE source-build-$choice prepared"
exit 0
fi
started=$(cat /tmp/phoebus-build-started)
if [[ $phase == execute ]]; then
if [[ $choice == balanced || $choice == tuned ]]; then
action="{\"action\":\"build_${choice}_kernel\",\"make_default\":false}"
else
action="{\"action\":\"convert_to_source\",\"app\":\"$choice\"}"
fi
/usr/local/bin/sys --legacy --yes --action "$action"
fi
portageq match / "$atom" > /tmp/phoebus-source-after
[[ -s /tmp/phoebus-source-after ]]
portageq match / sys-kernel/gentoo-kernel-bin > /tmp/phoebus-fallback-after
cmp /tmp/phoebus-fallback-before /tmp/phoebus-fallback-after
python3 - <<'PY'
import hashlib
import json
from pathlib import Path
for image, expected in json.loads(Path('/tmp/phoebus-fallback-images.json').read_text()).items():
assert hashlib.sha256(Path(image).read_bytes()).hexdigest() == expected, image
print('CASE generic-kernel-images-preserved PASS')
PY
if [[ -n $program ]]; then
python3 - <<'PY'
import hashlib
import json
from pathlib import Path
for file, expected in json.loads(Path('/tmp/phoebus-build-user-data.json').read_text()).items():
assert hashlib.sha256(Path(file).read_bytes()).hexdigest() == expected, file
print('CASE converted-user-data-preserved PASS')
PY
if [[ $old == */* ]]; then
[[ -z $(portageq match / "$old") ]]
else
if flatpak info --system "$old" >/dev/null 2>&1; then
echo 'replaced Flatpak is still installed' >&2
exit 1
fi
fi
# Use the real installation user. Browsers retain their normal sandbox.
timeout 60 runuser -u phoebus -- env QT_QPA_PLATFORM=offscreen "$program" --version
runuser -u phoebus -- python3 - "$choice" <<'PY'
import json
import subprocess
import sys
from pathlib import Path
directories = [Path.home() / '.local/share/applications',
Path('/usr/local/share/applications'), Path('/usr/share/applications'),
Path('/var/lib/flatpak/exports/share/applications')]
for mime, previous in json.loads(Path('/tmp/phoebus-build-desktop-defaults.json').read_text()).items():
desktop_id = subprocess.check_output(['xdg-mime', 'query', 'default', mime], text=True).strip()
assert desktop_id == previous, f'{mime}: desktop default changed from {previous} to {desktop_id}'
entry = next((directory / desktop_id for directory in directories
if (directory / desktop_id).is_file()), None)
assert desktop_id and entry, f'{mime}: default application no longer resolves'
text = entry.read_text()
removed_flatpaks = {'calibre': 'com.calibre_ebook.calibre.desktop', 'gimp': 'org.gimp.GIMP.desktop'}
if desktop_id == removed_flatpaks.get(sys.argv[1]):
assert 'flatpak run' not in text, f'{mime}: default still launches removed Flatpak'
assert 'Exec=firefox-bin' not in text and 'Exec=thunderbird-bin' not in text, f'{mime}: default still launches removed binary'
print('CASE converted-desktop-defaults-preserved PASS')
PY
else
test -s "/efi/loader/entries/phoebus-${choice}.conf"
grep -q -- "-phoebus-${choice}/linux" "/efi/loader/entries/phoebus-${choice}.conf"
if grep -q '^default \*$' /efi/loader/loader.conf; then
echo 'wildcard default could select the new source kernel' >&2
exit 1
fi
python3 - <<'PY'
from pathlib import Path
for entry in Path('/efi/loader/entries').glob('*.conf'):
for line in entry.read_text().splitlines():
words = line.split()
if len(words) == 2 and words[0] in ['linux', 'initrd']:
image = Path('/efi') / words[1].lstrip('/')
assert image.is_file(), f'{entry.name}: missing {image}'
if words[0] == 'linux':
modules = Path('/usr/lib/modules') / image.parent.name / 'kernel'
assert any(modules.rglob('*.ko*')), f'{entry.name}: missing kernel modules'
print('CASE all-boot-entry-images-present PASS')
PY
fi
echo "BUILD_SECONDS=$(( $(date +%s) - started ))"
echo "CASE source-build-$choice PASS"

View file

@ -0,0 +1,75 @@
#!/usr/bin/env python3
"""Exercise every installed build choice through the real assistant bridge.
Run as the desktop user inside a disposable Phoebus VM. Preparation must
produce approval-bound source plans without changing the package database.
Compilation/boot and the visible welcome journey are separate acceptance runs.
"""
import hashlib
import json
import pathlib
import subprocess
import sys
def installed_state():
records = sorted(str(p) for p in pathlib.Path('/var/db/pkg').glob('*/*'))
return hashlib.sha256('\n'.join(records).encode()).hexdigest()
def main():
before = installed_state()
bridge = subprocess.Popen(['/usr/local/bin/sys', '--assistant-bridge'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
text=True)
choices = [(app, {'action': 'convert_to_source', 'app': app}, atom)
for app, atom in [('firefox', 'www-client/firefox'),
('libreoffice', 'app-office/libreoffice'),
('thunderbird', 'mail-client/thunderbird'),
('calibre', 'app-text/calibre'),
('gimp', 'media-gfx/gimp')]]
choices += [(kind, {'action': f'build_{kind}_kernel', 'make_default': False},
'sys-kernel/gentoo-kernel') for kind in ['balanced', 'tuned']]
failures = 0
reviews = {}
try:
for request_id, (name, action, atom) in enumerate(choices, 1):
bridge.stdin.write(json.dumps({'id': request_id, 'op': 'prepare_build',
'action': action}) + '\n')
bridge.stdin.flush()
for line in bridge.stdout:
reply = json.loads(line)
if reply.get('id') == request_id and 'event' not in reply:
break
else:
raise RuntimeError('assistant bridge exited before returning a review')
result = reply.get('result') or {}
effects = result.get('effects') or []
source = any(e.get('source') == 'source'
and e.get('target', '').startswith(atom + '-')
and e.get('target', '')[len(atom) + 1:][:1].isdigit()
for e in effects)
ok = (reply.get('ok') and result.get('state') == 'prepared'
and result.get('plan_id') and result.get('digest')
and result.get('actions') == [action] and source)
if ok:
reviews[name] = result
print(f'CASE build-review-{name} PASS', flush=True)
else:
failures += 1
print(f'CASE build-review-{name} FAIL: '
+ str(reply.get('error') or 'missing bound source plan'), flush=True)
unchanged = before == installed_state()
print('CASE build-reviews-no-mutation ' + ('PASS' if unchanged else 'FAIL'), flush=True)
failures += int(not unchanged)
path = pathlib.Path('/tmp/phoebus-build-reviews.json')
path.touch(mode=0o600, exist_ok=True)
path.write_text(json.dumps(reviews, indent=2) + '\n')
finally:
bridge.stdin.close()
bridge.wait(timeout=30)
return int(failures != 0)
if __name__ == '__main__':
sys.exit(main())

View file

@ -0,0 +1,37 @@
#!/bin/bash
# Read-only boot acceptance inside the marked disposable QEMU installation.
set -euo pipefail
choice=${1:?choose generic/balanced/tuned}
[[ -f /var/lib/phoebus/postinstall-test-vm ]]
case "$(cat /sys/class/dmi/id/sys_vendor)" in QEMU|KVM) ;; *) exit 2 ;; esac
trap 'echo "CASE postinstall-kernel-boot-$choice FAIL"' ERR
release=$(uname -r)
case "$choice:$release" in
generic:*-gentoo-dist-bin|balanced:*-gentoo-dist-phoebus-balanced|tuned:*-gentoo-dist-phoebus-tuned) ;;
*) echo "unexpected kernel release: $release" >&2; exit 1 ;;
esac
printf 'KERNEL_RELEASE=%s\n' "$release"
[[ $(systemctl is-system-running) == running ]]
[[ $(systemctl --failed --no-legend --no-pager | wc -l) == 0 ]]
[[ -n $(portageq match / sys-kernel/gentoo-kernel-bin) ]]
[[ -d /usr/lib/modules/$release/kernel ]]
if [[ $choice != generic ]]; then
config="/usr/lib/modules/$release/build/.config"
grep -Fxq "CONFIG_LOCALVERSION=\"-gentoo-dist-phoebus-$choice\"" "$config"
for symbol in USB_USBNET USB_RTL8152 USB_UAS USB_STORAGE USB_SERIAL_FTDI_SIO EXFAT_FS; do
grep -Fxq "CONFIG_$symbol=m" "$config"
done
for module in uas r8152 cdc_ether usb_storage ftdi_sio exfat; do
file=$(modinfo -k "$release" -F filename "$module")
[[ -f $file ]]
done
if [[ $choice == tuned ]]; then
grep -Fxq 'CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y' "$config"
fi
echo "CASE postinstall-kernel-config-$choice PASS"
fi
# This must be the installed root, rather than the recovery snapshot.
grep -q 'rootflags=subvol=@ ' /proc/cmdline
sys history --legacy >/dev/null
[[ $(pgrep -xc greetd) -gt 0 ]]
echo "CASE postinstall-kernel-boot-$choice PASS"

View file

@ -0,0 +1,34 @@
#!/bin/bash
# Verify refusal before package/config changes on a running source kernel.
set -euo pipefail
[[ $EUID == 0 && -f /var/lib/phoebus/postinstall-test-vm ]]
case $(cat /sys/class/dmi/id/sys_vendor) in QEMU|KVM) ;; *) exit 2 ;; esac
case $(uname -r) in
*-gentoo-dist-phoebus-balanced) choice=tuned ;;
*-gentoo-dist-phoebus-tuned) choice=balanced ;;
*) echo 'This check requires a source-kernel test boot.' >&2; exit 2 ;;
esac
trap 'echo "CASE source-kernel-running-build-guard FAIL"' ERR
state=$(mktemp -d /var/tmp/phoebus-kernel-guard.XXXXXX)
trap 'rm -rf "$state"' EXIT
capture() {
python3 - <<'PY'
import hashlib
import json
from pathlib import Path
files = list(Path('/var/db/pkg').glob('*/*/COUNTER'))
files += [p for p in Path('/etc/kernel').rglob('*') if p.is_file()]
files += [Path('/efi/loader/loader.conf')]
print(json.dumps({str(p): hashlib.sha256(p.read_bytes()).hexdigest()
for p in sorted(files)}))
PY
}
capture > "$state/before"
if sys --legacy --yes --action "{\"action\":\"build_${choice}_kernel\",\"make_default\":false}" > "$state/output" 2>&1; then
echo 'replacement build was unexpectedly permitted' >&2
exit 1
fi
grep -q 'boot the prebuilt generic kernel before building a source kernel' "$state/output"
capture > "$state/after"
cmp "$state/before" "$state/after"
echo 'CASE source-kernel-running-build-guard PASS'