michaelb/sniprun

Improve shell scripts portability

davidsierradz opened this issue · 3 comments

Environment:

  • Neovim Nightly
  • NixOS

Additional context

Some shell scripts assume that the path /bin/bash exists, but that is not true on many systems, including the NixOS Linux distribution. As a result, we get the following error: bad interpreter: /bin/bash: no such file or directory

Could you please change that shebang path to use /usr/bin/env bash instead? Or maybe even /bin/sh, if the script works with any POSIX-compliant Bourne shell?

Scripts with /bin/bash shebang:

  • src/interpreters/Mathematica_original/init_repl.sh
  • src/interpreters/Mathematica_original/launcher.sh
  • src/interpreters/Julia_original/init_repl.sh
  • ressources/launcher_repl.sh
  • ressources/sync_repl.sh
  • ressources/init_repl.sh
  • doc/build.sh

Thanks!

Shebang (Unix) - Wikipedia

Hmm sure
(Doesn't nixvim already have patches for this? @GaetanLepage )

Will be part of the next release unless said otherwise, but I'd rather not create a new release just for this, so it may only come out in the coming months or so, depending on the bug reports or new features requests

(Doesn't nixvim already have patches for this? @GaetanLepage )

Indeed we are. The vimPlugins.sniprun package is patched so that it works fine on NixOS.
If you install the plugin using a traditional plugin manager (like lazy nvim), you will obviously not get those patches.

There are several ways of leveraging the vim plugins packaged in nixpkgs.

Thanks! I would like to keep using lazy.nvim for managing my neovim plugins. According to Introduction — Welcome to sniprun documentation, one can load the plugin and pass the binary path, I got the path from the sniprun-bin derivation and added it to the config (manually for now):

{
    'michaelb/sniprun',
    lazy = false,
    init = function()
      require('sniprun').setup({
        binary_path = '/nix/store/qk6cf20wfqx62y9asqlj0n34llqx3rzw-sniprun-bin-1.3.11/bin/sniprun',
        display = {
          'TerminalWithCode',
        },
        selected_interpreters = { 'JS_TS_deno' },
        repl_enable = { 'JS_TS_deno' },
        interpreter_options = {
          JS_TS_deno = {
            use_on_filetypes = { 'javascript' },
          },
        },
      })
    end,
  }

The healthcheck looks fine:

==============================================================================
sniprun: health#sniprun#check

Installation ~
- WARNING Rust toolchain not available
  - ADVICE:
    - [optionnal] Install the rust toolchain https://www.rust-lang.org/tools/install
- OK sniprun binary found at /nix/store/qk6cf20wfqx62y9asqlj0n34llqx3rzw-sniprun-bin-1.3.11/bin/sniprun
- OK Sent a ping to the sniprun binary
- OK sniprun binary runs correctly

When trying to run some code, in the logs:

tail: /home/neuromante/.cache/sniprun/sniprun.log: file truncated
[00:00:00.000] (7f657d70e7c0) INFO   [MAIN] SnipRun launched successfully
[00:00:00.000] (7f657d70e7c0) INFO   [MAIN] Start of main event loop
[00:00:00.000] (7f657d70e7c0) INFO   EVENT 1 RECEIVED ##################
[00:00:00.000] (7f657d70e7c0) INFO   [MAINLOOP] Run command received
[00:00:00.000] (7f657d70e7c0) INFO   [RUN] clone event handler
[00:00:00.000] (7f657ce006c0) INFO   [RUN] spawned thread
[00:00:00.000] (7f657ce006c0) INFO   [FILLDATA] got back eventual interpreter data
[00:00:00.000] (7f657ce006c0) INFO   values length: 4
[00:00:00.000] (7f657ce006c0) INFO   cli arguments are not a string: String(Utf8String { s: Ok("") })
[00:00:00.000] (7f657ce006c0) INFO   got data range: [1, 1]
[00:00:00.000] (7f657ce006c0) INFO   [FILLDATA] got sniprun root
[00:00:00.001] (7f657ce006c0) INFO   nvimcwd as value: nvim_cwd: String(Utf8String { s: Ok("/home/neuromante/nixos") })
[00:00:00.001] (7f657ce006c0) INFO   [FILLDATA] got neovim's current directory: /home/neuromante/nixos
[00:00:00.002] (7f657ce006c0) INFO   [FILLDATA] got filetype
[00:00:00.004] (7f657ce006c0) INFO   [FILLDATA] got current_line
[00:00:00.006] (7f657ce006c0) INFO   [FILLDATA] got current_bloc
[00:00:00.007] (7f657ce006c0) INFO   [FILLDATA] got filepath
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] got nvim_instance
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] got selected interpreters
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] got repl enabled interpreters
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] got repl disabled interpreters
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] display type found : Ok(TerminalWithCode(Both))
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] got display types
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] display type with 'no output'on found : Ok(Classic(Both))
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] display type with 'no output'on found : Ok(TempFloatingWindow(Both))
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] got show_no_output
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] got inline_messages setting
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] got neovim_pid value setting: 14149
[00:00:00.008] (7f657ce006c0) INFO   [FILLDATA] Done!
[00:00:00.008] (7f657ce006c0) INFO   [OVERRIDE] No data to override
[00:00:00.008] (7f657ce006c0) INFO   [RUN] filled dataholder
[00:00:00.008] (7f657ce006c0) INFO   [RUN] created launcher
[00:00:00.008] (7f657ce006c0) INFO   selecting an interpreter for filetype javascript
[00:00:00.008] (7f657ce006c0) INFO   considering interpreter JS_original ...
[00:00:00.008] (7f657ce006c0) INFO   considering interpreter JS_TS_deno ...
[00:00:00.008] (7f657ce006c0) INFO   considering interpreter JS_TS_bun ...
[00:00:00.009] (7f657ce006c0) INFO   key interpreter_options found
[00:00:00.009] (7f657ce006c0) INFO   key 'Generic' not found in interpreter option
[00:00:00.009] (7f657ce006c0) INFO   supported filetypes for generic are []
[00:00:00.009] (7f657ce006c0) INFO   selected JS_TS_deno
[00:00:00.009] (7f657ce006c0) INFO   [LAUNCHER] Selected interpreter: JS_TS_deno, at level Selected
[00:00:00.009] (7f657ce006c0) INFO   Checking cli-args: []
[00:00:00.009] (7f657ce006c0) INFO   REPL enabled
[00:00:00.009] (7f657ce006c0) INFO   reading previous code
[00:00:00.009] (7f657ce006c0) INFO   found interpreter_data
[00:00:00.009] (7f657ce006c0) INFO   launching kernel : "/home/neuromante/.local/share/nvim/lazy/sniprun/lua/../ressources/init_repl.sh" on "/home/neuromante/.cache/sniprun/js-ts_deno/14149"
[00:00:00.110] (7f657ce006c0) INFO   reading previous code
[00:00:00.110] (7f657ce006c0) INFO   found interpreter_data
[00:00:00.110] (7f657ce006c0) INFO   reading previous code
[00:00:00.110] (7f657ce006c0) INFO   found interpreter_data
[00:00:00.110] (7f657ce006c0) INFO   code saved:
kernel_launched

