Skip to content
Closed
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
10 changes: 10 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ pub fn ensure_root() -> eyre::Result<()> {
env_list.push("NIX_INSTALLER_CI=1".to_string());
}

// Record the current user's UID so that we can run the self-tests as this user.
// This works around issues where root users have a shell profile / config file that e.g.
// runs `mesg n` (which changes the permissions of `/dev/tty` and prevents SSH from doing
// certain things), as happens with Ubuntu 24.04.
// https://github.com/DeterminateSystems/nix-installer/issues/1412
env_list.push(format!(
"NIX_INSTALLER_CURRENT_UID={}",
nix::unistd::Uid::current()
));

if !env_list.is_empty() {
arg_vec_cstring
.push(CString::new("env").wrap_err("Building a `env` argument for `sudo`")?);
Expand Down
19 changes: 13 additions & 6 deletions src/self_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,24 @@ impl Shell {
#[tracing::instrument(skip_all)]
pub async fn self_test(&self) -> Result<(), SelfTestError> {
let executable = self.executable();
let mut command = match &self {
// On Mac, `bash -ic nix` won't work, but `bash -lc nix` will.

let mut command = if let Ok(uid) = std::env::var("NIX_INSTALLER_CURRENT_UID") {
let mut command = Command::new("sudo");
command.arg("-u");
command.arg(format!("#{uid}"));
command.arg(executable);
command
} else {
Command::new(executable)
};

match &self {
// On macOS and Ubuntu (at least), `bash -ic nix` won't work, but `bash -lc nix` will.
Shell::Sh | Shell::Bash => {
let mut command = Command::new(executable);
command.arg("-lc");
command
},
Shell::Zsh | Shell::Fish => {
let mut command = Command::new(executable);
command.arg("-ic");
command
},
};

Expand Down
Loading