From 2118496af75ae35885b6b78145d942144dd2295c Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Thu, 22 Jun 2023 08:14:34 +0000 Subject: [PATCH 1/3] fix: home-manager init --- Cargo.lock | 4 ++-- crates/cli/Cargo.toml | 2 +- crates/installers/Cargo.toml | 4 ++-- crates/installers/src/home_manager.rs | 5 ++++- crates/macros/Cargo.toml | 2 +- crates/macros/src/lib.rs | 30 +++++++++++++++++++++++++++ 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 873e524..7f7ce23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1121,7 +1121,7 @@ dependencies = [ [[package]] name = "crosup-installers" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "crosup-macros", @@ -1135,7 +1135,7 @@ dependencies = [ [[package]] name = "crosup-macros" -version = "0.1.3" +version = "0.1.4" [[package]] name = "crosup-migration" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 210f1db..9956d82 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -17,7 +17,7 @@ anyhow = "1.0.71" clap = "3.2.20" crosup-core = {path = "../core", version = "0.1.7"} crosup-entity = {version = "0.1.0", path = "../entity"} -crosup-installers = {path = "../installers", version = "0.1.4"} +crosup-installers = {path = "../installers", version = "0.1.5"} crosup-nix = {path = "../nix", version = "0.1.1"} crosup-repo = {path = "../repo", version = "0.1.0"} crosup-ssh = {path = "../ssh", version = "0.1.0"} diff --git a/crates/installers/Cargo.toml b/crates/installers/Cargo.toml index 4e02c9a..6875231 100644 --- a/crates/installers/Cargo.toml +++ b/crates/installers/Cargo.toml @@ -7,13 +7,13 @@ keywords = ["chromebook", "chromeos", "homebrew", "docker", "nix"] license = "MIT" name = "crosup-installers" repository = "https://github.com/tsirysndr/crosup" -version = "0.1.4" +version = "0.1.5" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] anyhow = "1.0.71" -crosup-macros = {path = "../macros", version = "0.1.3"} +crosup-macros = {path = "../macros", version = "0.1.4"} crosup-nix = {path = "../nix", version = "0.1.1"} crosup-ssh = {path = "../ssh", version = "0.1.0"} crosup-types = {path = "../types", version = "0.1.4"} diff --git a/crates/installers/src/home_manager.rs b/crates/installers/src/home_manager.rs index 229cc5f..bd6239d 100644 --- a/crates/installers/src/home_manager.rs +++ b/crates/installers/src/home_manager.rs @@ -1,10 +1,12 @@ use anyhow::Error; -use crosup_macros::{check_version, exec_bash_with_output}; +use crosup_macros::{check_version, exec_bash_with_output, home_manager_init}; use crosup_types::home_manager::Package; use owo_colors::OwoColorize; use ssh2::Session; use std::{any::Any, fs, io::BufRead, path::Path, process::Stdio}; +use crate::home_manager; + use super::Installer; #[derive(Default, Clone)] @@ -58,6 +60,7 @@ impl HomeManagerInstaller { "-> Running {}", "nix run home-manager/master -- init".bright_green() ); + home_manager_init!(self.session.clone()); Ok(()) } diff --git a/crates/macros/Cargo.toml b/crates/macros/Cargo.toml index cbd485b..f63a18a 100644 --- a/crates/macros/Cargo.toml +++ b/crates/macros/Cargo.toml @@ -7,7 +7,7 @@ keywords = ["chromebook", "chromeos", "homebrew", "docker", "nix"] license = "MIT" name = "crosup-macros" repository = "https://github.com/tsirysndr/crosup" -version = "0.1.3" +version = "0.1.4" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/crates/macros/src/lib.rs b/crates/macros/src/lib.rs index 356b1ca..220b2bd 100644 --- a/crates/macros/src/lib.rs +++ b/crates/macros/src/lib.rs @@ -492,6 +492,36 @@ macro_rules! fleek_install { }; } +#[macro_export] +macro_rules! home_manager_init { + ($session:expr) => { + match $session { + Some(session) => { + let command = format!("bash -c '. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix run home-manager/master -- init'"); + crosup_ssh::exec(session.clone(), &command)?; + } + None => { + let mut child = std::process::Command::new("bash") + .arg("-c") + .arg(format!(". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix run home-manager/master -- init")) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn()?; + let output = child.stdout.take().unwrap(); + let output = std::io::BufReader::new(output); + + for line in output.lines() { + println!("{}", line?); + } + let status = child.wait()?; + if !status.success() { + return Err(Error::msg(format!("Failed to initialize home-manager"))); + } + } + }; + }; +} + #[macro_export] macro_rules! exec_sudo { ($command:expr, $session:expr) => { From 613cda9e93106423ff1fa6a95d7f1bed1e13e075 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Thu, 22 Jun 2023 08:15:14 +0000 Subject: [PATCH 2/3] chore: bump version code --- Cargo.lock | 2 +- crates/cli/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f7ce23..ab4f0f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1069,7 +1069,7 @@ dependencies = [ [[package]] name = "crosup" -version = "0.4.1" +version = "0.4.2" dependencies = [ "anyhow", "clap 3.2.25", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 9956d82..7cddf03 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" name = "crosup" readme = "../../README.md" repository = "https://github.com/tsirysndr/crosup" -version = "0.4.1" +version = "0.4.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From e1f4aebefed710786431fc5d34b40b47645e211b Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Thu, 22 Jun 2023 08:17:34 +0000 Subject: [PATCH 3/3] remove unused imports --- crates/installers/src/home_manager.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/installers/src/home_manager.rs b/crates/installers/src/home_manager.rs index bd6239d..bb90143 100644 --- a/crates/installers/src/home_manager.rs +++ b/crates/installers/src/home_manager.rs @@ -5,8 +5,6 @@ use owo_colors::OwoColorize; use ssh2::Session; use std::{any::Any, fs, io::BufRead, path::Path, process::Stdio}; -use crate::home_manager; - use super::Installer; #[derive(Default, Clone)]