Skip to content

Commit

Permalink
Merge pull request #48 from tsirysndr/fix/pkgs/nix-installer
Browse files Browse the repository at this point in the history
[pkgs] fix nix installer
  • Loading branch information
tsirysndr committed Mar 15, 2024
2 parents 0cc5077 + a2d5160 commit 2cb14b9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,34 @@ 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.

```yaml
- uses: tsirysndr/setup-envhub@v1
with:
version: 'v0.2.16'
version: 'v0.2.17'
- run: envhub --help
```
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 = "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

Expand All @@ -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"}
Expand Down
3 changes: 2 additions & 1 deletion crates/pkgs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
34 changes: 27 additions & 7 deletions crates/pkgs/src/nix.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::PackageManager;
use anyhow::Error;
use std::{env, process::Command};
use users::get_current_username;

pub struct Nix {}

Expand All @@ -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!(
Expand All @@ -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(())
}
}

0 comments on commit 2cb14b9

Please sign in to comment.