Skip to content

Commit

Permalink
feat(cli): Allow --override-input to refer to flake name without `f…
Browse files Browse the repository at this point in the history
…lake/` prefix of devour_flake (#74)
  • Loading branch information
shivaraj-bh authored Jul 9, 2024
1 parent 4dd19eb commit c17f42f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
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);
}
}
}
}

0 comments on commit c17f42f

Please sign in to comment.