Skip to content

Commit

Permalink
feat: add derivation parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
louib committed Aug 14, 2023
1 parent 622b11b commit 6e8c6fe
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 8 deletions.
43 changes: 43 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ edition = "2021"

[dependencies]
clap = { version = "4", features = ["derive"] }

serde_json = "1.0"
serde = "1.0"
serde_derive = "1.0"
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#[macro_use]
extern crate clap;
#[macro_use]
extern crate serde_derive;

use clap::Parser;

Expand Down
55 changes: 47 additions & 8 deletions src/nix.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
extern crate serde;
extern crate serde_json;

use std::collections::HashMap;

use std::io::Error;
use std::process::Command;

pub fn get_derivation(file: &str) -> Result<Vec<u8>, Error> {
let output = Command::new("nix")
.arg("show-derivation")
.arg("-r")
.arg("-f")
.arg(file)
.output()?;
#[derive(Debug)]
#[derive(Serialize)]
#[derive(Deserialize)]
#[derive(Clone)]
struct Derivation {
outputs: HashMap<String, Output>,

#[serde(rename = "inputSrcs")]
inputs_sources: Vec<String>,

#[serde(rename = "inputDrvs")]
input_derivations: HashMap<String, Vec<String>>,

system: String,

builder: String,

args: Vec<String>,

env: HashMap<String, String>,

#[serde(flatten)]
extra: HashMap<String, serde_json::Value>,
}

impl Derivation {
pub fn parse_from_file(file: &str) -> Result<Vec<u8>, Error> {
let output = Command::new("nix")
.arg("show-derivation")
.arg("-r")
.arg(file)
.output()?;

Ok(output.stdout)
}
}

Ok(output.stdout)
#[derive(Debug)]
#[derive(Serialize)]
#[derive(Deserialize)]
#[derive(Clone)]
struct Output {
path: String,
}

0 comments on commit 6e8c6fe

Please sign in to comment.