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 8133612
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion 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 Down

0 comments on commit 8133612

Please sign in to comment.