Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Missing package molten after enable=true #1206

Closed
1 task done
xvrdm opened this issue Mar 5, 2024 · 15 comments · Fixed by #1248
Closed
1 task done

[BUG] Missing package molten after enable=true #1206

xvrdm opened this issue Mar 5, 2024 · 15 comments · Fixed by #1248
Labels
bug Something isn't working

Comments

@xvrdm
Copy link

xvrdm commented Mar 5, 2024

Field Description
Plugin molten
Nixpkgs 23.11
  • I have read the FAQ and my bug is not listed there.

Description

I am trying to use the molten package. Even though I enabled the package (found in the doc), I don't get any :Molten* command in nvim. Do I need to require it manually?

I started from nix flake init --template github:nix-community/nixvim and only changed config/default.nix. The other changes (colorschemes, lualine, lsp) were correctly pulled/activated.

Thanks for the awesome project!

Minimal, Reproducible Example (MRE)

in config/default.nix

{self, pkgs, ...}: {
# Import all your configuration modules here
	imports = [
		./bufferline.nix
	];
	colorschemes.gruvbox.enable = true;

	plugins = {
		lualine.enable = true;
	};

	plugins.lsp = {
		enable = true;
		servers = {
			tsserver.enable = true;
			lua-ls.enable = true;
			nixd.enable = true;
                        pyright.enable = true;
		};
	};

	plugins.molten = {
	  enable = true;
	};
}
@xvrdm xvrdm added the bug Something isn't working label Mar 5, 2024
@GaetanLepage
Copy link
Collaborator

No, there is no require for this plugin.
However, you need to properly set up the dependencies.
:UpdateRemoteDependencies should be recognized as a command. However, it fails on my side, saying that it misses the jupyter_client module.

@xvrdm
Copy link
Author

xvrdm commented Mar 5, 2024

Thanks a lot for looking at it so swiftly.
jupyter is indeed a dependency of molten.
However, even when do create a temp shell that has jupyter, :UpdateRemoteDependencies continues to fail.

# in my `nix flake init --template github:nix-community/nixvim` dir
nix-shell -p "python3.withPackages(ps: with ps; [ numpy pandas jupyter ])"
nix run .# 

Obviously, feel free to tell me if this is outside the scope of nixnvim support. I just wasn't sure if :UpdateRemoteDependencies was even supported or if it breaks nix paradigms.

@traxys
Copy link
Member

traxys commented Mar 5, 2024

I think we need to add it to the extraPythonPackages of nixvim

@xvrdm
Copy link
Author

xvrdm commented Mar 5, 2024

That's exactly what I was looking at.
Here is the molten example for nixos: https://github.com/benlubas/molten-nvim/blob/main/docs/NixOS.md

Using home-manager, they have this part:

...
      extraPython3Packages = ps: with ps; [
        # ... other python packages
        pynvim
        jupyter-client
        cairosvg # for image rendering
        pnglatex # for image rendering
        plotly # for image rendering
        pyperclip
      ];
...

Is there a similar user-defined argument in nixvim?

@traxys
Copy link
Member

traxys commented Mar 5, 2024

@xvrdm
Copy link
Author

xvrdm commented Mar 6, 2024

This helped a lot to go forward.

Now I have:

  • a tiny shell.nix for the environment (to be replaced by a flake)
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    python311
    quarto
  ];

  LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib";
}
  • Some molten python package dependency for nvim declared in the nixvim config/default.nix
{ self
, pkgs
, ...
}: {
  # Import all your configuration modules here
  imports = [
    ./bufferline.nix
  ];

  extraPython3Packages = p: with p; [ jupyter-client pynvim cairosvg pnglatex plotly pyperclip ];

  extraPlugins = [
    { plugin = pkgs.vimPlugins.quarto-nvim; }
    { plugin = pkgs.vimPlugins.otter-nvim; }
    {
      plugin = pkgs.vimUtils.buildVimPlugin {
        name = "jupytext-nvim";
        src = pkgs.fetchFromGitHub {
          owner = "GCBallesteros";
          repo = "jupytext.nvim";
          rev = "68fddf28119dbaddfaea6b71f3d6aa1e081afb93";
          sha256 = "x5emW+qfUTUDR72B9QdDgVdrb8wGH9D7AdtRrQm80sI=";
        };
      };
    }
  ];

  extraConfigLua = ''
    	require("jupytext").setup({
    			style = "markdown",
    			output_extension = "md",
    			force_ft = "markdown",
    			})
  '';

  plugins.lsp = {
    enable = true;
    servers = {
      tsserver.enable = true;
      lua-ls.enable = true;
      rnix-lsp.enable = true;
      pyright.enable = true;
    };
  };

  plugins.molten = {
    enable = true;
  };

}
  • The jupiter kernel and jupytext cli installed in a venv

