diff --git a/.fluentci/src/dagger/jobs.ts b/.fluentci/src/dagger/jobs.ts index 53f1b42..8fc662e 100644 --- a/.fluentci/src/dagger/jobs.ts +++ b/.fluentci/src/dagger/jobs.ts @@ -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", diff --git a/crates/ext/src/devbox.rs b/crates/ext/src/devbox.rs index 9c08018..43912f0 100644 --- a/crates/ext/src/devbox.rs +++ b/crates/ext/src/devbox.rs @@ -1,4 +1,5 @@ use std::{ + env, io::{BufRead, BufReader}, process::{Command, ExitStatus, Stdio}, sync::mpsc::{self, Receiver, Sender}, @@ -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, Receiver) = mpsc::channel(); let (stderr_tx, stderr_rx): (Sender, Receiver) = 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()) @@ -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()) @@ -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(()) diff --git a/crates/ext/src/devenv.rs b/crates/ext/src/devenv.rs index e54dd63..4bedc8e 100644 --- a/crates/ext/src/devenv.rs +++ b/crates/ext/src/devenv.rs @@ -1,4 +1,5 @@ use std::{ + env, io::{BufRead, BufReader}, process::{Command, ExitStatus, Stdio}, sync::mpsc::{self, Receiver, Sender}, @@ -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()?; @@ -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()?; diff --git a/crates/ext/src/flox.rs b/crates/ext/src/flox.rs index 7799883..83e1ee1 100644 --- a/crates/ext/src/flox.rs +++ b/crates/ext/src/flox.rs @@ -1,4 +1,5 @@ use std::{ + env, io::{BufRead, BufReader}, process::{Command, ExitStatus, Stdio}, sync::mpsc::{self, Receiver, Sender}, @@ -30,10 +31,20 @@ impl Extension for Flox { let (stdout_tx, stdout_rx): (Sender, Receiver) = mpsc::channel(); let (stderr_tx, stderr_rx): (Sender, Receiver) = 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()? @@ -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()) @@ -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()?; @@ -121,6 +144,7 @@ impl Extension for Flox { --accept-flake-config \ github:flox/flox", ) + .env("PATH", path) .spawn()? .wait()?; diff --git a/crates/ext/src/nix.rs b/crates/ext/src/nix.rs index db2a731..38b515d 100644 --- a/crates/ext/src/nix.rs +++ b/crates/ext/src/nix.rs @@ -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") @@ -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(()) diff --git a/crates/ext/src/pkgx.rs b/crates/ext/src/pkgx.rs index 22fa80f..5bfa8a4 100644 --- a/crates/ext/src/pkgx.rs +++ b/crates/ext/src/pkgx.rs @@ -16,9 +16,16 @@ pub struct Pkgx {} impl Pkgx { pub fn install(&self, pkgs: Vec<&str>) -> Result { 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()) @@ -45,9 +52,16 @@ impl Extension for Pkgx { let (stdout_tx, stdout_rx): (Sender, Receiver) = mpsc::channel(); let (stderr_tx, stderr_rx): (Sender, Receiver) = 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()) @@ -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()) diff --git a/fixtures/flox.graphql b/fixtures/flox.graphql index 1b3301a..8621570 100644 --- a/fixtures/flox.graphql +++ b/fixtures/flox.graphql @@ -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 } diff --git a/fixtures/pkgx.graphql b/fixtures/pkgx.graphql new file mode 100644 index 0000000..b671381 --- /dev/null +++ b/fixtures/pkgx.graphql @@ -0,0 +1,14 @@ +query Pkgx { + pipeline(name: "Demo") { + pkgx { + withWorkDir(path: "./pkgx-demo") { + withExec(args: ["pkgx", "--version"]) { + withExec(args: ["which", "deno"]) { + id + stdout + } + } + } + } + } +}