From f936e5401d1bc9b82084cf7b49402a5ee1a3b733 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 5 Jun 2024 14:30:17 -0400 Subject: [PATCH] feat: Improve `with_flakes` to transform existing `NixCmd` This enables it to work with an user-defined (via CLI) `NixCmd` --- src/command.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/command.rs b/src/command.rs index ab8f80e..9d7c656 100644 --- a/src/command.rs +++ b/src/command.rs @@ -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 { - 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 { + 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