phoebus_os/installer-rs/crates/phoebus-executor/src/services.rs
Phoebus 38214ea9e7 chore: import Phoebus OS installer and Rust migration
Initial public import of the proven Bash installer (installer/) and the production Rust workspace (installer-rs/). The reference ISO, build output and local agent transcripts are gitignored.

Verified: installer/tests/run_tests.sh and cargo test --workspace both pass.
2026-09-20 02:07:33 -07:00

57 lines
1.7 KiB
Rust

//! Target system services: hostname, keymap, timezone, locale and systemd
//! unit enablement.
use std::path::Path;
use phoebus_core::system as sysgen;
use phoebus_core::InstallConfig;
use crate::error::{ExecError, Result};
use crate::exec::Exec;
use crate::portage;
pub fn configure(exec: &Exec, config: &InstallConfig) -> Result<()> {
write_network(exec, config)?;
let target = exec.target();
target.write(
"etc/vconsole.conf",
format!("KEYMAP={}\n", config.system.keymap),
)?;
target.write(
"etc/locale.conf",
format!("LANG={}\n", config.system.locale),
)?;
set_timezone(exec, &config.system.timezone)?;
portage::write_locale_gen(exec, config)?;
let root = Path::new(&exec.root);
let _ = portage::chroot(exec, root, "locale-gen", &[]);
for svc in sysgen::target_services(config) {
if let Err(e) = portage::chroot(exec, root, "systemctl", &["enable", &svc]) {
exec.logger.warn(format!("could not enable {svc}: {e}"));
}
}
Ok(())
}
pub fn write_network(exec: &Exec, config: &InstallConfig) -> Result<()> {
let target = exec.target();
target.write("etc/hostname", format!("{}\n", config.system.hostname))?;
let hosts = format!(
"127.0.0.1\tlocalhost\n::1\t\tlocalhost\n127.0.1.1\t{}\n",
config.system.hostname
);
target.write("etc/hosts", hosts)?;
Ok(())
}
pub fn set_timezone(exec: &Exec, timezone: &str) -> Result<()> {
let target = exec.target();
target.ensure_dir("etc")?;
let link = target.etc("localtime")?;
let _ = std::fs::remove_file(&link);
let dest = format!("/usr/share/zoneinfo/{timezone}");
std::os::unix::fs::symlink(&dest, &link).map_err(|e| ExecError::io(link.clone(), e))?;
Ok(())
}