aux-search/flake-info/src/lib.rs

64 lines
1.7 KiB
Rust
Raw Normal View History

2021-08-17 08:55:08 +00:00
#![recursion_limit = "256"]
use anyhow::Result;
2022-07-21 10:20:52 +00:00
use data::{import::Kind, Export, Flake, Source};
use lazy_static::lazy_static;
use std::path::{Path, PathBuf};
2021-08-17 08:55:08 +00:00
pub mod commands;
pub mod data;
#[cfg(feature = "elastic")]
2021-08-17 08:55:08 +00:00
pub mod elastic;
pub use commands::get_flake_info;
use log::trace;
2021-08-17 08:55:08 +00:00
lazy_static! {
static ref DATADIR: PathBuf =
Path::new(option_env!("ROOTDIR").unwrap_or(env!("CARGO_MANIFEST_DIR"))).join("assets");
}
2021-08-17 08:55:08 +00:00
pub fn process_flake(
source: &Source,
kind: &data::import::Kind,
temp_store: bool,
extra: &[String],
2022-07-21 10:20:52 +00:00
) -> Result<(Flake, Vec<Export>)> {
2021-08-17 08:55:08 +00:00
let mut info = commands::get_flake_info(source.to_flake_ref(), temp_store, extra)?;
info.source = Some(source.clone());
let packages = commands::get_derivation_info(source.to_flake_ref(), *kind, temp_store, extra)?;
trace!("flake info: {:#?}", info);
trace!("flake content: {:#?}", packages);
2021-08-17 08:55:08 +00:00
let exports: Vec<Export> = packages
.into_iter()
.map(|p| Export::flake(info.clone(), p))
2022-07-21 10:20:52 +00:00
.collect::<Result<Vec<Export>>>()?;
2021-08-17 08:55:08 +00:00
2022-07-21 10:20:52 +00:00
Ok((info, exports))
2021-08-17 08:55:08 +00:00
}
pub fn process_nixpkgs(nixpkgs: &Source, kind: &Kind) -> Result<Vec<Export>, anyhow::Error> {
let drvs = if matches!(kind, Kind::All | Kind::Package) {
commands::get_nixpkgs_info(nixpkgs.to_flake_ref())?
} else {
Vec::new()
};
let mut options = if matches!(kind, Kind::All | Kind::Option) {
commands::get_nixpkgs_options(nixpkgs.to_flake_ref())?
} else {
Vec::new()
};
let mut all = drvs;
all.append(&mut options);
2022-07-21 10:20:52 +00:00
let exports = all
.into_iter()
.map(Export::nixpkgs)
.collect::<Result<Vec<Export>>>()?;
2021-08-17 08:55:08 +00:00
Ok(exports)
}