diff --git a/Cargo.lock b/Cargo.lock index a94bf02..c5b04d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -383,7 +383,7 @@ checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" [[package]] name = "envhub" -version = "0.2.14" +version = "0.2.15" dependencies = [ "anyhow", "clap 3.2.25", @@ -399,6 +399,7 @@ dependencies = [ "owo-colors", "tokio", "toml", + "users", ] [[package]] @@ -411,13 +412,14 @@ dependencies = [ [[package]] name = "envhub-hm" -version = "0.2.2" +version = "0.2.3" dependencies = [ "anyhow", "envhub-types", "indexmap 1.9.3", "nix-editor", "rnix 0.11.0", + "users", ] [[package]] @@ -1334,6 +1336,16 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +[[package]] +name = "users" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032" +dependencies = [ + "libc", + "log", +] + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/README.md b/README.md index 62ed810..e7c75e8 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,6 @@ You can use EnvHub as a [GitHub Action](https://github.com/tsirysndr/setup-envhu ```yaml - uses: tsirysndr/setup-envhub@v1 with: - version: 'v0.2.14' + version: 'v0.2.15' - run: envhub --help ``` diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 6ad4928..4aacf35 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" name = "envhub" readme = "../../README.md" repository = "https://github.com/tsirysndr/envhub" -version = "0.2.14" +version = "0.2.15" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -16,7 +16,7 @@ version = "0.2.14" anyhow = "1.0.71" clap = "3.2.20" envhub-ext = {path = "../ext", version = "0.1.1"} -envhub-hm = {path = "../hm", version = "0.2.2"} +envhub-hm = {path = "../hm", version = "0.2.3"} envhub-pkgs = {path = "../pkgs", version = "0.1.2"} envhub-providers = {path = "../providers", version = "0.2.0"} envhub-stow = {path = "../stow", version = "0.1.0"} @@ -27,3 +27,4 @@ inquire = "0.6.2" owo-colors = "3.5.0" tokio = {version = "1.28.2", features = ["full"]} toml = "0.7.4" +users = "0.11.0" diff --git a/crates/hm/Cargo.toml b/crates/hm/Cargo.toml index f77cb7e..f362f96 100644 --- a/crates/hm/Cargo.toml +++ b/crates/hm/Cargo.toml @@ -7,7 +7,7 @@ keywords = ["nix", "shell", "environment", "dotfiles"] license = "MIT" name = "envhub-hm" repository = "https://github.com/tsirysndr/envhub" -version = "0.2.2" +version = "0.2.3" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -17,3 +17,4 @@ envhub-types = {version = "0.2.0", path = "../types"} indexmap = {version = "1.9.3", features = ["serde"]} nix-editor = "0.3.0" rnix = "0.11.0" +users = "0.11.0" diff --git a/crates/hm/src/nix.rs b/crates/hm/src/nix.rs index c40c7b4..5fac54f 100644 --- a/crates/hm/src/nix.rs +++ b/crates/hm/src/nix.rs @@ -1,8 +1,15 @@ use std::{env, process::Command}; +use users::get_current_username; use anyhow::Error; pub fn install() -> Result<(), Error> { + let user = match get_current_username() { + Some(user) => user.to_string_lossy().to_string(), + None => "root".to_string(), + }; + + env::set_var("USER", user); env::set_var( "PATH", format!( @@ -11,6 +18,7 @@ pub fn install() -> Result<(), Error> { "/nix/var/nix/profiles/default/bin" ), ); + let linux = match std::env::consts::OS { "linux" => "linux --extra-conf 'sandbox = false' --init none", _ => "",