Skip to content

Commit eec2d73

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 eec2d73

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/push.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ 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),
16+
#[error("Nixeval command ouput contained an invalid UTF-8 sequence: {0}")]
17+
EvalStoreUtf8(std::str::Utf8Error),
1418
#[error("Failed to run Nix show-derivation command: {0}")]
1519
ShowDerivation(std::io::Error),
1620
#[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
247251

248252
// Nix 2.32+ returns relative paths (without /nix/store/ prefix) in show-derivation output
249253
// Normalize to always use full store paths
250-
let deriver = if deriver_key.starts_with("/nix/store/") {
254+
let nix_store_output = Command::new("nix")
255+
.arg("eval")
256+
.arg("--raw")
257+
.arg("--expr")
258+
.arg("builtins.storeDir")
259+
.output().await
260+
.map_err(PushProfileError::EvalStore)?;
261+
let nix_store = std::str::from_utf8(&nix_store_output.stdout).map_err(PushProfileError::EvalStoreUtf8)?;
262+
263+
let deriver = if deriver_key.starts_with(nix_store) {
251264
deriver_key.to_string()
252265
} else {
253-
format!("/nix/store/{}", deriver_key)
266+
format!("{}/{}", nix_store, deriver_key)
254267
};
255268

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

0 commit comments

Comments
 (0)