-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
executable file
·147 lines (144 loc) · 4.69 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
{
inputs = {
nixpkgs.url = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { flake-utils, nixpkgs, ... }@inputs:
flake-utils.lib.eachSystem [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
] (system:
let
pkgs = import nixpkgs { inherit system; };
# Theme bases
bases = [ "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ];
# Utility functions
utils = rec {
vimscript = conf: conf;
lua = conf: ''
lua << EOF
${conf}
EOF
'';
genericConfig = name: lua ''
require('${name}').setup({})
'';
baseToLua = theme: base:
let
basename = "base0${base}";
basevalue = builtins.getAttr basename theme;
in
"${basename} = '#${basevalue.hex.rgb}'";
themeToLua = theme: "{" + builtins.concatStringsSep ", " (map (baseToLua theme) bases) + "}";
};
# Settings not related to particular plugins
commonRc = utils.vimscript ''
let mapleader = " "
" use system clipboard
set clipboard=unnamedplus
" don't fold everything authomatically
set nofoldenable
" show line numbers in gutter,
" relative to cursor
set number
set relativenumber
" highlight current line number
set cursorline
set cursorlineopt=number
" don't beep
set visualbell
" show invisibles which shouldn't be there
set list
set listchars=tab:▸\ ,trail:·,nbsp:⍽
" Global statusline
set laststatus=3
" No tabs. Ever.
set autoindent
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
" trigger `autoread` when files changes on disk
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif
" GUI-specific
if exists("g:neovide")
endif
'';
in
rec {
# A function to make final derivation
mkNeovim =
{
# nixpkgs to use
pkgs
, # should we include language servers in final closure?
# takes up more space, but is more self-sufficient
withLanguageServers ? true
# base package to wrap
, neovim ? pkgs.neovim-unwrapped
# any extra packages to include in final closure
, runtime ? [ ]
, theme ? null
,
}:
let
# Assemble list of plugins
plugins = builtins.concatLists (
map
(file: import file {
inherit utils pkgs theme;
plugins = pkgs.vimPlugins;
})
[ ./ui.nix ./navigation.nix ./code.nix ]
);
# Assemble config
generatedConfig = pkgs.neovimUtils.makeNeovimConfig
{
plugins = plugins;
extraName = "-q_ink";
} //
# Add python language server to env
pkgs.lib.optionalAttrs withLanguageServers {
extraPython3Packages = (ps: [
ps.python-lsp-server
] ++ ps.python-lsp-server.passthru.optional-dependencies.all);
};
# Prepend non-plugin options to generated config,
# since `beforePlugins` isn't available with
# `makeNeovimConfig` for some reason
config = generatedConfig // {
neovimRcContent = commonRc + generatedConfig.neovimRcContent;
};
# Wrap final package
package = pkgs.wrapNeovimUnstable neovim config;
in
# ... and assemble closure with everything we may want at runtime
pkgs.symlinkJoin {
name = "nvim";
paths = [
package
] ++ pkgs.lib.optionals withLanguageServers
[
pkgs.haskellPackages.tidal
pkgs.haskellPackages.ghci
pkgs.nil
pkgs.rust-analyzer
pkgs.lua-language-server
] ++ runtime;
};
packages.default = mkNeovim { inherit pkgs; };
devShells.default = pkgs.mkShell {
buildInputs = [ packages.default ];
};
overlays.default = _: prev: {
neovim = mkNeovim { pkgs = prev; };
inherit mkNeovim;
};
});
}