Skip to content

Commit

Permalink
feat: parse the nix store metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
louib committed Aug 14, 2023
1 parent 36fec5b commit 571048a
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,74 @@ pub fn get_dependencies(path: &str) -> Vec<String> {
// TODO nix-store -qR /an/executable/path
vec![]
}

// Get the derivation path associated with a store object
pub fn get_derivation_path(store_path: &str) -> String {
// TODO nix-store -qd store_path
"".to_string()
}
pub fn get_packages() -> Result<HashMap<String, PackageMeta>, String> {
// There is currently no way with Nix to generate the meta information
// only for a single derivation. We need to generate the meta for
// all the derivations in the store and then extract the information
// we want from the global meta database.
let output = Command::new("nix-env")
.arg("-q")
.arg("-a")
.arg("--meta")
.arg("--json")
.arg("'.*'")
.output()
.map_err(|e| e.to_string())?;

let packages: HashMap<String, PackageMeta> =
serde_json::from_slice(&output.stdout).map_err(|e| e.to_string())?;
Ok(packages)
}

#[derive(Debug)]
#[derive(Serialize)]
#[derive(Deserialize)]
pub struct Meta {
pub packages: HashMap<String, PackageMeta>,
}

#[derive(Debug)]
#[derive(Serialize)]
#[derive(Deserialize)]
pub struct Package {
// name of the derivation
name: String,

// package name
pname: String,

// package version
version: String,

// name of the system for which this package was built
system: String,

// name of the output
#[serde(rename = "outputName")]
output_name: String,
}

#[derive(Debug)]
#[derive(Serialize)]
#[derive(Deserialize)]
pub struct PackageMeta {
available: Option<bool>,

broken: Option<bool>,

insecure: Option<bool>,

description: Option<String>,

unfree: Option<bool>,

unsupported: Option<bool>,

homepage: Option<String>,
}

0 comments on commit 571048a

Please sign in to comment.