feat(nix): default Nix on; flush finalize writes before unmount
Some checks are pending
ci / test (push) Waiting to run

Nix is on by default (NIX_ENABLED=no opts out); a desktop VM verified
nix-daemon active and 'nix shell nixpkgs#hello' -> Hello, world!. Create
/nix/var/nix/daemon-socket (the unit's ConditionPathIsReadWrite) and the
.wants links. finalize now runs sync before unmounting so the session script
and exported log are durable across a forced poweroff.
This commit is contained in:
Phoebus 2026-09-20 22:35:46 -07:00
parent fea647ac7d
commit b12b2768b4
9 changed files with 113 additions and 44 deletions

View file

@ -8,11 +8,16 @@ Format: Keep a Changelog. Dates are UTC.
## Unreleased ## Unreleased
### Added ### Added
- **Nix bootstrap (gated).** `phoebus-executor::nix` fetches the pinned, - **Nix bootstrap (on by default, VM-verified).** `phoebus-executor::nix`
SHA-256-verified official Nix release and bootstraps it into the target with fetches the pinned, SHA-256-verified official Nix release and bootstraps it
discrete commands (store copy, `nix-store --load-db`, `nixbld` users, profile into the target with discrete commands (store copy, `nix-store --load-db`,
and daemon units). `packages.nix` defaults off until a VM verifies it. A `nixbld` users, state dirs, profile and daemon units). A desktop VM confirmed
binary ebuild was ruled out because the upstream installer has no `DESTDIR`. `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 ### Changed
- **Installing Phoebus now requires an AI.** The installer refuses an install - **Installing Phoebus now requires an AI.** The installer refuses an install

View file

@ -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 - **Current focus:** four workstreams — AI-assisted install guidance, desktop
session reliability, signed-binary reuse, and snapshots/safe updates. session reliability, signed-binary reuse, and snapshots/safe updates.
- **Last verified:** static Rust binary install + detached boot - **Last verified:** static Rust binary install + detached boot
(`docs/VM-BOOT-VERIFICATION.md`); in this session additionally: a full dwl (`docs/VM-BOOT-VERIFICATION.md`); in this session additionally: the Debian-Live
desktop install + detached boot with the session's helpers waiting for the appliance ISO (firmware boot, full install, detached boot), the mandatory-AI
Wayland socket, the polkit agent running and all helpers reaped on logout; gate, desktop portals, and the **built-in Nix lane** (`nix-daemon` active,
`sys` snapshot/history and update preparation on an installed Btrfs VM; and `nix shell nixpkgs#hello` -> `Hello, world!`); `sys` snapshot/history and
the AI guided path (valid/invalid/malicious/conflicting/no-AI) by fixtures. update preparation on an installed Btrfs VM; and the AI guided path by
fixtures.
- **Public repo:** <https://git.phoebus.club/phoebus/phoebus_os> - **Public repo:** <https://git.phoebus.club/phoebus/phoebus_os>
(remote `origin`, SSH port 2222). (remote `origin`, SSH port 2222).
## Next actions (in order) ## Next actions (in order)
1. **Nix VM verification**: the pinned-release bootstrap is implemented and 1. **Re-verify the finalize `sync`** (build `3ba913ba`): the Nix lane is
gated behind `packages.nix=yes`; verify it in a disposable VM (store load, VM-verified (`nix-daemon` active, `nix shell` works) and on by default, but
`nix-daemon`, `nix shell`), then flip the default on. A binary ebuild was 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`). ruled out (upstream has no `DESTDIR`).
2. **Physical-seat desktop**: run `/usr/local/bin/phoebus-session` on a real VT 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 and check kitty, XWayland, the polkit agent, logout/reap and reboot

View file

@ -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 | | 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 | | — | 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 | | — | 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/` | | — | Git workflow + agent guide | Done | this `docs/` set, `.githooks/`, `scripts/` |
## Immediate next steps ## Immediate next steps

View file

@ -289,13 +289,26 @@ An appliance ISO was built **without root** by `installer/live/build.sh`
evidence below was recorded with build evidence below was recorded with build
`c0105bc9a282fddcbefab42baa577ea99843060f00fa45a75bcbc8358186bfd5`. `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 The current build is
`690936d15912bdef8eb0edb5932e3a845084b492073148687090a79ddb991078`; it carries `3ba913ba660fb7436e26e587e9777f1f65ed10dcc9b50d17458ebb3d3a739b5c`: Nix is now
the mandatory-AI install gate (`--no-ai`/`--legacy` break-glass), the `local` on by default, and `finalize` flushes the target (`sync`) before unmounting.
model provider, the desktop portals, and the gated (`packages.nix=no`) Nix That build was **not** re-run end to end because the host root filesystem
bootstrap. It was **not** re-run through the full install in this session reached ~98% and the base emerge became pathologically slow. Treat `c1846f0d`
(resource constraints); treat the earlier run as the boot/install evidence and as the verified artifact and `3ba913ba` as the current one.
this as the current artifact.
Firmware boot (UEFI/OVMF, no `-kernel`; the ISO's own grub chain): Firmware boot (UEFI/OVMF, no `-kernel`; the ISO's own grub chain):
@ -322,15 +335,17 @@ never configuration.
### Open items found in this run ### Open items found in this run
- The target came up with the default `gentoo` hostname (empty - **Resolved:** the earlier `gentoo` hostname anomaly did not recur; the target
`/etc/hostname`) even though the plan/config specified `phoebus`, unlike the boots as `phoebus` with `/etc/hostname` set, and DHCP comes up
earlier Gentoo-appliance installs. Needs a focused look (possible stage3 or (`enp0s2 UP 10.0.2.15/24`) once awaited.
ordering difference). - **Implemented, not re-verified:** `/usr/local/bin/phoebus-session` (and the
- The first detached boot reported `enp0s2 DOWN`; DHCP timing was not exported installer log) were absent after boot in the earlier runs. The
re-checked. The earlier Gentoo-appliance boot had `enp0s2 UP 10.0.2.15/24`. installer wrote and existence-checked them, and the root unmounted cleanly,
but comparison with a boot-time-created file showed the **finalize writes were
Neither affects the proven Gentoo-appliance boot path; both are recorded rather not on disk**: Btrfs commits lazily and the harness used `poweroff -f`. The
than hidden. 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 ## Known remaining work

View file

@ -72,8 +72,10 @@ option.
revision), never "latest". revision), never "latest".
4. **No NixOS model.** No `configuration.nix`, no system profiles, no 4. **No NixOS model.** No `configuration.nix`, no system profiles, no
Nix-managed services. Nix manages user environments only. Nix-managed services. Nix manages user environments only.
5. **Gated until verified.** `packages.nix` defaults off until a disposable-VM 5. **On by default, VM-verified.** A disposable-VM install confirmed the
install confirms the bootstrap; Nix never becomes a hard dependency. 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 ## Rules

View file

@ -310,8 +310,8 @@ pub struct PackagesConfig {
#[serde(default)] #[serde(default)]
pub package_use: Vec<PackageUse>, pub package_use: Vec<PackageUse>,
/// Bootstrap Nix into the target (the second, built-in package lane). /// Bootstrap Nix into the target (the second, built-in package lane).
/// Gated off until the bootstrap is VM-verified. /// On by default; set `NIX_ENABLED='no'` to skip.
#[serde(default)] #[serde(default = "default_enabled")]
pub nix: bool, pub nix: bool,
} }
@ -323,7 +323,7 @@ impl Default for PackagesConfig {
accept_license: "@FREE @BINARY-REDISTRIBUTABLE".into(), accept_license: "@FREE @BINARY-REDISTRIBUTABLE".into(),
build_jobs: None, build_jobs: None,
package_use: Vec::new(), package_use: Vec::new(),
nix: false, nix: true,
} }
} }
} }

View file

@ -61,7 +61,17 @@ pub fn write_session_script(exec: &Exec, config: &InstallConfig) -> Result<()> {
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)) std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755))
.map_err(|e| ExecError::io(path.clone(), e))?; .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(()) Ok(())
} }

View file

@ -107,6 +107,24 @@ fn bootstrap(exec: &Exec, root: &Path, tarball: &Path) -> Result<()> {
.map_err(|e| ExecError::io(extracted.join(".reginfo"), e))?; .map_err(|e| ExecError::io(extracted.join(".reginfo"), e))?;
crate::portage::chroot_stdin(exec, root, &nix_store_bin(), &["--load-db"], &reginfo)?; crate::portage::chroot_stdin(exec, root, &nix_store_bin(), &["--load-db"], &reginfo)?;
// 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). // Build users (`nixbld` group + N build users).
let _ = crate::portage::chroot(exec, root, "groupadd", &["--system", "nixbld"]); let _ = crate::portage::chroot(exec, root, "groupadd", &["--system", "nixbld"]);
for i in 1..=NIX_BUILD_USERS { 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", "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"); let unit = format!("{store_nix}/lib/systemd/system");
for name in ["nix-daemon.service", "nix-daemon.socket"] { for name in ["nix-daemon.service", "nix-daemon.socket"] {
let link = target_path(root, &format!("etc/systemd/system/{name}")); 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}")))?; relink(&link, Path::new(&format!("{unit}/{name}")))?;
} }
if let Err(e) = for (wants, name) in [
crate::portage::chroot(exec, root, "systemctl", &["enable", "nix-daemon.service"]) ("multi-user.target.wants", "nix-daemon.service"),
{ ("sockets.target.wants", "nix-daemon.socket"),
exec.logger ] {
.warn(format!("could not enable nix-daemon.service: {e}")); 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 exec.logger
.info(format!("Nix {NIX_VERSION} bootstrapped into the target")); .info(format!("Nix {NIX_VERSION} bootstrapped into the target"));

View file

@ -452,6 +452,21 @@ impl Installer {
return Ok(()); return Ok(());
} }
let _ = self.exec.export_log(); 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(); let _ = self.exec.umount_chroot();
storage::unmount_all( storage::unmount_all(
&self.exec, &self.exec,