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