Skip to content

Commit

Permalink
fix: more robust nixos check (#150)
Browse files Browse the repository at this point in the history
Fixes #149.
  • Loading branch information
DaniPopes authored Jan 17, 2025
1 parent dd58346 commit 99f1f8a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[profile.default]
retries = { backoff = "exponential", count = 2, delay = "3s", jitter = true }
slow-timeout = { period = "1m", terminate-after = 3 }
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- uses: taiki-e/install-action@cargo-nextest
- name: test
run: cargo test --workspace --all-targets
run: cargo nextest run --workspace --all-targets

feature-checks:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion crates/svm-rs/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fn patch_for_nixos(bin: &Path) -> Result<(), SvmError> {
bin.display()
))
.output()
.expect("Failed to execute command");
.map_err(|e| SvmError::CouldNotPatchForNixOs(String::new(), e.to_string()))?;

match output.status.success() {
true => Ok(()),
Expand Down
18 changes: 1 addition & 17 deletions crates/svm-rs/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub fn data_dir() -> &'static Path {
})
}

#[allow(dead_code)]
fn resolve_data_dir() -> PathBuf {
let home_dir = dirs::home_dir()
.expect("could not detect user home directory")
Expand Down Expand Up @@ -102,20 +103,3 @@ pub fn version_binary(version: &str) -> PathBuf {
binary.push(version);
PathBuf::from(binary)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_data_dir_resolution() {
let home_dir = dirs::home_dir().unwrap().join(".svm");
let data_dir = dirs::data_dir();
let resolved_dir = resolve_data_dir();
if home_dir.exists() || data_dir.is_none() {
assert_eq!(resolved_dir, home_dir);
} else {
assert_eq!(resolved_dir, data_dir.unwrap().join("svm"));
}
}
}
5 changes: 4 additions & 1 deletion crates/svm-rs/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ impl FromStr for Platform {
}

pub fn is_nixos() -> bool {
std::path::Path::new("/etc/NIXOS").exists()
cfg!(target_os = "linux")
&& (std::path::Path::new("/etc/nixos").exists()
|| std::path::Path::new("/etc/NIXOS").exists())
&& std::fs::read_to_string("/etc/os-release").is_ok_and(|s| s.contains("NixOS"))
}

/// Read the current machine's platform.
Expand Down

0 comments on commit 99f1f8a

Please sign in to comment.