Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair is_ci handling, sudo was erasing the variables #274

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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