Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Allow --override-input to refer to flake name without flake/ prefix of devour_flake #74

Merged
merged 7 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use nix_rs::{
use crate::{
config,
github::pull_request::{PullRequest, PullRequestRef},
nix::system_list::{SystemsList, SystemsListFlakeRef},
nix::{
devour_flake,
system_list::{SystemsList, SystemsListFlakeRef},
},
};

/// A reference to some flake living somewhere
Expand Down Expand Up @@ -68,11 +71,22 @@ pub struct CliArgs {

impl CliArgs {
/// Parse `CliArgs` from command-line args
pub async fn parse() -> Result<Self, NixCmdError> {
pub async fn parse() -> anyhow::Result<Self> {
let mut args = <Self as Parser>::parse();
args.nixcmd = args.nixcmd.with_flakes().await?;
args.preprocess().await?;
Ok(args)
}

// Pre-process `CliArgs`
pub async fn preprocess(&mut self) -> anyhow::Result<()> {
// Avoid using `--extra-experimental-features` if possible.
self.nixcmd = self.nixcmd.with_flakes().await?;
// Adjust to devour_flake's expectations
if let Command::Build(build_cfg) = &mut self.command {
devour_flake::transform_override_inputs(&mut build_cfg.extra_nix_build_args);
}
Ok(())
}
}

#[derive(Debug, Subcommand)]
Expand Down
14 changes: 14 additions & 0 deletions src/nix/devour_flake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ pub async fn devour_flake(
bail!("devour-flake failed to run (exited: {})", exit_code);
}
}

/// Transform `--override-input` arguments to use `flake/` prefix, which
/// devour_flake expects.
pub fn transform_override_inputs(args: &mut [String]) {
let mut iter = args.iter_mut().peekable();

while let Some(arg) = iter.next() {
if *arg == "--override-input" {
if let Some(next_arg) = iter.next() {
*next_arg = format!("flake/{}", next_arg);
}
}
}
}