Skip to content

nix-shell as root cd's to / #6083

@dermetfan

Description

@dermetfan

Describe the bug

Running nix-shell or nix develop or nix shell as root drops you into / instead of staying in the current directory.

Steps To Reproduce

nix shell example

sudo nix shell nixpkgs#hello

nix-shell example

# shell.nix
with import <nixpkgs> {};
mkShell {}
sudo nix-shell

nix develop example

# flake.nix
{
  outputs = { nixpkgs, ... }: {
    devShell.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.mkShell {};
  };
}
sudo nix develop

Expected behavior

Drops you into a shell in the current directory.

Additional context

nix (Nix) 2.7.0pre20220210_5b809f9

First noticed on 52f5231.

We worked around it for now using env -C "$PWD".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions