Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions crates/core/src/hive/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -305,10 +305,9 @@ pub enum Step {
PushKeyAgent,
Keys,
Evaluate,
PushEvaluatedOutput,
Build,
PushBuildOutput,
SwitchToConfiguration,
PushOutput,
}

impl Display for Step {
Expand All @@ -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),
}
}
Expand Down
41 changes: 22 additions & 19 deletions crates/core/src/hive/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
evaluate::Evaluate,
keys::{Keys, PushKeyAgent, UploadKeyAt},
ping::Ping,
push::{PushBuildOutput, PushEvaluatedOutput},
push::{PushOutput, PushOutputHandle},
},
},
};
Expand Down Expand Up @@ -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()),
}));
}

Expand Down Expand Up @@ -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()),
}));
}

Expand Down Expand Up @@ -380,7 +380,7 @@ mod tests {
evaluate::Evaluate,
keys::{Key, Keys, PushKeyAgent, Source, UploadKeyAt},
ping::Ping,
push::{PushBuildOutput, PushEvaluatedOutput},
push::{PushOutput, PushOutputHandle},
},
},
location,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -530,10 +530,10 @@ mod tests {
}),
}
.into(),
PushBuildOutput {
PushOutput {
substitute_on_destination: true,
target,
path: BuildOutputHandle::new(),
path: PushOutputHandle::Build(BuildOutputHandle::new()),
}
.into(),
]
Expand Down Expand Up @@ -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()
]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<String>::from_absolute_path(b"/nix/store/name").unwrap();
let cached = SafeStorePath::<String>::from_absolute_path(
b"/nix/store/0cg1bwya4a0r5y9vbi5c79jsvgmicg1p-name",
)
.unwrap();
let plan = plan_for_node(
&node,
name.clone(),
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/hive/steps/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
85 changes: 24 additions & 61 deletions crates/core/src/hive/steps/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Loading