Skip to content

Commit a52d835

Browse files
committed
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] #346 (comment)
1 parent 9c870f6 commit a52d835

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/push.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use tokio::process::Command;
1111

1212
#[derive(Error, Debug)]
1313
pub enum PushProfileError {
14+
#[error("Failed to run Nix eval command: {0}")]
15+
EvalStore(std::io::Error),
1416
#[error("Failed to run Nix show-derivation command: {0}")]
1517
ShowDerivation(std::io::Error),
1618
#[error("Nix show-derivation command resulted in a bad exit code: {0:?}")]
@@ -247,10 +249,19 @@ pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileE
247249

248250
// Nix 2.32+ returns relative paths (without /nix/store/ prefix) in show-derivation output
249251
// Normalize to always use full store paths
250-
let deriver = if deriver_key.starts_with("/nix/store/") {
252+
let nix_store_output = Command::new("nix")
253+
.arg("eval")
254+
.arg("--raw")
255+
.arg("--expr")
256+
.arg("builtins.storeDir")
257+
.output().await
258+
.map_err(PushProfileError::EvalStore)?;
259+
let nix_store = std::str::from_utf8(&nix_store_output.stdout).unwrap();
260+
261+
let deriver = if deriver_key.starts_with(nix_store) {
251262
deriver_key.to_string()
252263
} else {
253-
format!("/nix/store/{}", deriver_key)
264+
format!("{}/{}", nix_store, deriver_key)
254265
};
255266

256267
let new_deriver = if data.supports_flakes || data.deploy_data.merged_settings.remote_build.unwrap_or(false) {

0 commit comments

Comments
 (0)