diff --git a/src/command/apply_local.rs b/src/command/apply_local.rs index 52ba115..e6f6f1e 100644 --- a/src/command/apply_local.rs +++ b/src/command/apply_local.rs @@ -98,11 +98,8 @@ pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) { }; let goal = Goal::from_str(local_args.value_of("goal").unwrap()).unwrap(); - log::info!("Enumerating nodes..."); - let all_nodes = hive.deployment_info().await.unwrap(); - let target: Target = { - if let Some(info) = all_nodes.get(&hostname) { + if let Some(info) = hive.deployment_info_for(&hostname).await.unwrap() { if !info.allows_local_deployment() { log::error!("Local deployment is not enabled for host {}.", hostname); log::error!("Hint: Set deployment.allowLocalDeployment to true."); diff --git a/src/nix/hive.rs b/src/nix/hive.rs index f2cd23d..514bf43 100644 --- a/src/nix/hive.rs +++ b/src/nix/hive.rs @@ -46,7 +46,7 @@ impl Hive { &self.hive } - /// Retrieve deployment info for all nodes + /// Retrieve deployment info for all nodes. pub async fn deployment_info(&self) -> NixResult> { // FIXME: Really ugly :( let s: String = self.nix_instantiate("hive.deploymentConfigJson").eval() @@ -62,6 +62,15 @@ impl Hive { Ok(configs) } + /// Retrieve deployment info for a single node. + pub async fn deployment_info_for(&self, node: &str) -> NixResult> { + let expr = format!("toJSON (hive.nodes.\"{}\".config.deployment or null)", node); + let s: String = self.nix_instantiate(&expr).eval() + .capture_json().await?; + + Ok(serde_json::from_str(&s).unwrap()) + } + /// Evaluates selected nodes. /// /// Evaluation may take up a lot of memory, so we make it possible