Skip to content

Commit

Permalink
feat: Improve with_flakes to transform existing NixCmd
Browse files Browse the repository at this point in the history
This enables it to work with an user-defined (via CLI) `NixCmd`
  • Loading branch information
srid committed Jun 5, 2024
1 parent f61bd2c commit f936e54
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,15 @@ pub fn trace_cmd(cmd: &tokio::process::Command) {
}

impl NixCmd {
/// Return the [NixCmd] guaranteed to be flake-enabled
///
/// Unlike [NixCmd::default], this method will add options only when necessary.
pub async fn with_flakes() -> Result<Self, NixCmdError> {
let cmd = Self::default();
let cfg = super::config::NixConfig::from_nix(&cmd).await?;
if cfg.is_flakes_enabled() {
let cmd = Self {
extra_experimental_features: vec![],
..Default::default()
};
Ok(cmd)
} else {
Ok(cmd)
/// Return a `NixCmd` with flakes enabled, if not already enabled.
pub async fn with_flakes(&self) -> Result<Self, NixCmdError> {
let cfg = super::config::NixConfig::from_nix(&Self::default()).await?;
let mut cmd = self.clone();
if !cfg.is_flakes_enabled() {
cmd.extra_experimental_features
.append(vec!["nix-command".to_string(), "flakes".to_string()].as_mut());
}
Ok(cmd)
}

/// Return a [Command] for this [NixCmd] configuration
Expand Down

0 comments on commit f936e54

Please sign in to comment.