feat: minimal systemd support

This commit is contained in:
Patrick 2024-12-14 20:00:25 +01:00
parent 3052ba7b25
commit 09fb938cb4
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F
2 changed files with 22 additions and 10 deletions

View file

@ -10,18 +10,25 @@ use std::{
process::{Command, Output, Stdio}, process::{Command, Output, Stdio},
}; };
fn gen_systems_path(system: &str) -> String { fn gen_systems_path(system: &str, minimal: bool) -> String {
format!( if minimal {
".#nixosConfigurations.{}.config.system.build.toplevel", format!(
system ".#minimalConfigurations.{}.config.system.build.toplevel",
) system
)
} else {
format!(
".#nixosConfigurations.{}.config.system.build.toplevel",
system
)
}
} }
pub fn build(systems: &[String], show_trace: bool) -> Result<Output> { pub fn build(systems: &[String], show_trace: bool, minimal: bool) -> Result<Output> {
let dir = env::var("PRJ_ROOT") let dir = env::var("PRJ_ROOT")
.map(PathBuf::from) .map(PathBuf::from)
.or_else(|_| env::current_dir())?; .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 = Command::new("nom");
let mut cmd = if cmd let mut cmd = if cmd
.arg("--version") .arg("--version")
@ -51,7 +58,7 @@ pub fn build(systems: &[String], show_trace: bool) -> Result<Output> {
cmd.output().wrap_err("Error building systems") 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 let (systems, hosts): (Vec<_>, Vec<_>) = systems
.iter() .iter()
.map(|x| x.split_once('@').unwrap_or((x, x))) .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( build(
&systems.iter().map(|x| x.to_string()).collect::<Vec<_>>(), &systems.iter().map(|x| x.to_string()).collect::<Vec<_>>(),
show_trace, show_trace,
minimal,
)? )?
.stdout, .stdout,
)?; )?;
@ -85,6 +93,7 @@ pub async fn deploy(systems: &[String], show_trace: bool, mode: &str) -> Result<
) )
.arg("copy") .arg("copy")
.arg("--substitute-on-destination") .arg("--substitute-on-destination")
// Could add a --no-check-sigs option here to enable people who don't sign their stores
.arg("--to") .arg("--to")
.arg(format!("ssh-ng://root@{}?compress=true", host)) .arg(format!("ssh-ng://root@{}?compress=true", host))
.arg(toplevel); .arg(toplevel);

View file

@ -57,6 +57,9 @@ struct Deploy {
show_trace: bool, show_trace: bool,
#[arg(long, default_value_t = ("switch".to_string()))] #[arg(long, default_value_t = ("switch".to_string()))]
mode: 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)] #[derive(Args, Debug, Default)]
@ -142,7 +145,7 @@ async fn main() -> Result<()> {
) )
.exit() .exit()
} }
build(&opts.systems, opts.show_trace)?; build(&opts.systems, opts.show_trace, opts.minimal)?;
} }
CliCommands::Deploy(opts) => { CliCommands::Deploy(opts) => {
@ -154,7 +157,7 @@ async fn main() -> Result<()> {
) )
.exit() .exit()
} }
deploy(&opts.systems, opts.show_trace, &opts.mode).await?; deploy(&opts.systems, &opts.mode, opts.show_trace, opts.minimal).await?;
} }
}; };
Ok(()) Ok(())