Skip to content

Commit

Permalink
feat(api): Preprocess extra nix build args
Browse files Browse the repository at this point in the history
resolves #71
  • Loading branch information
shivaraj-bh committed Jul 9, 2024
1 parent 4dd19eb commit 55b9c8a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,37 @@ impl BuildConfig {
Ok(systems)
}
}
pub fn preprocess_extra_nix_build_args(&self) -> anyhow::Result<Vec<String>> {
let mut modified_args = Vec::new();
let mut iter = self.extra_nix_build_args.iter().peekable();

while let Some(arg) = iter.next() {
if arg == "--override-input" {
modified_args.push(arg.clone());

if let Some(next_arg) = iter.next() {
modified_args.push(format!("flake/{}", next_arg));
} else {
return Err(anyhow::anyhow!(
"Missing argument after --override-input".to_string()
));
}
} else {
modified_args.push(arg.clone());
}
}

Ok(modified_args)
}
pub fn preprocess(&self) -> anyhow::Result<BuildConfig> {
let preprocessed_extra_nix_build_args = self.preprocess_extra_nix_build_args()?;
Ok(BuildConfig {
flake_ref: self.flake_ref.clone(),
systems: self.systems.clone(),
extra_nix_build_args: preprocessed_extra_nix_build_args,
print_all_dependencies: self.print_all_dependencies,
})
}
}

async fn get_current_system(cmd: &NixCmd) -> Result<System, NixCmdError> {
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub async fn nixci(args: CliArgs) -> anyhow::Result<Vec<StorePath>> {
let cfg = args.command.get_config(&args.nixcmd).await?;
match args.command {
cli::Command::Build(build_cfg) => {
nixci_build(&args.nixcmd, args.verbose, &build_cfg, &cfg).await
nixci_build(&args.nixcmd, args.verbose, &build_cfg.preprocess()?, &cfg).await
}
cli::Command::DumpGithubActionsMatrix { systems, .. } => {
let matrix = github::matrix::GitHubMatrix::from(systems, &cfg.subflakes);
Expand All @@ -32,6 +32,8 @@ pub async fn nixci(args: CliArgs) -> anyhow::Result<Vec<StorePath>> {
}
}

// async fn preprocess(cmd: &NixCmd) -> NixCmd {}

async fn nixci_build(
cmd: &NixCmd,
verbose: bool,
Expand Down Expand Up @@ -118,8 +120,9 @@ async fn nixci_subflake(
if subflake.override_inputs.is_empty() {
nix::lock::nix_flake_lock_check(cmd, &url.sub_flake_url(subflake.dir.clone())).await?;
}

println!("{:?}", build_cfg.extra_nix_build_args);
let nix_args = subflake.nix_build_args_for_flake(build_cfg, url);
println!("{:?}", nix_args);
let outs = nix::devour_flake::devour_flake(cmd, verbose, nix_args).await?;
Ok(outs)
}

0 comments on commit 55b9c8a

Please sign in to comment.