From 09fb938cb462681aaf6d7016e35a90d4995aad8c Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 14 Dec 2024 20:00:25 +0100 Subject: [PATCH] feat: minimal systemd support --- src/deploy.rs | 25 +++++++++++++++++-------- src/main.rs | 7 +++++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/deploy.rs b/src/deploy.rs index cc2775e..bc309ac 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -10,18 +10,25 @@ use std::{ process::{Command, Output, Stdio}, }; -fn gen_systems_path(system: &str) -> String { - format!( - ".#nixosConfigurations.{}.config.system.build.toplevel", - system - ) +fn gen_systems_path(system: &str, minimal: bool) -> String { + if minimal { + format!( + ".#minimalConfigurations.{}.config.system.build.toplevel", + system + ) + } else { + format!( + ".#nixosConfigurations.{}.config.system.build.toplevel", + system + ) + } } -pub fn build(systems: &[String], show_trace: bool) -> Result { +pub fn build(systems: &[String], show_trace: bool, minimal: bool) -> Result { let dir = env::var("PRJ_ROOT") .map(PathBuf::from) .or_else(|_| env::current_dir())?; - let configs = systems.iter().map(|x| gen_systems_path(x)); + let configs = systems.iter().map(|x| gen_systems_path(x, minimal)); let mut cmd = Command::new("nom"); let mut cmd = if cmd .arg("--version") @@ -51,7 +58,7 @@ pub fn build(systems: &[String], show_trace: bool) -> Result { cmd.output().wrap_err("Error building systems") } -pub async fn deploy(systems: &[String], show_trace: bool, mode: &str) -> Result<()> { +pub async fn deploy(systems: &[String], mode: &str, show_trace: bool, minimal: bool) -> Result<()> { let (systems, hosts): (Vec<_>, Vec<_>) = systems .iter() .map(|x| x.split_once('@').unwrap_or((x, x))) @@ -69,6 +76,7 @@ pub async fn deploy(systems: &[String], show_trace: bool, mode: &str) -> Result< build( &systems.iter().map(|x| x.to_string()).collect::>(), show_trace, + minimal, )? .stdout, )?; @@ -85,6 +93,7 @@ pub async fn deploy(systems: &[String], show_trace: bool, mode: &str) -> Result< ) .arg("copy") .arg("--substitute-on-destination") + // Could add a --no-check-sigs option here to enable people who don't sign their stores .arg("--to") .arg(format!("ssh-ng://root@{}?compress=true", host)) .arg(toplevel); diff --git a/src/main.rs b/src/main.rs index d739ea8..a43a94f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,6 +57,9 @@ struct Deploy { show_trace: bool, #[arg(long, default_value_t = ("switch".to_string()))] mode: String, + /// This deploys a minimal configation, expected under flake output minimalConfigurations + #[arg(long, default_value_t = false)] + minimal: bool, } #[derive(Args, Debug, Default)] @@ -142,7 +145,7 @@ async fn main() -> Result<()> { ) .exit() } - build(&opts.systems, opts.show_trace)?; + build(&opts.systems, opts.show_trace, opts.minimal)?; } CliCommands::Deploy(opts) => { @@ -154,7 +157,7 @@ async fn main() -> Result<()> { ) .exit() } - deploy(&opts.systems, opts.show_trace, &opts.mode).await?; + deploy(&opts.systems, &opts.mode, opts.show_trace, opts.minimal).await?; } }; Ok(())