[00:00:00.110] (7f657ce006c0) INFO   [RUN] Interpreter return a result
[00:00:00.110] (7f657ce006c0) INFO   Display type chosen: [TerminalWithCode(Both)]
[00:00:00.110] (7f657ce006c0) INFO   message 'Deno kernel launched, re-run your snippet' cleaned out
[00:00:00.134] (7f657ce006c0) INFO   display terminal res = Ok(())


[00:00:07.054] (7f657d70e7c0) INFO   EVENT 2 RECEIVED ##################
[00:00:07.054] (7f657d70e7c0) INFO   [MAINLOOP] Run command received
[00:00:07.054] (7f657d70e7c0) INFO   [RUN] clone event handler
[00:00:07.054] (7f657ca006c0) INFO   [RUN] spawned thread
[00:00:07.054] (7f657ca006c0) INFO   [FILLDATA] got back eventual interpreter data
[00:00:07.054] (7f657ca006c0) INFO   values length: 4
[00:00:07.054] (7f657ca006c0) INFO   cli arguments are not a string: String(Utf8String { s: Ok("") })
[00:00:07.054] (7f657ca006c0) INFO   got data range: [1, 1]
[00:00:07.054] (7f657ca006c0) INFO   [FILLDATA] got sniprun root
[00:00:07.055] (7f657ca006c0) INFO   nvimcwd as value: nvim_cwd: String(Utf8String { s: Ok("/home/neuromante/nixos") })
[00:00:07.055] (7f657ca006c0) INFO   [FILLDATA] got neovim's current directory: /home/neuromante/nixos
[00:00:07.056] (7f657ca006c0) INFO   [FILLDATA] got filetype
[00:00:07.058] (7f657ca006c0) INFO   [FILLDATA] got current_line
[00:00:07.060] (7f657ca006c0) INFO   [FILLDATA] got current_bloc
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] got filepath
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] got nvim_instance
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] got selected interpreters
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] got repl enabled interpreters
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] got repl disabled interpreters
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] display type found : Ok(TerminalWithCode(Both))
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] got display types
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] display type with 'no output'on found : Ok(Classic(Both))
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] display type with 'no output'on found : Ok(TempFloatingWindow(Both))
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] got show_no_output
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] got inline_messages setting
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] got neovim_pid value setting: 14149
[00:00:07.061] (7f657ca006c0) INFO   [FILLDATA] Done!
[00:00:07.061] (7f657ca006c0) INFO   [OVERRIDE] No data to override
[00:00:07.061] (7f657ca006c0) INFO   [RUN] filled dataholder
[00:00:07.062] (7f657ca006c0) INFO   [RUN] created launcher
[00:00:07.062] (7f657ca006c0) INFO   selecting an interpreter for filetype javascript
[00:00:07.062] (7f657ca006c0) INFO   considering interpreter JS_original ...
[00:00:07.062] (7f657ca006c0) INFO   considering interpreter JS_TS_deno ...
[00:00:07.062] (7f657ca006c0) INFO   considering interpreter JS_TS_bun ...
[00:00:07.062] (7f657ca006c0) INFO   key interpreter_options found
[00:00:07.062] (7f657ca006c0) INFO   key 'Generic' not found in interpreter option
[00:00:07.062] (7f657ca006c0) INFO   supported filetypes for generic are []
[00:00:07.062] (7f657ca006c0) INFO   selected JS_TS_deno
[00:00:07.062] (7f657ca006c0) INFO   [LAUNCHER] Selected interpreter: JS_TS_deno, at level Selected
[00:00:07.062] (7f657ca006c0) INFO   Checking cli-args: []
[00:00:07.062] (7f657ca006c0) INFO   REPL enabled
[00:00:07.062] (7f657ca006c0) INFO   reading previous code
[00:00:07.062] (7f657ca006c0) INFO   found interpreter_data
[00:00:07.062] (7f657ca006c0) INFO   Deno kernel already running
[00:00:07.062] (7f657ca006c0) INFO   javascript/typescript self.code) = console.log(1)
[00:00:07.062] (7f657ca006c0) INFO   running launcher /home/neuromante/.local/share/nvim/lazy/sniprun/lua/../ressources/launcher_repl.sh
[00:00:07.062] (7f657ca006c0) INFO   cmd status: Err(Os { code: 2, kind: NotFound, message: "No such file or directory" })
[00:00:07.064] (7f657ca006c0) ERROR  thread '<unnamed>' panicked at 'could not run launcher: Os { code: 2, kind: NotFound, message: "No such file or directory" }': src/interpreters/JS_TS_deno.rs:352
   0: <backtrace::capture::Backtrace as core::default::Default>::default
   1: log_panics::Config::install_panic_hook::{{closure}}
   2: std::panicking::rust_panic_with_hook
   3: std::panicking::begin_panic_handler::{{closure}}
   4: std::sys_common::backtrace::__rust_end_short_backtrace
   5: rust_begin_unwind
   6: core::panicking::panic_fmt
   7: core::result::unwrap_failed
   8: <sniprun::interpreters::JS_TS_deno as sniprun::interpreter::ReplLikeInterpreter>::execute_repl
   9: sniprun::interpreter::Interpreter::run
  10: sniprun::launcher::Launcher::select_and_run
  11: std::sys_common::backtrace::__rust_begin_short_backtrace
  12: core::ops::function::FnOnce::call_once{{vtable.shim}}
  13: std::sys::unix::thread::Thread::new::thread_start
  14: start_thread
  15: __clone3

