From d7c14d66958d5539104c36a87c6a0f4f3996bdee Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Fri, 3 Mar 2023 09:49:46 -0800 Subject: [PATCH] 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 --- src/planner/linux.rs | 4 ++++ src/planner/mod.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/planner/linux.rs b/src/planner/linux.rs index 9eab5b3..7b947e5 100644 --- a/src/planner/linux.rs +++ b/src/planner/linux.rs @@ -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) => { diff --git a/src/planner/mod.rs b/src/planner/mod.rs index cbb1563..c46d797 100644 --- a/src/planner/mod.rs +++ b/src/planner/mod.rs @@ -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)), } } }