phoebus_os/installer/live/livefs-hook.sh
Phoebus b4a6b5df80
Some checks are pending
ci / test (push) Waiting to run
feat(nvidia): hardware-driven driver policy, installed integration and live payload
- resolve the NVIDIA branch and kernel-module flavor from PCI device IDs
  (Turing+ open modules; Maxwell/Pascal/Volta proprietary, masked below 595;
  Fermi/Kepler fall back to nouveau, reported; unknown IDs reported)
- capture pci_id/pci_address in the probe; drive VIDEO_CARDS, package.use,
  package.accept_keywords, package.mask, modprobe.d and dracut from the plan,
  preserving hybrid Intel/AMD
- add the nvidia_drivers install stage (after the kernel, before boot) that
  emerges the driver, regenerates the initramfs, records /etc/phoebus/nvidia and
  fails the install on failure; sys update rebuilds modules and the initramfs
- refuse AI changes to x11-drivers/nvidia-drivers
- live ISO: signed non-free components, stable-kernel pin (testing 7.2 breaks
  the 550 driver), DKMS build for the exact kernel, gated pre-greetd load,
  fail-safe entry, gpu-report, and a --verify-live-nvidia build gate that runs
  on cached rootfs builds and fails on any missing component
- docs: ADR 0012, STATUS/CHANGELOG/HANDOFF, live README
- also carries the pending OpenCode model-variant/streaming changes and fixes
  the GUI bridge install thread join that could hang
2026-09-22 21:53:28 -07:00

120 lines
5.2 KiB
Bash

