From 3b25988e0c6baa6e9c66c6fdc6bb385577ed1928 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 18 Dec 2024 14:59:07 -0500 Subject: [PATCH] fix: nix-store failing on symlinks --- crates/nix_rs/src/store/command.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/nix_rs/src/store/command.rs b/crates/nix_rs/src/store/command.rs index e473b893..cedf75bf 100644 --- a/crates/nix_rs/src/store/command.rs +++ b/crates/nix_rs/src/store/command.rs @@ -100,7 +100,17 @@ impl NixStoreCmd { /// Run `nix-store --add` on the give path and return the store path added. pub async fn nix_store_add(&self, path: &Path) -> Result { let mut cmd = self.command(); - cmd.arg("--add").arg(path); + cmd.arg("--add"); + + // nix-store is unable to accept absolute paths if it involves a symlink + // https://github.com/juspay/omnix/issues/363 + // To workaround this, we pass the file directly. + if let Some(parent) = path.parent() { + cmd.current_dir(parent); + cmd.arg(path.file_name().unwrap()); + } else { + cmd.arg(path); + } let stdout = run_awaiting_stdout(&mut cmd).await?; Ok(StorePath::new(PathBuf::from(