Skip to content

Commit a5619f5

Browse files
authored
Build every profile first, then push (#158)
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.
1 parent 3513523 commit a5619f5

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

src/cli.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -545,18 +545,27 @@ async fn run_deploy(
545545
print_deployment(&parts[..])?;
546546
}
547547

548-
for (deploy_flake, deploy_data, deploy_defs) in &parts {
549-
deploy::push::push_profile(deploy::push::PushProfileData {
550-
supports_flakes,
551-
check_sigs,
552-
repo: deploy_flake.repo,
553-
deploy_data,
554-
deploy_defs,
555-
keep_result,
556-
result_path,
557-
extra_build_args,
558-
})
559-
.await?;
548+
let data_iter = || {
549+
parts.iter().map(
550+
|(deploy_flake, deploy_data, deploy_defs)| deploy::push::PushProfileData {
551+
supports_flakes,
552+
check_sigs,
553+
repo: deploy_flake.repo,
554+
deploy_data,
555+
deploy_defs,
556+
keep_result,
557+
result_path,
558+
extra_build_args,
559+
},
560+
)
561+
};
562+
563+
for data in data_iter() {
564+
deploy::push::build_profile(data).await?;
565+
}
566+
567+
for data in data_iter() {
568+
deploy::push::push_profile(data).await?;
560569
}
561570

562571
let mut succeeded: Vec<(&deploy::DeployData, &deploy::DeployDefs)> = vec![];

src/push.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub async fn build_profile_remotely(data: &PushProfileData<'_>, derivation_name:
209209
Ok(())
210210
}
211211

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

221-
let ssh_opts_str = data
222-
.deploy_data
223-
.merged_settings
224-
.ssh_opts
225-
// This should provide some extra safety, but it also breaks for some reason, oh well
226-
// .iter()
227-
// .map(|x| format!("'{}'", x))
228-
// .collect::<Vec<String>>()
229-
.join(" ");
230-
231-
232221
show_derivation_command
233222
.arg("show-derivation")
234223
.arg(&data.deploy_data.profile.profile_settings.path);
@@ -259,12 +248,28 @@ pub async fn push_profile(data: PushProfileData<'_>) -> Result<(), PushProfileEr
259248
return Err(PushProfileError::RemoteBuildWithLegacyNix)
260249
}
261250

262-
// remote building guarantees that the resulting derivation is stored on the target system
263-
// no need to copy after building
264251
build_profile_remotely(&data, derivation_name).await?;
265252
} else {
266253
build_profile_locally(&data, derivation_name).await?;
254+
}
255+
256+
Ok(())
257+
}
258+
259+
pub async fn push_profile(data: PushProfileData<'_>) -> Result<(), PushProfileError> {
260+
let ssh_opts_str = data
261+
.deploy_data
262+
.merged_settings
263+
.ssh_opts
264+
// This should provide some extra safety, but it also breaks for some reason, oh well
265+
// .iter()
266+
// .map(|x| format!("'{}'", x))
267+
// .collect::<Vec<String>>()
268+
.join(" ");
267269

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

0 commit comments

Comments
 (0)