From d6b13d6c515e6cb59075ac5b9a703d804cdd0852 Mon Sep 17 00:00:00 2001 From: Collin Diekvoss Date: Sun, 1 Dec 2024 15:53:55 -0600 Subject: [PATCH] try build --- .github/workflows/build.yaml | 2 +- src/commands.rs | 39 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4f9b762..a7d7df8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -43,5 +43,5 @@ jobs: cd $NH_FLAKE nix flake init -t nix-darwin cd $NH_CHECKOUT - nix run -L darwin switch -- --hostname simple --dry + nix run -L .#nh darwin switch -- --hostname simple --dry name: Build Simple Nix Darwin Configuration diff --git a/src/commands.rs b/src/commands.rs index 2d595ed..124e43a 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -63,29 +63,30 @@ impl Command { pub fn run(&self) -> Result<()> { let cmd = if self.elevate { + let mut cmd = Exec::cmd("sudo"); + // Check for if sudo has the preserve-env flag #[cfg(target_os = "macos")] - let args = if Exec::cmd("sudo") - .args(&["--help"]) - .stderr(Redirection::None) - .stdout(Redirection::Pipe) - .capture()? - .stdout_str() - .contains("--preserve-env") { - vec!["--set-home", "--preserve-env=PATH", "env"] - } else { - vec!["--set-home"] - }; - - #[cfg(not(target_os = "macos"))] - let args = vec![]; - - Exec::cmd("sudo").args(&args).arg(&self.command).args(&self.args) + cmd = cmd.args( + if Exec::cmd("sudo") + .args(&["--help"]) + .stderr(Redirection::None) + .stdout(Redirection::Pipe) + .capture()? + .stdout_str() + .contains("--preserve-env") { + &["--set-home", "--preserve-env=PATH", "env"] + } else { + &["--set-home"] + } + ); + + cmd.arg(&self.command).args(&self.args) } else { Exec::cmd(&self.command).args(&self.args) } - .stderr(Redirection::None) - .stdout(Redirection::None); + .stderr(Redirection::None) + .stdout(Redirection::None); if let Some(m) = &self.message { info!("{}", m); @@ -186,7 +187,7 @@ impl Build { .stderr(Redirection::Merge) | Exec::cmd("nom").args(&["--json"]) } - .stdout(Redirection::None); + .stdout(Redirection::None); debug!(?cmd); cmd.join() } else {