diff --git a/src/cfg/manifest.rs b/src/cfg/manifest.rs deleted file mode 100644 index 7e126ab..0000000 --- a/src/cfg/manifest.rs +++ /dev/null @@ -1,181 +0,0 @@ -use std::{fmt::Debug, path::Path}; - -use bytesize::ByteSize; -use serde::{Deserialize, Serialize}; - -use super::{partition::PartitionType, script::Script}; - -const DEFAULT_VOLID: &str = "KATSU-LIVEOS"; - -fn _default_volid() -> String { - DEFAULT_VOLID.to_owned() -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -pub struct IsoConfig { - /// Volume ID for the ISO image - #[serde(default = "_default_volid")] - pub volume_id: String, -} - -#[derive(Default, Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "kebab-case")] -pub enum BuilderType { - #[default] - Dnf, -} - -pub trait BootstrapOption: Debug + dyn_clone::DynClone { - fn bootstrap_system(&self) -> color_eyre::Result<()>; -} - -mod bootstrap_option_serde { - use super::BootstrapOption; - - pub fn serialize<'se, S>( - bootstrap_option: &Box, serializer: S, - ) -> Result - where - S: serde::Serializer, - { - todo!() - } -} - -dyn_clone::clone_trait_object!(BootstrapOption); - -// todo: rewrite everything -#[derive(Deserialize, Debug, Clone, Serialize)] -pub struct Manifest { - /// Builder type - #[serde(default)] - pub builder: BuilderType, - /// The distro name for the build result - // entrypoint must have a distro name - #[serde(default)] - pub distro: Option, - - /// Output file name - // entrypoint must have an output location - #[serde(default)] - pub out_file: Option, - - #[serde(default)] - pub disk: Option, - - /// DNF configuration - // todo: dynamically load this? - #[serde(default)] - pub dnf: crate::builder::DnfRootBuilder, - - /// Scripts to run before and after the build - #[serde(default)] - pub scripts: super::script::ScriptsManifest, - - /// Users to add to the image - #[serde(default)] - pub users: Vec, - - /// Extra parameters to the kernel command line in bootloader configs - pub kernel_cmdline: Option, - - /// ISO config (optional) - /// This is only used for ISO images - #[serde(default)] - pub iso: Option, - - #[serde(default)] - pub bootloader: super::boot::Bootloader, -} - -impl Manifest { - #[must_use] - pub fn get_volid(&self) -> &str { - self.iso.as_ref().map_or(DEFAULT_VOLID, |iso| &iso.volume_id) - } - /// Load manifest from file - /// - /// # Errors - /// - /// This function will return an error if the file cannot be read or parsed. - pub fn load(path: &Path) -> color_eyre::Result { - Ok(hcl::de::from_body(ensan::parse(std::fs::read_to_string(path)?)?)?) - } -} - -/// Variable types used for validation in `[Var]` -#[derive(Deserialize, Debug, Clone, Serialize)] -pub enum VarType { - String, - Int, - Object, -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -pub struct Var { - #[serde(rename = "type")] - pub var_type: VarType, - pub default: Option, -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -pub enum BootstrapMethod { - Oci, - Tar, - Dir, - Squashfs, - Dnf, -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -#[serde(rename_all = "snake_case")] -#[serde(tag = "type")] -pub struct PartitionLayout { - // pub partition: Vec, -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -pub struct Partition { - pub size: ByteSize, - pub mountpoint: String, - pub filesystem: String, - #[serde(rename = "type")] - pub partition_type: PartitionType, - pub copy_blocks: Option, -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -pub struct CopyFiles { - pub source: String, - pub destination: String, -} - -/// A Katsu target -/// -/// Represented by a HCL block `target` -/// -/// ```hcl -/// output "type" "id" { -/// method = "oci" -/// } -/// ``` -// todo: evaluate dep graph for outputs, so we can build them in the correct order -#[derive(Debug, Clone, Serialize)] -#[serde(tag = "type")] -// an output can be a filesystem, a container image, or a disk image. -// It can also rely on other outputs for bootstrapping. -pub struct Target { - pub id: String, - /// Method to bootstrap the output filesystem - pub method: BootstrapMethod, - /// Copy files from the host to the output tree before packing - pub copy: Vec, - /// Scripts to run before and after the build - pub script: Vec