//! This module contains definitions to read the setup files. use anyhow::Context as _; use serde::de::DeserializeOwned; use std::{ fs, path::{Path, PathBuf} }; pub mod autostart; pub mod network; pub mod os; pub mod packages; use autostart::Autostart; use network::Network; use os::Os; use packages::Packages; pub struct Setup { pub os: Os, pub network: Network, pub packages: Packages, pub autostart: Autostart } impl Setup { fn read(path: &Path, file: &str) -> anyhow::Result { toml::from_slice(&fs::read(path.join(file)).with_context(|| format!("Failed to read {file}"))?) .with_context(|| format!("Failed to deserialize {file}")) } pub fn load() -> anyhow::Result { let path = PathBuf::from("setup"); let os = Self::read(&path, "os.toml")?; let network = Self::read(&path, "network.toml")?; let packages = Self::read(&path, "packages.toml")?; let autostart = Self::read(&path, "autostart.toml")?; Ok(Self { os, network, packages, autostart }) } }