forked from lix-project/lix-installer
Further fleshing out
This commit is contained in:
parent
8addef670d
commit
2ef7951994
|
@ -17,9 +17,9 @@ impl<'a> Actionable<'a> for ConfigureShellProfile {
|
|||
fn description(&self) -> Vec<ActionDescription> {
|
||||
vec![
|
||||
ActionDescription::new(
|
||||
"Start the systemd Nix daemon".to_string(),
|
||||
"Configure the shell profiles".to_string(),
|
||||
vec![
|
||||
"The `nix` command line tool communicates with a running Nix daemon managed by your init system".to_string()
|
||||
"Update shell profiles to import Nix".to_string()
|
||||
]
|
||||
),
|
||||
]
|
||||
|
|
|
@ -28,7 +28,7 @@ impl<'a> Actionable<'a> for FetchNix {
|
|||
vec![ActionDescription::new(
|
||||
format!("Fetch Nix from `{url}`"),
|
||||
vec![format!(
|
||||
"Fetch a Nix archive and unpack it to `{}`", destination.display()
|
||||
"Unpack it to `{}`, so it can later be moved into the Nix store at /nix", destination.display()
|
||||
)],
|
||||
)]
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ impl<'a> Actionable<'a> for SetupDefaultProfile {
|
|||
fn description(&self) -> Vec<ActionDescription> {
|
||||
vec![
|
||||
ActionDescription::new(
|
||||
"Start the systemd Nix daemon".to_string(),
|
||||
"Setup the default Nix profile".to_string(),
|
||||
vec![
|
||||
"The `nix` command line tool communicates with a running Nix daemon managed by your init system".to_string()
|
||||
"TODO".to_string()
|
||||
]
|
||||
),
|
||||
]
|
||||
|
@ -38,9 +38,9 @@ impl<'a> Revertable<'a> for SetupDefaultProfileReceipt {
|
|||
fn description(&self) -> Vec<ActionDescription> {
|
||||
vec![
|
||||
ActionDescription::new(
|
||||
"Stop the systemd Nix daemon".to_string(),
|
||||
"Unset the default Nix profile".to_string(),
|
||||
vec![
|
||||
"The `nix` command line tool communicates with a running Nix daemon managed by your init system".to_string()
|
||||
"TODO".to_string()
|
||||
]
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,13 +1,30 @@
|
|||
use tokio::task::JoinSet;
|
||||
|
||||
use crate::actions::base::{SetupDefaultProfile, ConfigureNixDaemonService, ConfigureShellProfile, SetupDefaultProfileReceipt, ConfigureNixDaemonServiceReceipt, ConfigureShellProfileReceipt};
|
||||
use crate::{HarmonicError, InstallSettings};
|
||||
|
||||
use crate::actions::{ActionDescription, ActionReceipt, Actionable, Revertable};
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
||||
pub struct ConfigureNix {}
|
||||
pub struct ConfigureNix {
|
||||
setup_default_profile: SetupDefaultProfile,
|
||||
configure_nix_daemon_service: ConfigureNixDaemonService,
|
||||
configure_shell_profile: Option<ConfigureShellProfile>,
|
||||
}
|
||||
|
||||
impl ConfigureNix {
|
||||
pub fn plan(settings: InstallSettings) -> Self {
|
||||
Self {}
|
||||
let setup_default_profile = SetupDefaultProfile::plan();
|
||||
let configure_nix_daemon_service = ConfigureNixDaemonService::plan();
|
||||
|
||||
let configure_shell_profile = if settings.modify_profile {
|
||||
Some(ConfigureShellProfile::plan())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
|
||||
Self { setup_default_profile, configure_nix_daemon_service, configure_shell_profile }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,23 +32,50 @@ impl ConfigureNix {
|
|||
impl<'a> Actionable<'a> for ConfigureNix {
|
||||
type Receipt = ConfigureNixReceipt;
|
||||
fn description(&self) -> Vec<ActionDescription> {
|
||||
vec![
|
||||
ActionDescription::new(
|
||||
"Configure the Nix daemon".to_string(),
|
||||
vec![
|
||||
"Blah".to_string()
|
||||
]
|
||||
),
|
||||
]
|
||||
let Self { setup_default_profile, configure_nix_daemon_service, configure_shell_profile } = &self;
|
||||
|
||||
let mut buf = setup_default_profile.description();
|
||||
buf.append(&mut configure_nix_daemon_service.description());
|
||||
if let Some(configure_shell_profile) = configure_shell_profile {
|
||||
buf.append(&mut configure_shell_profile.description());
|
||||
}
|
||||
|
||||
buf
|
||||
}
|
||||
|
||||
async fn execute(self) -> Result<Self::Receipt, HarmonicError> {
|
||||
todo!()
|
||||
let Self { setup_default_profile, configure_nix_daemon_service, configure_shell_profile } = self;
|
||||
|
||||
let (setup_default_profile, configure_nix_daemon_service, configure_shell_profile) = if let Some(configure_shell_profile) = configure_shell_profile {
|
||||
let (a, b, c) = tokio::try_join!(
|
||||
setup_default_profile.execute(),
|
||||
configure_nix_daemon_service.execute(),
|
||||
configure_shell_profile.execute(),
|
||||
)?;
|
||||
(a, b, Some(c))
|
||||
} else {
|
||||
let (a, b) = tokio::try_join!(
|
||||
setup_default_profile.execute(),
|
||||
configure_nix_daemon_service.execute(),
|
||||
)?;
|
||||
(a, b, None)
|
||||
};
|
||||
|
||||
Ok(Self::Receipt {
|
||||
setup_default_profile,
|
||||
configure_nix_daemon_service,
|
||||
configure_shell_profile,
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
||||
pub struct ConfigureNixReceipt {}
|
||||
pub struct ConfigureNixReceipt {
|
||||
setup_default_profile: SetupDefaultProfileReceipt,
|
||||
configure_nix_daemon_service: ConfigureNixDaemonServiceReceipt,
|
||||
configure_shell_profile: Option<ConfigureShellProfileReceipt>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<'a> Revertable<'a> for ConfigureNixReceipt {
|
||||
|
|
|
@ -38,28 +38,24 @@ impl<'a> Actionable<'a> for CreateUsersAndGroup {
|
|||
type Receipt = CreateUsersAndGroupReceipt;
|
||||
fn description(&self) -> Vec<ActionDescription> {
|
||||
let Self {
|
||||
create_users: _,
|
||||
create_group: _,
|
||||
settings: InstallSettings {
|
||||
explain: _,
|
||||
daemon_user_count,
|
||||
channels: _,
|
||||
modify_profile: _,
|
||||
nix_build_group_name,
|
||||
nix_build_group_id,
|
||||
nix_build_user_prefix,
|
||||
nix_build_user_id_base,
|
||||
nix_package_url,
|
||||
}
|
||||
..
|
||||
},
|
||||
..
|
||||
} = &self;
|
||||
|
||||
vec![
|
||||
ActionDescription::new(
|
||||
format!("Create build users and group"),
|
||||
vec![
|
||||
format!("The nix daemon requires system users it can act as in order to build"),
|
||||
format!("This action will create group `{nix_build_group_name}` with uid `{nix_build_group_id}`"),
|
||||
format!("This action will create {daemon_user_count} users with prefix `{nix_build_user_prefix}` starting at uid `{nix_build_user_id_base}`"),
|
||||
format!("The nix daemon requires system users (and a group they share) which it can act as in order to build"),
|
||||
format!("Create group `{nix_build_group_name}` with uid `{nix_build_group_id}`"),
|
||||
format!("Create {daemon_user_count} users with prefix `{nix_build_user_prefix}` starting at uid `{nix_build_user_id_base}`"),
|
||||
],
|
||||
)
|
||||
]
|
||||
|
@ -74,6 +70,7 @@ impl<'a> Actionable<'a> for CreateUsersAndGroup {
|
|||
// Create users
|
||||
// TODO(@hoverbear): Abstract this, it will be common
|
||||
let mut set = JoinSet::new();
|
||||
|
||||
let mut successes = Vec::with_capacity(create_users.len());
|
||||
let mut errors = Vec::default();
|
||||
|
||||
|
|
Loading…
Reference in a new issue