From 68ecb095b88e676eef7b1a7cdff79dfa7b3d38bd Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Thu, 28 Jan 2021 23:58:54 -0800 Subject: [PATCH] nix: Small fixes to logging --- src/nix/deployment.rs | 6 ++++-- src/nix/hive.rs | 29 +++++++++++++++++++++++------ src/nix/host.rs | 4 +++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/nix/deployment.rs b/src/nix/deployment.rs index e2afcba..f043fda 100644 --- a/src/nix/deployment.rs +++ b/src/nix/deployment.rs @@ -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; } }; diff --git a/src/nix/hive.rs b/src/nix/hive.rs index 8d8f8fb..47fe0cd 100644 --- a/src/nix/hive.rs +++ b/src/nix/hive.rs @@ -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, progress_bar: Option) -> NixResult> { - let nodes_expr = SerializedNixExpresssion::new(nodes)?; + pub async fn eval_selected(&self, nodes: &Vec, progress_bar: Option) -> (NixResult>, Option) { + // 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 diff --git a/src/nix/host.rs b/src/nix/host.rs index 8ff10e5..484a7a4 100644 --- a/src/nix/host.rs +++ b/src/nix/host.rs @@ -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<()> {