use super::lockfile::{boot_asset_cdn, boot_asset_version};
use arcbox_constants::env::BOOT_ASSET_VERSION as BOOT_ASSET_VERSION_ENV;
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct BootAssetConfig {
pub cdn_base_url: String,
pub version: String,
pub arch: String,
pub cache_dir: PathBuf,
pub custom_kernel: Option<PathBuf>,
pub allow_unpinned_manifest: bool,
}
impl Default for BootAssetConfig {
fn default() -> Self {
let version = std::env::var(BOOT_ASSET_VERSION_ENV)
.unwrap_or_else(|_| boot_asset_version().to_string());
let arch = if cfg!(target_arch = "aarch64") {
"arm64"
} else {
"x86_64"
}
.to_string();
Self {
cdn_base_url: boot_asset_cdn().to_string(),
version,
arch,
cache_dir: dirs::home_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join(".arcbox")
.join("boot"),
custom_kernel: None,
allow_unpinned_manifest: false,
}
}
}
impl BootAssetConfig {
#[must_use]
pub fn with_cache_dir(cache_dir: PathBuf) -> Self {
Self {
cache_dir,
..Default::default()
}
}
pub fn with_version(mut self, version: impl Into<String>) -> Self {
self.version = version.into();
self
}
#[must_use]
pub const fn with_unpinned_manifest_allowed(mut self, allowed: bool) -> Self {
self.allow_unpinned_manifest = allowed;
self
}
#[must_use]
pub fn version_cache_dir(&self) -> PathBuf {
self.cache_dir.join(&self.version)
}
}