diff --git a/crates/core/src/hive/node.rs b/crates/core/src/hive/node.rs index a573e92e..5419db78 100644 --- a/crates/core/src/hive/node.rs +++ b/crates/core/src/hive/node.rs @@ -21,7 +21,7 @@ use crate::hive::steps::build::Build; use crate::hive::steps::evaluate::Evaluate; use crate::hive::steps::keys::{Key, Keys, PushKeyAgent}; use crate::hive::steps::ping::Ping; -use crate::hive::steps::push::{PushBuildOutput, PushEvaluatedOutput}; +use crate::hive::steps::push::PushOutput; use crate::{SafeStorePath, StrictHostKeyChecking, SubCommandModifiers, open_remote_client}; use super::HiveLibError; @@ -305,10 +305,9 @@ pub enum Step { PushKeyAgent, Keys, Evaluate, - PushEvaluatedOutput, Build, - PushBuildOutput, SwitchToConfiguration, + PushOutput, } impl Display for Step { @@ -318,9 +317,8 @@ impl Display for Step { Self::PushKeyAgent(step) => step.fmt(f), Self::Keys(step) => step.fmt(f), Self::Evaluate(step) => step.fmt(f), - Self::PushEvaluatedOutput(step) => step.fmt(f), + Self::PushOutput(step) => step.fmt(f), Self::Build(step) => step.fmt(f), - Self::PushBuildOutput(step) => step.fmt(f), Self::SwitchToConfiguration(step) => step.fmt(f), } } diff --git a/crates/core/src/hive/plan.rs b/crates/core/src/hive/plan.rs index 382cd8b2..5cc942a6 100644 --- a/crates/core/src/hive/plan.rs +++ b/crates/core/src/hive/plan.rs @@ -20,7 +20,7 @@ use crate::{ evaluate::Evaluate, keys::{Keys, PushKeyAgent, UploadKeyAt}, ping::Ping, - push::{PushBuildOutput, PushEvaluatedOutput}, + push::{PushOutput, PushOutputHandle}, }, }, }; @@ -201,10 +201,10 @@ fn apply_plan( && !should_apply_locally && (node.build_remotely || matches!(goal, ApplyGoal::Push)) { - steps.push(Step::PushEvaluatedOutput(PushEvaluatedOutput { + steps.push(Step::PushOutput(PushOutput { substitute_on_destination: *substitute_on_destination, target: target.clone(), - path: evaluation_output_handle.clone(), + path: PushOutputHandle::Evaluation(evaluation_output_handle.clone()), })); } @@ -243,10 +243,10 @@ fn apply_plan( && !should_apply_locally && !matches!(goal, ApplyGoal::Keys | ApplyGoal::Push) { - steps.push(Step::PushBuildOutput(PushBuildOutput { + steps.push(Step::PushOutput(PushOutput { substitute_on_destination: *substitute_on_destination, target: target.clone(), - path: build_output_handle.clone(), + path: PushOutputHandle::Build(build_output_handle.clone()), })); } @@ -380,7 +380,7 @@ mod tests { evaluate::Evaluate, keys::{Key, Keys, PushKeyAgent, Source, UploadKeyAt}, ping::Ping, - push::{PushBuildOutput, PushEvaluatedOutput}, + push::{PushOutput, PushOutputHandle}, }, }, location, @@ -476,10 +476,10 @@ mod tests { output: EvaluationOutputHandle::new(), } .into(), - PushEvaluatedOutput { + PushOutput { substitute_on_destination: true, target: target.clone(), - path: EvaluationOutputHandle::new(), + path: PushOutputHandle::Evaluation(EvaluationOutputHandle::new()), } .into(), Build { @@ -530,10 +530,10 @@ mod tests { }), } .into(), - PushBuildOutput { + PushOutput { substitute_on_destination: true, target, - path: BuildOutputHandle::new(), + path: PushOutputHandle::Build(BuildOutputHandle::new()), } .into(), ] @@ -719,10 +719,10 @@ mod tests { output: EvaluationOutputHandle::new(), } .into(), - PushEvaluatedOutput { + PushOutput { substitute_on_destination: true, target, - path: EvaluationOutputHandle::new(), + path: PushOutputHandle::Evaluation(EvaluationOutputHandle::new()), } .into() ] @@ -769,10 +769,10 @@ mod tests { output: EvaluationOutputHandle::new(), } .into(), - PushEvaluatedOutput { + PushOutput { substitute_on_destination: true, target: target.clone(), - path: EvaluationOutputHandle::new(), + path: PushOutputHandle::Evaluation(EvaluationOutputHandle::new()), } .into(), Build { @@ -836,10 +836,10 @@ mod tests { output: EvaluationOutputHandle::new(), } .into(), - PushEvaluatedOutput { + PushOutput { substitute_on_destination: true, target: target.clone(), - path: EvaluationOutputHandle::new(), + path: PushOutputHandle::Evaluation(EvaluationOutputHandle::new()), } .into(), Build { @@ -916,7 +916,10 @@ mod tests { let node = Node::default(); let name = &Name(function_name!().into()); let should_quit = Arc::new(AtomicBool::new(false)); - let cached = SafeStorePath::::from_absolute_path(b"/nix/store/name").unwrap(); + let cached = SafeStorePath::::from_absolute_path( + b"/nix/store/0cg1bwya4a0r5y9vbi5c79jsvgmicg1p-name", + ) + .unwrap(); let plan = plan_for_node( &node, name.clone(), @@ -1027,10 +1030,10 @@ mod tests { output: EvaluationOutputHandle::new(), } .into(), - PushEvaluatedOutput { + PushOutput { substitute_on_destination: true, target: target.clone(), - path: EvaluationOutputHandle::new(), + path: PushOutputHandle::Evaluation(EvaluationOutputHandle::new()), } .into(), Build { diff --git a/crates/core/src/hive/steps/activate.rs b/crates/core/src/hive/steps/activate.rs index 4df41dce..e456d022 100644 --- a/crates/core/src/hive/steps/activate.rs +++ b/crates/core/src/hive/steps/activate.rs @@ -28,7 +28,7 @@ pub struct SwitchToConfiguration { impl Display for SwitchToConfiguration { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Run switch-to-configuration") + write!(f, "Activation") } } diff --git a/crates/core/src/hive/steps/push.rs b/crates/core/src/hive/steps/push.rs index ca50192f..602304e1 100644 --- a/crates/core/src/hive/steps/push.rs +++ b/crates/core/src/hive/steps/push.rs @@ -9,88 +9,51 @@ use crate::{ HiveLibError, hive::{ executor::{BuildOutputHandle, EvaluationOutputHandle}, - node::{Context, ExecuteStep, SharedTarget}, + node::{Context, ExecuteStep, Push, SharedTarget}, }, }; #[derive(Debug)] #[cfg_attr(test, derive(PartialEq))] -pub struct PushEvaluatedOutput { - pub substitute_on_destination: bool, - pub target: SharedTarget, - pub path: EvaluationOutputHandle, +pub enum PushOutputHandle { + Evaluation(EvaluationOutputHandle), + Build(BuildOutputHandle), } #[derive(Debug)] #[cfg_attr(test, derive(PartialEq))] -pub struct PushBuildOutput { +pub struct PushOutput { pub substitute_on_destination: bool, pub target: SharedTarget, - pub path: BuildOutputHandle, -} - -impl Display for PushEvaluatedOutput { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Push evaluated output") - } + pub path: PushOutputHandle, } -impl Display for PushBuildOutput { +impl Display for PushOutput { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Push build output") - } -} - -impl ExecuteStep for PushEvaluatedOutput { - #[instrument(skip_all, name = "push_eval")] - async fn execute(&self, ctx: &mut Context) -> Result<(), HiveLibError> { - let top_level = self.path.require().await?; - - if ctx.modifiers.experimental_nix_client { - crate::push_with_daemon( - ctx, - &self.target, - crate::hive::node::Push::Derivation(&top_level), - self.substitute_on_destination, - ) - .await?; - } else { - crate::commands::common::push( - ctx, - &self.target, - crate::hive::node::Push::Derivation(&top_level), - self.substitute_on_destination, - ) - .await?; - } - - Ok(()) + write!( + f, + "Push {} output", + match self.path { + PushOutputHandle::Evaluation(..) => "evaluation", + PushOutputHandle::Build(..) => "build", + } + ) } } -impl ExecuteStep for PushBuildOutput { - #[instrument(skip_all, name = "push_build")] +impl ExecuteStep for PushOutput { + #[instrument(skip_all, name = "push")] async fn execute(&self, ctx: &mut Context) -> Result<(), HiveLibError> { - let built_path = self.path.require().await?; + let push = match &self.path { + PushOutputHandle::Evaluation(handle) => Push::Derivation(&handle.require().await?), + PushOutputHandle::Build(handle) => Push::Path(&handle.require().await?), + }; if ctx.modifiers.experimental_nix_client { - crate::push_with_daemon( - ctx, - &self.target, - crate::hive::node::Push::Path(&built_path), - self.substitute_on_destination, - ) - .await?; + crate::push_with_daemon(ctx, &self.target, push, self.substitute_on_destination).await } else { - crate::commands::common::push( - ctx, - &self.target, - crate::hive::node::Push::Path(&built_path), - self.substitute_on_destination, - ) - .await?; + crate::commands::common::push(ctx, &self.target, push, self.substitute_on_destination) + .await } - - Ok(()) } }