Keep PATH when running nix commands

The documentation of std::process::Command mentions that setting PATH on
the command itself will influence the search path lookup. This seems to
interact differently with clear_env depending on the platform.

Fixes "No such file or directory" error on darwin.
This commit is contained in:
Daiderd Jordan 2018-02-02 22:38:51 +01:00
parent e62a62c9a6
commit 7659f4f85a
No known key found for this signature in database
GPG key ID: D02435D05B810C96
2 changed files with 45 additions and 3 deletions

View file

@ -1,10 +1,11 @@
use std::path::Path;
use std::env;
use std::ffi::OsString;
use std::process::{Command, Stdio};
use tempfile::tempfile;
use std::fs::File;
use std::io::Seek;
use std::io::SeekFrom;
use std::path::Path;
use std::process::{Command, Stdio};
use tempfile::tempfile;
#[derive(Clone, Debug, PartialEq)]
pub struct Nix {
@ -130,6 +131,10 @@ impl Nix {
command.env("HOME", "/homeless-shelter");
command.env("NIX_PATH", nixpath);
command.env("NIX_REMOTE", &self.remote);
let path = env::var("PATH").unwrap();
command.env("PATH", path);
command.args(&["--show-trace"]);
command.args(&["--option", "restrict-eval", "true"]);
command.args(
@ -268,6 +273,40 @@ mod tests {
use std::path::PathBuf;
use std::env;
#[test]
fn safe_command_environment() {
let nix = nix();
let ret: Result<File, File> = nix.run(nix.safe_command(
"./environment.sh",
build_path().as_path(),
vec![],
), true);
assert_run(
ret,
Expect::Pass,
vec!["HOME=/homeless-shelter", "NIX_PATH=nixpkgs=", "NIX_REMOTE=", "PATH="],
);
}
#[test]
fn safe_command_options() {
let nix = nix();
let ret: Result<File, File> = nix.run(nix.safe_command(
"echo",
build_path().as_path(),
vec![],
), true);
assert_run(
ret,
Expect::Pass,
vec!["--option restrict-eval true", "--option build-timeout 1800"],
);
}
#[test]
fn safely_build_attrs_success() {
let nix = nix();

View file

@ -0,0 +1,3 @@
#!/bin/sh
env