Detect WSL1 and error (#297)

* Detect WSL1 and error

WSL1 is not supported because some things Nix relies on to work are not
available.

* Update linux.rs

* Add link to MS docs on WSL1 -> WSL2 upgrade
This commit is contained in:
Cole Helbling 2023-03-03 09:49:46 -08:00 committed by GitHub
parent 3be93c54f6
commit d7c14d6695
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -39,6 +39,10 @@ impl Planner for Linux {
return Err(PlannerError::NixOs);
}
if std::env::var("WSL_DISTRO_NAME").is_ok() && std::env::var("WSL_INTEROP").is_err() {
return Err(PlannerError::Wsl1);
}
// We currently do not support SELinux
match Command::new("getenforce").output().await {
Ok(output) => {

View file

@ -301,6 +301,8 @@ pub enum PlannerError {
NixOs,
#[error("`nix` is already a valid command, so it is installed")]
NixExists,
#[error("WSL1 is not supported, please upgrade to WSL2: https://learn.microsoft.com/en-us/windows/wsl/install#upgrade-version-from-wsl-1-to-wsl-2")]
Wsl1,
}
impl HasExpectedErrors for PlannerError {
@ -315,6 +317,7 @@ impl HasExpectedErrors for PlannerError {
PlannerError::Custom(_) => None,
this @ PlannerError::NixOs => Some(Box::new(this)),
this @ PlannerError::NixExists => Some(Box::new(this)),
this @ PlannerError::Wsl1 => Some(Box::new(this)),
}
}
}