Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,25 @@ pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileE
)
.map_err(PushProfileError::ShowDerivationParse)?;

let &deriver = derivation_info
let deriver_key = derivation_info
.keys()
.next()
.ok_or(PushProfileError::ShowDerivationEmpty)?;

let new_deriver = &if data.supports_flakes || data.deploy_data.merged_settings.remote_build.unwrap_or(false) {
// 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/") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a check for just '/' would be better. That way people using nix store at different locations will also be able to use this.

deriver_key.to_string()
} else {
format!("/nix/store/{}", deriver_key)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't allow locations for nix store other than /nix/store. One solution would be to look at $NIX_STORE_DIR env var for location of the store and prepend that, only defaulting to /nix/store. Another would be to utilize the output of nix eval --expr builtins.storeDir.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the command is definitely better, because this can also be configured in nix.conf - https://nix.dev/manual/nix/2.32/command-ref/conf-file.html#conf-store

};

let new_deriver = if data.supports_flakes || data.deploy_data.merged_settings.remote_build.unwrap_or(false) {
// Since nix 2.15.0 'nix build <path>.drv' will build only the .drv file itself, not the
// derivation outputs, '^out' is used to refer to outputs explicitly
deriver.to_owned().to_string() + "^out"
deriver.clone() + "^out"
} else {
deriver.to_owned()
deriver.clone()
};

let path_info_output = Command::new("nix")
Expand All @@ -260,8 +268,8 @@ pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileE
.output().await
.map_err(PushProfileError::PathInfo)?;

let deriver = if std::str::from_utf8(&path_info_output.stdout).map(|s| s.trim()) == Ok(deriver) {
// In this case we're on 2.15.0 or newer, because 'nix path-infonix path-info <...>.drv'
let deriver = if std::str::from_utf8(&path_info_output.stdout).map(|s| s.trim()) == Ok(deriver.as_str()) {
// In this case we're on 2.15.0 or newer, because 'nix path-info <...>.drv'
// returns the same '<...>.drv' path.
// If 'nix path-info <...>.drv' returns a different path, then we're on pre 2.15.0 nix and
// derivation build result is already present in the /nix/store.
Expand Down