1use std::sync::{Arc, Mutex};
2
3use anyhow::Error;
4use fluentci_core::deps::{Graph, GraphCommand};
5use fluentci_ext::nix::Nix as NixExt;
6use fluentci_types::nix::{Nix, NixArgs};
7use uuid::Uuid;
8
9pub fn nix(graph: Arc<Mutex<Graph>>, reset: bool, args: NixArgs) -> Result<Nix, Error> {
10 let mut graph = graph.lock().unwrap();
11
12 if reset {
13 graph.reset();
14 }
15
16 graph.runner = Arc::new(Box::new(NixExt::new(args)));
17 graph.runner.setup()?;
18
19 let id = Uuid::new_v4().to_string();
20 graph.execute(GraphCommand::AddVertex(
21 id.clone(),
22 "nix".into(),
23 "".into(),
24 vec![],
25 Arc::new(Box::new(NixExt::default())),
26 ))?;
27
28 let nix = Nix { id };
29 Ok(nix)
30}