diff --git a/Cargo.toml b/Cargo.toml index 272be3b..c1de8ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,15 +16,14 @@ futures = "0.3.31" nix-compat = { git = "https://github.com/tvlfyi/tvix.git", version = "0.1.0" } regex = "1.11.1" reqwest = "0.12.15" -serde = { version = "1.0.219", features = [ "derive" ]} +serde = { version = "1.0.219", features = ["derive"] } serde_json = "1.0.140" sha2 = "0.10.8" -tokio = { version = "1.44.1", features = [ "full", "tracing", "parking_lot" ]} +tokio = { version = "1.44.1", features = ["full", "tracing", "parking_lot"] } tracing = "0.1.41" -url = { version = "2.5.4", features = [ "serde" ]} +url = { version = "2.5.4", features = ["serde"] } cxx = "1.0" console-subscriber = "0.4.1" -tempfile = "3.19.1" tokio-util = { version = "0.7.15", features = ["io"] } bytes = "1.10.1" object_store = { version = "0.12.0", features = ["aws"] } @@ -35,3 +34,6 @@ humansize = "2.1.3" [build-dependencies] cxx-build = "1.0" pkg-config = "0.3.32" + +[dev-dependencies] +tempfile = "3.19.1" diff --git a/src/path_info.rs b/src/path_info.rs index 1e1282d..213fd1a 100644 --- a/src/path_info.rs +++ b/src/path_info.rs @@ -28,6 +28,14 @@ impl PathInfo { let derivation = match drv.extension() { Some(ext) if ext == "drv" => drv.as_os_str().as_encoded_bytes(), _ => { + let drv = { + // resolve symlink + if drv.is_symlink() { + &drv.canonicalize()? + } else { + drv + } + }; &Command::new("nix") .arg("path-info") .arg("--derivation") diff --git a/tests/path_info.rs b/tests/path_info.rs index 57738fd..0f9543b 100644 --- a/tests/path_info.rs +++ b/tests/path_info.rs @@ -1,6 +1,8 @@ use nixcp::path_info::PathInfo; use std::path::PathBuf; +use tempfile::TempDir; + use crate::common::{HELLO, HELLO_DRV, HELLO_PATH}; mod common; @@ -25,6 +27,23 @@ async fn path_info_from_path() { assert_eq!(path_info.path.to_string(), HELLO_DRV); } +#[tokio::test] +async fn path_info_symlink() { + let ctx = common::context(); + + let temp_path = TempDir::new().unwrap(); + let link_path = temp_path.path().join("result"); + + // symlink at ./result (like `nix build`) + std::os::unix::fs::symlink(HELLO_PATH, &link_path).unwrap(); + + // should resolve symlink + let path_info = PathInfo::from_derivation(&link_path, &ctx.store) + .await + .expect("get pathinfo from package"); + assert_eq!(path_info.path.to_string(), HELLO_DRV); +} + #[tokio::test] async fn closure() { let ctx = common::context();