Skip to content

Commit

Permalink
Build every profile first, then push (#158)
Browse files Browse the repository at this point in the history
Try to build everything first before pushing to remotes. Since the build
is more likely to fail than the upload, if there is an error the deployment
will fail sooner and before uploading any potentially unusable configuration.
  • Loading branch information
2xsaiko authored Dec 29, 2022
1 parent 3513523 commit a5619f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
33 changes: 21 additions & 12 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,18 +545,27 @@ async fn run_deploy(
print_deployment(&parts[..])?;
}

for (deploy_flake, deploy_data, deploy_defs) in &parts {
deploy::push::push_profile(deploy::push::PushProfileData {
supports_flakes,
check_sigs,
repo: deploy_flake.repo,
deploy_data,
deploy_defs,
keep_result,
result_path,
extra_build_args,
})
.await?;
let data_iter = || {
parts.iter().map(
|(deploy_flake, deploy_data, deploy_defs)| deploy::push::PushProfileData {
supports_flakes,
check_sigs,
repo: deploy_flake.repo,
deploy_data,
deploy_defs,
keep_result,
result_path,
extra_build_args,
},
)
};

for data in data_iter() {
deploy::push::build_profile(data).await?;
}

for data in data_iter() {
deploy::push::push_profile(data).await?;
}

let mut succeeded: Vec<(&deploy::DeployData, &deploy::DeployDefs)> = vec![];
Expand Down
33 changes: 19 additions & 14 deletions src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub async fn build_profile_remotely(data: &PushProfileData<'_>, derivation_name:
Ok(())
}

pub async fn push_profile(data: PushProfileData<'_>) -> Result<(), PushProfileError> {
pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileError> {
debug!(
"Finding the deriver of store path for {}",
&data.deploy_data.profile.profile_settings.path
Expand All @@ -218,17 +218,6 @@ pub async fn push_profile(data: PushProfileData<'_>) -> Result<(), PushProfileEr
// `nix-store --query --deriver` doesn't work on invalid paths, so we parse output of show-derivation :(
let mut show_derivation_command = Command::new("nix");

let ssh_opts_str = data
.deploy_data
.merged_settings
.ssh_opts
// This should provide some extra safety, but it also breaks for some reason, oh well
// .iter()
// .map(|x| format!("'{}'", x))
// .collect::<Vec<String>>()
.join(" ");


show_derivation_command
.arg("show-derivation")
.arg(&data.deploy_data.profile.profile_settings.path);
Expand Down Expand Up @@ -259,12 +248,28 @@ pub async fn push_profile(data: PushProfileData<'_>) -> Result<(), PushProfileEr
return Err(PushProfileError::RemoteBuildWithLegacyNix)
}

// remote building guarantees that the resulting derivation is stored on the target system
// no need to copy after building
build_profile_remotely(&data, derivation_name).await?;
} else {
build_profile_locally(&data, derivation_name).await?;
}

Ok(())
}

pub async fn push_profile(data: PushProfileData<'_>) -> Result<(), PushProfileError> {
let ssh_opts_str = data
.deploy_data
.merged_settings
.ssh_opts
// This should provide some extra safety, but it also breaks for some reason, oh well
// .iter()
// .map(|x| format!("'{}'", x))
// .collect::<Vec<String>>()
.join(" ");

// remote building guarantees that the resulting derivation is stored on the target system
// no need to copy after building
if !data.deploy_data.merged_settings.remote_build.unwrap_or(false) {
info!(
"Copying profile `{}` to node `{}`",
data.deploy_data.profile_name, data.deploy_data.node_name
Expand Down

0 comments on commit a5619f5

Please sign in to comment.