Detect if plan already done
This commit is contained in:
parent
e57311a807
commit
72d3fcd942
|
@ -184,4 +184,8 @@ impl Action for ConfigureNix {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,6 +212,10 @@ impl Action for ConfigureNixDaemonService {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -181,6 +181,10 @@ impl Action for ConfigureShellProfile {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -214,6 +214,10 @@ impl Action for CreateDirectory {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -188,6 +188,10 @@ impl Action for CreateFile {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -160,6 +160,10 @@ impl Action for CreateGroup {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -134,6 +134,10 @@ impl Action for CreateNixTree {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -223,6 +223,10 @@ impl Action for CreateOrAppendFile {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -254,6 +254,10 @@ impl Action for CreateUser {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -229,6 +229,10 @@ impl Action for CreateUsersAndGroup {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -115,6 +115,10 @@ impl Action for FetchNix {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -106,6 +106,10 @@ impl Action for MoveUnpackedNix {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -130,6 +130,10 @@ impl Action for PlaceChannelConfiguration {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -115,6 +115,10 @@ impl Action for PlaceNixConfiguration {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -168,6 +168,10 @@ impl Action for ProvisionNix {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -181,6 +181,10 @@ impl Action for SetupDefaultProfile {
|
|||
*action_state = ActionState::Completed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -106,6 +106,10 @@ impl Action for BootstrapVolume {
|
|||
*action_state = ActionState::Completed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -289,6 +289,10 @@ impl Action for CreateApfsVolume {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -98,6 +98,10 @@ impl Action for CreateSyntheticObjects {
|
|||
*action_state = ActionState::Completed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -130,6 +130,10 @@ impl Action for CreateVolume {
|
|||
*action_state = ActionState::Completed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -109,6 +109,10 @@ impl Action for EnableOwnership {
|
|||
*action_state = ActionState::Completed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -86,6 +86,10 @@ impl Action for EncryptVolume {
|
|||
*action_state = ActionState::Completed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -96,6 +96,10 @@ impl Action for KickstartLaunchctlService {
|
|||
*action_state = ActionState::Completed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -117,6 +117,10 @@ impl Action for UnmountVolume {
|
|||
*action_state = ActionState::Completed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -185,6 +185,10 @@ impl Action for CreateSystemdSysext {
|
|||
*action_state = ActionState::Uncompleted;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -98,6 +98,10 @@ impl Action for StartSystemdUnit {
|
|||
*action_state = ActionState::Completed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -102,6 +102,10 @@ impl Action for SystemdSysextMerge {
|
|||
*action_state = ActionState::Completed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_state(&self) -> ActionState {
|
||||
self.action_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
|
@ -13,11 +13,12 @@ pub trait Action: Send + Sync + std::fmt::Debug + dyn_clone::DynClone {
|
|||
// They should also have an `async fn plan(args...) -> Result<ActionState<Self>, Box<dyn std::error::Error + Send + Sync>>;`
|
||||
async fn execute(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
||||
async fn revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
||||
fn action_state(&self) -> ActionState;
|
||||
}
|
||||
|
||||
dyn_clone::clone_trait_object!(Action);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Copy)]
|
||||
pub enum ActionState {
|
||||
Completed,
|
||||
// Only applicable to meta-actions that start multiple sub-actions.
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
process::ExitCode,
|
||||
};
|
||||
|
||||
use crate::{plan::RECEIPT_LOCATION, BuiltinPlanner, InstallPlan, Planner};
|
||||
use crate::{plan::RECEIPT_LOCATION, BuiltinPlanner, InstallPlan, Planner, action::ActionState};
|
||||
use clap::{ArgAction, Parser};
|
||||
use eyre::{eyre, WrapErr};
|
||||
|
||||
|
@ -62,11 +62,17 @@ impl CommandExecute for Install {
|
|||
|
||||
match existing_receipt {
|
||||
Some(existing_receipt) => {
|
||||
if existing_receipt.planner.typetag_name() == chosen_planner.typetag_name() {
|
||||
existing_receipt
|
||||
} else {
|
||||
if existing_receipt.planner.typetag_name() != chosen_planner.typetag_name() {
|
||||
return Err(eyre!("Found existing plan in `/nix/receipt.json` which used a different planner, try uninstalling the existing install"))
|
||||
}
|
||||
if existing_receipt.planner.settings().map_err(|e| eyre!(e))? != chosen_planner.settings().map_err(|e| eyre!(e))? {
|
||||
return Err(eyre!("Found existing plan in `/nix/receipt.json` which used different planner settings, try uninstalling the existing install"))
|
||||
}
|
||||
if existing_receipt.actions.iter().all(|v| v.action_state() == ActionState::Completed) {
|
||||
return Err(eyre!("Found existing plan in `/nix/receipt.json`, with the same settings, already completed, try uninstalling and reinstalling if Nix isn't working"))
|
||||
}
|
||||
|
||||
existing_receipt
|
||||
} ,
|
||||
None => {
|
||||
planner.plan().await.map_err(|e| eyre!(e))?
|
||||
|
|
|
@ -45,7 +45,7 @@ impl InstallPlan {
|
|||
},
|
||||
planner = planner.typetag_name(),
|
||||
plan_settings = planner
|
||||
.describe()?
|
||||
.settings()?
|
||||
.into_iter()
|
||||
.map(|(k, v)| format!("* {k}: {v}", k = k.bold().white()))
|
||||
.collect::<Vec<_>>()
|
||||
|
|
|
@ -98,7 +98,7 @@ impl Planner for DarwinMulti {
|
|||
})
|
||||
}
|
||||
|
||||
fn describe(
|
||||
fn settings(
|
||||
&self,
|
||||
) -> Result<HashMap<String, serde_json::Value>, Box<dyn std::error::Error + Sync + Send>> {
|
||||
let Self {
|
||||
|
|
|
@ -36,7 +36,7 @@ impl Planner for LinuxMulti {
|
|||
})
|
||||
}
|
||||
|
||||
fn describe(
|
||||
fn settings(
|
||||
&self,
|
||||
) -> Result<HashMap<String, serde_json::Value>, Box<dyn std::error::Error + Sync + Send>> {
|
||||
let Self { settings } = self;
|
||||
|
|
|
@ -13,7 +13,7 @@ pub trait Planner: std::fmt::Debug + Send + Sync + dyn_clone::DynClone {
|
|||
where
|
||||
Self: Sized;
|
||||
async fn plan(self) -> Result<InstallPlan, Box<dyn std::error::Error + Sync + Send>>;
|
||||
fn describe(
|
||||
fn settings(
|
||||
&self,
|
||||
) -> Result<HashMap<String, serde_json::Value>, Box<dyn std::error::Error + Sync + Send>>;
|
||||
fn boxed(self) -> Box<dyn Planner>
|
||||
|
|
|
@ -36,7 +36,7 @@ impl Planner for SteamDeck {
|
|||
})
|
||||
}
|
||||
|
||||
fn describe(
|
||||
fn settings(
|
||||
&self,
|
||||
) -> Result<HashMap<String, serde_json::Value>, Box<dyn std::error::Error + Sync + Send>> {
|
||||
let Self { settings } = self;
|
||||
|
|
Loading…
Reference in a new issue