-
Notifications
You must be signed in to change notification settings - Fork 462
/
Copy pathdefault.nix
200 lines (194 loc) · 6.6 KB
/
default.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# home-manager module of neovim setup
{ config
, lib
, pkgs
, ...
}:
with lib; let
cfg = config.programs.neovim.nvimdots;
in
{
options = {
programs.neovim = {
nvimdots = {
enable = mkEnableOption ''
Activate "ayamir/nvimdots".
Have a look at https://github.com/ayamir/nvimdots for details
'';
bindLazyLock = mkEnableOption ''
Bind lazy-lock.json in your repository to $XDG_CONFIG_HOME/nvim.
Very powerful in terms of keeping the environment consistent, but has the following side effects.
You cannot update it even if you run the Lazy command, because it binds read-only.
'';
setBuildEnv = mkEnableOption ''
Sets environment variables that resolve build dependencies as required by `mason.nvim` and `nvim-treesitter`
Environment variables are only visible to `nvim` and have no effect on any parent sessions.
Required for NixOS.
'';
withBuildTools = mkEnableOption ''
Include basic build tools like `gcc` and `pkg-config`.
Required for NixOS.
'';
withHaskell = mkEnableOption ''
Enable the Haskell compiler. Set to `true` to
use Haskell plugins.
'';
extraHaskellPackages = mkOption {
type = with types;
let fromType = listOf package;
in coercedTo fromType
(flip warn const ''
Assigning a plain list to extraHaskellPackages is deprecated.
Please assign a function taking a package set as argument, so
extraHaskellPackages = [ pkgs.haskellPackages.xxx ];
should become
extraHaskellPackages = ps: [ ps.xxx ];
'')
(functionTo fromType);
default = _: [ ];
defaultText = literalExpression "ps: [ ]";
example = literalExpression "hsPkgs: with hsPkgs; [ mtl ]";
description = ''
The extra Haskell packages required for your plugins to work.
This option accepts a function that takes a Haskell package set as an argument,
and selects the required Haskell packages from this package set.
See the example for more info.
'';
};
extraDependentPackages = mkOption {
type = with types; listOf package;
default = [ ];
example = literalExpression "[ pkgs.openssl ]";
description = "Extra build depends to add `LIBRARY_PATH` and `CPATH`.";
};
};
};
};
config =
let
# Inspired from https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/programs/nix-ld.nix
build-dependent-pkgs = with pkgs; builtins.filter (package: !package.meta.unsupported) [
# manylinux
acl
attr
bzip2
curl
glibc
libsodium
libssh
libxml2
openssl
stdenv.cc.cc
stdenv.cc.cc.lib
systemd
util-linux
xz
zlib
zstd
# Packages not included in `nix-ld`'s NixOSModule
glib
libcxx
]
++ cfg.extraDependentPackages;
makePkgConfigPath = x: makeSearchPathOutput "dev" "lib/pkgconfig" x;
makeIncludePath = x: makeSearchPathOutput "dev" "include" x;
neovim-build-deps = pkgs.buildEnv {
name = "neovim-build-deps";
paths = build-dependent-pkgs;
extraOutputsToInstall = [ "dev" ];
pathsToLink = [ "/lib" "/include" ];
ignoreCollisions = true;
};
buildEnv = [
''CPATH=''${CPATH:+''${CPATH}:}${neovim-build-deps}/include''
''CPLUS_INCLUDE_PATH=''${CPLUS_INCLUDE_PATH:+''${CPLUS_INCLUDE_PATH}:}:${neovim-build-deps}/include/c++/v1''
''LD_LIBRARY_PATH=''${LD_LIBRARY_PATH:+''${LD_LIBRARY_PATH}:}${neovim-build-deps}/lib''
''LIBRARY_PATH=''${LIBRARY_PATH:+''${LIBRARY_PATH}:}${neovim-build-deps}/lib''
''NIX_LD_LIBRARY_PATH=''${NIX_LD_LIBRARY_PATH:+''${NIX_LD_LIBRARY_PATH}:}${neovim-build-deps}/lib''
''PKG_CONFIG_PATH=''${PKG_CONFIG_PATH:+''${PKG_CONFIG_PATH}:}${neovim-build-deps}/include/pkgconfig''
];
in
mkIf cfg.enable {
xdg.configFile = {
"nvim/init.lua".source = ../../init.lua;
"nvim/lua".source = ../../lua;
"nvim/snips".source = ../../snips;
"nvim/tutor".source = ../../tutor;
} // lib.optionalAttrs cfg.bindLazyLock {
"nvim/lazy-lock.json".source = ../../lazy-lock.json;
};
home = {
packages = with pkgs; [
ripgrep
];
shellAliases = optionalAttrs (cfg.setBuildEnv && (lib.versionOlder config.home.stateVersion "24.05")) {
nvim = concatStringsSep " " buildEnv + " nvim";
};
};
programs.neovim = {
enable = true;
withNodeJs = true;
withPython3 = true;
extraPackages = with pkgs;
[
# Dependent packages used by default plugins
doq
tree-sitter
]
++ optionals cfg.withBuildTools [
cargo
clang
cmake
gcc
gnumake
go
lua51Packages.luarocks
ninja
pkg-config
yarn
]
++ optionals cfg.withHaskell [
(pkgs.writeShellApplication {
name = "stack";
text = ''
exec "${pkgs.stack}/bin/stack" "--extra-include-dirs=${config.home.profileDirectory}/lib/nvim-depends/include" "--extra-lib-dirs=${config.home.profileDirectory}/lib/nvim-depends/lib" "$@"
'';
})
(haskellPackages.ghcWithPackages (ps: cfg.extraHaskellPackages ps))
];
extraPython3Packages = ps: with ps; [
docformatter
isort
pynvim
];
}
// lib.optionalAttrs (lib.versionAtLeast config.home.stateVersion "24.05") {
extraWrapperArgs = lib.optionals cfg.setBuildEnv [
"--suffix"
"CPATH"
":"
"${neovim-build-deps}/include"
"--suffix"
"CPLUS_INCLUDE_PATH"
":"
"${neovim-build-deps}/include/c++/v1"
"--suffix"
"LD_LIBRARY_PATH"
":"
"${neovim-build-deps}/lib"
"--suffix"
"LIBRARY_PATH"
":"
"${neovim-build-deps}/lib"
"--suffix"
"PKG_CONFIG_PATH"
":"
"${neovim-build-deps}/include/pkgconfig"
"--suffix"
"NIX_LD_LIBRARY_PATH"
":"
"${neovim-build-deps}/lib"
];
};
};
}