nix: Small fixes to logging

This commit is contained in:
Zhaofeng Li 2021-01-28 23:58:54 -08:00
parent ade2095919
commit 68ecb095b8
3 changed files with 30 additions and 9 deletions

View file

@ -276,7 +276,9 @@ impl Deployment {
"Evaluating configurations for {} nodes"
);
let drv = match arc_self.hive.eval_selected(&chunk, Some(bar.clone())).await {
let (eval, logs) = arc_self.hive.eval_selected(&chunk, Some(bar.clone())).await;
let drv = match eval {
Ok(drv) => {
bar.finish_and_clear();
drv
@ -287,7 +289,7 @@ impl Deployment {
let mut results = arc_self.results.lock().await;
let stage = DeploymentStage::Evaluate(chunk.clone());
results.push(DeploymentResult::failure(stage, None));
results.push(DeploymentResult::failure(stage, logs));
return;
}
};

View file

@ -59,8 +59,15 @@ impl Hive {
/// Evaluation may take up a lot of memory, so we make it possible
/// to split up the evaluation process into chunks and run them
/// concurrently with other processes (e.g., build and apply).
pub async fn eval_selected(&self, nodes: &Vec<String>, progress_bar: Option<ProgressBar>) -> NixResult<StoreDerivation<ProfileMap>> {
let nodes_expr = SerializedNixExpresssion::new(nodes)?;
pub async fn eval_selected(&self, nodes: &Vec<String>, progress_bar: Option<ProgressBar>) -> (NixResult<StoreDerivation<ProfileMap>>, Option<String>) {
// FIXME: The return type is ugly...
let nodes_expr = SerializedNixExpresssion::new(nodes);
if let Err(e) = nodes_expr {
return (Err(e), None);
}
let nodes_expr = nodes_expr.unwrap();
let expr = format!("hive.buildSelected {{ names = {}; }}", nodes_expr.expression());
let command = self.nix_instantiate(&expr).instantiate();
@ -71,11 +78,21 @@ impl Hive {
}
let eval = execution
.capture_store_path().await?;
let drv = eval.to_derivation()
.expect("The result should be a store derivation");
.capture_store_path().await;
Ok(drv)
let (_, stderr) = execution.get_logs();
match eval {
Ok(path) => {
let drv = path.to_derivation()
.expect("The result should be a store derivation");
(Ok(drv), stderr.cloned())
}
Err(e) => {
(Err(e), stderr.cloned())
}
}
}
/// Evaluates an expression using values from the configuration

View file

@ -149,7 +149,9 @@ impl Host for Local {
execution.run().await?;
let (stdout, _) = execution.get_logs();
let (stdout, stderr) = execution.get_logs();
self.logs += stderr.unwrap();
stdout.unwrap().lines().map(|p| p.to_string().try_into()).collect()
}
async fn activate(&mut self, profile: &Profile, goal: DeploymentGoal) -> NixResult<()> {