Skip to content

Commit

Permalink
add nix to PATH
Browse files Browse the repository at this point in the history
add nix to PATH

add nix to PATH

add pkgx to PATH
  • Loading branch information
tsirysndr committed Mar 16, 2024
1 parent 708588a commit 31fb564
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .fluentci/src/dagger/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ export async function e2e(
.withServiceBinding("fluentci-engine", engine)
.sync();

ctr = ctr.withExec([
"bash",
"-c",
`http POST http://fluentci-engine:6880/graphql Content-Type:application/json query="$(cat pkgx.graphql)" --ignore-stdin`,
]);

ctr = ctr.withExec([
"bash",
"-c",
Expand Down
13 changes: 13 additions & 0 deletions crates/ext/src/devbox.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
env,
io::{BufRead, BufReader},
process::{Command, ExitStatus, Stdio},
sync::mpsc::{self, Receiver, Sender},
Expand Down Expand Up @@ -41,12 +42,22 @@ impl Extension for Devbox {
return Ok(ExitStatus::default());
}

let home = env::var("HOME")?;
let nix_path = format!("{}/.nix-profile/bin", home);
let path = format!(
"{}:{}:{}",
nix_path,
"/nix/var/nix/profiles/default/bin",
env::var("PATH")?
);

let (stdout_tx, stdout_rx): (Sender<String>, Receiver<String>) = mpsc::channel();
let (stderr_tx, stderr_rx): (Sender<String>, Receiver<String>) = mpsc::channel();

Command::new("bash")
.arg("-c")
.arg("[ -f devbox.json ] || devbox init")
.env("PATH", &path)
.current_dir(work_dir)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
Expand All @@ -56,6 +67,7 @@ impl Extension for Devbox {
let mut child = Command::new("bash")
.arg("-c")
.arg(format!("devbox run {}", cmd))
.env("PATH", &path)
.current_dir(work_dir)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
Expand Down Expand Up @@ -114,6 +126,7 @@ impl Extension for Devbox {
let mut child = Command::new("sh")
.arg("-c")
.arg("type devbox > /dev/null || curl -fsSL https://get.jetpack.io/devbox | bash")
.env("FORCE", "1")
.spawn()?;
child.wait()?;
Ok(())
Expand Down
14 changes: 14 additions & 0 deletions crates/ext/src/devenv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
env,
io::{BufRead, BufReader},
process::{Command, ExitStatus, Stdio},
sync::mpsc::{self, Receiver, Sender},
Expand Down Expand Up @@ -99,9 +100,19 @@ impl Extension for Devenv {

fn setup(&self) -> Result<(), Error> {
Nix::default().setup()?;
let home = env::var("HOME")?;
let nix_path = format!("{}/.nix-profile/bin", home);
let path = format!(
"{}:{}:{}",
nix_path,
"/nix/var/nix/profiles/default/bin",
env::var("PATH")?
);

let mut child = Command::new("sh")
.arg("-c")
.arg("type devenv > /dev/null")
.env("PATH", &path)
.spawn()?;
let status = child.wait()?;

Expand All @@ -118,18 +129,21 @@ impl Extension for Devenv {
Command::new("sh")
.arg("-c")
.arg("nix profile install --accept-flake-config github:cachix/cachix")
.env("PATH", &path)
.spawn()?
.wait()?;

Command::new("sh")
.arg("-c")
.arg("cachix use devenv")
.env("PATH", &path)
.spawn()?
.wait()?;

Command::new("sh")
.arg("-c")
.arg("nix profile install --accept-flake-config github:cachix/devenv/latest")
.env("PATH", &path)
.spawn()?
.wait()?;

Expand Down
24 changes: 24 additions & 0 deletions crates/ext/src/flox.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
env,
io::{BufRead, BufReader},
process::{Command, ExitStatus, Stdio},
sync::mpsc::{self, Receiver, Sender},
Expand Down Expand Up @@ -30,10 +31,20 @@ impl Extension for Flox {
let (stdout_tx, stdout_rx): (Sender<String>, Receiver<String>) = mpsc::channel();
let (stderr_tx, stderr_rx): (Sender<String>, Receiver<String>) = mpsc::channel();

let home = env::var("HOME")?;
let nix_path = format!("{}/.nix-profile/bin", home);
let path = format!(
"{}:{}:{}",
nix_path,
"/nix/var/nix/profiles/default/bin",
env::var("PATH")?
);

Command::new("bash")
.arg("-c")
.arg("[ -d .flox ] || flox init")
.current_dir(work_dir)
.env("PATH", &path)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()?
Expand All @@ -42,6 +53,7 @@ impl Extension for Flox {
let mut child = Command::new("bash")
.arg("-c")
.arg(format!("flox activate -- {}", cmd))
.env("PATH", &path)
.current_dir(work_dir)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
Expand Down Expand Up @@ -97,9 +109,20 @@ impl Extension for Flox {

fn setup(&self) -> Result<(), Error> {
Nix::default().setup()?;

let home = env::var("HOME")?;
let nix_path = format!("{}/.nix-profile/bin", home);
let path = format!(
"{}:{}:{}",
nix_path,
"/nix/var/nix/profiles/default/bin",
env::var("PATH")?
);

let status = Command::new("sh")
.arg("-c")
.arg("type flox > /dev/null")
.env("PATH", &path)
.spawn()?
.wait()?;

Expand All @@ -121,6 +144,7 @@ impl Extension for Flox {
--accept-flake-config \
github:flox/flox",
)
.env("PATH", path)
.spawn()?
.wait()?;

Expand Down
24 changes: 20 additions & 4 deletions crates/ext/src/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,28 @@ impl Extension for Nix {
};

env::set_var("USER", user);
let home = match env::var("HOME") {
Ok(home) => home,
Err(_) => "/root".to_string(),
};
let nix_path = format!("{}/.nix-profile/bin", home);
env::set_var(
"PATH",
format!(
"{}:{}",
"{}:{}:{}",
env::var("PATH")?,
"/nix/var/nix/profiles/default/bin"
"/nix/var/nix/profiles/default/bin",
nix_path
),
);
let nix_path = format!("{}/.nix-profile/bin", home);
let path = format!(
"{}:{}:{}",
nix_path,
"/nix/var/nix/profiles/default/bin",
env::var("PATH")?
);

let mut child = Command::new("sh")
.arg("-c")
.arg("type systemctl > /dev/null")
Expand All @@ -126,15 +140,17 @@ impl Extension for Nix {
"linux" => format!("linux --extra-conf 'sandbox = false' {}", init),
_ => "".to_string(),
};
let mut child = Command::new("sh")
let mut child = Command::new("bash")
.arg("-c")
.arg(format!("type nix > /dev/null || curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install {}", linux))
.env("PATH", &path)
.spawn()?;
child.wait()?;

let mut child = Command::new("sh")
let mut child = Command::new("bash")
.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))
.env("PATH", &path)
.spawn()?;
child.wait()?;
Ok(())
Expand Down
27 changes: 20 additions & 7 deletions crates/ext/src/pkgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ pub struct Pkgx {}
impl Pkgx {
pub fn install(&self, pkgs: Vec<&str>) -> Result<ExitStatus, Error> {
self.setup()?;
let path = format!(
"{}:{}",
env::var("PATH")?,
format!("{}/.local/bin", env::var("HOME")?)
);

let mut child = Command::new("sh")
.arg("-c")
.arg(format!("pkgx install {}", pkgs.join(" ")))
.env("PATH", &path)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
Expand All @@ -45,9 +52,16 @@ impl Extension for Pkgx {
let (stdout_tx, stdout_rx): (Sender<String>, Receiver<String>) = mpsc::channel();
let (stderr_tx, stderr_rx): (Sender<String>, Receiver<String>) = mpsc::channel();

let path = format!(
"{}:{}",
env::var("PATH")?,
format!("{}/.local/bin", env::var("HOME")?)
);

let mut child = Command::new("bash")
.arg("-c")
.arg(format!("eval \"$(pkgx --shellcode)\" && {}", cmd))
.env("PATH", &path)
.current_dir(work_dir)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
Expand Down Expand Up @@ -102,17 +116,16 @@ impl Extension for Pkgx {
}

fn setup(&self) -> Result<(), Error> {
env::set_var(
"PATH",
format!(
"{}:{}",
env::var("PATH")?,
format!("{}/.local/bin", env::var("HOME")?)
),
let path = format!(
"{}:{}",
env::var("PATH")?,
format!("{}/.local/bin", env::var("HOME")?)
);
env::set_var("PATH", &path);
let mut child = Command::new("sh")
.arg("-c")
.arg("type pkgx > /dev/null || curl -fsS https://pkgx.sh | sh")
.env("PATH", &path)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
Expand Down
4 changes: 2 additions & 2 deletions fixtures/flox.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ query Flox {
pipeline(name: "Demo") {
flox {
withWorkDir(path: "./flox-demo") {
withExec(args: ["echo", "hello"]) {
withExec(args: ["flox", "--version"]) {
withExec(args: ["flox", "--version"]) {
withExec(args: ["which", "jq"]) {
id
stdout
}
Expand Down
14 changes: 14 additions & 0 deletions fixtures/pkgx.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
query Pkgx {
pipeline(name: "Demo") {
pkgx {
withWorkDir(path: "./pkgx-demo") {
withExec(args: ["pkgx", "--version"]) {
withExec(args: ["which", "deno"]) {
id
stdout
}
}
}
}
}
}

0 comments on commit 31fb564

Please sign in to comment.