Skip to content

Commit

Permalink
Repair is_ci handling, sudo was erasing the variables (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoverbear authored Feb 24, 2023
1 parent db329ea commit 3fc5857
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn ensure_root() -> eyre::Result<()> {
let mut arg_vec_cstring = vec![];
arg_vec_cstring.push(sudo_cstring.clone());

let mut preserve_env_list = vec![];
let mut env_list = vec![];
for (key, value) in std::env::vars() {
let preserve = match key.as_str() {
// Rust logging/backtrace bits we use
Expand All @@ -112,14 +112,21 @@ pub fn ensure_root() -> eyre::Result<()> {
_ => false,
};
if preserve {
preserve_env_list.push(format!("{key}={value}"));
env_list.push(format!("{key}={value}"));
}
}

if !preserve_env_list.is_empty() {
#[cfg(feature = "diagnostics")]
if is_ci::cached() {
// Normally `sudo` would erase those envs, so we detect and pass that along specifically to avoid having to pass around
// a bunch of environment variables
env_list.push(format!("NIX_INSTALLER_CI=1"));
}

if !env_list.is_empty() {
arg_vec_cstring
.push(CString::new("env").wrap_err("Building a `env` argument for `sudo`")?);
for env in preserve_env_list {
for env in env_list {
arg_vec_cstring.push(
CString::new(env.clone())
.wrap_err_with(|| format!("Building a `{}` argument for `sudo`", env))?,
Expand Down
3 changes: 2 additions & 1 deletion src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ impl DiagnosticData {
Ok(os_release) => (os_release.name, os_release.version),
Err(_) => ("unknown".into(), "unknown".into()),
};
let is_ci = is_ci::cached();
let is_ci = is_ci::cached()
|| std::env::var("NIX_INSTALLER_CI").unwrap_or_else(|_| "0".into()) == "1";
Self {
endpoint,
version: env!("CARGO_PKG_VERSION").into(),
Expand Down

0 comments on commit 3fc5857

Please sign in to comment.