Skip to content

Commit

Permalink
health: use table
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Oct 17, 2024
1 parent 6d32e20 commit de7224b
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions crates/nix_health/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,47 @@ pub async fn run_checks_with(flake_url: Option<FlakeUrl>) -> anyhow::Result<Vec<
None => Ok(NixHealth::default()),
}?;

tracing::info!(
"🩺️ Checking the health of your Nix setup{}",
match flake_url.as_ref() {
Some(flake_url) => format!(" using config from flake '{}'", flake_url),
None => "".to_string(),
},
);
tracing::info!(" - System: {}", nix_info.nix_config.system.value);
tracing::info!(" - OS: {}", nix_info.nix_env.os);
if nix_info.nix_env.os != OS::NixOS {
tracing::info!(" - Nix installer: {}", nix_info.nix_env.installer);
}
tracing::info!(" - RAM: {:?}", nix_info.nix_env.total_memory);
tracing::info!(" - Disk Space: {:?}", nix_info.nix_env.total_disk_space);
tracing::info!("🩺️ Checking the health of your Nix setup");

print_info_banner(flake_url.as_ref(), nix_info).await?;

let checks = health.run_checks(nix_info, flake_url.clone());
let checks = health.run_checks(nix_info, flake_url);
Ok(checks)
}

async fn print_info_banner(flake_url: Option<&FlakeUrl>, nix_info: &NixInfo) -> anyhow::Result<()> {
let pwd = std::env::current_dir()?;
let md = async |s: &str| render_markdown(&pwd, s).await;

let mut table = String::from("| Property | Value |\n|----------|-------|\n");
table.push_str(&format!(
"| Flake | {} |\n",
match flake_url {
Some(url) => url.to_string(),
None => "N/A".to_string(),
}
));
table.push_str(&format!(
"| System | {} |\n",
nix_info.nix_config.system.value
));
table.push_str(&format!("| OS | {} |\n", nix_info.nix_env.os));
if nix_info.nix_env.os != OS::NixOS {
table.push_str(&format!(
"| Nix installer | {} |\n",
nix_info.nix_env.installer
));
}
table.push_str(&format!("| RAM | {:?} |\n", nix_info.nix_env.total_memory));
table.push_str(&format!(
"| Disk Space | {:?} |",
nix_info.nix_env.total_disk_space
));

tracing::info!("{}", md(&table).await?);
Ok(())
}

/// A convenient type to aggregate check failures, and summary report at end.
enum AllChecksResult {
Pass,
Expand Down

0 comments on commit de7224b

Please sign in to comment.