aboutsummaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/bin/deploy.rs84
1 files changed, 62 insertions, 22 deletions
diff --git a/src/bin/deploy.rs b/src/bin/deploy.rs
index 3ee2ec2..8bd8b18 100644
--- a/src/bin/deploy.rs
+++ b/src/bin/deploy.rs
@@ -151,43 +151,84 @@ enum GetDeploymentDataError {
DecodeUtf8(#[from] std::string::FromUtf8Error),
#[error("Error decoding the JSON from evaluation: {0}")]
DecodeJson(#[from] serde_json::error::Error),
+ #[error("Impossible happened: profile is set but node is not")]
+ ProfileNoNode,
}
/// Evaluates the Nix in the given `repo` and return the processed Data from it
async fn get_deployment_data(
supports_flakes: bool,
- repo: &str,
+ flake: &deploy::DeployFlake<'_>,
extra_build_args: &[String],
) -> Result<deploy::data::Data, GetDeploymentDataError> {
- info!("Evaluating flake in {}", repo);
+ info!("Evaluating flake in {}", flake.repo);
- let mut c = match supports_flakes {
- true => Command::new("nix"),
- false => Command::new("nix-instantiate"),
+ let mut c = if supports_flakes {
+ Command::new("nix")
+ } else {
+ Command::new("nix-instantiate")
};
- let mut build_command = match supports_flakes {
- true => {
- c.arg("eval")
+ if supports_flakes {
+ c.arg("eval")
.arg("--json")
- .arg(format!("{}#deploy", repo))
- }
- false => {
- c
- .arg("--strict")
- .arg("--read-write-mode")
- .arg("--json")
- .arg("--eval")
- .arg("-E")
- .arg(format!("let r = import {}/.; in if builtins.isFunction r then (r {{}}).deploy else r.deploy", repo))
+ .arg(format!("{}#deploy", flake.repo))
+ // We use --apply instead of --expr so that we don't have to deal with builtins.getFlake
+ .arg("--apply");
+ match (&flake.node, &flake.profile) {
+ (Some(node), Some(profile)) => {
+ // Ignore all nodes and all profiles but the one we're evaluating
+ c.arg(format!(
+ r#"
+ deploy:
+ (deploy // {{
+ nodes = {{
+ "{0}" = deploy.nodes."{0}" // {{
+ profiles = {{
+ inherit (deploy.nodes."{0}".profiles) "{1}";
+ }};
+ }};
+ }};
+ }})
+ "#,
+ node, profile
+ ))
+ }
+ (Some(node), None) => {
+ // Ignore all nodes but the one we're evaluating
+ c.arg(format!(
+ r#"
+ deploy:
+ (deploy // {{
+ nodes = {{
+ inherit (deploy.nodes) "{}";
+ }};
+ }})
+ "#,
+ node
+ ))
+ }
+ (None, None) => {
+ // We need to evaluate all profiles of all nodes anyway, so just do it strictly
+ c.arg(format!("deploy: deploy"))
+ }
+ (None, Some(_)) => return Err(GetDeploymentDataError::ProfileNoNode),
}
+ } else {
+ c
+ .arg("--strict")
+ .arg("--read-write-mode")
+ .arg("--json")
+ .arg("--eval")
+ .arg("-E")
+ .arg(format!("let r = import {}/.; in if builtins.isFunction r then (r {{}}).deploy else r.deploy", flake.repo))
};
for extra_arg in extra_build_args {
- build_command = build_command.arg(extra_arg);
+ c.arg(extra_arg);
}
- let build_child = build_command
+ let build_child = c
.stdout(Stdio::piped())
.spawn()
.map_err(GetDeploymentDataError::NixEval)?;
@@ -519,8 +560,7 @@ async fn run() -> Result<(), RunError> {
check_deployment(supports_flakes, deploy_flake.repo, &opts.extra_build_args).await?;
}
- let data =
- get_deployment_data(supports_flakes, deploy_flake.repo, &opts.extra_build_args).await?;
+ let data = get_deployment_data(supports_flakes, &deploy_flake, &opts.extra_build_args).await?;
let result_path = opts.result_path.as_deref();