diff --git a/Cargo.lock b/Cargo.lock index 85ae05a..d4ecdde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -383,7 +383,7 @@ checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" [[package]] name = "envhub" -version = "0.2.16" +version = "0.2.17" dependencies = [ "anyhow", "clap 3.2.25", @@ -424,9 +424,10 @@ dependencies = [ [[package]] name = "envhub-pkgs" -version = "0.1.2" +version = "0.1.3" dependencies = [ "anyhow", + "users", ] [[package]] diff --git a/README.md b/README.md index 61e8d3d..e41a848 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,27 @@ file ".gradle/gradle.properties" { See [demo](demo) and [examples](examples) for a more complete example. +## 🧩 As a Dagger Module + +Call from the command line: + +```bash +dagger -m github.com/tsirysndr/daggerverse/envhub call \ + use --environment github:tsirysndr/dotfiles-example \ + --src . +``` + +call from a [Fluent CI](https://fluentci.io/) module: + +```typescript +import { use } from 'jsr:@fx/envhub'; + +await use( + ".", + "github:tsirysndr/dotfiles-example" +); +``` + ## As a GitHub Action You can use EnvHub as a [GitHub Action](https://github.com/tsirysndr/setup-envhub) to manage your dotfiles and packages in your CI/CD workflow. @@ -108,6 +129,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.16' + version: 'v0.2.17' - run: envhub --help ``` diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 2efa0bc..78c9f98 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.16" +version = "0.2.17" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -17,7 +17,7 @@ anyhow = "1.0.71" clap = "3.2.20" envhub-ext = {path = "../ext", version = "0.1.1"} envhub-hm = {path = "../hm", version = "0.2.4"} -envhub-pkgs = {path = "../pkgs", version = "0.1.2"} +envhub-pkgs = {path = "../pkgs", version = "0.1.3"} envhub-providers = {path = "../providers", version = "0.2.0"} envhub-stow = {path = "../stow", version = "0.1.0"} envhub-types = {path = "../types", version = "0.2.2"} diff --git a/crates/pkgs/Cargo.toml b/crates/pkgs/Cargo.toml index ed1db42..babba34 100644 --- a/crates/pkgs/Cargo.toml +++ b/crates/pkgs/Cargo.toml @@ -7,9 +7,10 @@ keywords = ["nix", "shell", "environment", "dotfiles"] license = "MIT" name = "envhub-pkgs" repository = "https://github.com/tsirysndr/envhub" -version = "0.1.2" +version = "0.1.3" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] anyhow = "1.0.71" +users = "0.11.0" diff --git a/crates/pkgs/src/nix.rs b/crates/pkgs/src/nix.rs index 067e34f..63346b3 100644 --- a/crates/pkgs/src/nix.rs +++ b/crates/pkgs/src/nix.rs @@ -1,6 +1,7 @@ use crate::PackageManager; use anyhow::Error; use std::{env, process::Command}; +use users::get_current_username; pub struct Nix {} @@ -21,6 +22,12 @@ impl PackageManager for Nix { } fn setup(&self) -> 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!( @@ -30,17 +37,30 @@ impl PackageManager for Nix { ), ); let mut child = Command::new("sh") - .arg("-c") - .arg("type nix > /dev/null || curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install") - .spawn()?; - child.wait()?; + .arg("-c") + .arg("type systemctl > /dev/null") + .spawn()?; + let status = child.wait()?; + let init = match status.code() { + Some(0) => "", + _ => "--init none", + }; + let linux = match std::env::consts::OS { + "linux" => format!("linux --extra-conf 'sandbox = false' {}", init), + _ => "".to_string(), + }; let mut child = Command::new("sh") - .arg("-c") - .arg("type nix > /dev/null || curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --no-confirm ") - .spawn()?; + .arg("-c") + .arg(format!("type nix > /dev/null || curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install {}", linux)) + .spawn()?; child.wait()?; + let mut child = Command::new("sh") + .arg("-c") + .arg(format!("type nix > /dev/null || curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install {} --no-confirm", linux)) + .spawn()?; + child.wait()?; Ok(()) } }