diff options
author | Alexander Bantyev | 2021-02-07 13:37:41 +0300 |
---|---|---|
committer | Alexander Bantyev | 2021-02-07 13:37:41 +0300 |
commit | 99f2127ccee5e612b1c26a7300f7380f5d1575b0 (patch) | |
tree | 5203fdc4082bbdfe6599de79144cc5027b1b85e5 /src | |
parent | 80ab1d753818752405acb8d4d3f3dc11ef83f5a9 (diff) |
fixup! Evaluate deploy output lazily
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/deploy.rs | 92 |
1 files changed, 42 insertions, 50 deletions
diff --git a/src/bin/deploy.rs b/src/bin/deploy.rs index 6da2110..30ebd25 100644 --- a/src/bin/deploy.rs +++ b/src/bin/deploy.rs @@ -52,10 +52,6 @@ struct Opts { #[clap(short, long)] skip_checks: bool, - /// Always evaluate deploy attribute strictly - #[clap(long)] - strict_eval: bool, - /// Override the SSH user with the given value #[clap(long)] ssh_user: Option<String>, @@ -160,12 +156,13 @@ 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, - strict_eval: bool, flake: &deploy::DeployFlake<'_>, extra_build_args: &[String], ) -> Result<deploy::data::Data, GetDeploymentDataError> { @@ -178,54 +175,49 @@ async fn get_deployment_data( }; if supports_flakes { - c - .arg("eval") + c.arg("eval") .arg("--json") - .arg(format!("{}#deploy", flake.repo)); - match (&flake.node, strict_eval) { - (Some(node), false) => { - // We use --apply instead of --expr so that we don't have to deal with builtins.getFlake - c.arg("--apply"); - info!("Evaluating the flake lazily; Use --strict-eval for old behavior"); - match &flake.profile { - None => { - // Ignore all nodes but the one we're evaluating - c.arg(format!( - r#" - deploy: - (deploy // {{ - nodes = {{ - inherit (deploy.nodes) "{}"; - }}; - }}) - "#, - 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 - )) - } - } + .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 + c.arg(format!("deploy: deploy")) } + (None, Some(_)) => return Err(GetDeploymentDataError::ProfileNoNode), } } else { c @@ -573,7 +565,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, opts.strict_eval, &deploy_flake, &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(); |