feat: add guix support (github #44)

This commit is contained in:
Gabriel Santos 2025-04-07 16:53:12 +00:00 committed by GitHub
parent 5bb3773ba3
commit e1b818530c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,7 +14,7 @@ pub fn get_package_manager(data: &mut Data) -> Option<String> {
}
for package_manager in &[
"apt", "dnf", "emerge", "nix", "pacman", "yum",
"apt", "dnf", "emerge", "guix", "nix", "pacman", "yum",
// "zypper",
] {
if data.executables.iter().any(|exe| exe == package_manager) {
@ -99,6 +99,24 @@ pub fn get_packages(
Some(packages)
}
}
"guix" => {
let result = command_output(
shell,
&format!("{} locate {}", package_manager, executable),
);
if result.is_empty() {
return None;
}
let packages: Vec<String> = result
.lines()
.map(|line| line.split_whitespace().next().unwrap().to_string())
.collect();
if packages.is_empty() {
None
} else {
Some(packages)
}
}
"nix" => {
if !data.executables.contains(&"nix-locate".to_string()) {
eprintln!(
@ -183,6 +201,7 @@ pub fn install_package(data: &mut Data, package_manager: &str, package: &str) ->
format!("{} install {}", package_manager, package)
}
"emerge" => format!("emerge {}", package),
"guix" => format!("guix package -i {}", package),
"nix" => format!("nix profile install nixpkgs#{}", package),
"pacman" => format!("pacman -S {}", package),
_ => match package_manager.ends_with("command-not-found") {
@ -201,10 +220,10 @@ pub fn install_package(data: &mut Data, package_manager: &str, package: &str) ->
},
};
// nix does not require privilege escalation
// guix and nix do not require privilege escalation
#[allow(clippy::single_match)]
match package_manager {
"nix" => {}
"guix" | "nix" => {}
_ => elevate(data, &mut install),
}