#!/bin/bash
# mmdebstrap customize hook: turn a Debian testing rootfs into the Phoebus live
# desktop (Mango + DankMaterialShell). Runs as root inside mmdebstrap's userns.
#
# Payload installation (binaries, branding, Quickshell UI, the live marker) is
# done by build.sh after the rootfs is extracted, so a cached rootfs
# (PHOEBUS_REUSE_ROOTFS=1) still picks up changed assets. This hook only does
# the expensive, root-requiring work: user accounts, the Mango build and the
# DMS install.
#
# Environment (set by build.sh):
# PHOEBUS_SRC directory with the verified pinned source tarballs
# MANGO_VERSION, DMS_VERSION
set -euo pipefail
root="$1"
: "${PHOEBUS_SRC:?}"
MANGO_VERSION="${MANGO_VERSION:-0.17.2}"
DMS_VERSION="${DMS_VERSION:-1.6.2}"
LIVE_USER=phoebus
in_root() {
chroot "$root" /usr/bin/env -i \
PATH=/usr/sbin:/usr/bin:/sbin:/bin HOME=/root TERM=linux LANG=C.UTF-8 \
"$@"
}
say() { echo "livefs-hook: $*"; }
say "live user"
if ! in_root id "$LIVE_USER" >/dev/null 2>&1; then
in_root useradd --create-home --shell /bin/bash \
--groups sudo,video,render,input,audio "$LIVE_USER"
fi
install -d -m 0755 "$root/etc/sudoers.d"
printf '%s ALL=(ALL) NOPASSWD: ALL\n' "$LIVE_USER" > "$root/etc/sudoers.d/90-phoebus-live"
chmod 440 "$root/etc/sudoers.d/90-phoebus-live"
# A well-known live password so the serial/recovery console is usable; the
# graphical session still logs in automatically via greetd. This is live-only
# and is never written to an installed system.
echo "$LIVE_USER:phoebus" | chroot "$root" chpasswd
# greetd validates its default-session user at startup even when an
# initial_session is configured, so the greeter account must exist.
if ! in_root id greeter >/dev/null 2>&1; then
in_root useradd --system --no-create-home --home-dir /var/lib/greetd \
--shell /sbin/nologin --comment "Phoebus greeter" greeter
fi
say "build Mango ${MANGO_VERSION}"
tar -xzf "$PHOEBUS_SRC/mango-${MANGO_VERSION}.tar.gz" -C "$root/tmp"
in_root sh -c "cd /tmp/mango-${MANGO_VERSION} && \
meson setup build --prefix=/usr --buildtype=release -Dxwayland=enabled && \
ninja -C build && ninja -C build install"
rm -rf "$root/tmp/mango-${MANGO_VERSION}"
say "install DankMaterialShell ${DMS_VERSION}"
mkdir -p "$root/tmp/dms-full"
tar -xzf "$PHOEBUS_SRC/dms-full-amd64.tar.gz" -C "$root/tmp/dms-full"
dmsdir="$root/tmp/dms-full"
[ -x "$dmsdir/bin/dms" ] || { echo "livefs-hook: dms binary missing" >&2; exit 1; }
install -D -m 0755 "$dmsdir/bin/dms" "$root/usr/bin/dms"
install -d "$root/usr/share/quickshell"
cp -a "$dmsdir/dms" "$root/usr/share/quickshell/dms"
if [ -f "$root/usr/share/quickshell/dms/assets/systemd/dms.service" ]; then
install -D -m 0644 \
"$root/usr/share/quickshell/dms/assets/systemd/dms.service" \
"$root/usr/lib/systemd/user/dms.service"
install -d "$root/etc/systemd/user/mango-session.target.wants"
ln -sf /usr/lib/systemd/user/dms.service \
"$root/etc/systemd/user/mango-session.target.wants/dms.service"
fi
for entry in "$root/usr/share/quickshell/dms/assets/"*.desktop; do
[ -f "$entry" ] || continue
install -D -m 0644 "$entry" \
"$root/usr/share/applications/$(basename "$entry")"
done
if [ -d "$dmsdir/completions" ]; then
install -d "$root/usr/share/bash-completion/completions"
[ -f "$dmsdir/completions/completion.bash" ] && \
install -m 0644 "$dmsdir/completions/completion.bash" \
"$root/usr/share/bash-completion/completions/dms"
fi
rm -rf "$root/tmp/dms-full"
say "build NVIDIA kernel modules"
# The accelerated driver must be compiled for the exact kernel this image boots.
# Nothing is built or downloaded at boot; a failure here fails the build.
kernel_version="$(ls -1 "$root"/boot/vmlinuz-* 2>/dev/null | sed 's#.*/vmlinuz-##' | sort -V | tail -1)"
[ -n "$kernel_version" ] || { echo "livefs-hook: no kernel image found for NVIDIA" >&2; exit 1; }
if ! in_root dkms autoinstall -k "$kernel_version"; then
echo "livefs-hook: DKMS failed to build NVIDIA modules for $kernel_version" >&2
exit 1
fi
# Debian's nvidia-kernel-dkms renames the modules nvidia-current*; accept either
# naming so the hook does not depend on the packaging detail.
check_module() { # upstream-name debian-suffix
find "$root/lib/modules/$kernel_version" \
\( -name "$1.ko*" -o -name "nvidia-current$2.ko*" \) -print -quit 2>/dev/null | grep -q .
}
for pair in "nvidia:" "nvidia_modeset:-modeset" "nvidia_uvm:-uvm" "nvidia_drm:-drm"; do
upstream="${pair%%:*}"; suffix="${pair##*:}"
if ! check_module "$upstream" "$suffix"; then
echo "livefs-hook: $upstream.ko is missing for kernel $kernel_version" >&2
exit 1
fi
done
echo "livefs-hook: NVIDIA modules built for $kernel_version"
say "enable services"
# Regenerate the initramfs now that live-boot/live-config and the desktop
# packages are installed, so the live boot hooks are present.
in_root update-initramfs -u -k all >/dev/null 2>&1 || \
echo "livefs-hook: update-initramfs reported an issue" >&2
for svc in greetd.service NetworkManager.service bluetooth.service systemd-resolved.service \
serial-getty@ttyS0.service; do
in_root systemctl enable "$svc" >/dev/null 2>&1 \
|| echo "livefs-hook: could not enable $svc" >&2
done
say "desktop rootfs ready"