Fix config hash to show actual deployed nix store hash
- Replace git commit hash with nix store hash extraction - Read from /run/current-system symlink target - Extract first 8 characters of nix store hash: d8ivwiar - Shows actual deployed configuration, not just source - Enables proper rebuild completion detection - Accurate deployment verification
This commit is contained in:
parent
a7e237e2ff
commit
fb6ee6d7ae
@ -63,27 +63,32 @@ impl NixOSCollector {
|
|||||||
Ok("unknown".to_string())
|
Ok("unknown".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get configuration hash from cloned nixos-config git repository
|
/// Get configuration hash from deployed nix store system
|
||||||
fn get_config_hash(&self) -> Result<String, Box<dyn std::error::Error>> {
|
fn get_config_hash(&self) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
// Get git hash from the cloned nixos-config directory
|
// Read the symlink target of /run/current-system to get nix store path
|
||||||
let config_path = "/var/lib/cm-dashboard/nixos-config";
|
let output = Command::new("readlink")
|
||||||
|
.arg("/run/current-system")
|
||||||
let output = Command::new("git")
|
|
||||||
.args(&["log", "-1", "--format=%h"])
|
|
||||||
.current_dir(config_path)
|
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
return Err("git log command failed".into());
|
return Err("readlink command failed".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let hash = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
let binding = String::from_utf8_lossy(&output.stdout);
|
||||||
|
let store_path = binding.trim();
|
||||||
|
|
||||||
if hash.is_empty() {
|
// Extract hash from nix store path
|
||||||
return Err("Empty git hash output".into());
|
// Format: /nix/store/HASH-nixos-system-HOSTNAME-VERSION
|
||||||
|
if let Some(hash_part) = store_path.strip_prefix("/nix/store/") {
|
||||||
|
if let Some(hash) = hash_part.split('-').next() {
|
||||||
|
if hash.len() >= 8 {
|
||||||
|
// Return first 8 characters of nix store hash
|
||||||
|
return Ok(hash[..8].to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(hash)
|
Err("Could not extract hash from nix store path".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get currently active users
|
/// Get currently active users
|
||||||
@ -178,7 +183,7 @@ impl Collector for NixOSCollector {
|
|||||||
name: "system_config_hash".to_string(),
|
name: "system_config_hash".to_string(),
|
||||||
value: MetricValue::String(hash),
|
value: MetricValue::String(hash),
|
||||||
unit: None,
|
unit: None,
|
||||||
description: Some("NixOS configuration git hash".to_string()),
|
description: Some("NixOS deployed configuration hash".to_string()),
|
||||||
status: Status::Ok,
|
status: Status::Ok,
|
||||||
timestamp,
|
timestamp,
|
||||||
});
|
});
|
||||||
@ -189,7 +194,7 @@ impl Collector for NixOSCollector {
|
|||||||
name: "system_config_hash".to_string(),
|
name: "system_config_hash".to_string(),
|
||||||
value: MetricValue::String("unknown".to_string()),
|
value: MetricValue::String("unknown".to_string()),
|
||||||
unit: None,
|
unit: None,
|
||||||
description: Some("Config hash (failed to detect)".to_string()),
|
description: Some("Deployed config hash (failed to detect)".to_string()),
|
||||||
status: Status::Unknown,
|
status: Status::Unknown,
|
||||||
timestamp,
|
timestamp,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user