diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 132463b..cd09597 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,11 +8,16 @@ Format: Keep a Changelog. Dates are UTC. ## Unreleased ### Added -- **Nix bootstrap (gated).** `phoebus-executor::nix` fetches the pinned, - SHA-256-verified official Nix release and bootstraps it into the target with - discrete commands (store copy, `nix-store --load-db`, `nixbld` users, profile - and daemon units). `packages.nix` defaults off until a VM verifies it. A - binary ebuild was ruled out because the upstream installer has no `DESTDIR`. +- **Nix bootstrap (on by default, VM-verified).** `phoebus-executor::nix` + fetches the pinned, SHA-256-verified official Nix release and bootstraps it + into the target with discrete commands (store copy, `nix-store --load-db`, + `nixbld` users, state dirs, profile and daemon units). A desktop VM confirmed + `nix-daemon.service` active and `nix shell nixpkgs#hello` printing + `Hello, world!`. A binary ebuild was ruled out: the upstream installer has no + `DESTDIR` and runs `nix-store --load-db` against the real root. +- `finalize` now flushes the target (`sync`) before unmounting, so late writes + such as `/usr/local/bin/phoebus-session` and the exported installer log are on + disk even after a forced poweroff. ### Changed - **Installing Phoebus now requires an AI.** The installer refuses an install diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md index fff5641..8b7ace1 100644 --- a/docs/HANDOFF.md +++ b/docs/HANDOFF.md @@ -7,19 +7,22 @@ commit it. It should be short and current; use `git log` for detail. - **Current focus:** four workstreams — AI-assisted install guidance, desktop session reliability, signed-binary reuse, and snapshots/safe updates. - **Last verified:** static Rust binary install + detached boot - (`docs/VM-BOOT-VERIFICATION.md`); in this session additionally: a full dwl - desktop install + detached boot with the session's helpers waiting for the - Wayland socket, the polkit agent running and all helpers reaped on logout; - `sys` snapshot/history and update preparation on an installed Btrfs VM; and - the AI guided path (valid/invalid/malicious/conflicting/no-AI) by fixtures. + (`docs/VM-BOOT-VERIFICATION.md`); in this session additionally: the Debian-Live + appliance ISO (firmware boot, full install, detached boot), the mandatory-AI + gate, desktop portals, and the **built-in Nix lane** (`nix-daemon` active, + `nix shell nixpkgs#hello` -> `Hello, world!`); `sys` snapshot/history and + update preparation on an installed Btrfs VM; and the AI guided path by + fixtures. - **Public repo:** (remote `origin`, SSH port 2222). ## Next actions (in order) -1. **Nix VM verification**: the pinned-release bootstrap is implemented and - gated behind `packages.nix=yes`; verify it in a disposable VM (store load, - `nix-daemon`, `nix shell`), then flip the default on. A binary ebuild was +1. **Re-verify the finalize `sync`** (build `3ba913ba`): the Nix lane is + VM-verified (`nix-daemon` active, `nix shell` works) and on by default, but + the one-line durability fix that should make `/usr/local/bin/phoebus-session` + survive a forced poweroff was not re-run end to end (host root was ~98% full + and the base emerge became pathologically slow). A binary Nix ebuild was ruled out (upstream has no `DESTDIR`). 2. **Physical-seat desktop**: run `/usr/local/bin/phoebus-session` on a real VT and check kitty, XWayland, the polkit agent, logout/reap and reboot diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 98f98f9..53f39d8 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -22,7 +22,7 @@ more interesting. Status vocabulary: **Done**, **Partial**, **Next**, **Later**. | 15 | Recovery environment | Later | recovery BLS entry generated; full recovery image not built | | — | Rust TUI | Partial | ratatui UI with plan/ERASE and AI provider selection; not yet the default on all paths | | — | AI-guided install optimization | Partial | DeepSeek/OpenAI/local providers, evidence-gated typed review, mandatory at install with `--no-ai` break-glass; fixture-verified, no live call | -| — | Nix as a built-in second lane | Partial | pinned-release bootstrap in the target chroot with `nix-daemon`; `packages.nix` gated off pending VM verification | +| — | Nix as a built-in second lane | Partial | pinned-release bootstrap; `nix-daemon` active and `nix shell nixpkgs#hello` VM-verified; on by default | | — | Git workflow + agent guide | Done | this `docs/` set, `.githooks/`, `scripts/` | ## Immediate next steps diff --git a/docs/VM-BOOT-VERIFICATION.md b/docs/VM-BOOT-VERIFICATION.md index 57f6951..20149de 100644 --- a/docs/VM-BOOT-VERIFICATION.md +++ b/docs/VM-BOOT-VERIFICATION.md @@ -289,13 +289,26 @@ An appliance ISO was built **without root** by `installer/live/build.sh` evidence below was recorded with build `c0105bc9a282fddcbefab42baa577ea99843060f00fa45a75bcbc8358186bfd5`. +A desktop install was re-run and verified with build +`c1846f0d18ed9813e5ef3e699b9110f4fb04ab09a4c5ed800970b1d54971d114`: + +- mandatory-AI gate refused the install until `--no-ai` was passed + (`GATE_REFUSED_OK`); +- Nix: `/nix/store/2nhrwv91g6ycpyxvhmvc0xs8p92wp4bk-nix-2.24.9` present, + `nix (Nix) 2.24.9`, `nix-daemon.service` **enabled and active**, and + `nix shell nixpkgs#hello` downloaded from `cache.nixos.org` and printed + `Hello, world!`; +- desktop portals: `xdg-desktop-portal 1.20.4`, `-gtk 1.15.3`, `-wlr 0.7.1`; +- desktop binaries present: `dwl`, `waybar`, `kitty`, `wofi`, `Xwayland`; +- hostname `phoebus`, networking `enp0s2 UP 10.0.2.15/24`, systemd PID 1, + `running`, `0 loaded units listed`. + The current build is -`690936d15912bdef8eb0edb5932e3a845084b492073148687090a79ddb991078`; it carries -the mandatory-AI install gate (`--no-ai`/`--legacy` break-glass), the `local` -model provider, the desktop portals, and the gated (`packages.nix=no`) Nix -bootstrap. It was **not** re-run through the full install in this session -(resource constraints); treat the earlier run as the boot/install evidence and -this as the current artifact. +`3ba913ba660fb7436e26e587e9777f1f65ed10dcc9b50d17458ebb3d3a739b5c`: Nix is now +on by default, and `finalize` flushes the target (`sync`) before unmounting. +That build was **not** re-run end to end because the host root filesystem +reached ~98% and the base emerge became pathologically slow. Treat `c1846f0d` +as the verified artifact and `3ba913ba` as the current one. Firmware boot (UEFI/OVMF, no `-kernel`; the ISO's own grub chain): @@ -322,15 +335,17 @@ never configuration. ### Open items found in this run -- The target came up with the default `gentoo` hostname (empty - `/etc/hostname`) even though the plan/config specified `phoebus`, unlike the - earlier Gentoo-appliance installs. Needs a focused look (possible stage3 or - ordering difference). -- The first detached boot reported `enp0s2 DOWN`; DHCP timing was not - re-checked. The earlier Gentoo-appliance boot had `enp0s2 UP 10.0.2.15/24`. - -Neither affects the proven Gentoo-appliance boot path; both are recorded rather -than hidden. +- **Resolved:** the earlier `gentoo` hostname anomaly did not recur; the target + boots as `phoebus` with `/etc/hostname` set, and DHCP comes up + (`enp0s2 UP 10.0.2.15/24`) once awaited. +- **Implemented, not re-verified:** `/usr/local/bin/phoebus-session` (and the + exported installer log) were absent after boot in the earlier runs. The + installer wrote and existence-checked them, and the root unmounted cleanly, + but comparison with a boot-time-created file showed the **finalize writes were + not on disk**: Btrfs commits lazily and the harness used `poweroff -f`. The + fix is a `sync` in `finalize` before unmounting (build `3ba913ba`). It has not + been re-run end to end (host disk pressure). Until it is, treat the session + script as **unverified** in the shipped ISO. ## Known remaining work diff --git a/docs/adr/0006-package-lanes.md b/docs/adr/0006-package-lanes.md index cd1ee92..aa19dcb 100644 --- a/docs/adr/0006-package-lanes.md +++ b/docs/adr/0006-package-lanes.md @@ -72,8 +72,10 @@ option. revision), never "latest". 4. **No NixOS model.** No `configuration.nix`, no system profiles, no Nix-managed services. Nix manages user environments only. -5. **Gated until verified.** `packages.nix` defaults off until a disposable-VM - install confirms the bootstrap; Nix never becomes a hard dependency. +5. **On by default, VM-verified.** A disposable-VM install confirmed the + bootstrap (`nix-daemon` active, `nix shell nixpkgs#hello` works), so + `packages.nix` is on by default; `NIX_ENABLED='no'` opts out. Nix is never a + hard dependency of boot, run or recovery. ## Rules diff --git a/installer-rs/crates/phoebus-core/src/config.rs b/installer-rs/crates/phoebus-core/src/config.rs index 31bf5ec..d37d2e5 100644 --- a/installer-rs/crates/phoebus-core/src/config.rs +++ b/installer-rs/crates/phoebus-core/src/config.rs @@ -310,8 +310,8 @@ pub struct PackagesConfig { #[serde(default)] pub package_use: Vec, /// Bootstrap Nix into the target (the second, built-in package lane). - /// Gated off until the bootstrap is VM-verified. - #[serde(default)] + /// On by default; set `NIX_ENABLED='no'` to skip. + #[serde(default = "default_enabled")] pub nix: bool, } @@ -323,7 +323,7 @@ impl Default for PackagesConfig { accept_license: "@FREE @BINARY-REDISTRIBUTABLE".into(), build_jobs: None, package_use: Vec::new(), - nix: false, + nix: true, } } } diff --git a/installer-rs/crates/phoebus-executor/src/desktop.rs b/installer-rs/crates/phoebus-executor/src/desktop.rs index 32a9d63..bb5645b 100644 --- a/installer-rs/crates/phoebus-executor/src/desktop.rs +++ b/installer-rs/crates/phoebus-executor/src/desktop.rs @@ -61,7 +61,17 @@ pub fn write_session_script(exec: &Exec, config: &InstallConfig) -> Result<()> { use std::os::unix::fs::PermissionsExt; std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)) .map_err(|e| ExecError::io(path.clone(), e))?; - exec.logger.info("wrote /usr/local/bin/phoebus-session"); + if !path.is_file() { + return Err(ExecError::operation( + "desktop", + "write session script", + format!("session script missing after write: {}", path.display()), + )); + } + exec.logger.info(format!( + "wrote /usr/local/bin/phoebus-session ({})", + path.display() + )); Ok(()) } diff --git a/installer-rs/crates/phoebus-executor/src/nix.rs b/installer-rs/crates/phoebus-executor/src/nix.rs index 236c4bc..56739c9 100644 --- a/installer-rs/crates/phoebus-executor/src/nix.rs +++ b/installer-rs/crates/phoebus-executor/src/nix.rs @@ -107,6 +107,24 @@ fn bootstrap(exec: &Exec, root: &Path, tarball: &Path) -> Result<()> { .map_err(|e| ExecError::io(extracted.join(".reginfo"), e))?; crate::portage::chroot_stdin(exec, root, &nix_store_bin(), &["--load-db"], ®info)?; + // State directories. `nix-daemon.service` is gated on + // ConditionPathIsReadWrite=/nix/var/nix/daemon-socket, so it must exist. + for rel in [ + "nix/var/nix/profiles", + "nix/var/nix/profiles/per-user", + "nix/var/nix/gcroots", + "nix/var/nix/temproots", + "nix/var/nix/daemon-socket", + ] { + let dir = target_path(root, rel); + std::fs::create_dir_all(&dir).map_err(|e| ExecError::io(dir.clone(), e))?; + } + { + use std::os::unix::fs::PermissionsExt; + let sock = target_path(root, "nix/var/nix/daemon-socket"); + let _ = std::fs::set_permissions(&sock, std::fs::Permissions::from_mode(0o755)); + } + // Build users (`nixbld` group + N build users). let _ = crate::portage::chroot(exec, root, "groupadd", &["--system", "nixbld"]); for i in 1..=NIX_BUILD_USERS { @@ -157,21 +175,22 @@ fn bootstrap(exec: &Exec, root: &Path, tarball: &Path) -> Result<()> { "export PATH=/nix/var/nix/profiles/default/bin:$PATH\n", )?; - // The daemon units ship inside the store; symlink and enable them. + // The daemon units ship inside the store; symlink them and create the + // `.wants` links directly (systemctl enable can be a no-op in a chroot). let unit = format!("{store_nix}/lib/systemd/system"); for name in ["nix-daemon.service", "nix-daemon.socket"] { let link = target_path(root, &format!("etc/systemd/system/{name}")); - if let Some(parent) = link.parent() { - std::fs::create_dir_all(parent).map_err(|e| ExecError::io(parent.to_path_buf(), e))?; - } relink(&link, Path::new(&format!("{unit}/{name}")))?; } - if let Err(e) = - crate::portage::chroot(exec, root, "systemctl", &["enable", "nix-daemon.service"]) - { - exec.logger - .warn(format!("could not enable nix-daemon.service: {e}")); + for (wants, name) in [ + ("multi-user.target.wants", "nix-daemon.service"), + ("sockets.target.wants", "nix-daemon.socket"), + ] { + let link = target_path(root, &format!("etc/systemd/system/{wants}/{name}")); + relink(&link, Path::new(&format!("{unit}/{name}")))?; } + let _ = crate::portage::chroot(exec, root, "systemctl", &["enable", "nix-daemon.service"]); + let _ = crate::portage::chroot(exec, root, "systemctl", &["enable", "nix-daemon.socket"]); exec.logger .info(format!("Nix {NIX_VERSION} bootstrapped into the target")); diff --git a/installer-rs/crates/phoebus-installer/src/orchestrate.rs b/installer-rs/crates/phoebus-installer/src/orchestrate.rs index 48983ec..284c8fe 100644 --- a/installer-rs/crates/phoebus-installer/src/orchestrate.rs +++ b/installer-rs/crates/phoebus-installer/src/orchestrate.rs @@ -452,6 +452,21 @@ impl Installer { return Ok(()); } let _ = self.exec.export_log(); + // Rewrite the desktop entry point last so it cannot be shadowed by an + // earlier stage; a no-op for non-desktop profiles. + if let Err(e) = desktop::write_session_script(&self.exec, &self.config) { + self.exec + .logger + .warn(format!("could not write session script: {e}")); + } + // Durability: Btrfs commits lazily (~30s) and the installer's writes + // are not fsynced; flush before unmounting so a forced poweroff cannot + // lose the final files (the session script and the exported log). + let _ = self.exec.run(phoebus_executor::command::CommandSpec::new( + "finalize", + "flush target", + "sync", + )); let _ = self.exec.umount_chroot(); storage::unmount_all( &self.exec,