From eec2d731972d365bd19598aa1c03e3dd5f9cecc9 Mon Sep 17 00:00:00 2001 From: David Guibert Date: Thu, 27 Nov 2025 11:03:09 +0100 Subject: [PATCH] allow custom nix store #346 fixes compatibility with Nix 2.32+ but as stated in [1] it doesn't allow locations for nix store other than /nix/store. This patch calls nix eval to retreive the storeDir not relying one the hard-coded value. [1] https://github.com/serokell/deploy-rs/pull/346#discussion_r2506384375 --- src/push.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/push.rs b/src/push.rs index a206afc..6ab0274 100644 --- a/src/push.rs +++ b/src/push.rs @@ -11,6 +11,10 @@ use tokio::process::Command; #[derive(Error, Debug)] pub enum PushProfileError { + #[error("Failed to run Nix eval command: {0}")] + EvalStore(std::io::Error), + #[error("Nixeval command ouput contained an invalid UTF-8 sequence: {0}")] + EvalStoreUtf8(std::str::Utf8Error), #[error("Failed to run Nix show-derivation command: {0}")] ShowDerivation(std::io::Error), #[error("Nix show-derivation command resulted in a bad exit code: {0:?}")] @@ -247,10 +251,19 @@ pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileE // Nix 2.32+ returns relative paths (without /nix/store/ prefix) in show-derivation output // Normalize to always use full store paths - let deriver = if deriver_key.starts_with("/nix/store/") { + let nix_store_output = Command::new("nix") + .arg("eval") + .arg("--raw") + .arg("--expr") + .arg("builtins.storeDir") + .output().await + .map_err(PushProfileError::EvalStore)?; + let nix_store = std::str::from_utf8(&nix_store_output.stdout).map_err(PushProfileError::EvalStoreUtf8)?; + + let deriver = if deriver_key.starts_with(nix_store) { deriver_key.to_string() } else { - format!("/nix/store/{}", deriver_key) + format!("{}/{}", nix_store, deriver_key) }; let new_deriver = if data.supports_flakes || data.deploy_data.merged_settings.remote_build.unwrap_or(false) {