With these three parts, I can :MoltenInit and run code in notebook cells 🥳


The current blocker is that I could only make this works with the line:

  LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib";

in shell.nix, which helps pass :UpdateRemotePlugins but also seem to break the pyright lsp. Without it I have normal LSP support, with it the LSP fails to attach to the buffer with the :LspLog error message:

/lib/libstdc++.so.6: version `GLIBXX_3.4.32' not found

@Charging1948
Copy link

Charging1948 commented Mar 6, 2024

I also had the same problem, where molten would never load by just enabling it. I fixed it by fetching the plugin manually from github and passing the required dependencies through to it.

  plugins.molten = {
    enable = true;
    package = pkgs.vimUtils.buildVimPlugin {
      pname = "molten-nvim";
      version = "2024-02-23";
      src = pkgs.fetchFromGitHub {
        owner = "benlubas";
        repo = "molten-nvim";
        rev = "8346bba69e0de96278dad2038e9be74605908b7d";
        # sha256 = lib.fakeSha256;
        sha256 = "08f3zxzka43f87fks56594476h57yq01x7a1zdsn4acc278xg1nb";
      };
      passthru.python3Dependencies = ps:
        with ps; [
          pynvim
          jupyter-client
          cairosvg
          ipython
          nbformat
        ];
      meta.homepage = "https://github.com/benlubas/molten-nvim/";
    };
  };

Maybe the original package in nixpkgs can also be overwritten with overrideAttrs but the above code worked for me, so i did not experiment further.

@xvrdm
Copy link
Author

xvrdm commented Mar 6, 2024

Thank you for sharing @Charging1948
I tried it but for me it did not change the situation.

  • With LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib"; in shell.nix (which breaks pyright LSP): molten is responsive and I get results below cells.
Screenshot 2024-03-06 at 13 13 17
  • Without LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib"; in shell.nix (which fixes pyright LSP): the entire nvim becomes extremely sluggish after :MoltenInit and I get "on hold" below cells.
Screenshot 2024-03-06 at 13 11 23

@Charging1948
Copy link

Charging1948 commented Mar 6, 2024

@xvrdm Very Interesting. I do not override the LD_LIBRARY_PATH and it just works.

My config is a mess, but maybe it helps: https://github.com/Charging1948/neovim

@xvrdm
Copy link
Author

xvrdm commented Mar 6, 2024

@Charging1948 I actually tried your config after your first config, very impressive, but a bit overwhelming for my level of understanding. Definitely an inspiration.

I put my tiny attempt here: https://github.com/xvrdm/nixvim_sandbox

@Charging1948
Copy link

@xvrdm I tried to replicate the behavior you are experiencing, but i was able to use molten without problems:
image

The only thing i have added was the ipykernel, because it was missing.

At this point i dont know what the problem could be, sorry.

@xvrdm
Copy link
Author

xvrdm commented Mar 6, 2024

Thanks a lot for trying.
So you manage to have both molten working and LSP support in normal python files 🤔 ?
I wonder if it could be because I am trying on an arm vm. I will try it on another architecture.

@GaetanLepage
Copy link
Collaborator

In the end, I am not sure about what we could/should do at the nixvim level.
Should we add the few recommended packages to extraPython3Packages ? What do you think @traxys ?

@xvrdm
Copy link
Author

xvrdm commented Mar 7, 2024

@GaetanLepage, do you mean that they could have been automatically when a user enable molten?

From a user perspective, I think it makes sense that I have to add these python packages via the extrapython3packages argument @traxys pointed me to. Except if for other packages you tend to do it for the user (but I guess it would be quite challenging to keep track of).

@traxys
Copy link
Member

traxys commented Mar 12, 2024

I think we should add the required package to the extraPython3Packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants