Make dashboard -V show actual config hash for rebuild verification

Replace hardcoded version with first 8 characters of current system's
nix store hash. This makes it easy to verify when rebuilds complete
as the hash changes with each deployment.

No fallback - fails hard if config hash cannot be determined.
This commit is contained in:
Christoffer Martinsson 2025-10-25 14:31:20 +02:00
parent 4b54a59e35
commit 3d187c9220

View File

@ -11,10 +11,31 @@ mod ui;
use app::Dashboard;
/// Get version showing current system config hash for easy rebuild verification
fn get_version() -> &'static str {
use std::process::Command;
// Get config hash from current system
let output = Command::new("readlink").arg("/run/current-system").output().expect("Failed to run readlink");
assert!(output.status.success(), "readlink command failed");
let store_path = String::from_utf8_lossy(&output.stdout);
let store_path = store_path.trim();
// Extract hash from nix store path
let hash_part = store_path.strip_prefix("/nix/store/").expect("Not a nix store path");
let hash = hash_part.split('-').next().expect("Invalid nix store path format");
assert!(hash.len() >= 8, "Hash too short");
// Return first 8 characters of nix store hash
let short_hash = hash[..8].to_string();
Box::leak(short_hash.into_boxed_str())
}
#[derive(Parser)]
#[command(name = "cm-dashboard")]
#[command(about = "CM Dashboard TUI with individual metric consumption")]
#[command(version)]
#[command(version = get_version())]
struct Cli {
/// Increase logging verbosity (-v, -vv)
#[arg(short, long, action = clap::ArgAction::Count)]