fix interactive shells
This commit is contained in:
parent
2f3d596bb6
commit
328f923b2c
2 changed files with 31 additions and 4 deletions
|
@ -27,6 +27,7 @@ pub struct NixCommand {
|
||||||
env: Vec<(String, String)>,
|
env: Vec<(String, String)>,
|
||||||
impure: bool,
|
impure: bool,
|
||||||
print_build_logs: bool,
|
print_build_logs: bool,
|
||||||
|
interactive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NixCommand {
|
impl NixCommand {
|
||||||
|
@ -37,6 +38,7 @@ impl NixCommand {
|
||||||
env: Vec::new(),
|
env: Vec::new(),
|
||||||
impure: false,
|
impure: false,
|
||||||
print_build_logs: true,
|
print_build_logs: true,
|
||||||
|
interactive: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +66,11 @@ impl NixCommand {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn interactive(mut self, yes: bool) -> Self {
|
||||||
|
self.interactive = yes;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn print_build_logs(mut self, yes: bool) -> Self {
|
pub fn print_build_logs(mut self, yes: bool) -> Self {
|
||||||
self.print_build_logs = yes;
|
self.print_build_logs = yes;
|
||||||
self
|
self
|
||||||
|
@ -87,6 +94,13 @@ impl NixCommand {
|
||||||
cmd.env(k, v);
|
cmd.env(k, v);
|
||||||
}
|
}
|
||||||
cmd.args(&self.args);
|
cmd.args(&self.args);
|
||||||
|
|
||||||
|
if self.interactive {
|
||||||
|
cmd.stdout(Stdio::inherit());
|
||||||
|
cmd.stderr(Stdio::inherit());
|
||||||
|
return cmd.status();
|
||||||
|
}
|
||||||
|
|
||||||
cmd.stdout(Stdio::piped());
|
cmd.stdout(Stdio::piped());
|
||||||
cmd.stderr(Stdio::piped());
|
cmd.stderr(Stdio::piped());
|
||||||
|
|
||||||
|
@ -149,8 +163,14 @@ impl NixCommand {
|
||||||
cmd.env(k, v);
|
cmd.env(k, v);
|
||||||
}
|
}
|
||||||
cmd.args(&self.args);
|
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()
|
cmd.output()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ pub fn handle_nix_shell(
|
||||||
fixer: &dyn NixFileFixer,
|
fixer: &dyn NixFileFixer,
|
||||||
classifier: &dyn NixErrorClassifier,
|
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 {
|
for arg in args {
|
||||||
cmd = cmd.arg(arg);
|
cmd = cmd.arg(arg);
|
||||||
}
|
}
|
||||||
|
@ -18,9 +20,10 @@ pub fn handle_nix_shell(
|
||||||
.run_with_logs(StdIoInterceptor)
|
.run_with_logs(StdIoInterceptor)
|
||||||
.expect("failed to run nix shell");
|
.expect("failed to run nix shell");
|
||||||
if status.success() {
|
if status.success() {
|
||||||
return;
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to capture error output for retry logic
|
||||||
let output = NixCommand::new("shell")
|
let output = NixCommand::new("shell")
|
||||||
.print_build_logs(true)
|
.print_build_logs(true)
|
||||||
.args(args.iter().cloned())
|
.args(args.iter().cloned())
|
||||||
|
@ -33,6 +36,7 @@ pub fn handle_nix_shell(
|
||||||
info!("{}", Paint::green("✔ Fixed hash mismatch, retrying..."));
|
info!("{}", Paint::green("✔ Fixed hash mismatch, retrying..."));
|
||||||
let retry_status = NixCommand::new("shell")
|
let retry_status = NixCommand::new("shell")
|
||||||
.print_build_logs(true)
|
.print_build_logs(true)
|
||||||
|
.interactive(true)
|
||||||
.args(args.iter().cloned())
|
.args(args.iter().cloned())
|
||||||
.run_with_logs(StdIoInterceptor)
|
.run_with_logs(StdIoInterceptor)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -48,6 +52,7 @@ pub fn handle_nix_shell(
|
||||||
);
|
);
|
||||||
let retry_status = NixCommand::new("shell")
|
let retry_status = NixCommand::new("shell")
|
||||||
.print_build_logs(true)
|
.print_build_logs(true)
|
||||||
|
.interactive(true)
|
||||||
.args(args.iter().cloned())
|
.args(args.iter().cloned())
|
||||||
.env("NIXPKGS_ALLOW_UNFREE", "1")
|
.env("NIXPKGS_ALLOW_UNFREE", "1")
|
||||||
.impure(true)
|
.impure(true)
|
||||||
|
@ -64,6 +69,7 @@ pub fn handle_nix_shell(
|
||||||
);
|
);
|
||||||
let retry_status = NixCommand::new("shell")
|
let retry_status = NixCommand::new("shell")
|
||||||
.print_build_logs(true)
|
.print_build_logs(true)
|
||||||
|
.interactive(true)
|
||||||
.args(args.iter().cloned())
|
.args(args.iter().cloned())
|
||||||
.env("NIXPKGS_ALLOW_INSECURE", "1")
|
.env("NIXPKGS_ALLOW_INSECURE", "1")
|
||||||
.impure(true)
|
.impure(true)
|
||||||
|
@ -78,6 +84,7 @@ pub fn handle_nix_shell(
|
||||||
);
|
);
|
||||||
let retry_status = NixCommand::new("shell")
|
let retry_status = NixCommand::new("shell")
|
||||||
.print_build_logs(true)
|
.print_build_logs(true)
|
||||||
|
.interactive(true)
|
||||||
.args(args.iter().cloned())
|
.args(args.iter().cloned())
|
||||||
.env("NIXPKGS_ALLOW_BROKEN", "1")
|
.env("NIXPKGS_ALLOW_BROKEN", "1")
|
||||||
.impure(true)
|
.impure(true)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue