Skip to content

Emacs tramp failed with /sudo:: #644

Description

@shrubbroom

Bug description

The emacs would failed to use tramp with /sudo::. For example, invoking find-file with the following path would result in emacs hang

/sudo::/etc/nixos/configurations.nix

The reason for this bug is believed that the /bin/sh (tramp-default-remote-shell in emacs) does not pick the environment variables set by tramp. Feasible solution is to use dash as the remote shell.

I do not have access to NixOS other than WSL. Therefore the bug is reported to the repository with the environment that the bug can be reproduced. It would be kind of you to investigate if it is a NixOS bug and report to upstream.

Related upstreams bugs is NixOS/nixpkgs#3368 .

To Reproduce

Steps to reproduce the behavior:
The following configuration.nix and flake.nix could be used to produce the require environment

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
    nixos-wsl.url = "github:nix-community/NixOS-WSL/main";
  };

  outputs = { self, nixpkgs, nixos-wsl, ... }: {
    nixosConfigurations = {
      win1729 = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          nixos-wsl.nixosModules.default
          {
            system.stateVersion = "24.11";
            wsl.enable = true;
          }
        ];
      };
    };
  };
}
{ config, lib, pkgs, ... }:

{
  environment.systemPackages = with pkgs; [
    emacs
  ];
}

Then, in emacs

(find-file "/sudo::/etc/nixos/configurations.nix")

Logs

The logs can be produced with

(setq tramp-verbose 10)

The cirtical part is shown as follows

tramp-send-string (10) # exec env TERM='dumb' INSIDE_EMACS='30.1,tramp:2.7.1.30.1' ENV='' HISTFILE=~/.tramp_history PROMPT_COMMAND='' PS1=///6beec2b2cfc620b1fa8ce64df44c5eca\#\$ PS2='' PS3='' /bin/sh  -i

The PS1 is not picked by /bin/sh, which results in wrong prompt after sudo

sh-5.2#

WSL version

WSL Version: 2.4.12.0
Kernel Version: 5.15.167.4-1
WSLg Version: 1.0.65
MSRDC Version: 1.2.5716
Direct3D Version: 1.611.1-81528511
DXCore Version: 10.0.26100.1-240331-1435.ge-release
Windows Version: 10.0.26100.3476

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions