Compare commits

..

No commits in common. "fea647ac7da09fec7087bb8fa3b3d712e32760f0" and "32a124e3f90de196b0a40741158cef2d7bcef1d6" have entirely different histories.

9 changed files with 22 additions and 290 deletions

View file

@ -7,13 +7,6 @@ Format: Keep a Changelog. Dates are UTC.
## Unreleased ## 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`.
### Changed ### Changed
- **Installing Phoebus now requires an AI.** The installer refuses an install - **Installing Phoebus now requires an AI.** The installer refuses an install
with no provider unless the explicit break-glass `--no-ai` (alias `--legacy`, with no provider unless the explicit break-glass `--no-ai` (alias `--legacy`,

View file

@ -17,10 +17,9 @@ commit it. It should be short and current; use `git log` for detail.
## Next actions (in order) ## Next actions (in order)
1. **Nix VM verification**: the pinned-release bootstrap is implemented and 1. **Nix packaging**: author a `sys-apps/nix` ebuild (Phoebus overlay) +
gated behind `packages.nix=yes`; verify it in a disposable VM (store load, `nix-daemon.service`, wire it into the installer, and VM-verify. This is the
`nix-daemon`, `nix shell`), then flip the default on. A binary ebuild was remaining piece of "Nix is built in"; it was deliberately not faked.
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
(`docs/DEVELOPMENT.md` -> "Physical VT / real-seat check"). (`docs/DEVELOPMENT.md` -> "Physical VT / real-seat check").

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 | Next | `sys-apps/nix` Portage overlay + `nix-daemon`; installer wiring; not yet packaged |
| — | 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

@ -290,12 +290,11 @@ evidence below was recorded with build
`c0105bc9a282fddcbefab42baa577ea99843060f00fa45a75bcbc8358186bfd5`. `c0105bc9a282fddcbefab42baa577ea99843060f00fa45a75bcbc8358186bfd5`.
The current build is The current build is
`690936d15912bdef8eb0edb5932e3a845084b492073148687090a79ddb991078`; it carries `fec8e312bfe641c423f2656970ae4271a1544b3a6107b407a8a29cb71f8850be`; it carries
the mandatory-AI install gate (`--no-ai`/`--legacy` break-glass), the `local` the mandatory-AI install gate (`--no-ai`/`--legacy` break-glass), the `local`
model provider, the desktop portals, and the gated (`packages.nix=no`) Nix model provider, and the desktop portals. It was **not** re-run through the full
bootstrap. It was **not** re-run through the full install in this session install in this session (resource constraints); treat the earlier run as the
(resource constraints); treat the earlier run as the boot/install evidence and boot/install evidence and this as the current artifact.
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):

View file

@ -55,25 +55,20 @@ Nix is **baked in**, but "baked in" describes availability, not authority:
## How Nix is baked in without surrendering ownership ## How Nix is baked in without surrendering ownership
A normal binary ebuild is **not possible**: the upstream Nix installer hardcodes 1. **Ship it as a Portage package, not the upstream installer.** Provide a
`/nix`, calls `sudo`, and runs `nix-store --load-db` against the real root, with Phoebus overlay ebuild for Nix (e.g. `sys-apps/nix`) that installs the
no `DESTDIR`/`--root` support. Repackaging it into a target image would require toolchain, creates the store and `nixbld` build users, and installs a
re-implementing that bootstrap; building Nix from source is a separate, large `nix-daemon.service` unit. The installer adds the overlay and emerges it as
option. part of the base/desktop package set.
2. **Multi-user, system-managed.** Because it is a real package, a root
1. **Bootstrap the pinned, verified official release** with discrete commands in `nix-daemon` is acceptable: it is enabled like any other service, updated
the target chroot (no `curl | sh`, no `sh -c`), reproducing the installer's through `emerge`, and audited with the rest of the system.
steps: copy the store, `nix-store --load-db`, create the `nixbld` group and 3. **Pinned and verified.** The ebuild pins the Nix version and verifies the
users, wire the profile, and install/enable the `nix-daemon` units. upstream release tarball by SHA-256. The upstream `curl | sh` installer is
2. **Multi-user, systemd-managed.** `nix-daemon.service`/`.socket` are installed never used. nixpkgs itself is pinned per environment (flake lock / channel
and enabled; the store lives at `/nix`. revision), not "latest".
3. **Pinned and verified.** The Nix version and tarball SHA-256 are embedded and
checked fail-closed; nixpkgs is pinned per environment (flake lock / channel
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
install confirms the bootstrap; Nix never becomes a hard dependency.
## Rules ## Rules

View file

@ -309,10 +309,6 @@ pub struct PackagesConfig {
/// Extra scoped USE entries appended to `package.use`. /// Extra scoped USE entries appended to `package.use`.
#[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).
/// Gated off until the bootstrap is VM-verified.
#[serde(default)]
pub nix: bool,
} }
impl Default for PackagesConfig { impl Default for PackagesConfig {
@ -323,7 +319,6 @@ 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,
} }
} }
} }
@ -508,7 +503,6 @@ impl InstallConfig {
Some(parse_num(key, value)?) Some(parse_num(key, value)?)
} }
} }
"NIX" | "NIX_ENABLED" => self.packages.nix = parse_bool(value),
"DESKTOP_PROFILE" => self.desktop.profile = DesktopProfile::from_str(value)?, "DESKTOP_PROFILE" => self.desktop.profile = DesktopProfile::from_str(value)?,
"FLATPAK" => self.desktop.flatpak = parse_bool(value), "FLATPAK" => self.desktop.flatpak = parse_bool(value),

