Add missing tasks

Signed-off-by: trivernis <trivernis@protonmail.com>
integration-not-installation
trivernis 2 years ago
parent d19f405911
commit e27e798a38
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,3 +1,5 @@
def main [cfg] { def main [cfg] {
echo "Running after creating users" echo "Running after creating users"
$TRM_CONFIG | describe
$TRM_CONFIG
} }

@ -1,15 +1,65 @@
use serde::Serialize; use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::tasks::{ use crate::tasks::{
BootloaderConfig, DesktopConfig, LocaleConfig, NetworkConfig, PartitionsConfig, UsersConfig, BootloaderConfig, BootloaderPreset, DesktopConfig, ExtraPackages, Kernel, KernelConfig,
LocaleConfig, NetworkConfig, Partitions, PartitionsConfig, RootUserConfig, UnakiteConfig,
UsersConfig,
}; };
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Config { pub struct Config {
pub local: LocaleConfig, pub locale: LocaleConfig,
pub network: NetworkConfig, pub network: NetworkConfig,
pub partitions: PartitionsConfig, pub partitions: PartitionsConfig,
pub bootloader: BootloaderConfig, pub bootloader: BootloaderConfig,
pub kernels: KernelConfig,
pub desktop: DesktopConfig, pub desktop: DesktopConfig,
pub users: UsersConfig, pub users: UsersConfig,
pub root_user: RootUserConfig,
pub unakite: Option<UnakiteConfig>,
pub extra_packages: ExtraPackages,
pub enable_timeshift: bool,
pub enable_flatpak: bool,
pub enable_zramd: bool,
}
impl Config {
pub(crate) fn empty() -> Self {
Self {
locale: LocaleConfig {
locale: Vec::new(),
keymap: String::new(),
timezone: String::new(),
},
network: NetworkConfig {
hostname: String::new(),
ipv6_loopback: false,
},
partitions: PartitionsConfig {
device: PathBuf::new(),
efi_partition: false,
partitions: Partitions::Auto,
},
bootloader: BootloaderConfig {
preset: BootloaderPreset::GrubEfi,
location: PathBuf::new(),
},
kernels: KernelConfig {
default: Kernel(String::new()),
additional: Vec::new(),
},
desktop: DesktopConfig::KdePlasma,
users: UsersConfig { users: Vec::new() },
root_user: RootUserConfig {
password: String::new(),
},
unakite: None,
extra_packages: Vec::new(),
enable_timeshift: false,
enable_flatpak: false,
enable_zramd: false,
}
}
} }

@ -9,7 +9,7 @@ pub type AppResult<T> = std::result::Result<T, AppError>;
#[derive(Error, Diagnostic, Debug)] #[derive(Error, Diagnostic, Debug)]
pub enum AppError { pub enum AppError {
#[error("Miette error")] #[error("Miette error")]
#[diagnostic(code(tourmaline::error))] #[diagnostic()]
Miette(miette::Error), Miette(miette::Error),
#[error("Error while evaluating nu script")] #[error("Error while evaluating nu script")]
@ -20,7 +20,7 @@ pub enum AppError {
ScriptNotFound(PathBuf), ScriptNotFound(PathBuf),
#[diagnostic()] #[diagnostic()]
#[error("Could not parse the source file")] #[error("Could not parse the source file: {0}")]
ParseError(#[from] nu_parser::ParseError), ParseError(#[from] nu_parser::ParseError),
#[diagnostic()] #[diagnostic()]
@ -29,6 +29,9 @@ pub enum AppError {
#[error("Failed to execute script")] #[error("Failed to execute script")]
FailedToExecuteScript, FailedToExecuteScript,
#[error("Missing config")]
MissingConfig,
} }
impl From<miette::Error> for AppError { impl From<miette::Error> for AppError {

@ -1,7 +1,8 @@
use config::Config; use config::Config;
use error::AppResult; use error::{AppError, AppResult};
use scripting::{ use scripting::{
loader::{HookType, ScriptLoader}, loader::{HookType, ScriptLoader},
record::RecordValue,
script::{NuScript, Script, ScriptArgs}, script::{NuScript, Script, ScriptArgs},
}; };
use tasks::*; use tasks::*;
@ -12,11 +13,6 @@ pub(crate) mod scripting;
pub mod tasks; pub mod tasks;
pub(crate) mod utils; pub(crate) mod utils;
pub struct TaskExecutor {
config: Option<Config>,
loader: ScriptLoader,
}
macro_rules! tasks { macro_rules! tasks {
($($function:ident => $script:ident),+) => { ($($function:ident => $script:ident),+) => {
$( $(
@ -28,17 +24,64 @@ macro_rules! tasks {
} }
} }
pub struct TaskExecutor {
config: Option<Config>,
loader: ScriptLoader,
}
impl TaskExecutor { impl TaskExecutor {
tasks!( tasks!(
setup_users => SetupUsersScript, setup_users => SetupUsersScript,
configure_network => ConfigureNetworkScript, configure_network => ConfigureNetworkScript,
configure_unakite => ConfigureUnakiteScript,
create_partitions => CreatePartitionsScript, create_partitions => CreatePartitionsScript,
install_base => InstallBaseScript, install_base => InstallBaseScript,
install_bootloader => InstallBootloaderScript, install_bootloader => InstallBootloaderScript,
install_desktop => InstallDesktopScript, install_desktop => InstallDesktopScript,
configure_local => ConfigureLocaleScript install_extra_packages => InstallExtraPackagesScript,
install_flatpak => InstallFlatpakScript,
install_kernels => InstallKernelsScript,
install_timeshift => InstallTimeshiftScript,
install_zramd => InstallZRamDScript,
setup_root_user => SetupRootUserScript,
configure_locale => ConfigureLocaleScript
); );
/// Installs the system from the given system configuration
#[tracing::instrument(level = "trace", skip(self))]
pub async fn install_from_config(&self) -> AppResult<()> {
let config = self
.config
.as_ref()
.ok_or_else(|| AppError::MissingConfig)?;
self.create_partitions(&config.partitions).await?;
self.install_base(&()).await?;
self.install_kernels(&config.kernels).await?;
self.install_bootloader(&config.bootloader).await?;
self.configure_locale(&config.locale).await?;
self.configure_network(&config.network).await?;
if config.enable_zramd {
self.install_zramd(&()).await?;
}
if config.enable_timeshift {
self.install_timeshift(&()).await?;
}
if config.enable_flatpak {
self.install_flatpak(&()).await?;
}
self.setup_users(&config.users).await?;
self.setup_root_user(&config.root_user).await?;
self.install_desktop(&config.desktop).await?;
self.install_extra_packages(&config.extra_packages).await?;
if let Some(unakite) = &config.unakite {
self.configure_unakite(unakite).await?;
}
Ok(())
}
async fn execute_task<S: Script>(&self, args: &S::Args) -> AppResult<()> { async fn execute_task<S: Script>(&self, args: &S::Args) -> AppResult<()> {
if let Some(pre_hook) = self.loader.load_hook::<S>(HookType::Pre) { if let Some(pre_hook) = self.loader.load_hook::<S>(HookType::Pre) {
self.execute(pre_hook, args).await?; self.execute(pre_hook, args).await?;
@ -58,7 +101,7 @@ impl TaskExecutor {
if let Some(cfg) = self.config.as_ref() { if let Some(cfg) = self.config.as_ref() {
script.set_global_var("TRM_CONFIG", cfg.get_args()) script.set_global_var("TRM_CONFIG", cfg.get_args())
} else { } else {
&mut script script.set_global_var("TRM_CONFIG", RecordValue::from(Config::empty().get_args()))
} }
.set_global_var("TRM_VERSION", env!("CARGO_PKG_VERSION")) .set_global_var("TRM_VERSION", env!("CARGO_PKG_VERSION"))
.execute(args) .execute(args)

@ -110,7 +110,7 @@ impl NuExecutor {
// create a call to the main method wit the given arguments and execute it // create a call to the main method wit the given arguments and execute it
let call_block = create_call(main_id, args); let call_block = create_call(main_id, args);
nu_engine::eval_block( let data = nu_engine::eval_block(
&engine_state, &engine_state,
&mut stack, &mut stack,
&call_block, &call_block,
@ -118,6 +118,9 @@ impl NuExecutor {
false, false,
false, false,
)?; )?;
// the last print is returned as the result pipeline of the script so
// we need to print it manually
data.print(&mut engine_state, &mut stack, false, true);
AppResult::Ok(()) AppResult::Ok(())
}) })

@ -1,4 +1,4 @@
use serde::Serialize; use serde::{Deserialize, Serialize};
use crate::script; use crate::script;
@ -7,7 +7,7 @@ script!(ConfigureLocaleScript {
args = LocaleConfig args = LocaleConfig
}); });
#[derive(Clone, Serialize, Debug)] #[derive(Clone, Deserialize, Serialize, Debug)]
pub struct LocaleConfig { pub struct LocaleConfig {
pub locale: Vec<String>, pub locale: Vec<String>,
pub keymap: String, pub keymap: String,

@ -1,4 +1,4 @@
use serde::Serialize; use serde::{Deserialize, Serialize};
use crate::script; use crate::script;
@ -7,7 +7,7 @@ script!(ConfigureNetworkScript {
args = NetworkConfig args = NetworkConfig
}); });
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct NetworkConfig { pub struct NetworkConfig {
pub hostname: String, pub hostname: String,
pub ipv6_loopback: bool, pub ipv6_loopback: bool,

@ -0,0 +1,18 @@
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::script;
script!(ConfigureUnakiteScript {
file = "configure-unakite"
args = UnakiteConfig
});
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct UnakiteConfig {
pub root: PathBuf,
pub old_root: PathBuf,
pub efidir: PathBuf,
pub bootdev: PathBuf,
}

@ -1,6 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use serde::Serialize; use serde::{Deserialize, Serialize};
use crate::script; use crate::script;
@ -9,27 +9,27 @@ script!(CreatePartitionsScript {
args = PartitionsConfig args = PartitionsConfig
}); });
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PartitionsConfig { pub struct PartitionsConfig {
pub device: PathBuf, pub device: PathBuf,
pub efi_partition: bool, pub efi_partition: bool,
pub partitions: Partitions, pub partitions: Partitions,
} }
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub enum Partitions { pub enum Partitions {
Auto, Auto,
Manual(Vec<Partition>), Manual(Vec<Partition>),
} }
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Partition { pub struct Partition {
pub mountpoint: PathBuf, pub mountpoint: PathBuf,
pub blockdevice: PathBuf, pub blockdevice: PathBuf,
pub filesystem: Option<FileSystem>, pub filesystem: Option<FileSystem>,
} }
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub enum FileSystem { pub enum FileSystem {
VFAT, VFAT,
BFS, BFS,

@ -1,6 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use serde::Serialize; use serde::{Deserialize, Serialize};
use crate::script; use crate::script;
@ -9,13 +9,13 @@ script!(InstallBootloaderScript {
args = BootloaderConfig args = BootloaderConfig
}); });
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BootloaderConfig { pub struct BootloaderConfig {
preset: BootloaderPreset, pub preset: BootloaderPreset,
location: PathBuf, pub location: PathBuf,
} }
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub enum BootloaderPreset { pub enum BootloaderPreset {
GrubEfi, GrubEfi,
Legacy, Legacy,

@ -1,4 +1,4 @@
use serde::Serialize; use serde::{Deserialize, Serialize};
use crate::script; use crate::script;
@ -7,7 +7,7 @@ script!(InstallDesktopScript {
args = DesktopConfig args = DesktopConfig
}); });
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub enum DesktopConfig { pub enum DesktopConfig {
Onyx, Onyx,
KdePlasma, KdePlasma,

@ -0,0 +1,8 @@
use crate::script;
script!(InstallExtraPackagesScript {
file = "install-extra-packages"
args = ExtraPackages
});
pub type ExtraPackages = Vec<String>;

@ -0,0 +1,8 @@
use crate::script;
script!(InstallFlatpakScript {
file = "install-flatpak"
args = FlatpakConfig
});
pub type FlatpakConfig = ();

@ -0,0 +1,17 @@
use serde::{Deserialize, Serialize};
use crate::script;
script!(InstallKernelsScript {
file = "install-kernels"
args = KernelConfig
});
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct KernelConfig {
pub default: Kernel,
pub additional: Vec<Kernel>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Kernel(pub String);

@ -0,0 +1,8 @@
use crate::script;
script!(InstallTimeshiftScript {
file = "install-timeshift"
args = TimeshiftConfig
});
pub type TimeshiftConfig = ();

@ -0,0 +1,8 @@
use crate::script;
script!(InstallZRamDScript {
file = "install-zramd"
args = ZRamDConfig
});
pub type ZRamDConfig = ();

@ -1,15 +1,29 @@
mod configure_locale; mod configure_locale;
mod configure_network; mod configure_network;
mod configure_unakite;
mod create_partitions; mod create_partitions;
mod install_base; mod install_base;
mod install_bootloader; mod install_bootloader;
mod install_desktop; mod install_desktop;
mod install_extra_packages;
mod install_flatpak;
mod install_kernels;
mod install_timeshift;
mod install_zramd;
mod setup_root_user;
mod setup_users; mod setup_users;
pub use configure_locale::*; pub use configure_locale::*;
pub use configure_network::*; pub use configure_network::*;
pub use configure_unakite::*;
pub use create_partitions::*; pub use create_partitions::*;
pub use install_base::*; pub use install_base::*;
pub use install_bootloader::*; pub use install_bootloader::*;
pub use install_desktop::*; pub use install_desktop::*;
pub use install_extra_packages::*;
pub use install_flatpak::*;
pub use install_kernels::*;
pub use install_timeshift::*;
pub use install_zramd::*;
pub use setup_root_user::*;
pub use setup_users::*; pub use setup_users::*;

@ -0,0 +1,13 @@
use serde::{Deserialize, Serialize};
use crate::script;
script!(SetupRootUserScript {
file = "setup-root-user"
args = RootUserConfig
});
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RootUserConfig {
pub password: String,
}

@ -1,4 +1,4 @@
use serde::Serialize; use serde::{Deserialize, Serialize};
use crate::script; use crate::script;
@ -7,12 +7,12 @@ script!(SetupUsersScript {
args = UsersConfig args = UsersConfig
}); });
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct UsersConfig { pub struct UsersConfig {
pub users: Vec<User>, pub users: Vec<User>,
} }
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct User { pub struct User {
pub name: String, pub name: String,
pub password: String, pub password: String,

Loading…
Cancel
Save