Skip to content

Commit 3bf6a59

Browse files
dguibertneunenak
authored andcommitted
allow custom nix store
serokell#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] serokell#346 (comment)
1 parent e92ebe3 commit 3bf6a59

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/push.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ use tokio::process::Command;
1010

1111
#[derive(Error, Debug)]
1212
pub enum PushProfileError {
13+
#[error("Failed to run Nix eval command: {0}")]
14+
EvalStore(std::io::Error),
15+
#[error("Nixeval command ouput contained an invalid UTF-8 sequence: {0}")]
16+
EvalStoreUtf8(std::str::Utf8Error),
1317
#[error("Failed to run Nix show-derivation command: {0}")]
1418
ShowDerivation(std::io::Error),
1519
#[error("Nix show-derivation command resulted in a bad exit code: {0:?}")]
@@ -266,10 +270,19 @@ pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileE
266270

267271
// Nix 2.32+ returns relative paths (without /nix/store/ prefix) in show-derivation output
268272
// Normalize to always use full store paths
269-
let deriver = if deriver_key.starts_with("/nix/store/") {
273+
let nix_store_output = Command::new("nix")
274+
.arg("eval")
275+
.arg("--raw")
276+
.arg("--expr")
277+
.arg("builtins.storeDir")
278+
.output().await
279+
.map_err(PushProfileError::EvalStore)?;
280+
let nix_store = std::str::from_utf8(&nix_store_output.stdout).map_err(PushProfileError::EvalStoreUtf8)?;
281+
282+
let deriver = if deriver_key.starts_with(nix_store) {
270283
deriver_key.to_string()
271284
} else {
272-
format!("/nix/store/{}", deriver_key)
285+
format!("{}/{}", nix_store, deriver_key)
273286
};
274287

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

0 commit comments

Comments
 (0)