Update README and make config_key optional

config-extension
trivernis 2 years ago
parent 0cad5f7d02
commit 2c998d1445
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -8,13 +8,15 @@ Tourmaline is a (planned) agnostic, asynchronous and awesome installer framework
Just run `cargo run -- help` or `trm help` for now.
## Scripts
## Distro Config
Scripts for all supported distros are stored in the `config` folder of this repository.
Scripts and config files for all supported distros are stored in the `config` folder of this repository.
Each distro has its own folder with several subfolders corresponding to all integration tasks.
```
<distro>
| distro.toml
| config.schema.json
| <task>
| up.nu
| down.nu
@ -23,6 +25,68 @@ Each distro has its own folder with several subfolders corresponding to all inte
| down.nu
```
### Distro config
The `distro.toml` file contains config options of the distro and allows one to define additional
tasks to perform on install.
The basic schema of this config file looks like this:
```toml
# Distro metadata
[distro]
# Name of the distro
name = "Distro Name"
# Website of the distro
website = "https://mydistro.com"
# Configuration of the OSConfig file
[config]
# Reference to the JSON Schema describing the config extension of that distro
#[default: "config.schema.json"]
schema = "config.schema.json"
# Task-related configuration
[tasks]
# The key correspons to the name of the task on the file system.
# In this case the scripts `custom-task/up.nu` and `custom-task/down.nu` must
# exist in the distro's config folder
[tasks.custom-task]
# The key inside the extended config that is used to pass the config
# value to this task
# If this key is empty no value is passed to the task
# [default: none]
config_key = "enable_flatpak"
# If set to true, the task will be skipped if the value of the task's config
# (indexed by config_key) is null or false. This setting is ignored when
# no config_key is defined for this task
# [default: false]
skip_on_false = true
# The order in which the task(s) should be executed. Note that
# custom tasks alsways get executed after the base task.
# [default: usize::MAX]
order = 10
```
# Config Schema
The config schema describing the extended OSConfig for that distro can be configured in the
`distro.toml` and defaults to `config.schema.json`.
This file is a [JSON Schema](https://json-schema.org/) describing the additional fields
required in the config. Make sure to mark required values as such so that the config
get's properly validated.
### Scripts
The `up.nu` scripts contain the required steps to apply the change described by the task.
This can include installing packages, creating configuration files and starting systemd units.

@ -39,7 +39,7 @@ pub struct OSConfigMetadata {
#[derive(Clone, Debug, Deserialize)]
pub struct TaskConfig {
/// The name of the config field
pub config_key: String,
pub config_key: Option<String>,
/// If the task should be skipped if the
/// config value of that task is null

@ -1,12 +1,14 @@
use std::path::PathBuf;
use embed_nu::IntoValue;
use crate::{distro::OSConfig, error::AppResult};
use super::{exec_builder::ExecBuilder, TaskTrait};
#[derive(Clone, Debug)]
pub struct CustomTask {
config_key: String,
config_key: Option<String>,
up_script: PathBuf,
down_script: PathBuf,
skip_on_false: bool,
@ -14,7 +16,12 @@ pub struct CustomTask {
}
impl CustomTask {
pub fn new(name: String, config_key: String, skip_on_false: bool, order: usize) -> Self {
pub fn new(
name: String,
config_key: Option<String>,
skip_on_false: bool,
order: usize,
) -> Self {
let base_path = PathBuf::from(name);
Self {
config_key,
@ -29,9 +36,13 @@ impl CustomTask {
impl TaskTrait for CustomTask {
#[tracing::instrument(level = "trace", skip_all)]
fn up(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>> {
let task_config = config.get_nu_value(&self.config_key)?;
let task_config = if let Some(key) = self.config_key.as_ref() {
config.get_nu_value(key)?
} else {
Option::<()>::None.into_value()
};
if self.skip_on_false && config_is_falsy(&task_config) {
if self.skip_on_false && self.config_key.is_some() && config_is_falsy(&task_config) {
Ok(None)
} else {
Ok(Some(ExecBuilder {
@ -44,9 +55,13 @@ impl TaskTrait for CustomTask {
#[tracing::instrument(level = "trace", skip_all)]
fn down(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>> {
let task_config = config.get_nu_value(&self.config_key)?;
let task_config = if let Some(key) = self.config_key.as_ref() {
config.get_nu_value(key)?
} else {
Option::<()>::None.into_value()
};
if self.skip_on_false && config_is_falsy(&task_config) {
if self.skip_on_false && self.config_key.is_some() && config_is_falsy(&task_config) {
Ok(None)
} else {
Ok(Some(ExecBuilder {

Loading…
Cancel
Save