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

Make Neve modular #96

Closed
tuxiqae opened this issue Jul 21, 2024 · 13 comments
Closed

Make Neve modular #96

tuxiqae opened this issue Jul 21, 2024 · 13 comments

Comments

@tuxiqae
Copy link

tuxiqae commented Jul 21, 2024

Allow users to customize their Neve experience using Nix options

@redyf
Copy link
Owner

redyf commented Jul 25, 2024

Hello tuxi, could you provide an example?

@tuxiqae
Copy link
Author

tuxiqae commented Jul 26, 2024

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
Copy link
Owner

redyf commented Jul 26, 2024

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

@rolfschr
Copy link

rolfschr commented Aug 3, 2024

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
Copy link
Owner

redyf commented Aug 4, 2024

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

@redyf redyf pinned this issue Aug 4, 2024
@glwbr
Copy link

glwbr commented Aug 30, 2024

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
Copy link
Owner

redyf commented Sep 6, 2024

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
Copy link
Contributor

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
Copy link
Owner

redyf commented Oct 17, 2024

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 👍 Thanks for supporting Neve.

@redyf
Copy link
Owner

redyf commented Oct 17, 2024

8e39471
@Shyrogan let me know what you think 😄

@Shyrogan
Copy link
Contributor

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
Copy link
Owner

redyf commented Oct 20, 2024

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
Copy link
Contributor

Shyrogan commented Oct 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants