Implement git clone approach for nixos-rebuild

Replace direct directory access with git clone/pull approach:
- Add git configuration options (url, branch, working_dir) to NixOS module
- Update SystemConfig and AgentCommand to use git parameters
- Implement ensure_git_repository() method for clone/pull operations
- Agent clones nixosbox to /var/lib/cm-dashboard/nixos-config
- Maintains security while solving permission denied issues

The agent now manages its own copy of the configuration without
needing access to /home/cm directory.
This commit is contained in:
2025-10-24 19:16:44 +02:00
parent 864cafd61f
commit b3c67f4b7f
5 changed files with 95 additions and 20 deletions

View File

@@ -22,6 +22,7 @@ pub struct Dashboard {
terminal: Option<Terminal<CrosstermBackend<io::Stdout>>>,
headless: bool,
initial_commands_sent: std::collections::HashSet<String>,
config: DashboardConfig,
}
impl Dashboard {
@@ -132,6 +133,7 @@ impl Dashboard {
terminal,
headless,
initial_commands_sent: std::collections::HashSet::new(),
config,
})
}
@@ -297,8 +299,10 @@ impl Dashboard {
}
UiCommand::SystemRebuild { hostname } => {
info!("Sending system rebuild command to {}", hostname);
let agent_command = AgentCommand::SystemRebuild {
nixos_path: "/home/cm/nixosbox".to_string(), // Fixed path per requirements
let agent_command = AgentCommand::SystemRebuild {
git_url: self.config.system.nixos_config_git_url.clone(),
git_branch: self.config.system.nixos_config_branch.clone(),
working_dir: self.config.system.nixos_config_working_dir.clone(),
};
self.zmq_command_sender.send_command(&hostname, agent_command).await?;
}

View File

@@ -23,7 +23,9 @@ pub enum AgentCommand {
},
/// Rebuild NixOS system
SystemRebuild {
nixos_path: String, // Path to nixosbox directory
git_url: String,
git_branch: String,
working_dir: String,
},
}

View File

@@ -7,6 +7,7 @@ use std::path::Path;
pub struct DashboardConfig {
pub zmq: ZmqConfig,
pub hosts: HostsConfig,
pub system: SystemConfig,
}
/// ZMQ consumer configuration
@@ -21,6 +22,14 @@ pub struct HostsConfig {
pub predefined_hosts: Vec<String>,
}
/// System configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SystemConfig {
pub nixos_config_git_url: String,
pub nixos_config_branch: String,
pub nixos_config_working_dir: String,
}
impl DashboardConfig {
pub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self> {
let path = path.as_ref();