Add configuration hash display to system panel

- Collect config hash from cloned nixos-config git repository
- Display "Config: xxxxx" after "Build: xxxxx" in NixOS section
- Uses /var/lib/cm-dashboard/nixos-config directory
- Shows actual configuration hash vs nixpkgs build hash
This commit is contained in:
2025-10-25 01:30:46 +02:00
parent 996a199050
commit 2d3844b5dd
2 changed files with 60 additions and 0 deletions

View File

@@ -63,6 +63,29 @@ impl NixOSCollector {
Ok("unknown".to_string())
}
/// Get configuration hash from cloned nixos-config git repository
fn get_config_hash(&self) -> Result<String, Box<dyn std::error::Error>> {
// Get git hash from the cloned nixos-config directory
let config_path = "/var/lib/cm-dashboard/nixos-config";
let output = Command::new("git")
.args(&["log", "-1", "--format=%h"])
.current_dir(config_path)
.output()?;
if !output.status.success() {
return Err("git log command failed".into());
}
let hash = String::from_utf8_lossy(&output.stdout).trim().to_string();
if hash.is_empty() {
return Err("Empty git hash output".into());
}
Ok(hash)
}
/// Get currently active users
fn get_active_users(&self) -> Result<Vec<String>, Box<dyn std::error::Error>> {
let output = Command::new("who").output()?;
@@ -148,6 +171,31 @@ impl Collector for NixOSCollector {
}
}
// Collect config hash
match self.get_config_hash() {
Ok(hash) => {
metrics.push(Metric {
name: "system_config_hash".to_string(),
value: MetricValue::String(hash),
unit: None,
description: Some("NixOS configuration git hash".to_string()),
status: Status::Ok,
timestamp,
});
}
Err(e) => {
debug!("Failed to get config hash: {}", e);
metrics.push(Metric {
name: "system_config_hash".to_string(),
value: MetricValue::String("unknown".to_string()),
unit: None,
description: Some("Config hash (failed to detect)".to_string()),
status: Status::Unknown,
timestamp,
});
}
}
// Collect agent hash
match self.get_agent_hash() {
Ok(hash) => {