nushell / nushell

A new type of shell
https://www.nushell.sh/
MIT License
32.03k stars 1.65k forks source link

NU_PLUGIN_DIRS not working #13040

Closed j-xella closed 3 weeks ago

j-xella commented 4 months ago

Describe the bug

It seems that the latest version of nu shell ignores NU_PLUGIN_DIRS variable

How to reproduce

# There are 2 folders in NU_PLUGIN_DIRS
~/linux/local/stow> $env.NU_PLUGIN_DIRS                                                                       03/06/24 16:14:54
╭───┬─────────────────────────────────────────────╮
│ 0 │ /users/XXXXX/.config/nushell/plugins      │
│ 1 │ /users/XXXXX/linux/local/share/nu/plugins │
╰───┴─────────────────────────────────────────────╯

# And one of them contains plugins
~/linux/local/stow> ls ...($env.NU_PLUGIN_DIRS)                                                               03/06/24 16:14:57
╭───────┬────────────────────────────────────────────────────────────────────────────┬─────────┬──────────────┬───────────────╮
│     # │                                    name                                    │  type   │     size     │   modified    │
├───────┼────────────────────────────────────────────────────────────────────────────┼─────────┼──────────────┼───────────────┤
│     0 │ /users/XXXXX/linux/local/share/nu/plugins/nu_plugin_custom_values        │ file    │      9.0 MiB │ 3 days ago    │
│     1 │ /users/XXXXX/linux/local/share/nu/plugins/nu_plugin_example              │ file    │      5.7 MiB │ 3 days ago    │
│     2 │ /users/XXXXX/linux/local/share/nu/plugins/nu_plugin_formats              │ file    │      7.9 MiB │ 3 days ago    │
│     3 │ /users/XXXXX/linux/local/share/nu/plugins/nu_plugin_gstat                │ file    │     10.8 MiB │ 3 days ago    │
│     4 │ /users/XXXXX/linux/local/share/nu/plugins/nu_plugin_inc                  │ file    │      3.7 MiB │ 3 days ago    │
│     5 │ /users/XXXXX/linux/local/share/nu/plugins/nu_plugin_polars               │ file    │     55.8 MiB │ 3 days ago    │
│     6 │ /users/XXXXX/linux/local/share/nu/plugins/nu_plugin_query                │ file    │      6.5 MiB │ 3 days ago    │
│     7 │ /users/XXXXX/linux/local/share/nu/plugins/nu_plugin_stress_internals     │ file    │    745.6 KiB │ 3 days ago    │
╰───────┴────────────────────────────────────────────────────────────────────────────┴─────────┴──────────────┴───────────────╯

~/linux/local/stow> plugin list                                                                               03/06/24 16:15:03
╭────┬─────────┬────────────┬─────┬─────────────────────────────────────────────────────────────────────────────┬───────┬─────╮
│  # │  name   │ is_running │ pid │                                  filename                                   │ shell │ ... │
├────┼─────────┼────────────┼─────┼─────────────────────────────────────────────────────────────────────────────┼───────┼─────┤
│  0 │ polars  │ false      │     │ /users/XXXXX/linux/local/stow/nu-0.94.1/share/nu/plugins/nu_plugin_polars │       │ ... │
│  1 │ query   │ false      │     │ /users/XXXXX/linux/local/stow/nu-0.94.1/share/nu/plugins/nu_plugin_query  │       │ ... │
╰────┴─────────┴────────────┴─────┴─────────────────────────────────────────────────────────────────────────────┴───────┴─────╯

