1use std::{collections::BTreeMap, io::Read};
2
3use nix_compat::derivation::Derivation;
4use serde_json::json;
5
6use mimalloc::MiMalloc;
7
8#[global_allocator]
9static GLOBAL: MiMalloc = MiMalloc;
10
11fn build_serde_json_value(drv: Derivation) -> serde_json::Value {
19 json!({
20 "args": drv.arguments,
21 "builder": drv.builder,
22 "env": drv.environment.into_iter().map(|(k,v)| (k, v.to_string())).collect::<BTreeMap<String, String>>(),
23 "inputDrvs": drv.input_derivations,
24 "inputSrcs": drv.input_sources,
25 "outputs": drv.outputs,
26 "system": drv.system,
27 })
28}
29
30fn main() {
31 let mut buf = Vec::new();
33 std::io::stdin()
34 .read_to_end(&mut buf)
35 .expect("failed to read from stdin");
36
37 match Derivation::from_aterm_bytes(&buf) {
38 Ok(drv) => {
39 println!(
40 "{}",
41 serde_json::to_string_pretty(&build_serde_json_value(drv))
42 .expect("unable to serialize")
43 );
44 }
45 Err(e) => eprintln!("unable to parse derivation: {:#?}", e),
46 }
47}