LGUG2Z / JeezyVim

A fast, reliable NeoVim configuration as a Nix Flake for people who want to use NeoVim as an editor and not as an IDE
21 stars 4 forks source link

cannot set treesitter settings #5

Open bj0 opened 1 month ago

bj0 commented 1 month ago

I'm trying to customize your nixos-wsl-starter setup, and I ran into an issue trying to change a treesitter setting in jeezyvim. To test it, I pulled down a fresh copy of the starter repo and then only changed this:

 (jeezyvim.nixvimExtend {
      config.plugins.treesitter.settings.auto_install = true;
    })

based on https://github.com/LGUG2Z/JeezyVim?tab=readme-ov-file#extending and https://nix-community.github.io/nixvim/plugins/treesitter/settings/index.html#pluginstreesittersettings

when i do a nix flake check it gives the error:

error:
       … while checking flake output 'nixosConfigurations'
         at /nix/store/vl7g123kll841jg8dkwv8qslaxjnbbpd-source/flake.nix:83:7:
           82|
           83|       nixosConfigurations.nixos = mkNixosConfiguration {
             |       ^
           84|         hostname = "nixos";

       … while checking the NixOS configuration 'nixosConfigurations.nixos'
         at /nix/store/vl7g123kll841jg8dkwv8qslaxjnbbpd-source/flake.nix:83:7:
           82|
           83|       nixosConfigurations.nixos = mkNixosConfiguration {
             |       ^
           84|         hostname = "nixos";

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: The option `plugins.treesitter.settings' does not exist. Definition values:
       - In `<unknown-file>':
           {
             auto_install = true;
           }

Am I trying to set this wrong?

LGUG2Z commented 1 month ago

https://github.com/nix-community/nixvim/commit/435ef287ab8658f75599ab4508b0454c95a4274d

Looks like this option was only added 3 days ago. I'm going to look around for a GitHub action that can automatically update the upstream NixVim dependency so that the latest options are always available for people to use as overrides.

bj0 commented 1 month ago

Oh wow, I just looked at it 2 days ago and didn't realize it was so new. I'm relatively new to these nix setups, whats the easiest way to work around it for now? add in nixvim input and do something like inputs.jeezyvim.inputs.nixvim.follows =?

edit: I tried it and got past that error, but it ran into another error:

error: attribute 'cmp-ai' missing
       at /nix/store/i14h4i6hra9b046ywr8p4n53mk7481wd-source/plugins/completion/cmp/sources/_mk-cmp-plugin.nix:11:20:
           10|   sourceName,
           11|   defaultPackage ? pkgs.vimPlugins.${pluginName},
             |                    ^
           12|   maintainers ? [ lib.maintainers.GaetanLepage ],
       Did you mean one of cmp-dap, cmp-git or cmp-rg?

so maybe there are other api changes that need to be accounted for too.

LGUG2Z commented 1 month ago

https://github.com/LGUG2Z/JeezyVim/commit/7e85b4daa6655b0f3835aa1f9032217da8073802 pushed the upstream update here

bj0 commented 1 month ago

that fixed it, thanks!

now I am just having this issue, and it might just be my ignorance in how nixvim works:

error: The option `colorscheme' has conflicting definition values:
       - In `/nix/store/i14h4i6hra9b046ywr8p4n53mk7481wd-source/plugins/colorschemes/tokyonight.nix': "tokyonight"
       - In `/nix/store/i14h4i6hra9b046ywr8p4n53mk7481wd-source/plugins/colorschemes/kanagawa.nix': "kanagawa"
       Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.

now my customization of jeezy is just this:

    (jeezyvim.nixvimExtend {
      config.colorschemes.tokyonight = {
        enable = true;
        style = "night";
      };
      config.plugins.treesitter.settings.auto_install = true;
    })

This is probably just my ignorance but I thought that adding the tokyonight enable would make it the colorscheme, am I missing another setting? do I have to disable the default one?

LGUG2Z commented 1 month ago
    (jeezyvim.nixvimExtend {
      config.colorschemes.tokyonight = {
        enable = pkgs.lib.mkForce true;
        style = "night";
      };
      config.plugins.treesitter.settings.auto_install = true;
    })

I think for this you need to use pkgs.lib.mkForce, even though I have set colorschemes.kanagawa.enable = pkgs.lib.mkDefault true. I think this is because colorscheme (minus the "s") is a computed value and if multiple colorschemes have enable = true one of them needs to be given a higher priority.

bj0 commented 1 month ago

I tried adding mkForce but it produced the same error. It worked if i added enable = false; for kanagawa.

bj0 commented 1 month ago

Ok, I'm not sure if I should move this to your wsl starter repo, but now that everything is working and building (minus nix-index, which i haven't figured out yet), Im having one more jeezyvim related issue: it doesn't seem to get installed.

here's my repo which is my attempt to merge your starter files into my home-manager repo, all the packages are in home/common.nix, and they all seem to get installed except jeezyvim. Do I need more than just the snippet already pasted in this issue to get it to install?

LGUG2Z commented 1 month ago

The installed binary is still nvim - if you want to call it as jvim or jeezyvim you should add a fish or a zsh alias depending on the shell you're using.

bj0 commented 1 month ago

Right, what I meant to say is the jeezyvim configuration isn't installed anywhere (there's no ~/.config/nvim directory). And nvim just launches with a blank, unconfigured session.

LGUG2Z commented 1 month ago

I don't have access to the repo - can you paste the block with your extended configuration so that I can try building it as well?

bj0 commented 1 month ago

sorry I forgot that I had created it as private incase I accidently pushed some keys or soemthing up.

The relevant config in flake.nix is:

      nixosConfigurations.nazdoz = mkNixosConfiguration {
        hostname = "nazdoz";
        username = "bjp";
        modules = [
          nixos-wsl.nixosModules.wsl
          ./home/wsl.nix
        ];
      };

wsl.nix is mostly unchanged except for imports:

  home-manager.users.${username} = {
    imports = [
      ./home.nix
      ./bjp.nix
    ];
  };

home.nix just creates some options and imports the real config:

{
  lib,
  nix-index-database,
  ...
}: {
  # just define some options for use in user specific modules
  options.home = with lib; {
    name = mkOption {
      type = types.str;
      default = "Example User";
    };
    email = mkOption {
      type = types.str;
      default = "user@example.com";
    };
  };
  imports = [
    nix-index-database.hmModules.nix-index
    ./common.nix
  ];
}

here's common.nix, which includes the packages:

{
  inputs,
  config,
  pkgs,
  ...
}: let
  unstable-packages = with pkgs.unstable; [
    bat
    bottom
    btop
    coreutils
    curl
    du-dust
    fd
    findutils
    fish
    fx
    fzf
    git
    git-crypt
    htop
    jq
    killall
    lazygit
    mosh
    nerdfonts
    ncdu
    procs
    ripgrep
    sd
    tmux
    tree
    unzip
    vim
    wget
    zip

    inputs.nix-coconut.packages.${system}.coco # coconut jupyter console
  ];

  stable-packages = with pkgs; [
    # you can add plugins, change keymaps etc using (jeezyvim.nixvimExtend {})
    # https://github.com/LGUG2Z/JeezyVim#extending
    (jeezyvim.nixvimExtend {
      config.colorschemes.tokyonight = {
        enable = pkgs.lib.mkForce true;
        style = "night";
      };
      config.plugins.treesitter.settings.auto_install = true;
      config.colorschemes.kanagawa.enable = false;
    })
    #jeezyvim

    # key tools
    gh # for bootstrapping
    just

    # core languages
    rustup
    gcc
    #cargo
    python312
    poetry

    # rust stuff
    cargo-cache
    cargo-expand

    # local dev stuf
    mkcert
    httpie

    # treesitter
    tree-sitter

    # language servers
    nodePackages.vscode-langservers-extracted # html, css, json, eslint
    nodePackages.yaml-language-server
    #nil # nix
    inputs.nil-lsp # nix lsp

    # formatters and linters
    alejandra # nix
    deadnix # nix
    nodePackages.prettier
    shellcheck
    shfmt
    stylua
    statix # nix
  ];
in {
  # imports = [
  # ];
  home.stateVersion = "24.05"; # Please read the comment before changing.
  # The home.packages option allows you to install Nix packages into your
  # environment.
  home.packages =
    stable-packages
    ++ unstable-packages
    ++ [
      # # It is sometimes useful to fine-tune packages, for example, by applying
      # # overrides. You can do that directly here, just don't forget the
      # # parentheses. Maybe you want to install Nerd Fonts with a limited number of
      # # fonts?
      # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; })

      # # You can also create simple shell scripts directly inside your
      # # configuration. For example, this adds a command 'my-hello' to your
      # # environment:
      # (pkgs.writeShellScriptBin "my-hello" ''
      #   echo "Hello, ${config.home.username}!"
      # '')
    ];

  # Home Manager is pretty good at managing dotfiles. The primary way to manage
  # plain files is through 'home.file'.
  home.file = {
    # # Building this configuration will create a copy of 'dotfiles/screenrc' in
    # # the Nix store. Activating the configuration will then make '~/.screenrc' a
    # # symlink to the Nix store copy.
    # ".screenrc".source = dotfiles/screenrc;

    # # You can also set the file content immediately.
    # ".gradle/gradle.properties".text = ''
    #   org.gradle.console=verbose
    #   org.gradle.daemon.idletimeout=3600000
    # '';
    #".config/fish/functions/nvims.fish".source = fish/functions/nvims.fish;
  };

  xdg.configFile = {
    "fish/functions/nvims.fish".source = ../fish/functions/nvims.fish;
    "nvim-lazy" = {
      source = ../nvim-lazy;
      recursive = true;
    };
  };

  # Home Manager can also manage your environment variables through
  # 'home.sessionVariables'. These will be explicitly sourced when using a
  # shell provided by Home Manager. If you don't want to manage your shell
  # through Home Manager then you have to manually source 'hm-session-vars.sh'
  # located at either
  #
  #  ~/.nix-profile/etc/profile.d/hm-session-vars.sh
  #
  # or
  #
  #  ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh
  #
  # or
  #
  #  /etc/profiles/per-user/bjp/etc/profile.d/hm-session-vars.sh
  #
  home.sessionVariables = {
    SHELL = "/etc/profiles/per-user/${config.home.username}/bin/fish";
    EDITOR = "nvim";
  };

  programs = {
    nix-index = {
       enable = true;
       enableFishIntegration = true;
     };
     nix-index-database.comma.enable = true;

    # FIXME: disable this if you don't want to use the starship prompt
    starship.enable = true;
    starship.settings = {
      aws.disabled = true;
      gcloud.disabled = true;
      kubernetes.disabled = false;
      git_branch.style = "242";
      directory.style = "blue";
      directory.truncate_to_repo = false;
      directory.truncation_length = 8;
      python.disabled = true;
      ruby.disabled = true;
      hostname.ssh_only = false;
      hostname.style = "bold green";
    };

    lsd.enable = true;
    lsd.enableAliases = true;
    zoxide.enable = true;
    zoxide.enableFishIntegration = true;
    zoxide.options = ["--cmd cd"];
    broot.enable = true;
    broot.enableFishIntegration = true;

    fish = {
      enable = true;
      plugins = with pkgs.fishPlugins; [
        {
          name = "fzf-fish";
          src = fzf-fish.src;
        }
      ];
      shellAbbrs =
        {
          gi = "./gradlew installDebug";
          gb = "./gradlew build";
          gc = "./gradlew clean";
          gim = "./gradlew installMilDebug";
          g = "git";
          lg = "lazygit";
          #ls = "ls -Fog";
          myip = "curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+";
        }
        // {
          ".." = "cd ..";
          "..." = "cd ../../";
          "...." = "cd ../../../";
          "....." = "cd ../../../../";
        };
      shellAliases = {
        pbcopy = "/mnt/c/Windows/System32/clip.exe";
        pbpaste = "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -command 'Get-Clipboard'";
        explorer = "/mnt/c/Windows/explorer.exe";
      };
    };

    neovim = {
      enable = true;
      defaultEditor = true;
      viAlias = true;
      vimAlias = true;
    };

    # use plugin instead
    fzf = {
      enable = true;
      enableFishIntegration = false;
      defaultCommand = "fd --type f --strip-cwd-prefix --hidden --follow --exclude .git";
      tmux.enableShellIntegration = true;
    };

    direnv = {
      enable = true;
      #enableFishIntegration = true;
      nix-direnv.enable = true;
    };

    bat.extraPackages = with pkgs.bat-extras; [batman batdiff];

    git = {
      enable = true;
      userName = config.home.name;
      userEmail = config.home.email;

      package = pkgs.unstable.git;
      delta.enable = true;
      delta.options = {
        line-numbers = true;
        side-by-side = true;
        navigate = true;
      };

      aliases = {
        a = "add";
        c = "commit";
        co = "checkout";
        d = "diff";
        f = "fetch";
        fa = "fetch --all";
        lol = "log --graph --decorate --pretty=oneline --abbrev-commit";
        lola = "log --graph --decorate --pretty=oneline --abbrev-commit --all";
        pl = "pull";
        ps = "push";
        r = "remote";
        st = "status";
        rs = "remote show";
      };

      extraConfig = {
        # FIXME: uncomment the next lines if you want to be able to clone private https repos
        # url = {
        #   "https://oauth2:${secrets.github_token}@github.com" = {
        #     insteadOf = "https://github.com";
        #   };
        #   "https://oauth2:${secrets.gitlab_token}@gitlab.com" = {
        #     insteadOf = "https://gitlab.com";
        #   };
        # };
        credential.helper = "store";
        push.autoSetupRemote = true;
      };
    };

    ssh = {
      enable = true;
      controlMaster = "auto";
      serverAliveInterval = 60;

      matchBlocks = {
        bird = {
          host = "pigeon bird";
          hostname = "bird.mx";
          user = "bjp";
        };

        github = {
          host = "github";
          hostname = "github.com";
          user = "git";
        };
      };
    };

    # Let Home Manager install and manage itself.
    home-manager.enable = true;
  };
}

If you need, I can temporarily switch the repo to public so you can see more of the files but they're mostly boilerplate.

LGUG2Z commented 1 month ago

At a quick glance I think that a clash here might be the issue:

    neovim = {
      enable = true;
      defaultEditor = true;
      viAlias = true;
      vimAlias = true;
    };

Try removing this block ^

bj0 commented 1 month ago

Ahh yea, that worked, I now get JeezyVim when launching nvim. I'm still not sure where the config files are located, where do they get placed?

I realized that on nixos auto_install will not work without also setting parser_install_dir. I tried to set it to what it was in the documentation (https://nix-community.github.io/nixvim/plugins/treesitter/settings/index.html#pluginstreesittersettings), but it says that's invalid:

error: cannot coerce a set to a string

I also tried setting ensure_installed = "all"; form the docs, but it also gave an error:

error: A definition for option `plugins.treesitter.settings.ensure_installed' is not of type `null or (list of (string or raw lua code))'. Definition values:
       - In `<unknown-file>': "all"

Are these more cases of nixvim updating too recently?

LGUG2Z commented 1 month ago

4 days ago :)

LGUG2Z commented 1 month ago

I've updated the dependency and also added a job to update the dependencies every night: https://github.com/LGUG2Z/JeezyVim/commit/43c75f102ee9d2e4c4c9d3490f3825316176cfce

bj0 commented 1 month ago

Dang, they update their docs so quick. Is there a way to use their most recent updates without bothering you to update the jeezy repo so much?

edit: haha ok thanks