I have deno globally installed as well:

image

Maybe I'm doing something wrong?

Edit:

I understand better, Nix's buildVimPlugin is also patching all the shebangs as well:

image

I guess using /usr/bin/env bash would allow using upstream code with nix binary.

Edit:

Manually patching the shebangs in /home/neuromante/.local/share/nvim/lazy/sniprun/... indeed solves the issue:

[00:00:04.142] (7fc457f277c0) INFO   EVENT 2 RECEIVED ##################
[00:00:04.142] (7fc457f277c0) INFO   [MAINLOOP] Run command received
[00:00:04.143] (7fc457f277c0) INFO   [RUN] clone event handler
[00:00:04.143] (7fc4572006c0) INFO   [RUN] spawned thread
[00:00:04.144] (7fc4572006c0) INFO   [FILLDATA] got back eventual interpreter data
[00:00:04.144] (7fc4572006c0) INFO   values length: 4
[00:00:04.144] (7fc4572006c0) INFO   cli arguments are not a string: String(Utf8String { s: Ok("") })
[00:00:04.144] (7fc4572006c0) INFO   got data range: [1, 1]
[00:00:04.144] (7fc4572006c0) INFO   [FILLDATA] got sniprun root
[00:00:04.145] (7fc4572006c0) INFO   nvimcwd as value: nvim_cwd: String(Utf8String { s: Ok("/home/neuromante/nixos") })
[00:00:04.146] (7fc4572006c0) INFO   [FILLDATA] got neovim's current directory: /home/neuromante/nixos
[00:00:04.147] (7fc4572006c0) INFO   [FILLDATA] got filetype
[00:00:04.148] (7fc4572006c0) INFO   [FILLDATA] got current_line
[00:00:04.151] (7fc4572006c0) INFO   [FILLDATA] got current_bloc
[00:00:04.152] (7fc4572006c0) INFO   [FILLDATA] got filepath
[00:00:04.152] (7fc4572006c0) INFO   [FILLDATA] got nvim_instance
[00:00:04.152] (7fc4572006c0) INFO   [FILLDATA] got selected interpreters
[00:00:04.152] (7fc4572006c0) INFO   [FILLDATA] got repl enabled interpreters
[00:00:04.153] (7fc4572006c0) INFO   [FILLDATA] got repl disabled interpreters
[00:00:04.153] (7fc4572006c0) INFO   [FILLDATA] display type found : Ok(TerminalWithCode(Both))
[00:00:04.153] (7fc4572006c0) INFO   [FILLDATA] got display types
[00:00:04.153] (7fc4572006c0) INFO   [FILLDATA] display type with 'no output'on found : Ok(Classic(Both))
[00:00:04.154] (7fc4572006c0) INFO   [FILLDATA] display type with 'no output'on found : Ok(TempFloatingWindow(Both))
[00:00:04.154] (7fc4572006c0) INFO   [FILLDATA] got show_no_output
[00:00:04.154] (7fc4572006c0) INFO   [FILLDATA] got inline_messages setting
[00:00:04.155] (7fc4572006c0) INFO   [FILLDATA] got neovim_pid value setting: 21665
[00:00:04.155] (7fc4572006c0) INFO   [FILLDATA] Done!
[00:00:04.156] (7fc4572006c0) INFO   [OVERRIDE] No data to override
[00:00:04.156] (7fc4572006c0) INFO   [RUN] filled dataholder
[00:00:04.156] (7fc4572006c0) INFO   [RUN] created launcher
[00:00:04.156] (7fc4572006c0) INFO   selecting an interpreter for filetype javascript
[00:00:04.156] (7fc4572006c0) INFO   considering interpreter JS_original ...
[00:00:04.157] (7fc4572006c0) INFO   considering interpreter JS_TS_deno ...
[00:00:04.157] (7fc4572006c0) INFO   considering interpreter JS_TS_bun ...
[00:00:04.157] (7fc4572006c0) INFO   key interpreter_options found
[00:00:04.157] (7fc4572006c0) INFO   key 'Generic' not found in interpreter option
[00:00:04.157] (7fc4572006c0) INFO   supported filetypes for generic are []
[00:00:04.157] (7fc4572006c0) INFO   selected JS_TS_deno
[00:00:04.158] (7fc4572006c0) INFO   [LAUNCHER] Selected interpreter: JS_TS_deno, at level Selected
[00:00:04.158] (7fc4572006c0) INFO   Checking cli-args: []
[00:00:04.158] (7fc4572006c0) INFO   REPL enabled
[00:00:04.158] (7fc4572006c0) INFO   reading previous code
[00:00:04.159] (7fc4572006c0) INFO   found interpreter_data
[00:00:04.159] (7fc4572006c0) INFO   Deno kernel already running
[00:00:04.159] (7fc4572006c0) INFO   javascript/typescript self.code) = console.log(1)
[00:00:04.159] (7fc4572006c0) INFO   running launcher /home/neuromante/.local/share/nvim/lazy/sniprun/lua/../ressources/launcher_repl.sh
[00:00:04.160] (7fc4572006c0) INFO   cmd status: Ok(Child { stdin: None, stdout: None, stderr: None, .. })
[00:00:04.161] (7fc4572006c0) INFO   outfile : "/home/neuromante/.cache/sniprun/js-ts_deno/21665/fifo_repl/out_file"
[00:00:04.161] (7fc4572006c0) INFO   searching for things between "sniprun_started_id=1" and "sniprun_finished_id=1"
[00:00:04.211] (7fc4572006c0) INFO   errfile exists
[00:00:04.211] (7fc4572006c0) INFO   err to display : "\n"
[00:00:04.211] (7fc4572006c0) INFO   file exists
[00:00:04.211] (7fc4572006c0) INFO   relevant Deno 1.40.5
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
sniprun_started_id=1
1
sniprun_finished_id=1
[00:00:04.211] (7fc4572006c0) INFO   file could be read : "Deno 1.40.5\nexit using ctrl+d, ctrl+c, or close()\nREPL is running with all permissions allowed.\nTo specify permissions, run `deno repl` with allow flags.\nsniprun_started_id=1\n1\nsniprun_finished_id=1"
[00:00:04.211] (7fc4572006c0) INFO   out found
[00:00:04.211] (7fc4572006c0) INFO   [RUN] Interpreter return a result
[00:00:04.211] (7fc4572006c0) INFO   Display type chosen: [TerminalWithCode(Both)]
[00:00:04.211] (7fc4572006c0) INFO   message '1' cleaned out
[00:00:04.225] (7fc4572006c0) INFO   display terminal res = Ok(())

@michaelb Feel free to close the issue when updating the shebangs.

Thanks!