Compare commits

..

2 commits

Author SHA1 Message Date
Patrick 3052ba7b25
fix: deploy 2024-12-04 22:47:24 +01:00
Patrick 803f8ba1f2
WIP 2024-12-04 22:36:27 +01:00

View file

@ -1,5 +1,5 @@
use color_eyre::{
eyre::{Context, Result},
eyre::{bail, Context, Result},
owo_colors::OwoColorize,
};
use futures::future::join_all;
@ -21,17 +21,11 @@ pub fn build(systems: &[String], show_trace: bool) -> Result<Output> {
let dir = env::var("PRJ_ROOT")
.map(PathBuf::from)
.or_else(|_| env::current_dir())?;
let mut configs = Vec::new();
for s in systems.iter().map(|x| gen_systems_path(x)) {
configs.push(format!(
".#nixosConfigurations.{}.config.system.build.toplevel",
s
));
}
let configs = systems.iter().map(|x| gen_systems_path(x));
let mut cmd = Command::new("nom");
let mut cmd = if cmd
.arg("--version")
.current_dir(dir)
.current_dir(&dir)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
@ -46,10 +40,14 @@ pub fn build(systems: &[String], show_trace: bool) -> Result<Output> {
cmd.arg("--show-trace");
};
let cmd = cmd
.current_dir(dir)
.arg("build")
.arg("--print-out-paths")
.arg("--no-link")
.args(configs);
.args(configs)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::inherit());
cmd.output().wrap_err("Error building systems")
}
@ -81,11 +79,19 @@ pub async fn deploy(systems: &[String], show_trace: bool, mode: &str) -> Result<
println!("Copyings toplevel for {}", system.blue());
let mut cmd = Command::new("nix");
let cmd = cmd
.env(
"NIX_SSHOPTS",
format!("-S {}", con.control_socket().to_str().unwrap()),
)
.arg("copy")
.arg("--substitute-on-destination")
.arg("--to")
.arg(format!("ssh://{}", host))
.arg(format!("ssh-ng://root@{}?compress=true", host))
.arg(toplevel);
cmd.spawn()?.wait()?;
if !cmd.spawn()?.wait()?.success() {
bail!("nix copy failed");
}
let prev_system = con
.command("readlink")
.arg("-e")
@ -93,6 +99,8 @@ pub async fn deploy(systems: &[String], show_trace: bool, mode: &str) -> Result<
.output()
.await?
.stdout;
println!("Applying system: {}", system.blue());
// register toplevel
con.command("nix-env")
.arg("--profile")
@ -100,19 +108,25 @@ pub async fn deploy(systems: &[String], show_trace: bool, mode: &str) -> Result<
.arg("--set")
.arg(toplevel)
.spawn()
.await?
.wait()
.await?;
con.command(format!("{}/bin/switch-to-configuration", toplevel))
.arg(mode)
.spawn()
.await?
.wait()
.await?;
if !prev_system.is_empty() {
con.command("nvd")
.arg("--color")
.arg("--always")
.arg("always")
.arg("diff")
.arg(String::from_utf8(prev_system)?)
.arg(toplevel)
.spawn()
.await?
.wait()
.await?;
}
}