forked from lix-project/lix-installer
Planner error if on NixOS
This commit is contained in:
parent
673464ede7
commit
91f286a37f
|
@ -3,7 +3,7 @@ use std::path::PathBuf;
|
|||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum HarmonicError {
|
||||
#[error("Error executing action")]
|
||||
ActionError(
|
||||
Action(
|
||||
#[source]
|
||||
#[from]
|
||||
Box<dyn std::error::Error + Send + Sync>,
|
||||
|
|
|
@ -90,7 +90,7 @@ impl InstallPlan {
|
|||
if let Err(err) = write_receipt(self.clone()).await {
|
||||
tracing::error!("Error saving receipt: {:?}", err);
|
||||
}
|
||||
return Err(HarmonicError::ActionError(err));
|
||||
return Err(HarmonicError::Action(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ impl InstallPlan {
|
|||
if let Err(err) = write_receipt(self.clone()).await {
|
||||
tracing::error!("Error saving receipt: {:?}", err);
|
||||
}
|
||||
return Err(HarmonicError::ActionError(err));
|
||||
return Err(HarmonicError::Action(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
planner::Planner,
|
||||
BuiltinPlanner, CommonSettings, InstallPlan,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, path::Path};
|
||||
|
||||
#[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)]
|
||||
pub struct LinuxMulti {
|
||||
|
@ -24,12 +24,29 @@ impl Planner for LinuxMulti {
|
|||
}
|
||||
|
||||
async fn plan(self) -> Result<InstallPlan, Box<dyn std::error::Error + Sync + Send>> {
|
||||
// If on NixOS, running `harmonic` is pointless
|
||||
if Path::new("/etc/NIXOS").exists() {
|
||||
return Err(Error::NixOs.into());
|
||||
}
|
||||
|
||||
Ok(InstallPlan {
|
||||
planner: Box::new(self.clone()),
|
||||
actions: vec![
|
||||
Box::new(CreateDirectory::plan("/nix", None, None, 0o0755, true).await?),
|
||||
Box::new(ProvisionNix::plan(self.settings.clone()).await?),
|
||||
Box::new(ConfigureNix::plan(self.settings).await?),
|
||||
Box::new(
|
||||
CreateDirectory::plan("/nix", None, None, 0o0755, true)
|
||||
.await
|
||||
.map_err(|v| Error::Action(v.into()))?,
|
||||
),
|
||||
Box::new(
|
||||
ProvisionNix::plan(self.settings.clone())
|
||||
.await
|
||||
.map_err(|v| Error::Action(v.into()))?,
|
||||
),
|
||||
Box::new(
|
||||
ConfigureNix::plan(self.settings)
|
||||
.await
|
||||
.map_err(|v| Error::Action(v.into()))?,
|
||||
),
|
||||
],
|
||||
})
|
||||
}
|
||||
|
@ -51,3 +68,15 @@ impl Into<BuiltinPlanner> for LinuxMulti {
|
|||
BuiltinPlanner::LinuxMulti(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
enum Error {
|
||||
#[error("NixOS already has Nix installed")]
|
||||
NixOs,
|
||||
#[error("Error planning action")]
|
||||
Action(
|
||||
#[source]
|
||||
#[from]
|
||||
Box<dyn std::error::Error + Send + Sync>,
|
||||
),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue