NixOS-WSL icon indicating copy to clipboard operation
NixOS-WSL copied to clipboard

nu shell (nushell) with no PATH set on nixos-wsl

Open qknight opened this issue 1 year ago • 13 comments

Using nushell as default shell results in PATH not being set correctly so totally unusable.

Using: 23.11.2413.32f63574c85f (Tapir)

users = {
  defaultUserShell= pkgs.nushell;
};

In case you need to revert the changes, the binaries are here:

  • /run/current-system/sw/bin/vim
  • /run/wrappers/bin/sudo /run/wrappers/bin/su
  • /run/current-system/sw/bin/nixos-rebuild switch

nix-shell -p nushell

using 'nu' from the bash shell works.

qknight avatar Jan 12 '24 00:01 qknight

This is also not supported in NixOS (https://github.com/NixOS/nixpkgs/issues/193880) so likely a NixOS problem.

Also as this is not recommended upstream, I would blame them for not providing a posix compliant shell.

SuperSandro2000 avatar Jan 12 '24 10:01 SuperSandro2000

This works on nixos but not on nixos-wsl.

qknight avatar Jan 12 '24 16:01 qknight

Hello @qknight , I did as you said but in my system, the path is set and so all the programs work, here is my system metadata:

$ nix-shell -p nix-info --run "nix-info -m"

 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.133.1-microsoft-standard-WSL2, NixOS, 24.05 (Uakari), 24.05.20240210.d934204`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"home-manager, nixos-23.11, nixos-wsl"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Here is the PATH in nushel:

╭────┬──────────────────────────────────────────────────────────────────────────────────────────────────╮
│  0 │ /run/wrappers/bin                                                                                │
│  1 │ /home/aikoo7/.nix-profile/bin                                                                    │
│  2 │ /nix/profile/bin                                                                                 │
│  3 │ /home/aikoo7/.local/state/nix/profile/bin                                                        │
│  4 │ /etc/profiles/per-user/aikoo7/bin                                                                │
│  5 │ /nix/var/nix/profiles/default/bin                                                                │
│  6 │ /run/current-system/sw/bin                                                                       │
│  7 │ /mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminalPreview_1.18.1462.0_x64__8wekyb3d8bbwe │
│  8 │ /mnt/c/Program Files (x86)/gnupg/bin                                                             │
│  9 │ /mnt/c/Program Files (x86)/VMware/VMware Workstation/bin/                                        │
│ 10 │ /mnt/c/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/um                               │
│ 11 │ /mnt/c/Program Files/Alacritty/                                                                  │
│ 12 │ /mnt/c/Program Files/CryFS/0.11.4/bin                                                            │
│ 13 │ /mnt/c/Users/Computador/AppData/Local/Programs/VSCodium/bin                                      │
│ 14 │ /mnt/c/Users/Computador/AppData/Roaming/minisign                                                 │
│ 15 │ /mnt/c/msys64/mingw64/bin                                                                        │
│ 16 │ /mnt/c/Ninja                                                                                     │
│ 17 │ /mnt/c/Users/Computador/Documents/rclone-v1.63.1-windows-amd64                                   │
│ 18 │ /mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common                                       │
│ 19 │ /mnt/c/Program Files/Common Files/Oracle/Java/javapath                                           │
│ 20 │ /mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath                                     │
│ 21 │ /mnt/c/ProgramData/Oracle/Java/javapath                                                          │
│ 22 │ /mnt/c/WINDOWS/system32                                                                          │
│ 23 │ /mnt/c/WINDOWS                                                                                   │
│ 24 │ /mnt/c/WINDOWS/System32/Wbem                                                                     │
│ 25 │ /mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/                                                  │
│ 26 │ /mnt/c/WINDOWS/System32/OpenSSH/                                                                 │
│ 27 │ /mnt/c/ProgramData/chocolatey/bin                                                                │
│ 28 │ /mnt/c/ProgramData/chocolatey/lib/mpv.install/tools                                              │
│ 29 │ /mnt/c/Program Files/Git/cmd                                                                     │
│ 30 │ /mnt/c/Program Files/dotnet/                                                                     │
│ 31 │ /mnt/c/Users/Computador/.dotnet/tools                                                            │
│ 32 │ /mnt/c/Program Files (x86)/dotnet/                                                               │
│ 33 │ /mnt/c/Users/Computador/AppData/Local/Microsoft/WindowsApps                                      │
│ 34 │ /mnt/c/Users/Computador/AppData/Local/Keybase/                                                   │
│ 35 │ /mnt/c/adb                                                                                       │
│ 36 │ /mnt/c/Program Files/Go/bin                                                                      │
│ 37 │ /mnt/c/Program Files/CMake/bin                                                                   │
│ 38 │ /mnt/c/HashiCorp/Vagrant/bin                                                                     │
│ 39 │ /mnt/c/Program Files (x86)/FAHClient                                                             │
│ 40 │ /mnt/c/Program Files/GitHub CLI/                                                                 │
│ 41 │ /mnt/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/                          │
│ 42 │ /mnt/c/Strawberry/c/bin                                                                          │
│ 43 │ /mnt/c/Strawberry/perl/site/bin                                                                  │
│ 44 │ /mnt/c/Strawberry/perl/bin                                                                       │
│ 45 │ /mnt/c/Program Files/NASM                                                                        │
│ 46 │ /mnt/c/Program Files (x86)/Windows Kits/8.1/Windows Performance Toolkit/                         │
│ 47 │ /mnt/c/metasploit-framework/bin/                                                                 │
│ 48 │ /mnt/c/Program Files/PuTTY/                                                                      │
│ 49 │ /mnt/c/Program Files/Docker/Docker/resources/bin                                                 │
│ 50 │ /mnt/c/Program Files/WezTerm                                                                     │
│ 51 │ /mnt/c/Program Files/nodejs/                                                                     │
│ 52 │ /mnt/c/Program Files/PowerShell/7/                                                               │
│ 53 │ /mnt/c/Users/Computador/AppData/Local/pnpm                                                       │
│ 54 │ /mnt/c/Users/Computador/.cargo/bin                                                               │
│ 55 │ /mnt/c/Users/Computador/AppData/Local/Programs/Python/Python38/Scripts/                          │
│ 56 │ /mnt/c/Users/Computador/AppData/Local/Programs/Python/Python38/                                  │
│ 57 │ /mnt/c/Users/Computador/AppData/Local/Programs/Python/Python311/Scripts/                         │
│ 58 │ /mnt/c/Users/Computador/AppData/Local/Programs/Python/Python311/                                 │
│ 59 │ /mnt/c/Users/Computador/scoop/shims                                                              │
│ 60 │ /mnt/c/Users/Computador/AppData/Local/Programs/Microsoft VS Code/bin                             │
│ 61 │ /mnt/c/Users/Computador/AppData/Local/Programs/oh-my-posh/bin                                    │
│ 62 │ /mnt/c/Users/Computador/AppData/Local/spicetify                                                  │
│ 63 │ /mnt/c/Users/Computador/go/bin                                                                   │
│ 64 │ /mnt/c/Program Files/JetBrains/PyCharm Community Edition 2023.1.4/bin                            │
│ 65 │ /mnt/c/Users/Computador/AppData/Local/JetBrains/Toolbox/scripts                                  │
│ 66 │ /mnt/d/texlive/2023/bin/windows                                                                  │
│ 67 │ /mnt/c/Users/Computador/AppData/Local/Programs/Espanso                                           │
│ 68 │ /mnt/c/Users/Computador/Documents/evilginx                                                       │
│ 69 │ /mnt/c/Users/Computador/.aftman/bin                                                              │
│ 70 │ /mnt/c/Users/Computador/AppData/Roaming/npm                                                      │
│ 71 │ /mnt/c/Program Files/Neovim/bin                                                                  │
│ 72 │ /mnt/c/Users/Computador/AppData/Local/Pandoc/                                                    │
│ 73 │ /home/aikoo7/                                                                                    │
╰────┴──────────────────────────────────────────────────────────────────────────────────────────────────╯

And here is the PATH in zsh (my default shell):

/run/wrappers/bin:/home/aikoo7/.nix-profile/bin:/nix/profile/bin:/home/aikoo7/.local/state/nix/profile/bin:/etc/profiles/per-user/aikoo7/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminalPreview_1.18.1462.0_x64__8wekyb3d8bbwe:/mnt/c/Program Files (x86)/gnupg/bin:/mnt/c/Program Files (x86)/VMware/VMware Workstation/bin/:/mnt/c/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/um:/mnt/c/Program Files/Alacritty/:/mnt/c/Program Files/CryFS/0.11.4/bin:/mnt/c/Users/Computador/AppData/Local/Programs/VSCodium/bin:/mnt/c/Users/Computador/AppData/Roaming/minisign:/mnt/c/msys64/mingw64/bin:/mnt/c/Ninja:/mnt/c/Users/Computador/Documents/rclone-v1.63.1-windows-amd64:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/Common Files/Oracle/Java/javapath:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/ProgramData/Oracle/Java/javapath:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/ProgramData/chocolatey/lib/mpv.install/tools:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/dotnet/:/mnt/c/Users/Computador/.dotnet/tools:/mnt/c/Program Files (x86)/dotnet/:/mnt/c/Users/Computador/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/Computador/AppData/Local/Keybase/:/mnt/c/adb:/mnt/c/Program Files/Go/bin:/mnt/c/Program Files/CMake/bin:/mnt/c/HashiCorp/Vagrant/bin:/mnt/c/Program Files (x86)/FAHClient:/mnt/c/Program Files/GitHub CLI/:/mnt/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/:/mnt/c/Strawberry/c/bin:/mnt/c/Strawberry/perl/site/bin:/mnt/c/Strawberry/perl/bin:/mnt/c/Program Files/NASM:/mnt/c/Program Files (x86)/Windows Kits/8.1/Windows Performance Toolkit/:/mnt/c/metasploit-framework/bin/:/mnt/c/Program Files/PuTTY/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Program Files/WezTerm:/mnt/c/Program Files/nodejs/:/mnt/c/Program Files/PowerShell/7/:/mnt/c/Users/Computador/AppData/Local/pnpm:/mnt/c/Users/Computador/.cargo/bin:/mnt/c/Users/Computador/AppData/Local/Programs/Python/Python38/Scripts/:/mnt/c/Users/Computador/AppData/Local/Programs/Python/Python38/:/mnt/c/Users/Computador/AppData/Local/Programs/Python/Python311/Scripts/:/mnt/c/Users/Computador/AppData/Local/Programs/Python/Python311/:/mnt/c/Users/Computador/scoop/shims:/mnt/c/Users/Computador/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/Computador/AppData/Local/Programs/oh-my-posh/bin:/mnt/c/Users/Computador/AppData/Local/spicetify:/mnt/c/Users/Computador/go/bin:/mnt/c/Program Files/JetBrains/PyCharm Community Edition 2023.1.4/bin:/mnt/c/Users/Computador/AppData/Local/JetBrains/Toolbox/scripts:/mnt/d/texlive/2023/bin/windows:/mnt/c/Users/Computador/AppData/Local/Programs/Espanso:/mnt/c/Users/Computador/Documents/evilginx:/mnt/c/Users/Computador/.aftman/bin:/mnt/c/Users/Computador/AppData/Roaming/npm:/mnt/c/Program Files/Neovim/bin:/mnt/c/Users/Computador/AppData/Local/Pandoc/::/home/aikoo7/.zsh/plugins/powerlevel10k:/home/aikoo7/.zsh/plugins/powerlevel10k-config:/home/aikoo7/.zsh/plugins/zsh-autosuggestions

They are different, but I didn't find any issues in clang and nvim. Can you tell us what programs you had a problem with?

aikooo7 avatar Feb 11 '24 21:02 aikooo7

@aikooo7 you mentioned that you disabled native systemd in #305. Given that nushell isn't broken in the tests (which can't use native systemd, because they run in an emulated wsl environment) i'm pretty sure that this is the reason, why the environment variables show up for you

nzbr avatar Feb 12 '24 02:02 nzbr

@aikooo7 you mentioned that you disabled native systemd in #305. Given that nushell isn't broken in the tests (which can't use native systemd, because they run in an emulated wsl environment) i'm pretty sure that this is the reason, why the environment variables show up for you

I will test it even when I have time, but if it is indeed because of native systemd then we should start make a list of what is broken because of it

aikooo7 avatar Feb 12 '24 04:02 aikooo7

i think i can confirm the use of native systemd is at fault here. for reference, here is my path when wsl.nativeSystemd is false

╭───┬─────────────────────────────────────────╮
│ 0 │ /run/wrappers/bin                       │
│ 1 │ /home/seth/.nix-profile/bin             │
│ 2 │ /nix/profile/bin                        │
│ 3 │ /home/seth/.local/state/nix/profile/bin │
│ 4 │ /etc/profiles/per-user/seth/bin         │
│ 5 │ /nix/var/nix/profiles/default/bin       │
│ 6 │ /run/current-system/sw/bin              │
╰───┴─────────────────────────────────────────╯

and true

╭────┬─────────────────────────────────────────────────────────────────╮
│  0 │ /usr/local/sbin                                                 │
│  1 │ /usr/local/bin                                                  │
│  2 │ /usr/sbin                                                       │
│  3 │ /usr/bin                                                        │
│  4 │ /sbin                                                           │
│  5 │ /bin                                                            │
│  6 │ /usr/games                                                      │
│  7 │ /usr/local/games                                                │
│  8 │ /usr/lib/wsl/lib                                                │
│  9 │ /mnt/c/WINDOWS/system32                                         │
│ 10 │ /mnt/c/WINDOWS                                                  │
│ 11 │ /mnt/c/WINDOWS/System32/Wbem                                    │
│ 12 │ /mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/                 │
│ 13 │ /mnt/c/WINDOWS/System32/OpenSSH/                                │
│ 14 │ /mnt/c/Program Files/Tailscale/                                 │
│ 15 │ /mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common      │
│ 16 │ /mnt/c/Program Files/PowerShell/7/                              │
│ 17 │ /mnt/c/Program Files/dotnet/                                    │
│ 18 │ /mnt/c/Program Files/Mullvad VPN/resources                      │
│ 19 │ /mnt/c/Users/setha/scoop/apps/gpg/current/bin                   │
│ 20 │ /mnt/c/Users/setha/scoop/apps/temurin8-jdk/current/bin          │
│ 21 │ /mnt/c/Users/setha/scoop/apps/temurin17-jdk/current/bin         │
│ 22 │ /mnt/c/Users/setha/scoop/apps/rustup-msvc/current/.cargo/bin    │
│ 23 │ /mnt/c/Users/setha/scoop/shims                                  │
│ 24 │ /mnt/c/Users/setha/AppData/Local/Microsoft/WindowsApps          │
│ 25 │ /mnt/c/Users/setha/AppData/Local/Programs                       │
│ 26 │ /mnt/c/Users/setha/AppData/Local/Programs/Microsoft VS Code/bin │
│ 27 │ /mnt/c/Users/setha/AppData/Local/JetBrains/Toolbox/scripts      │
│ 28 │ /mnt/c/Users/setha/AppData/Local/Microsoft/WindowsApps          │
╰────┴─────────────────────────────────────────────────────────────────╯

and here is the full config i'm using for the module

{
  wsl = {
    enable = true;
    defaultUser = "seth";
    nativeSystemd = true;
    wslConf.network = {
      hostname = "glados-wsl";
      generateResolvConf = true;
    };
    startMenuLaunchers = false;
    interop.includePath = false;
  };
}

if you haven't noticed yet, wsl.interop.includePath is also ignored when nativeSystemd is true - maybe there's a correlation here?

here's my nix-info output just in case it's needed. nixos-wsl is at c8ddba82ca6b791be1acaae4b336ff8e857ec70b

nix-info -m
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.133.1-microsoft-standard-WSL2, NixOS, 24.05 (Uakari), 24.05.20240216.5863c27`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/etc/nix/inputs/nixpkgs`

getchoo avatar Feb 18 '24 07:02 getchoo

+1 Tested on my current install of nixos-wsl and can confirm @getchoo's comment above. wsl.nativeSystemd.enable = true causes nix related paths to not be added to $env.PATH when using nushell as the default user shell.

lychronicity avatar Feb 18 '24 22:02 lychronicity

I looked into this a bit. In syschdemd, we explicitly sourced /etc/set-environment before starting the shell. With native systemd, we can't do that, because the code that starts the shell comes from microsoft

nzbr avatar Feb 19 '24 20:02 nzbr

I can't find any nushell related options on search.nixos.org. Does nushell work correctly on bare-metal NixOS?

nzbr avatar Feb 19 '24 21:02 nzbr

@nzbr, Just tested this with a fresh NixOS VM (not exactly "bare-metal" but it's as close as I can get with what hardware I've got :P ); anyway, happy to report that nushell behaves as expected on your normal NixOS install, so it looks like this is specifically linked to NixOS-WSL weirdness.

Edit: Probably helps if I mention the config... From the clean install, all I added to the configuration.nix was simply users.users.my-user.shell = pkgs.nushell;

lychronicity avatar Feb 19 '24 23:02 lychronicity

@nzbr, Just tested this with a fresh NixOS VM (not exactly "bare-metal" but it's as close as I can get with what hardware I've got :P ); anyway, happy to report that nushell behaves as expected on your normal NixOS install, so it looks like this is specifically linked to NixOS-WSL weirdness.

Edit: Probably helps if I mention the config... From the clean install, all I added to the configuration.nix was simply users.users.my-user.shell = pkgs.nushell;

For what I see this yet again confirms this might be another native wsl systemd

aikooo7 avatar Feb 24 '24 18:02 aikooo7

@nzbr, Just tested this with a fresh NixOS VM (not exactly "bare-metal" but it's as close as I can get with what hardware I've got :P ); anyway, happy to report that nushell behaves as expected on your normal NixOS install, so it looks like this is specifically linked to NixOS-WSL weirdness.

Edit: Probably helps if I mention the config... From the clean install, all I added to the configuration.nix was simply users.users.my-user.shell = pkgs.nushell;

For what I see this yet again confirms this might be another native wsl systemd problem

aikooo7 avatar Feb 24 '24 18:02 aikooo7

@nzbr, Just tested this with a fresh NixOS VM (not exactly "bare-metal" but it's as close as I can get with what hardware I've got :P ); anyway, happy to report that nushell behaves as expected on your normal NixOS install, so it looks like this is specifically linked to NixOS-WSL weirdness.

Edit: Probably helps if I mention the config... From the clean install, all I added to the configuration.nix was simply users.users.my-user.shell = pkgs.nushell;

For what I see this yet again confirms this might be another native wsl systemd problem

aikooo7 avatar Feb 24 '24 18:02 aikooo7

I had a similar problem using zsh as the default user shell.

pkg-config was not finding libxml-2.0 (from pkgs.libxml2) in the PKG_CONFIG_PATH, i.e. pkg-config --libs libxml-2.0 was returning not found.

At the same time, running nix-shell -p libxml2 pkg-config --run 'pkg-config --libs libxml-2.0' was working (makes no sense to me lol).

Then I noticed that PKG_CONFIG_PATH was empty in the WSL shell, while being correctly set in the nix-shell call.

To fix this, I had to manually add the env initialization to my dotfiles (commit).

This issue only occurred in WSL. On NixOS everything was working fine.

mqzabin avatar Mar 12 '24 19:03 mqzabin

Finally got around to testing the changes introduced in #452, and I can confirm that it has resolved the nushell PATH issue.

nushell environment variables are now correctly set when using nushell as the user's default shell with wsl.nativeSystemd = true;

Thanks for looking into this and for your hard work here, @nzbr! ❤️

lychronicity avatar May 06 '24 19:05 lychronicity