File size: 702 Bytes
2d766b8
 
89b790c
2d766b8
89b790c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d766b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use std::process::Command;

pub struct NixExecutor;

impl NixExecutor {
    pub fn execute(cmd: &str, packages: Vec<&str>) -> String {
        // This runs the command inside a nix-shell with the requested packages
        let mut nix_cmd = Command::new("nix-shell");
        nix_cmd.arg("-p").args(packages).arg("--run").arg(cmd);

        match nix_cmd.output() {
            Ok(output) => {
                let stdout = String::from_utf8_lossy(&output.stdout);
                let stderr = String::from_utf8_lossy(&output.stderr);
                format!("STDOUT: {}\nSTDERR: {}", stdout, stderr)
            }
            Err(e) => format!("Failed to execute Nix command: {}", e),
        }
    }
}