aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornotgne22020-10-23 22:44:52 -0700
committernotgne22020-10-23 22:44:52 -0700
commit72b066b293befec048f6a1b2f8d7a4b103ae4edf (patch)
tree620f9ff02ef16b0a6f45968a533b2c6ceb14bb93
parent4084e0516d3903acd80ca465f9906e5d3bce2659 (diff)
Add an option to keep build results
Diffstat (limited to '')
-rw-r--r--src/main.rs27
-rw-r--r--src/utils/push.rs43
2 files changed, 54 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index 5d76e3d..1358a83 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -33,6 +33,13 @@ struct Opts {
/// Extra arguments to be passed to nix build
extra_build_args: Vec<String>,
+ /// Keep the build outputs of each built profile
+ #[clap(short, long)]
+ keep_result: bool,
+ /// Location to keep outputs from built profiles in
+ #[clap(short, long)]
+ result_path: Option<String>,
+
/// Override the SSH user with the given value
#[clap(long)]
ssh_user: Option<String>,
@@ -71,6 +78,8 @@ async fn push_all_profiles(
top_settings: &utils::data::GenericSettings,
check_sigs: bool,
cmd_overrides: &utils::CmdOverrides,
+ keep_result: bool,
+ result_path: Option<&str>,
) -> Result<(), Box<dyn std::error::Error>> {
info!("Pushing all profiles for `{}`", node_name);
@@ -115,6 +124,8 @@ async fn push_all_profiles(
repo,
&deploy_data,
&deploy_defs,
+ keep_result,
+ result_path,
)
.await?;
}
@@ -221,9 +232,7 @@ async fn get_deployment_data(
build_command = build_command.arg(extra_arg);
}
- let build_child = build_command
- .stdout(Stdio::piped())
- .spawn()?;
+ let build_child = build_command.stdout(Stdio::piped()).spawn()?;
let build_output = build_child.wait_with_output().await?;
@@ -245,6 +254,8 @@ async fn run_deploy(
supports_flakes: bool,
check_sigs: bool,
cmd_overrides: utils::CmdOverrides,
+ keep_result: bool,
+ result_path: Option<&str>,
) -> Result<(), Box<dyn std::error::Error>> {
match (deploy_flake.node, deploy_flake.profile) {
(Some(node_name), Some(profile_name)) => {
@@ -274,6 +285,8 @@ async fn run_deploy(
deploy_flake.repo,
&deploy_data,
&deploy_defs,
+ keep_result,
+ result_path,
)
.await?;
@@ -293,6 +306,8 @@ async fn run_deploy(
&data.generic_settings,
check_sigs,
&cmd_overrides,
+ keep_result,
+ result_path,
)
.await?;
@@ -310,6 +325,8 @@ async fn run_deploy(
&data.generic_settings,
check_sigs,
&cmd_overrides,
+ keep_result,
+ result_path,
)
.await?;
}
@@ -360,12 +377,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let data =
get_deployment_data(supports_flakes, deploy_flake.repo, &opts.extra_build_args).await?;
+ let result_path = opts.result_path.as_deref();
+
run_deploy(
deploy_flake,
data,
supports_flakes,
opts.checksigs,
cmd_overrides,
+ opts.keep_result,
+ result_path,
)
.await?;
diff --git a/src/utils/push.rs b/src/utils/push.rs
index a82c9d4..5e87d5c 100644
--- a/src/utils/push.rs
+++ b/src/utils/push.rs
@@ -11,25 +11,27 @@ pub async fn push_profile(
repo: &str,
deploy_data: &super::DeployData<'_>,
deploy_defs: &super::DeployDefs<'_>,
+ keep_result: bool,
+ result_path: Option<&str>,
) -> Result<(), Box<dyn std::error::Error>> {
info!(
"Building profile `{}` for node `{}`",
deploy_data.profile_name, deploy_data.node_name
);
- let build_exit_status = if supports_flakes {
+ let mut build_c = if supports_flakes {
Command::new("nix")
- .arg("build")
- .arg("--no-link")
- .arg(format!(
- "{}#deploy.nodes.{}.profiles.{}.path",
- repo, deploy_data.node_name, deploy_data.profile_name
- ))
- .stdout(Stdio::null())
- .status()
- .await?
} else {
Command::new("nix-build")
+ };
+
+ let mut build_command = if supports_flakes {
+ build_c.arg("build").arg("--no-link").arg(format!(
+ "{}#deploy.nodes.{}.profiles.{}.path",
+ repo, deploy_data.node_name, deploy_data.profile_name
+ ))
+ } else {
+ build_c
.arg(&repo)
.arg("--no-out-link")
.arg("-A")
@@ -37,11 +39,26 @@ pub async fn push_profile(
"deploy.nodes.{}.profiles.{}.path",
deploy_data.node_name, deploy_data.profile_name
))
- .stdout(Stdio::null())
- .status()
- .await?
};
+ build_command = match (keep_result, supports_flakes) {
+ (true, _) => {
+ let result_path = match result_path {
+ Some(x) => x,
+ None => "./.deploy-gc",
+ };
+
+ build_command.arg("--out-link").arg(format!(
+ "{}/{}/{}",
+ result_path, deploy_data.node_name, deploy_data.profile_name
+ ))
+ }
+ (false, false) => build_command.arg("--no-out-link"),
+ (false, true) => build_command.arg("--no-link"),
+ };
+
+ let build_exit_status = build_command.stdout(Stdio::null()).status().await?;
+
if !build_exit_status.success() {
good_panic!("`nix build` failed");
}