Skip to content

Commit

Permalink
Pipe nix build output
Browse files Browse the repository at this point in the history
  • Loading branch information
lucperkins committed Jul 22, 2024
1 parent f1da923 commit 8e0139a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
6 changes: 0 additions & 6 deletions src/cli/cmd/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ impl CommandExecute for ApplySubcommand {
return Err(FhError::MissingProfile(profile_path).into());
}

tracing::debug!(
"Running: nix build --print-build-logs --max-jobs 0 --profile {} {}",
&profile_path,
&resolved_path.store_path,
);

nix_command(&[
"build",
"--print-build-logs",
Expand Down
26 changes: 10 additions & 16 deletions src/cli/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,30 +385,24 @@ macro_rules! flakehub_url {
async fn nix_command(args: &[&str]) -> Result<(), FhError> {
command_exists("nix")?;

tracing::debug!(
"Running: nix build --extra-experimental-features 'nix-command-flakes' {}",
args.join(" ")
);

let output = tokio::process::Command::new("nix")
.args(["--extra-experimental-features", "nix-command flakes"])
.args(args)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?
.wait_with_output()
.await?;

if output.status.success() {
Ok(())
} else {
let mut s = String::new();

let stdout = String::from_utf8_lossy(&output.stdout).to_string();
if !stdout.is_empty() {
s.push_str(stdout.trim());
}

let stderr = String::from_utf8_lossy(&output.stderr).to_string();
if !stderr.is_empty() {
s.push_str(stderr.trim());
}

Err(FhError::FailedCommand(s))
Err(FhError::FailedNixCommand)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cli/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[derive(Debug, thiserror::Error)]
pub(crate) enum FhError {
#[error("failed command: {0}")]
FailedCommand(String),
#[error("Nix command failed")]
FailedNixCommand,

#[error("file error: {0}")]
Filesystem(#[from] std::io::Error),
Expand Down

0 comments on commit 8e0139a

Please sign in to comment.