-
Notifications
You must be signed in to change notification settings - Fork 104
/
home-manager.nix
362 lines (315 loc) · 9.13 KB
/
home-manager.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
{ config, pkgs, lib, ... }:
let name = "%NAME%";
user = "%USER%";
email = "%EMAIL%"; in
{
# Shared shell configuration
zsh = {
enable = true;
autocd = false;
plugins = [
{
name = "powerlevel10k";
src = pkgs.zsh-powerlevel10k;
file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme";
}
{
name = "powerlevel10k-config";
src = lib.cleanSource ./config;
file = "p10k.zsh";
}
];
initExtraFirst = ''
if [[ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]]; then
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
. /nix/var/nix/profiles/default/etc/profile.d/nix.sh
fi
# Define variables for directories
export PATH=$HOME/.pnpm-packages/bin:$HOME/.pnpm-packages:$PATH
export PATH=$HOME/.npm-packages/bin:$HOME/bin:$PATH
export PATH=$HOME/.local/share/bin:$PATH
# Remove history data we don't want to see
export HISTIGNORE="pwd:ls:cd"
# Emacs is my editor
export ALTERNATE_EDITOR=""
export EDITOR="emacsclient -t"
export VISUAL="emacsclient -c -a emacs"
e() {
emacsclient -t "$@"
}
# nix shortcuts
shell() {
nix-shell '<nixpkgs>' -A "$1"
}
# Use difftastic, syntax-aware diffing
alias diff=difft
# Always color ls and group directories
alias ls='ls --color=auto'
'';
};
git = {
enable = true;
ignores = [ "*.swp" ];
userName = name;
userEmail = email;
lfs = {
enable = true;
};
extraConfig = {
init.defaultBranch = "main";
core = {
editor = "vim";
autocrlf = "input";
};
pull.rebase = true;
rebase.autoStash = true;
};
};
vim = {
enable = true;
plugins = with pkgs.vimPlugins; [ vim-airline vim-airline-themes vim-startify vim-tmux-navigator ];
settings = { ignorecase = true; };
extraConfig = ''
"" General
set number
set history=1000
set nocompatible
set modelines=0
set encoding=utf-8
set scrolloff=3
set showmode
set showcmd
set hidden
set wildmenu
set wildmode=list:longest
set cursorline
set ttyfast
set nowrap
set ruler
set backspace=indent,eol,start
set laststatus=2
set clipboard=autoselect
" Dir stuff
set nobackup
set nowritebackup
set noswapfile
set backupdir=~/.config/vim/backups
set directory=~/.config/vim/swap
" Relative line numbers for easy movement
set relativenumber
set rnu
"" Whitespace rules
set tabstop=8
set shiftwidth=2
set softtabstop=2
set expandtab
"" Searching
set incsearch
set gdefault
"" Statusbar
set nocompatible " Disable vi-compatibility
set laststatus=2 " Always show the statusline
let g:airline_theme='bubblegum'
let g:airline_powerline_fonts = 1
"" Local keys and such
let mapleader=","
let maplocalleader=" "
"" Change cursor on mode
:autocmd InsertEnter * set cul
:autocmd InsertLeave * set nocul
"" File-type highlighting and configuration
syntax on
filetype on
filetype plugin on
filetype indent on
"" Paste from clipboard
nnoremap <Leader>, "+gP
"" Copy from clipboard
xnoremap <Leader>. "+y
"" Move cursor by display lines when wrapping
nnoremap j gj
nnoremap k gk
"" Map leader-q to quit out of window
nnoremap <leader>q :q<cr>
"" Move around split
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
"" Easier to yank entire line
nnoremap Y y$
"" Move buffers
nnoremap <tab> :bnext<cr>
nnoremap <S-tab> :bprev<cr>
"" Like a boss, sudo AFTER opening the file to write
cmap w!! w !sudo tee % >/dev/null
let g:startify_lists = [
\ { 'type': 'dir', 'header': [' Current Directory '. getcwd()] },
\ { 'type': 'sessions', 'header': [' Sessions'] },
\ { 'type': 'bookmarks', 'header': [' Bookmarks'] }
\ ]
let g:startify_bookmarks = [
\ '~/.local/share/src',
\ ]
let g:airline_theme='bubblegum'
let g:airline_powerline_fonts = 1
'';
};
alacritty = {
enable = true;
settings = {
cursor = {
style = "Block";
};
window = {
opacity = 1.0;
padding = {
x = 24;
y = 24;
};
};
font = {
normal = {
family = "MesloLGS NF";
style = "Regular";
};
size = lib.mkMerge [
(lib.mkIf pkgs.stdenv.hostPlatform.isLinux 10)
(lib.mkIf pkgs.stdenv.hostPlatform.isDarwin 14)
];
};
dynamic_padding = true;
decorations = "full";
title = "Terminal";
class = {
instance = "Alacritty";
general = "Alacritty";
};
colors = {
primary = {
background = "0x1f2528";
foreground = "0xc0c5ce";
};
normal = {
black = "0x1f2528";
red = "0xec5f67";
green = "0x99c794";
yellow = "0xfac863";
blue = "0x6699cc";
magenta = "0xc594c5";
cyan = "0x5fb3b3";
white = "0xc0c5ce";
};
bright = {
black = "0x65737e";
red = "0xec5f67";
green = "0x99c794";
yellow = "0xfac863";
blue = "0x6699cc";
magenta = "0xc594c5";
cyan = "0x5fb3b3";
white = "0xd8dee9";
};
};
};
};
ssh = {
enable = true;
includes = [
(lib.mkIf pkgs.stdenv.hostPlatform.isLinux
"/home/${user}/.ssh/config_external"
)
(lib.mkIf pkgs.stdenv.hostPlatform.isDarwin
"/Users/${user}/.ssh/config_external"
)
];
matchBlocks = {
"github.com" = {
identitiesOnly = true;
identityFile = [
(lib.mkIf pkgs.stdenv.hostPlatform.isLinux
"/home/${user}/.ssh/id_github"
)
(lib.mkIf pkgs.stdenv.hostPlatform.isDarwin
"/Users/${user}/.ssh/id_github"
)
];
};
};
};
tmux = {
enable = true;
plugins = with pkgs.tmuxPlugins; [
vim-tmux-navigator
sensible
yank
prefix-highlight
{
plugin = power-theme;
extraConfig = ''
set -g @tmux_power_theme 'gold'
'';
}
{
plugin = resurrect; # Used by tmux-continuum
# Use XDG data directory
# https://github.com/tmux-plugins/tmux-resurrect/issues/348
extraConfig = ''
set -g @resurrect-dir '$HOME/.cache/tmux/resurrect'
set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-pane-contents-area 'visible'
'';
}
{
plugin = continuum;
extraConfig = ''
set -g @continuum-restore 'on'
set -g @continuum-save-interval '5' # minutes
'';
}
];
terminal = "screen-256color";
prefix = "C-x";
escapeTime = 10;
historyLimit = 50000;
extraConfig = ''
# Remove Vim mode delays
set -g focus-events on
# Enable full mouse support
set -g mouse on
# -----------------------------------------------------------------------------
# Key bindings
# -----------------------------------------------------------------------------
# Unbind default keys
unbind C-b
unbind '"'
unbind %
# Split panes, vertical or horizontal
bind-key x split-window -v
bind-key v split-window -h
# Move around panes with vim-like bindings (h,j,k,l)
bind-key -n M-k select-pane -U
bind-key -n M-h select-pane -L
bind-key -n M-j select-pane -D
bind-key -n M-l select-pane -R
# Smart pane switching with awareness of Vim splits.
# This is copy paste from https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
'';
};
}