From 328f923b2c6420403d662c37c074a2936603aabb Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 22 Jul 2025 01:44:50 +0300 Subject: [PATCH] fix interactive shells --- eh/src/command.rs | 24 ++++++++++++++++++++++-- eh/src/shell.rs | 11 +++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/eh/src/command.rs b/eh/src/command.rs index 2ea1b11..f94623e 100644 --- a/eh/src/command.rs +++ b/eh/src/command.rs @@ -27,6 +27,7 @@ pub struct NixCommand { env: Vec<(String, String)>, impure: bool, print_build_logs: bool, + interactive: bool, } impl NixCommand { @@ -37,6 +38,7 @@ impl NixCommand { env: Vec::new(), impure: false, print_build_logs: true, + interactive: false, } } @@ -64,6 +66,11 @@ impl NixCommand { self } + pub fn interactive(mut self, yes: bool) -> Self { + self.interactive = yes; + self + } + pub fn print_build_logs(mut self, yes: bool) -> Self { self.print_build_logs = yes; self @@ -87,6 +94,13 @@ impl NixCommand { cmd.env(k, v); } cmd.args(&self.args); + + if self.interactive { + cmd.stdout(Stdio::inherit()); + cmd.stderr(Stdio::inherit()); + return cmd.status(); + } + cmd.stdout(Stdio::piped()); cmd.stderr(Stdio::piped()); @@ -149,8 +163,14 @@ impl NixCommand { cmd.env(k, v); } cmd.args(&self.args); - cmd.stdout(Stdio::piped()); - cmd.stderr(Stdio::piped()); + + if self.interactive { + cmd.stdout(Stdio::inherit()); + cmd.stderr(Stdio::inherit()); + } else { + cmd.stdout(Stdio::piped()); + cmd.stderr(Stdio::piped()); + } cmd.output() } diff --git a/eh/src/shell.rs b/eh/src/shell.rs index 5a56147..f6053a3 100644 --- a/eh/src/shell.rs +++ b/eh/src/shell.rs @@ -10,7 +10,9 @@ pub fn handle_nix_shell( fixer: &dyn NixFileFixer, classifier: &dyn NixErrorClassifier, ) { - let mut cmd = NixCommand::new("shell").print_build_logs(true); + let mut cmd = NixCommand::new("shell") + .print_build_logs(true) + .interactive(true); for arg in args { cmd = cmd.arg(arg); } @@ -18,9 +20,10 @@ pub fn handle_nix_shell( .run_with_logs(StdIoInterceptor) .expect("failed to run nix shell"); if status.success() { - return; + std::process::exit(0); } + // Try to capture error output for retry logic let output = NixCommand::new("shell") .print_build_logs(true) .args(args.iter().cloned()) @@ -33,6 +36,7 @@ pub fn handle_nix_shell( info!("{}", Paint::green("✔ Fixed hash mismatch, retrying...")); let retry_status = NixCommand::new("shell") .print_build_logs(true) + .interactive(true) .args(args.iter().cloned()) .run_with_logs(StdIoInterceptor) .unwrap(); @@ -48,6 +52,7 @@ pub fn handle_nix_shell( ); let retry_status = NixCommand::new("shell") .print_build_logs(true) + .interactive(true) .args(args.iter().cloned()) .env("NIXPKGS_ALLOW_UNFREE", "1") .impure(true) @@ -64,6 +69,7 @@ pub fn handle_nix_shell( ); let retry_status = NixCommand::new("shell") .print_build_logs(true) + .interactive(true) .args(args.iter().cloned()) .env("NIXPKGS_ALLOW_INSECURE", "1") .impure(true) @@ -78,6 +84,7 @@ pub fn handle_nix_shell( ); let retry_status = NixCommand::new("shell") .print_build_logs(true) + .interactive(true) .args(args.iter().cloned()) .env("NIXPKGS_ALLOW_BROKEN", "1") .impure(true)