fix(nix): use nix shell -c and improve nix-index usage

This commit is contained in:
technofab 2025-07-07 15:52:16 +02:00
parent d9c5ff21cf
commit e2bd052f85
No known key found for this signature in database

View file

@ -139,7 +139,13 @@ pub fn get_packages(
return None; return None;
} }
let result = let result =
command_output(shell, &format!("nix-locate --regex 'bin/{}$'", executable)); command_output(
shell,
&format!(
"nix-locate --minimal --no-group --top-level --type x --type s --whole-name --at-root '/bin/{}'",
executable,
),
);
if result.is_empty() { if result.is_empty() {
return None; return None;
} }
@ -149,9 +155,7 @@ pub fn get_packages(
line.split_whitespace() line.split_whitespace()
.next() .next()
.unwrap() .unwrap()
.rsplit_once('.') .trim_end_matches(".out") // remove .out, keep the rest as is
.unwrap()
.0
.to_string() .to_string()
}) })
.collect(); .collect();
@ -258,10 +262,7 @@ pub fn shell_package(data: &Data, package_manager: &str, package: &str) -> Strin
match package_manager { match package_manager {
"guix" => format!("guix shell {} -- {}", package, command), "guix" => format!("guix shell {} -- {}", package, command),
"nix" => format!( "nix" => format!(r#"nix shell nixpkgs#{} -c {}"#, package, command),
r#"nix-shell -p {} --command "{};return""#,
package, command
),
_ => unreachable!("Only `nix` and `guix` are supported for shell installation"), _ => unreachable!("Only `nix` and `guix` are supported for shell installation"),
} }
} }