aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs89
-rw-r--r--src/utils/data.rs2
-rw-r--r--src/utils/deploy.rs1
3 files changed, 50 insertions, 42 deletions
diff --git a/src/main.rs b/src/main.rs
index cde4fc3..e084f0f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -156,64 +156,73 @@ async fn deploy_all_profiles(
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();
-
- match opts.subcmd {
- SubCommand::Deploy(deploy_opts) => {
- let deploy_flake = utils::parse_flake(deploy_opts.flake.as_str());
+async fn test_flake_support() -> Result<bool, Box<dyn std::error::Error>> {
+ Ok(Command::new("nix")
+ .arg("eval")
+ .arg("--expr")
+ .arg("builtins.getFlake")
+ .stdout(Stdio::null())
+ .stderr(Stdio::null())
+ .status()
+ .await?
+ .success())
+}
- let test_flake_status = Command::new("nix")
+async fn get_deployment_data(
+ supports_flakes: bool,
+ repo: &str,
+) -> Result<utils::data::Data, Box<dyn std::error::Error>> {
+ let data_json = match supports_flakes {
+ true => {
+ let c = Command::new("nix")
.arg("eval")
- .arg("--expr")
- .arg("builtins.getFlake")
+ .arg("--json")
+ .arg(format!("{}#deploy", repo))
.stdout(Stdio::null())
.stderr(Stdio::null())
- .status()
+ // TODO forward input args?
+ .output()
.await?;
- let supports_flakes = test_flake_status.success();
-
- let data_json = match supports_flakes {
- true => {
- let c = Command::new("nix")
- .arg("eval")
- .arg("--json")
- .arg(format!("{}#deploy", deploy_flake.repo))
- .stdout(Stdio::null())
- .stderr(Stdio::null())
- // TODO forward input args?
- .output()
- .await?;
-
- String::from_utf8(c.stdout)?
- }
- false => {
- let c = Command::new("nix-instanciate")
+ String::from_utf8(c.stdout)?
+ }
+ false => {
+ let c = Command::new("nix-instanciate")
.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", deploy_flake.repo))
+ .arg(format!("let r = import {}/.; in if builtins.isFunction r then (r {{}}).deploy else r.deploy", repo))
.stdout(Stdio::null())
.stderr(Stdio::null())
.output()
.await?;
- String::from_utf8(c.stdout)?
- }
- };
+ String::from_utf8(c.stdout)?
+ }
+ };
+
+ 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();
+
+ match opts.subcmd {
+ SubCommand::Deploy(deploy_opts) => {
+ let deploy_flake = utils::parse_flake(deploy_opts.flake.as_str());
+
+ let supports_flakes = test_flake_support().await?;
- let data: utils::data::Data = serde_json::from_str(&data_json)?;
+ let data = get_deployment_data(supports_flakes, deploy_flake.repo).await?;
match (deploy_flake.node, deploy_flake.profile) {
(Some(node_name), Some(profile_name)) => {
diff --git a/src/utils/data.rs b/src/utils/data.rs
index 779d913..b28b6cd 100644
--- a/src/utils/data.rs
+++ b/src/utils/data.rs
@@ -1,6 +1,6 @@
use merge::Merge;
-use std::{collections::HashMap};
+use std::collections::HashMap;
#[derive(Deserialize, Debug, Clone, Merge)]
pub struct GenericSettings {
diff --git a/src/utils/deploy.rs b/src/utils/deploy.rs
index 7260e55..900743c 100644
--- a/src/utils/deploy.rs
+++ b/src/utils/deploy.rs
@@ -1,6 +1,5 @@
use super::data;
-
use tokio::process::Command;
pub async fn deploy_profile(