jordanisaacs / neovim-flake

Nix flake for neovim with configuration
https://jordanisaacs.github.io/neovim-flake
MIT License
259 stars 56 forks source link

Allow users to provide custom inputs in `neovimConfiguration` #18

Closed antotocar34 closed 1 year ago

antotocar34 commented 1 year ago

Hey love the work you've done with this. I really like the idea of a home-manager but for neovim :D

It would be great if in a user's custom flake.nix there could an extraInputs argument:

{
  inputs = {
      neovim-flake.url = "path:/home/carneca/Documents/projects/neovim-flake";
      leap = {
        url = "github:ggandor/leap.nvim";
        flake = false;
      };
  };

  outputs = {nixpkgs, neovim-flake, ...}@inputs: let
    system = "x86_64-linux";
    pkgs = nixpkgs.legacyPackages.${system};
    configModule = {
      config.vim.leap.enable = true;
    };

    customNeovim = neovim-flake.lib.neovimConfiguration {
      extraInputs = {
        inherit (inputs) leap;
      };
      modules = [
        configModule
        ./modules/leap.nix
      ];
      inherit pkgs;
    };
  in {
    packages.${system}.neovim = customNeovim.neovim;
  };
}

where leap.nix is

{
  pkgs,
  lib,
  config,
  ...
}:
with lib;
with builtins; let
  cfg = config.vim.leap;
  writeIf = cond: message: if cond then message else "";
in {
  options.vim.leap = {
    enable = mkEnableOption "enable leap";
  };

  config = mkIf cfg.enable {
      vim.startPlugins = [ "leap" ];

      vim.luaConfigRC.leap = nvim.dag.entryAnywhere ''
        require('leap').add_default_mappings()
      '';
  };
}

and for that to just work.

I tried adding this extraInputs argument in neovim-flake's flake.nix but then the module system complains that startPlugins can't accept "leap" and wants a derivation instead.

It would be nice if the user didn't have to package all the inputs they add themselves in that situation.

jordanisaacs commented 1 year ago

Yes I definitely agree that you should be able to pass in your own plugins and have them be built for you. I don't think it will be possible to pass them in as a string due to the way the evaluation works. I am thinking of adding a third type, an attrset, to the plugin options: {name= pname; source = package}. If it detects this then the plug-in is built. Could provide a library function for generating the attrset from an input.

Does that look good?

Edit: never mind I think I have an idea how this might work.

jordanisaacs commented 1 year ago

@antotocar34 I created a branch extra-inputs. Feel free to switch to that and let me know if it works. Should achieve exactly what your example has. I haven't had the chance to test it yet so it might fail.

antotocar34 commented 1 year ago

I tried it there. I think you forgot to add extraInputs as an argument to neovimConfiguration in the flake.nix. After adding that though the "leap" was still not in the type enum, and calling lib.trace on extraPluginNames in types-plugin.nix returns an empty list. Looked for a bit but didn't see why that was happening. I'm probably missing something obvious though, it's late :)

antotocar34 commented 1 year ago

Ok I fixed it, I'll make a PR to the branch

antotocar34 commented 1 year ago

See #19

jordanisaacs commented 1 year ago

I have some code cleanup I need to do and then I'll merge the branch into master.

jordanisaacs commented 1 year ago

I have finished a way to do this in #30 that works within the module system.. There is a new option rawPlugin with a lib function to easily generate the attribute set from the inputs and a list of available plugins. Documentation forthcoming.