View file

@ -16,7 +16,6 @@ pub mod error;
pub mod exec; pub mod exec;
pub mod kernel; pub mod kernel;
pub mod log; pub mod log;
pub mod nix;
pub mod opencode; pub mod opencode;
pub mod portage; pub mod portage;
pub mod probe; pub mod probe;

View file

@ -1,241 +0,0 @@
//! Nix as a built-in second package lane (bootstrap).
//!
//! The upstream Nix installer hardcodes `/nix`, calls `sudo`, and must run
//! `nix-store --load-db` against the real root, so it cannot be repackaged as a
//! normal binary ebuild. Instead we fetch the **pinned, SHA-256-verified**
//! official release and reproduce its bootstrap with discrete commands in the
//! target chroot. There is no `curl | sh` and no `sh -c`.
//!
//! Gated behind `packages.nix` because it is not VM-verified yet.
use std::path::{Path, PathBuf};
use crate::command::CommandSpec;
use crate::error::{ExecError, Result};
use crate::exec::Exec;
pub const NIX_VERSION: &str = "2.24.9";
pub const NIX_URL: &str =
"https://releases.nixos.org/nix/nix-2.24.9/nix-2.24.9-x86_64-linux.tar.xz";
pub const NIX_SHA256: &str = "3c0779e4878d1289cf3fbb158ec5ea9bdf61dfb9b4efac6b3b0b6bec5ba4cf13";
const NIX_TARBALL_DIR: &str = "nix-2.24.9-x86_64-linux";
const NIX_STORE_NAME: &str = "2nhrwv91g6ycpyxvhmvc0xs8p92wp4bk-nix-2.24.9";
const NIX_BUILD_USERS: u32 = 8;
fn nix_store_bin() -> String {
format!("/nix/store/{NIX_STORE_NAME}/bin/nix-store")
}
fn target_path(root: &Path, rel: &str) -> PathBuf {
root.join(rel)
}
/// Whether the pinned manifest entry looks usable (not a placeholder).
pub fn manifest_is_pinned() -> bool {
NIX_URL.ends_with(".tar.xz")
&& NIX_SHA256.len() == 64
&& NIX_SHA256.chars().all(|c| c.is_ascii_hexdigit())
&& NIX_SHA256.chars().any(|c| c != '0')
}
/// Fetch, verify and bootstrap the pinned Nix release into `root`.
pub fn install(exec: &Exec, root: &Path) -> Result<()> {
exec.require_tools(&["curl", "tar", "sha256sum"])?;
if !manifest_is_pinned() {
return Err(ExecError::operation(
"nix",
"bootstrap",
"the embedded Nix manifest is not pinned",
));
}
if exec.dry_run {
exec.logger.info(format!(
"[dry-run] would bootstrap Nix {NIX_VERSION} into the target"
));
return Ok(());
}
let tarball = exec.state_dir.join("nix.tar.xz");
exec.logger.info(format!("Nix: fetching {NIX_URL}"));
exec.run(
CommandSpec::new("nix", "download Nix", "curl")
.args(["-fL", "--retry", "3", "-o"])
.arg(tarball.to_string_lossy().to_string())
.arg(NIX_URL),
)?;
if !crate::opencode::checksum_ok(&tarball, NIX_SHA256)? {
return Err(ExecError::operation(
"nix",
"verify Nix",
"SHA-256 mismatch; discarding download",
));
}
exec.logger.info("Nix: checksum verified");
let result = bootstrap(exec, root, &tarball);
let _ = std::fs::remove_file(&tarball);
result
}
fn bootstrap(exec: &Exec, root: &Path, tarball: &Path) -> Result<()> {
// Stage and extract inside the target so paths are target-relative.
let tmp = target_path(root, "tmp");
std::fs::create_dir_all(&tmp).map_err(|e| ExecError::io(tmp.clone(), e))?;
let staged = tmp.join("nix.tar.xz");
std::fs::copy(tarball, &staged).map_err(|e| ExecError::io(staged.clone(), e))?;
exec.run(
CommandSpec::new("nix", "extract Nix", "tar")
.args(["-xJf"])
.arg(staged.to_string_lossy().to_string())
.args(["-C"])
.arg(tmp.to_string_lossy().to_string()),
)?;
let extracted = tmp.join(NIX_TARBALL_DIR);
// The Nix store.
let nix_dir = target_path(root, "nix");
std::fs::create_dir_all(&nix_dir).map_err(|e| ExecError::io(nix_dir.clone(), e))?;
exec.run(
CommandSpec::new("nix", "install Nix store", "cp")
.args(["-a"])
.arg(extracted.join("store").to_string_lossy().to_string())
.arg(nix_dir.to_string_lossy().to_string()),
)?;
// Register the store paths from the shipped database.
let reginfo = std::fs::read(extracted.join(".reginfo"))
.map_err(|e| ExecError::io(extracted.join(".reginfo"), e))?;
crate::portage::chroot_stdin(exec, root, &nix_store_bin(), &["--load-db"], &reginfo)?;
// Build users (`nixbld` group + N build users).
let _ = crate::portage::chroot(exec, root, "groupadd", &["--system", "nixbld"]);
for i in 1..=NIX_BUILD_USERS {
let name = format!("nixbld{i}");
let _ = crate::portage::chroot(
exec,
root,
"useradd",
&[
"--system",
"--gid",
"nixbld",
"--home-dir",
"/var/empty",
"--shell",
"/sbin/nologin",
"--comment",
"Nix build user",
name.as_str(),
],
);
}
// Configuration and profile wiring.
write_file(
root,
"etc/nix/nix.conf",
"# Phoebus: Nix as a second package lane.\n\
build-users-group = nixbld\n\
sandbox = false\n\
experimental-features = nix-command flakes\n\
substituters = https://cache.nixos.org\n\
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=\n",
)?;
let profile = "nix/var/nix/profiles";
std::fs::create_dir_all(target_path(root, profile))
.map_err(|e| ExecError::io(target_path(root, profile), e))?;
let default_profile = target_path(root, "nix/var/nix/profiles/default");
let store_nix = format!("/nix/store/{NIX_STORE_NAME}");
relink(&default_profile, Path::new(&store_nix))?;
relink(
&target_path(root, "root/.nix-profile"),
Path::new("/nix/var/nix/profiles/default"),
)?;
write_file(
root,
"etc/profile.d/nix.sh",
"export PATH=/nix/var/nix/profiles/default/bin:$PATH\n",
)?;
// The daemon units ship inside the store; symlink and enable them.
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}"));
}
exec.logger
.info(format!("Nix {NIX_VERSION} bootstrapped into the target"));
// Clean up the staging files.
let _ = std::fs::remove_file(&staged);
let _ = std::fs::remove_dir_all(&extracted);
Ok(())
}
fn write_file(root: &Path, rel: &str, contents: &str) -> Result<()> {
let path = target_path(root, rel);
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent).map_err(|e| ExecError::io(parent.to_path_buf(), e))?;
}
std::fs::write(&path, contents).map_err(|e| ExecError::io(path, e))
}
fn relink(link: &Path, target: &Path) -> Result<()> {
if let Some(parent) = link.parent() {
std::fs::create_dir_all(parent).map_err(|e| ExecError::io(parent.to_path_buf(), e))?;
}
let _ = std::fs::remove_file(link);
std::os::unix::fs::symlink(target, link).map_err(|e| ExecError::io(link.to_path_buf(), e))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::command::RecordingRunner;
use crate::log::Logger;
use phoebus_core::Redactor;
fn make_exec(runner: RecordingRunner, dry_run: bool) -> Exec {
let path = tempfile::tempdir().unwrap().keep();
let logger = Logger::open(path.join("l.log"), Redactor::new(), false);
Exec::new(Box::new(runner), logger, dry_run, path.join("root"), path)
}
#[test]
fn manifest_is_pinned_to_a_real_release() {
assert!(manifest_is_pinned());
assert!(NIX_URL.contains(NIX_VERSION));
assert_eq!(NIX_SHA256.len(), 64);
}
#[test]
fn dry_run_bootstraps_nothing() {
let runner = RecordingRunner::new();
let exec = make_exec(runner.clone(), true);
install(&exec, Path::new(&exec.root)).unwrap();
assert!(
runner.recorded().is_empty(),
"dry-run must not run commands"
);
}
#[test]
fn checksum_policy_reuses_the_shared_verifier() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("nix.tar.xz");
std::fs::write(&file, b"fixture").unwrap();
let good = crate::opencode::sha256_hex(b"fixture");
assert!(crate::opencode::checksum_ok(&file, &good).unwrap());
assert!(!crate::opencode::checksum_ok(&file, &"0".repeat(64)).unwrap());
assert!(!crate::opencode::checksum_ok(&file, "deadbeef").unwrap());
}
}

View file

@ -11,7 +11,7 @@ use phoebus_core::validate::ValidationIssue;
use phoebus_core::{validate, HardwareReport, InstallConfig, InstallPlan, SecretString}; use phoebus_core::{validate, HardwareReport, InstallConfig, InstallPlan, SecretString};
use phoebus_executor::storage::StorageState; use phoebus_executor::storage::StorageState;
use phoebus_executor::{ use phoebus_executor::{
boot, desktop, encryption, kernel, nix, portage, probe, services, stage3, storage, users, Exec, boot, desktop, encryption, kernel, portage, probe, services, stage3, storage, users, Exec,
Result, Result,
}; };
@ -410,13 +410,7 @@ impl Installer {
return Ok(()); return Ok(());
} }
self.exec.mount_chroot()?; self.exec.mount_chroot()?;
let result: Result<()> = (|| { let result = services::configure(&self.exec, &self.config);
services::configure(&self.exec, &self.config)?;
if self.config.packages.nix {
nix::install(&self.exec, std::path::Path::new(&self.exec.root))?;
}
Ok(())
})();
self.exec.umount_chroot()?; self.exec.umount_chroot()?;
result result
} }