Some checks are pending
ci / test (push) Waiting to run
- Mango + DankMaterialShell desktop option (desktop.profile = "mango") through the GURU overlay with scoped ~amd64 keywords, a sealed session entry point and a dwl fallback session (ADR 0009). - Coherent rollback/recovery: coordinated @ + @var snapshots, fstab and BLS root-subvolume rewriting, matching-kernel selection, snapshot recovery entry, retention/space gates and sys undo (ADR 0007). - Installed assistant (sys ask) with an OS-level systemd sandbox boundary and fail-closed typed plans; resolved package effects bound to approval. - Nix build isolation enforced (sandbox, no fallback) plus lifecycle/cleanup. - Desktop helpers (menu/lock/idle), transaction log, release gates with atomic publish and signing helpers, and a Debian-Live appliance VM harness.
258 lines
9 KiB
Rust
258 lines
9 KiB
Rust
//! Structured installation plan.
|
|
//!
|
|
//! The plan is canonical data. The human-readable rendering is derived from it,
|
|
//! so the review screen, the destructive confirmation, dry-run and the actual
|
|
//! execution all describe the same thing.
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::config::{InstallConfig, KernelProfile};
|
|
use crate::hardware::HardwareReport;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum InstallStep {
|
|
StoragePrepare,
|
|
StageInstall,
|
|
FstabGenerate,
|
|
PortageConfigure,
|
|
PackagesBase,
|
|
KernelInstall,
|
|
BootInstall,
|
|
UsersConfigure,
|
|
ServicesConfigure,
|
|
DesktopInstall,
|
|
Finalize,
|
|
}
|
|
|
|
impl InstallStep {
|
|
pub fn name(self) -> &'static str {
|
|
match self {
|
|
InstallStep::StoragePrepare => "storage_prepare",
|
|
InstallStep::StageInstall => "stage_install",
|
|
InstallStep::FstabGenerate => "fstab_generate",
|
|
InstallStep::PortageConfigure => "portage_configure",
|
|
InstallStep::PackagesBase => "packages_base",
|
|
InstallStep::KernelInstall => "kernel_install",
|
|
InstallStep::BootInstall => "boot_install",
|
|
InstallStep::UsersConfigure => "users_configure",
|
|
InstallStep::ServicesConfigure => "services_configure",
|
|
InstallStep::DesktopInstall => "desktop_install",
|
|
InstallStep::Finalize => "finalize",
|
|
}
|
|
}
|
|
|
|
/// The proven order. Do not reorder without understanding the fstab and
|
|
/// subvolume ordering constraints documented in VM-BOOT-VERIFICATION.md.
|
|
pub fn sequence() -> Vec<InstallStep> {
|
|
vec![
|
|
InstallStep::StoragePrepare,
|
|
InstallStep::StageInstall,
|
|
InstallStep::FstabGenerate,
|
|
InstallStep::PortageConfigure,
|
|
InstallStep::PackagesBase,
|
|
InstallStep::KernelInstall,
|
|
InstallStep::BootInstall,
|
|
InstallStep::UsersConfigure,
|
|
InstallStep::ServicesConfigure,
|
|
InstallStep::DesktopInstall,
|
|
InstallStep::Finalize,
|
|
]
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct InstallPlan {
|
|
pub steps: Vec<InstallStep>,
|
|
}
|
|
|
|
impl InstallPlan {
|
|
pub fn for_config(_config: &InstallConfig) -> Self {
|
|
Self {
|
|
steps: InstallStep::sequence(),
|
|
}
|
|
}
|
|
|
|
pub fn render_human(
|
|
&self,
|
|
config: &InstallConfig,
|
|
hardware: Option<&HardwareReport>,
|
|
) -> String {
|
|
let mut o = String::new();
|
|
let enc = config.encryption.mode.as_str();
|
|
let fs = config.storage.filesystem.as_str();
|
|
let firmware = hardware.map(|h| h.firmware_str()).unwrap_or("unknown");
|
|
let kernel_pkg = config.kernel.selected_package();
|
|
|
|
o.push_str("Installation plan\n");
|
|
o.push_str("=================\n\n");
|
|
o.push_str("System:\n");
|
|
o.push_str(&format!(" Distribution : {}\n", config.system.distro_name));
|
|
o.push_str(&format!(" Architecture : {}\n", config.system.arch));
|
|
o.push_str(&format!(" Init system : {}\n", config.system.init_system));
|
|
o.push_str(&format!(" Firmware : {firmware}\n\n"));
|
|
|
|
o.push_str("Identity:\n");
|
|
o.push_str(&format!(" Hostname : {}\n", config.system.hostname));
|
|
o.push_str(&format!(" Keymap : {}\n", config.system.keymap));
|
|
o.push_str(&format!(" Locale : {}\n", config.system.locale));
|
|
o.push_str(&format!(" Timezone : {}\n", config.system.timezone));
|
|
let user = if config.user.username.is_empty() {
|
|
"<not set>"
|
|
} else {
|
|
&config.user.username
|
|
};
|
|
o.push_str(&format!(" User : {user}\n\n"));
|
|
|
|
o.push_str("Storage:\n");
|
|
let disk = if config.storage.disk.is_empty() {
|
|
"<not selected>".to_string()
|
|
} else {
|
|
config.storage.disk.clone()
|
|
};
|
|
o.push_str(&format!(" Target disk : {disk}\n"));
|
|
o.push_str(&format!(
|
|
" Partitioning : GPT ({})\n",
|
|
config.storage.partition_scheme
|
|
));
|
|
o.push_str(&format!(" Encryption : {enc}\n"));
|
|
o.push_str(&format!(" Filesystem : {fs}\n\n"));
|
|
o.push_str(" Layout:\n");
|
|
o.push_str(&format!(
|
|
" EFI System Partition (FAT32) {} MiB -> {}\n",
|
|
config.storage.efi_size_mib, config.storage.efi_mount
|
|
));
|
|
o.push_str(&format!(
|
|
" {:<36} remainder\n",
|
|
format!("{enc} container")
|
|
));
|
|
o.push_str(&format!(" {:<34}\n", fs));
|
|
for sv in &config.storage.subvols {
|
|
o.push_str(&format!(" {sv}\n"));
|
|
}
|
|
o.push('\n');
|
|
|
|
o.push_str("Boot and kernel:\n");
|
|
o.push_str(&format!(
|
|
" Bootloader : {} (BLS entries)\n",
|
|
"systemd-boot"
|
|
));
|
|
o.push_str(&format!(
|
|
" Unified UKI : {} (deferred; BLS used)\n",
|
|
if config.kernel.uki { "yes" } else { "no" }
|
|
));
|
|
let profile = match config.kernel.profile {
|
|
KernelProfile::Safe => "safe",
|
|
KernelProfile::Optimized => "optimized",
|
|
KernelProfile::Aggressive => "aggressive",
|
|
};
|
|
o.push_str(&format!(
|
|
" Kernel : {kernel_pkg} ({profile} profile)\n"
|
|
));
|
|
o.push_str(&format!(
|
|
" Keep kernels : {}\n\n",
|
|
config.kernel.keep_kernels
|
|
));
|
|
|
|
o.push_str("Software:\n");
|
|
o.push_str(&format!(" Package policy : {}\n", config.packages.policy));
|
|
o.push_str(&format!(
|
|
" Binary pkgs : {}\n",
|
|
if config.packages.binary_packages {
|
|
"yes"
|
|
} else {
|
|
"no"
|
|
}
|
|
));
|
|
o.push_str(&format!(
|
|
" Accept license : {}\n",
|
|
config.packages.accept_license
|
|
));
|
|
o.push_str(&format!(" Desktop : {}\n", config.desktop.profile));
|
|
if config.desktop.profile == crate::config::DesktopProfile::Mango {
|
|
o.push_str(
|
|
" Session : Mango + DankMaterialShell (GURU overlay; dwl fallback)\n",
|
|
);
|
|
}
|
|
o.push_str(&format!(
|
|
" Flatpak : {}\n",
|
|
if config.desktop.flatpak { "yes" } else { "no" }
|
|
));
|
|
o.push_str(&format!(
|
|
" Audio : {}\n",
|
|
config.desktop.audio_stack
|
|
));
|
|
o.push_str(&format!(
|
|
" AI assistant : {}\n",
|
|
if config.ai.enabled { "yes" } else { "no" }
|
|
));
|
|
o
|
|
}
|
|
|
|
pub fn destructive_preview(&self, config: &InstallConfig, disk_layout: &str) -> String {
|
|
let mut o = String::new();
|
|
o.push_str(&format!("TARGET: {}\n\n", config.storage.disk));
|
|
o.push_str("ALL DATA ON THIS DEVICE WILL BE DESTROYED.\n");
|
|
o.push_str("This cannot be undone.\n\n");
|
|
o.push_str(&format!(
|
|
" EFI (FAT32): {} MiB\n",
|
|
config.storage.efi_size_mib
|
|
));
|
|
if config.is_encrypted() {
|
|
o.push_str(&format!(
|
|
" {} (passphrase): remainder\n",
|
|
config.encryption.mode.as_str().to_uppercase()
|
|
));
|
|
}
|
|
o.push_str(&format!(" {}:\n", config.storage.filesystem.as_str()));
|
|
for sv in &config.storage.subvols {
|
|
o.push_str(&format!(" {sv}\n"));
|
|
}
|
|
o.push_str("\nExisting partitions on the target:\n");
|
|
for line in disk_layout.lines() {
|
|
o.push_str(" ");
|
|
o.push_str(line);
|
|
o.push('\n');
|
|
}
|
|
o
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn sequence_matches_proven_order() {
|
|
let names: Vec<&str> = InstallStep::sequence().iter().map(|s| s.name()).collect();
|
|
assert_eq!(names[0], "storage_prepare");
|
|
assert_eq!(names[1], "stage_install");
|
|
assert_eq!(names[2], "fstab_generate");
|
|
assert_eq!(names[3], "portage_configure");
|
|
assert_eq!(names[names.len() - 1], "finalize");
|
|
}
|
|
|
|
#[test]
|
|
fn render_contains_key_facts() {
|
|
let mut cfg = InstallConfig::default();
|
|
cfg.system.hostname = "phoebus-test".into();
|
|
cfg.user.username = "tester".into();
|
|
cfg.storage.disk = "/dev/vda".into();
|
|
let plan = InstallPlan::for_config(&cfg);
|
|
let text = plan.render_human(&cfg, None);
|
|
assert!(text.contains("Installation plan"));
|
|
assert!(text.contains("phoebus-test"));
|
|
assert!(text.contains("@snapshots"));
|
|
assert!(text.contains("luks2"));
|
|
}
|
|
|
|
#[test]
|
|
fn destructive_preview_warns_loudly() {
|
|
let mut cfg = InstallConfig::default();
|
|
cfg.storage.disk = "/dev/vda".into();
|
|
let text = InstallPlan::for_config(&cfg).destructive_preview(&cfg, "NAME SIZE\nvda 30G");
|
|
assert!(text.contains("ALL DATA ON THIS DEVICE WILL BE DESTROYED."));
|
|
assert!(text.contains("TARGET: /dev/vda"));
|
|
assert!(text.contains("vda 30G"));
|
|
}
|
|
}
|