# However, adding a plugin with just a file name fails
~/linux/local/stow> plugin add nu_plugin_gstat                                                                03/06/24 16:15:15
Error: nu::shell::io_error

  × I/O error
   ╭─[entry #23:1:12]
 1 │ plugin add nu_plugin_gstat
   ·            ───────┬───────
   ·                   ╰── No such file or directory (os error 2)
   ╰────

Expected behavior

As per documentation:

Run the nu_plugin_gstat plugin from the current directory or $env.NU_PLUGIN_DIRS and install its signatures.

Screenshots

No response

Configuration

~/linux/local/stow> sys host                            1 03/06/24 16:16:10
╭─────────────────┬───────────────────────────────────────────╮
│ name            │ Red Hat Enterprise Linux Server           │
│ os_version      │ 7.9                                       │
│ long_os_version │ Linux 7.9 Red Hat Enterprise Linux Server │
│ kernel_version  │ 3.10.0-1160.81.1.el7.x86_64               │

~/linux/local/stow> version                                                                                   03/06/24 16:14:51
╭────────────────────┬──────────────────────────────────────────────────────────────────────╮
│ version            │ 0.94.1                                                               │
│ major              │ 0                                                                    │
│ minor              │ 94                                                                   │
│ patch              │ 1                                                                    │
│ branch             │                                                                      │
│ commit_hash        │ f3cf693ec701ab3086f984a8aeadfc9b50fadd90                             │
│ build_os           │ linux-x86_64                                                         │
│ build_target       │ x86_64-unknown-linux-musl                                            │
│ rust_version       │ rustc 1.77.2 (25ef9e3d8 2024-04-09)                                  │
│ rust_channel       │ 1.77.2-x86_64-unknown-linux-gnu                                      │
│ cargo_version      │ cargo 1.77.2 (e52e36006 2024-03-26)                                  │
│ build_time         │ 2024-05-30 23:10:19 +00:00                                           │
│ build_rust_channel │ release                                                              │
│ allocator          │ mimalloc                                                             │
│ features           │ default, sqlite, static-link-openssl, system-clipboard, trash, which │
│ installed_plugins  │ polars, query                                                        │
╰────────────────────┴──────────────────────────────────────────────────────────────────────╯

Additional context

No response

fdncred commented 4 months ago

I don't use plugins this way and don't use NU_PLUGIN_DIRS at all. I always keep the plugins in ~/.cargo/bin regardless of operating system and since ~/.cargo/bin is in my path they are easily found and plugin add/rm work fine.

Kissaki commented 4 months ago

I can reproduce this with 0.94.2 and no additional $env.NU_PLUGIN_DIRS dir values.

  1. Copy bin\nu_plugin_gstat.exe into Roaming\nushell\plugins\
  2. Run plugin add nu_plugin_qstat

The trace says found but then errors with not found.

> nu -c '$env.NU_PLUGIN_DIRS'                                                                                                                        took 4s
╭───┬──────────────────────────────────────────────╮
│ 0 │ C:\Users\<redacted>\AppData\Roaming\nushell\plugins │
╰───┴──────────────────────────────────────────────╯
> nu --log-level trace -c 'plugin add nu_plugin_qstat'
2024-06-05 12:16:26.977 PM [TRACE] nu_parser::parser: [crates\nu-parser\src\parser.rs:2214] -- found nu_plugin_qstat
Error: nu::shell::io_error

  × I/O error
   ╭─[source:1:12]
 1 │ plugin add nu_plugin_qstat
   ·            ───────┬───────
   ·                   ╰── The system cannot find the file specified. (os error 2)
   ╰────

Did this work before, until now? I have not been using official or plugin-dir plugins until now.

Commit d717e8faeb5a7e842b47de20fe573ba05a628f26 changed the default env.nu (in file version 0.87.2)

Dropping

# FIXME: This default is not implemented in rust code as of 2023-09-06.
Kissaki commented 4 months ago

The trace says found even if no such plugin file exists

> nu --log-level trace -c 'plugin add nu_plugin_qstatss' 
2024-06-05 12:28:46.429 PM [TRACE] nu_parser::parser: [crates\nu-parser\src\parser.rs:2214] -- found nu_plugin_qstatss
Error: nu::shell::io_error

  × I/O error
   ╭─[source:1:12]
 1 │ plugin add nu_plugin_qstatss
   ·            ────────┬────────
   ·                    ╰── The system cannot find the file specified. (os error 2)
   ╰────
fdncred commented 4 months ago

/cc @devyn for his thoughts

ArmoredPony commented 1 month ago

I have my .\cargo\bin folder in both PATH and NU_PLUGIN_DIRS. The plugin is installed via cargo install and work fine if I supply the absolute path to plugin add. However, without path, the command returns os error 2. I also have to supply the .exe extension since I'm on Windows.

The outcome remains same when I try to load my plugin from Roaming\nushell\plugins, but when I run nushell with --log-level trace, I also get this ...\nu-parser-0.98.0\src\parser.rs:2391] -- found nu_plugin_... message.

fdncred commented 1 month ago

I've never tried plugin add file. I've always provided the full path to the plugin file, with the extension.

I tried and it doesn't work for me either. nu_plugin_polars is in ~/.cargo/bin already. Seems like a bug.

❯ $env.NU_PLUGIN_DIRS
╭───┬────────────────────────────────────────────────────────────╮
│ 0 │ /Users/fdncred/Library/Application Support/nushell/plugins │
│ 1 │ /Users/fdncred/.cargo/bin                                  │
╰───┴────────────────────────────────────────────────────────────╯
❯ plugin add nu_plugin_polars
Error: nu::shell::io_error

  × I/O error
   ╭─[entry #2:1:12]
 1 │ plugin add nu_plugin_polars
   ·            ────────┬───────
   ·                    ╰── No such file or directory (os error 2)
   ╰────
fdncred commented 1 month ago

The problem is that locate_in_dirs() is not finding the plugin. https://github.com/nushell/nushell/blob/6e1e824473e15eba246e1c43704c5d88fa237a17/crates/nu-cmd-plugin/src/commands/plugin/add.rs#L87-L90

fdncred commented 1 month ago

I think I fixed it https://github.com/nushell/nushell/pull/13877