redyf / Neve

Neve is a Neovim configuration built with Nixvim, it allows you to use Nix language to manage Neovim plugins/options.
MIT License
152 stars 61 forks source link

Make Neve modular #96

Closed tuxiqae closed 1 week ago

tuxiqae commented 3 months ago

Allow users to customize their Neve experience using Nix options

redyf commented 3 months ago

Hello tuxi, could you provide an example?

tuxiqae commented 3 months ago

Hi! For example, since I don't see a need to use Discord or WakaTime I just cloned the repo, edited the relevant files in order to disable those features, and now I use this fork instead of redyf/Neve

In Nix you can create a module, and within it define options (using mkOption), the consumers of your flake Neve will be able to enable and disable specific features by toggling on specific features.

For example: https://nix.dev/tutorials/module-system/a-basic-module/index.html

For example, the NixOS moduleservices.tailscale:

redyf commented 3 months ago

That's an amazing idea, I'll take a deeper look into it. Thanks! 😄

rolfschr commented 2 months ago

FYI, this is how I approached this: I used the Neve flake with a custom config that I provide using nixvimExtend. This allows me to fully customize to my needs (including deactivation) while still following upstream.


# flake.nix
inputs.neve.url = "github:redyf/Neve";
...
myConfig = {
    extraPackages = with pkgs; [
      alejandra # nix formatter
      ...
    ];

    extraPlugins = with pkgs.vimPlugins; [
      eyeliner-nvim
      ...
    ];

    plugins = {
      alpha.enable = pkgs.lib.mkForce false; # welcome screen
      copilot-lua.enable = pkgs.lib.mkForce false;
      indent-blankline.enable = pkgs.lib.mkForce false; # indentation guides
      lint = {
        lintersByFt = {
          sh = ["shellcheck"];
     ...
    };
    extraConfigLua = ''
      require("cmp").setup {
       ...
    };
    keymaps = ...
};

...
myNeve = neve.packages."${system}".default.nixvimExtend { config = myConfig;};
redyf commented 2 months ago

I had no idea you could do that haha, really cool :fire:

glwbr commented 1 month ago

Hi! I couldn't find another way to contact you through your profile, so I'm using this issue for discussion. I'm currently working on my own NixVim configuration, taking inspiration from Neve and other projects. One challenge I encountered is the need for certain packages to be installed on the host system, such as prettierd, golines, gopls, ruff, etc., to get them working in Nix/Neovim.

I'm trying to solve this by creating a fully independent configuration that automatically enables LSPs, completions, and snippets based on the languages installed on the system. For example, if a user has Go installed, then the Go LSP and related features will be enabled; the same would apply for Node.js, Python, and other languages.

Have you considered this approach? The methods used by @tuxiqae and @rolfschr seem like a perfect example of how to achieve this. Currently, I have a basic initial configuration set up for this purpose.

# packages.nix
{pkgs}: let
  commandExists = cmd: builtins.pathExists (pkgs.lib.getExe cmd);
in {
  inherit commandExists;
  pythonAvailable = commandExists pkgs.python3;
  nodeAvailable = commandExists pkgs.nodejs;
  goAvailable = commandExists pkgs.go;
  rustAvailable = commandExists pkgs.rustc;
}
# helpers.nix
{
  pkgs,
  helpers,
}: let
  pythonPackages = with pkgs;
    if helpers.pythonAvailable
    then [
      black
      ruff
    ]
    else [];

  nodePackages = with pkgs.nodePackages;
    if helpers.nodeAvailable
    then [
      eslint_d
      prettierd
    ]
    else [];

  goPackages = with pkgs;
    if helpers.goAvailable
    then [
      gofumpt
      golines
      golangci-lint
    ]
    else [];

  generalPackages = with pkgs; [
    alejandra
    ripgrep
    fd
    jq
  ];
in {
  inherit pythonPackages goPackages nodePackages generalPackages;
  allPackages = pythonPackages ++ nodePackages ++ goPackages ++ generalPackages;
}

If these packages are not installed, the formatters will still attempt to run, but they won't function correctly since they are not present in the host system's PATH. A straightforward solution would be to install these packages, but the approach I'm taking is to configure it so that if a package isn't available, it simply won't be installed or used.

In conform, we might have:

# conform.nix
plugins.conform-nvim = {
    enable = true;
    formatters = {
      black.enable = pythonAvailable;
      prettier.enable = nodeAvailable;
      gofmt.enable = goAvailable;
      rustfmt.enable = rustAvailable;
    };
    formattersByFt = {
      python = lib.mkIf pythonAvailable ["black"];
      javascript = lib.mkIf nodeAvailable ["prettier"];
      typescript = lib.mkIf nodeAvailable ["prettier"];
      go = lib.mkIf goAvailable ["gofmt"];
      rust = lib.mkIf rustAvailable ["rustfmt"];
    };
  };

In Neve this will "throw an error" on Conform maybe in other parts too Neve Conform.nvim

By having these shipped with the configuration, we might be able to make it completely independent of the host.

Corgix Confor.nvim

redyf commented 1 month ago

I've never considered this approach, but it does look interesting. Usually what I do is just use a nix flake + direnv. It's great to see there are so many ways available to setup an environment with nix.

Shyrogan commented 1 week ago

Hey @redyf, would you be fine with providing a bit of documentation on how to use #111 now that it's been merged ? Thank you for the awesome work.

redyf commented 1 week ago

Hey @redyf, would you be fine with providing a bit of documentation on how to use #111 now that it's been merged ? Thank you for the awesome work.

Sure! I'll add it asap, it might seem complex but it's really not. I'll explain it in the readme :+1: Thanks for supporting Neve.

redyf commented 1 week ago

https://github.com/redyf/Neve/commit/8e39471736f6f6070c1dfbf74945ff3a5936f15d @Shyrogan let me know what you think :smile:

Shyrogan commented 6 days ago

8e39471 @Shyrogan let me know what you think 😄

I think an example that uses nixvimExtend extend would be better. Using this basically allows us to override your settings without touching the sources of Neve directly, that would be lovely

I'll try to write one myself on my free-time and comment it here

redyf commented 5 days ago

8e39471 @Shyrogan let me know what you think 😄

I think an example that uses nixvimExtend extend would be better. Using this basically allows us to override your settings without touching the sources of Neve directly, that would be lovely

I'll try to write one myself on my free-time and comment it here

Indeed, that sounds good. I'll be kinda busy with work and some exams in the next few days so a PR would be very much appreciated for that one. Thanks for the suggestion 🙂

Shyrogan commented 51 minutes ago

@redyf that required small changes, PR those changes are available in #113