Detect if nix is installed (#51)

* Add Nix installed detection

* Call nix-env --version instead
This commit is contained in:
Ana Hobden 2022-11-15 08:22:51 -08:00 committed by GitHub
parent 2dcda0a801
commit 6f64bb0092
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,16 @@ impl Planner for LinuxMulti {
return Err(Error::NixOs.into()); return Err(Error::NixOs.into());
} }
// For now, we don't try to repair the user's Nix install or anything special.
if let Ok(_) = tokio::process::Command::new("nix-env")
.arg("--version")
.stdin(std::process::Stdio::null())
.status()
.await
{
return Err(Error::NixExists.into());
}
Ok(InstallPlan { Ok(InstallPlan {
planner: Box::new(self.clone()), planner: Box::new(self.clone()),
actions: vec![ actions: vec![
@ -74,6 +84,8 @@ impl Into<BuiltinPlanner> for LinuxMulti {
enum Error { enum Error {
#[error("NixOS already has Nix installed")] #[error("NixOS already has Nix installed")]
NixOs, NixOs,
#[error("`nix` is already a valid command, so it is installed")]
NixExists,
#[error("Error planning action")] #[error("Error planning action")]
Action( Action(
#[source] #[source]