fix interactive shells

This commit is contained in:
raf 2025-07-22 01:44:50 +03:00
commit 328f923b2c
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 31 additions and 4 deletions

View file

@ -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()
}

View file

@ -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)