aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs57
1 files changed, 34 insertions, 23 deletions
diff --git a/src/main.rs b/src/main.rs
index 9e50674..75842e5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -147,7 +147,7 @@ async fn test_flake_support() -> Result<bool, Box<dyn std::error::Error>> {
async fn get_deployment_data(
supports_flakes: bool,
repo: &str,
- extra_build_args: Vec<String>,
+ extra_build_args: &[String],
) -> Result<utils::data::Data, Box<dyn std::error::Error>> {
let mut c = match supports_flakes {
true => Command::new("nix"),
@@ -160,12 +160,12 @@ async fn get_deployment_data(
}
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("--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))
}
};
@@ -190,23 +190,13 @@ async fn get_deployment_data(
Ok(serde_json::from_str(&data_json)?)
}
-#[tokio::main]
-async fn main() -> Result<(), Box<dyn std::error::Error>> {
- if std::env::var("DEPLOY_LOG").is_err() {
- std::env::set_var("DEPLOY_LOG", "info");
- }
-
- pretty_env_logger::init_custom_env("DEPLOY_LOG");
-
- let opts: Opts = Opts::parse();
-
- let deploy_flake = utils::parse_flake(opts.flake.as_str());
-
- let supports_flakes = test_flake_support().await?;
-
- let data =
- get_deployment_data(supports_flakes, deploy_flake.repo, opts.extra_build_args).await?;
+async fn run_deploy(
+ deploy_flake: utils::DeployFlake<'_>,
+ data: utils::data::Data,
+ supports_flakes: bool,
+ opts: &Opts,
+) -> Result<(), Box<dyn std::error::Error>> {
match (deploy_flake.node, deploy_flake.profile) {
(Some(node_name), Some(profile_name)) => {
let node = match data.nodes.get(node_name) {
@@ -293,3 +283,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
+#[tokio::main]
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+ if std::env::var("DEPLOY_LOG").is_err() {
+ std::env::set_var("DEPLOY_LOG", "info");
+ }
+
+ pretty_env_logger::init_custom_env("DEPLOY_LOG");
+
+ let opts: Opts = Opts::parse();
+
+ let deploy_flake = utils::parse_flake(opts.flake.as_str());
+
+ let supports_flakes = test_flake_support().await?;
+
+ let data =
+ get_deployment_data(supports_flakes, deploy_flake.repo, &opts.extra_build_args).await?;
+
+ run_deploy(deploy_flake, data, supports_flakes, &opts).await?;
+
+ Ok(())
+}