Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(agent-tools): resolve bash and bwrap via PATH for NixOS (#8691)
Akarshan Biswas3fb4ad02eb8f
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/jail.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/jail.rsindex b5f590381..f25f24fe2 100644--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/jail.rs+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/jail.rs@@ -258,6 +258,11 @@ pub fn wrap(cfg: &ShellConfig, policy: &Policy) -> Option<ShellConfig> {// bubblewrap (Linux)// ---------------------------------------------------------------------------+/// The fixed FHS locations are preferred so a directory prepended to `PATH`+/// cannot shadow the system bwrap; `PATH` is the fallback for distros with no+/// FHS layout at all (NixOS keeps bwrap only at a Nix-store path). A planted+/// `bwrap` found via `PATH` gains nothing: it runs as the same user, and+/// [`bwrap_usable`]'s live probe still has to pass before it is trusted.#[cfg(target_os = "linux")]fn bwrap_path() -> Option<PathBuf> {static PATH: OnceLock<Option<PathBuf>> = OnceLock::new();@@ -266,6 +271,7 @@ fn bwrap_path() -> Option<PathBuf> {.into_iter().map(PathBuf::from).find(|p| p.is_file())+ .or_else(|| super::proc::which("bwrap"))}).clone()}diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rsindex b6d401709..6b1083f40 100644--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rs+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rs@@ -50,9 +50,13 @@ fn resolve_shell() -> ShellConfig {}#[cfg(unix)]{- if Path::new("/bin/bash").exists() {- return c("/bin/bash", &["-c"]);- }+ // Prefer the bash on `PATH` over the fixed `/bin/bash`: on NixOS the+ // shell lives only at a Nix-store path resolved via `which`, so a+ // hardcoded `/bin/bash` does not exist there and the fixed path would be+ // wrong.+ // `/bin/bash` stays as the fallback for systems where `which` is absent+ // or `PATH` is degenerate but `/bin/bash` is real (e.g. cron); `/bin/sh`+ // is the guaranteed-POSIX last resort.if let Some(p) = which("bash") {return ShellConfig {program: p,@@ -60,6 +64,9 @@ fn resolve_shell() -> ShellConfig {via_stdin: false,};}+ if Path::new("/bin/bash").exists() {+ return c("/bin/bash", &["-c"]);+ }c("/bin/sh", &["-c"])}#[cfg(windows)]@@ -100,8 +107,10 @@ fn resolve_shell() -> ShellConfig {}}-/// Locate an executable on PATH via the platform's own resolver.-fn which(name: &str) -> Option<PathBuf> {+/// Locate an executable on PATH via the platform's own resolver. Also used by+/// [`super::jail`] to find `bwrap` on distros with no FHS paths (NixOS keeps it+/// only at a Nix-store path).+pub(crate) fn which(name: &str) -> Option<PathBuf> {#[cfg(unix)]let finder = "which";#[cfg(windows)]