Skip to content

Commit

Permalink
refactor: decompose the fn
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed May 5, 2024
1 parent 1f9e138 commit 90f375b
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tokio::sync::OnceCell;
use cli::{BuildConfig, CliArgs};
use colored::Colorize;
use nix::{
devour_flake::DevourFlakeOutput,
devour_flake::{DevourFlakeOutput, DrvOut},
nix_store::{NixStoreCmd, StorePath},
};
use nix_rs::{command::NixCmd, flake::url::FlakeUrl};
Expand Down Expand Up @@ -48,7 +48,34 @@ async fn nixci_build(
) -> anyhow::Result<Vec<StorePath>> {
let mut all_outs = HashSet::new();

let mut all_devour_flake_outs = HashSet::new();
let all_devour_flake_outs = nixci_subflakes(verbose, build_cfg, cfg).await?;

if build_cfg.print_all_dependencies {
let all_deps = NixStoreCmd
.fetch_all_deps(all_devour_flake_outs.into_iter().collect())
.await?;
all_outs.extend(all_deps.into_iter());
} else {
let store_paths: HashSet<StorePath> = all_devour_flake_outs
.into_iter()
.map(devour_flake::DrvOut::as_store_path)
.collect();
all_outs.extend(store_paths);
}

for out in &all_outs {
println!("{}", out);
}

Ok(all_outs.into_iter().collect())
}

async fn nixci_subflakes(
verbose: bool,
build_cfg: &BuildConfig,
cfg: &config::Config,
) -> anyhow::Result<HashSet<DrvOut>> {
let mut result = HashSet::new();

let systems = build_cfg.get_systems().await?;

Expand All @@ -66,7 +93,7 @@ async fn nixci_build(
if subflake.can_build_on(&systems) {
let outs =
nixci_subflake(verbose, build_cfg, &cfg.flake_url, subflake_name, subflake).await?;
all_devour_flake_outs.extend(outs.0);
result.extend(outs.0);
} else {
tracing::info!(
"🍊 {} {}",
Expand All @@ -76,24 +103,7 @@ async fn nixci_build(
}
}

if build_cfg.print_all_dependencies {
let all_deps = NixStoreCmd
.fetch_all_deps(all_devour_flake_outs.into_iter().collect())
.await?;
all_outs.extend(all_deps.into_iter());
} else {
let store_paths: HashSet<StorePath> = all_devour_flake_outs
.into_iter()
.map(devour_flake::DrvOut::as_store_path)
.collect();
all_outs.extend(store_paths);
}

for out in &all_outs {
println!("{}", out);
}

Ok(all_outs.into_iter().collect())
Ok(result)
}

#[instrument(skip(build_cfg, url))]
Expand Down

0 comments on commit 90f375b

Please sign in to comment.