forked from traxys/nvim-flake
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathflake.nix
156 lines (148 loc) · 5.62 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{
description = "Luca's simple Neovim flake for easy configuration";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils = {
inputs.nixpkgs.follows = "nixpkgs";
url = "github:numtide/flake-utils";
};
# Theme
"plugin_onedark-vim" = {
url = "github:joshdick/onedark.vim";
flake = false;
};
# Git
"plugin_gitsigns" = {
url = "github:lewis6991/gitsigns.nvim";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
# This line makes this package availeable for all systems
# ("x86_64-linux", "aarch64-linux", "i686-linux", "x86_64-darwin",...)
flake-utils.lib.eachDefaultSystem (system:
let
# Once we add this overlay to our nixpkgs, we are able to
# use `pkgs.neovimPlugins`, which is a map of our plugins.
# Each input in the format:
# ```
# "plugin_yourPluginName" = {
# url = "github:exampleAuthor/examplePlugin";
# flake = false;
# };
# ```
# included in the `inputs` section is packaged to a (neo-)vim
# plugin and can then be used via
# ```
# pkgs.neovimPlugins.yourPluginName
# ```
pluginOverlay = final: prev:
let
inherit (prev.vimUtils) buildVimPluginFrom2Nix;
treesitterGrammars = prev.tree-sitter.withPlugins (_: prev.tree-sitter.allGrammars);
plugins = builtins.filter
(s: (builtins.match "plugin_.*" s) != null)
(builtins.attrNames inputs);
plugName = input:
builtins.substring
(builtins.stringLength "plugin_")
(builtins.stringLength input)
input;
buildPlug = name: buildVimPluginFrom2Nix {
pname = plugName name;
version = "master";
src = builtins.getAttr name inputs;
# Tree-sitter fails for a variety of lang grammars unless using :TSUpdate
# For now install imperatively
#postPatch =
# if (name == "nvim-treesitter") then ''
# rm -r parser
# ln -s ${treesitterGrammars} parser
# '' else "";
};
in
{
neovimPlugins = builtins.listToAttrs (map
(plugin: {
name = plugName plugin;
value = buildPlug plugin;
})
plugins);
};
# Apply the overlay and load nixpkgs as `pkgs`
pkgs = import nixpkgs {
inherit system;
overlays = [
pluginOverlay
];
};
# neovimBuilder is a function that takes your prefered
# configuration as input and just returns a version of
# neovim where the default config was overwritten with your
# config.
#
# Parameters:
# customRC | your init.vim as string
# viAlias | allow calling neovim using `vi`
# vimAlias | allow calling neovim using `vim`
# start | The set of plugins to load on every startup
# | The list is in the form ["yourPluginName" "anotherPluginYouLike"];
# |
# | Important: The default is to load all plugins, if
# | `start = [ "blabla" "blablabla" ]` is
# | not passed as an argument to neovimBuilder!
# |
# | Make sure to add:
# | ```
# | "plugin_yourPluginName" = {
# | url = "github:exampleAuthor/examplePlugin";
# | flake = false;
# | };
# |
# | "plugin_anotherPluginYouLike" = {
# | url = "github:exampleAuthor/examplePlugin";
# | flake = false;
# | };
# | ```
# | to your imports!
# opt | List of optional plugins to load only when
# | explicitly loaded from inside neovim
neovimBuilder = { customRC ? ""
, viAlias ? true
, vimAlias ? true
, start ? builtins.attrValues pkgs.neovimPlugins
, opt ? []
, debug ? false }:
let
myNeovimUnwrapped = pkgs.neovim-unwrapped.overrideAttrs (prev: {
propagatedBuildInputs = with pkgs; [ pkgs.stdenv.cc.cc.lib ];
});
in
pkgs.wrapNeovim myNeovimUnwrapped {
inherit viAlias;
inherit vimAlias;
configure = {
customRC = customRC;
packages.myVimPackage = with pkgs.neovimPlugins; {
start = start;
opt = opt;
};
};
};
in
rec {
defaultApp = apps.nvim;
defaultPackage = packages.neovimLuca;
apps.nvim = {
type = "app";
program = "${defaultPackage}/bin/nvim";
};
packages.neovimLuca = neovimBuilder {
# the next line loads a trivial example of a init.vim:
customRC = pkgs.lib.readFile ./init.vim;
# if you wish to only load the onedark-vim colorscheme:
# start = with pkgs.neovimPlugins; [ onedark-vim ];
};
}
);
}