Skip to content

Commit

Permalink
Merge pull request #62 from tsirysndr/fix/home-manager-init
Browse files Browse the repository at this point in the history
fix: home manager init
  • Loading branch information
tsirysndr authored Jun 22, 2023
2 parents 1033c06 + e1f4aeb commit 0e1a683
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"}
Expand Down
4 changes: 2 additions & 2 deletions crates/installers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
3 changes: 2 additions & 1 deletion crates/installers/src/home_manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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;
Expand Down Expand Up @@ -58,6 +58,7 @@ impl HomeManagerInstaller {
"-> Running {}",
"nix run home-manager/master -- init".bright_green()
);
home_manager_init!(self.session.clone());
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 30 additions & 0 deletions crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 0e1a683

Please sign in to comment.