File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed
Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,16 @@ pub fn ensure_root() -> eyre::Result<()> {
133133 env_list. push ( "NIX_INSTALLER_CI=1" . to_string ( ) ) ;
134134 }
135135
136+ // Record the current user's UID so that we can run the self-tests as this user.
137+ // This works around issues where root users have a shell profile / config file that e.g.
138+ // runs `mesg n` (which changes the permissions of `/dev/tty` and prevents SSH from doing
139+ // certain things), as happens with Ubuntu 24.04.
140+ // https://github.com/DeterminateSystems/nix-installer/issues/1412
141+ env_list. push ( format ! (
142+ "NIX_INSTALLER_CURRENT_UID={}" ,
143+ nix:: unistd:: Uid :: current( )
144+ ) ) ;
145+
136146 if !env_list. is_empty ( ) {
137147 arg_vec_cstring
138148 . push ( CString :: new ( "env" ) . wrap_err ( "Building a `env` argument for `sudo`" ) ?) ;
Original file line number Diff line number Diff line change @@ -77,17 +77,24 @@ impl Shell {
7777 #[ tracing:: instrument( skip_all) ]
7878 pub async fn self_test ( & self ) -> Result < ( ) , SelfTestError > {
7979 let executable = self . executable ( ) ;
80- let mut command = match & self {
81- // On Mac, `bash -ic nix` won't work, but `bash -lc nix` will.
80+
81+ let mut command = if let Ok ( uid) = std:: env:: var ( "NIX_INSTALLER_CURRENT_UID" ) {
82+ let mut command = Command :: new ( "sudo" ) ;
83+ command. arg ( "-u" ) ;
84+ command. arg ( format ! ( "#{uid}" ) ) ;
85+ command. arg ( executable) ;
86+ command
87+ } else {
88+ Command :: new ( executable)
89+ } ;
90+
91+ match & self {
92+ // On macOS and Ubuntu (at least), `bash -ic nix` won't work, but `bash -lc nix` will.
8293 Shell :: Sh | Shell :: Bash => {
83- let mut command = Command :: new ( executable) ;
8494 command. arg ( "-lc" ) ;
85- command
8695 } ,
8796 Shell :: Zsh | Shell :: Fish => {
88- let mut command = Command :: new ( executable) ;
8997 command. arg ( "-ic" ) ;
90- command
9198 } ,
9299 } ;
93100
You can’t perform that action at this time.
0 commit comments