-
Notifications
You must be signed in to change notification settings - Fork 2
/
home.nix
933 lines (858 loc) · 30.8 KB
/
home.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
{ config, pkgs, ... }:
let
sources = import ./nix/sources.nix;
overlays = let path = ./nix/overlays; in
with builtins;
map (n: import (path + ("/" + n)))
(filter
(n: match ".*\\.nix" n != null ||
pathExists (path + ("/" + n + "/default.nix")))
(attrNames (readDir path)));
pkgs = import sources.nixpkgs {
# Get all files in overlays
overlays = [
(_self: super: { inherit sources; })
# temporarily disable as I'm trying out #doom
# (import sources.emacs-overlay)
] ++ overlays;
};
niv = import sources.niv { };
link = config.lib.file.mkOutOfStoreSymlink;
# Darwin specific run-or-raise style script for emacs.
osascript = ''
open $HOME/.nix-profile/Applications/Emacs.app
command -v osascript > /dev/null 2>&1 && \
osascript -e 'tell application "System Events" to tell process "Emacs"
set frontmost to true
windows where title contains "Emacs"
if result is not {} then perform action "AXRaise" of item 1 of result
end tell' &> /dev/null || exit 0'';
python3Custom = pkgs.python3.buildEnv.override {
extraLibs = with pkgs.python3Packages; [ ipython pip virtualenv ];
};
espanso_app = let
app = "espanso.app";
version = "2.2.1";
sources = {
darwin-x86_64 = pkgs.fetchzip {
url = "https://github.com/federico-terzi/espanso/releases/download/v${version}/Espanso-Mac-Intel.zip";
hash = "sha256-lVO8Vwn7WIMIuLP1bKdG9fmsp6ll9JwzfiSGXMI9MR0=";
};
darwin-aarch64 = pkgs.fetchzip {
url = "https://github.com/federico-terzi/espanso/releases/download/v${version}/Espanso-Mac-M1.zip";
hash = "sha256-L4jEGJw1CIH7sXIh79oovlQnDG+RHEKjglmeGQUx398=";
};
};
in
pkgs.stdenvNoCC.mkDerivation rec {
pname = "espanso";
inherit version;
src = if pkgs.stdenv.isAarch64 then sources.darwin-aarch64 else sources.darwin-x86_64;
sourceRoot = "source";
postPatch = pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
# substituteInPlace Espanso.app/Contents/Info.plist \
# --replace "<string>espanso</string>" "<string>${placeholder "out"}/Applications/Espanso.app/Contents/MacOS/espanso</string>"
# substituteInPlace espanso/src/res/macos/com.federicoterzi.espanso.plist \
# --replace "<string>/Applications/Espanso.app/Contents/MacOS/espanso</string>" "<string>${placeholder "out"}/Applications/Espanso.app/Contents/MacOS/espanso</string>" \
# --replace "<string>/usr/bin" "<string>${placeholder "out"}/bin:/usr/bin"
'';
installPhase = ''
mkdir -p "$out/Applications/Espanso.app"
cp -R . "$out/Applications/Espanso.app"
mkdir -p "$out/bin"
ln -s "$out/Applications/Espanso.app/Contents/MacOS/espanso" "$out/bin/espanso"
'';
meta = {
description = "Cross-platform Text Expander written in Rust";
homepage = "https://espanso.org";
license = pkgs.lib.licenses.gpl3Plus;
platforms = pkgs.lib.platforms.darwin;
longDescription = ''
Espanso detects when you type a keyword and replaces it while you're typing.
'';
};
};
wezterm_app = let
altIcon = pkgs.fetchurl {
url = "https://github.com/mikker/wezterm-icon/raw/main/wezterm.icns";
hash = "sha256-svfuxXlRmFW+9n40LBm3JygzLbp90C4LAnCQAr4XFDw=";
};
# this works on my old intels and github
wezterm_app_intel = pkgs.stdenvNoCC.mkDerivation rec {
pname = "wezterm";
version = "20240203-110809-5046fc22";
src = pkgs.fetchzip {
url = "https://github.com/wez/wezterm/releases/download/${version}/WezTerm-macos-${version}.zip";
hash = "sha256-Az+HlnK/lRJpUSGm5UKyma1l2PaBKNCGFiaYnLECMX8=";
};
nativeBuildInputs = [
pkgs.installShellFiles
pkgs.ncurses # tic for terminfo
];
buildInputs = [ pkgs.undmg ];
installPhase = ''
mkdir -p "$out/Applications/"
cp -R . "$out/Applications/"
cp ${altIcon} $out/Applications/WezTerm.app/Contents/Resources/terminal.icns
mkdir -p $out/nix-support
echo "${passthru.terminfo}" >> $out/nix-support/propagated-user-env-packages
install -Dm644 ./WezTerm.app/Contents/Resources/wezterm.sh -t $out/etc/profile.d
'';
passthru = {
terminfo = pkgs.runCommand "wezterm-terminfo"
{
nativeBuildInputs = [ pkgs.ncurses ];
} ''
mkdir -p $out/share/terminfo $out/nix-support
tic -x -o $out/share/terminfo ${pkgs.wezterm.src}/termwiz/data/wezterm.terminfo
'';
};
meta = {
description = "A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust";
homepage = "https://wezfurlong.org/wezterm";
changelog = "https://wezfurlong.org/wezterm/changelog.html#${version}";
license = pkgs.lib.licenses.mit;
platforms = pkgs.lib.platforms.darwin;
};
};
# this works on my m1
wezterm_app_m1 = pkgs.wezterm.overrideAttrs (old: {
postPatch = old.postPatch + ''
cp ${altIcon} assets/macos/WezTerm.app/Contents/Resources/terminal.icns
'';
});
in
(if (pkgs.stdenv.isDarwin && pkgs.stdenv.isAarch64) then wezterm_app_m1 else wezterm_app_intel);
wrapEmacsclient = { emacs }:
pkgs.writeShellScriptBin "emacs.bash" (''
${emacs}/bin/emacsclient --no-wait --eval \
"(if (> (length (frame-list)) 0) 't)" 2> /dev/null | grep -q t
if [[ "$?" -eq 1 ]]; then
${emacs}/bin/emacsclient \
--quiet --create-frame --alternate-editor="" "$@"
else
${emacs}/bin/emacsclient --quiet "$@"
fi
''
+ pkgs.lib.optionalString pkgs.stdenv.isDarwin osascript)
;
theEmacs =
let
spacemacsIcon = pkgs.fetchurl {
url = "https://github.com/nashamri/spacemacs-logo/raw/917f2f2694019d534098f5e2e365b5f6e5ddbd37/spacemacs.icns";
sha256 = "sha256:0049lkmc8pmb9schjk5mqy372b3m7gg1xp649gibriabz9y8pnxk";
};
emacsSource = pkgs.emacs29-macport.overrideAttrs (old: {
patches =
(old.patches or [])
++ [
# Fix OS window role (needed for window managers like yabai)
(pkgs.fetchpatch {
url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/fix-window-role.patch";
sha256 = "sha256-+z/KfsBm1lvZTZNiMbxzXQGRTjkCFO4QPlEK35upjsE=";
})
# Use poll instead of select to get file descriptors
(pkgs.fetchpatch {
url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-29/poll.patch";
sha256 = "sha256-jN9MlD8/ZrnLuP2/HUXXEVVd6A+aRZNYFdZF8ReJGfY=";
})
# Enable rounded window with no decoration
(pkgs.fetchpatch {
url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-29/round-undecorated-frame.patch";
sha256 = "sha256-uYIxNTyfbprx5mCqMNFVrBcLeo+8e21qmBE3lpcnd+4=";
})
# Make Emacs aware of OS-level light/dark mode
# points to emacs-28, as 29 is just a symlink
(pkgs.fetchpatch {
url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/system-appearance.patch";
sha256 = "sha256-oM6fXdXCWVcBnNrzXmF0ZMdp8j0pzkLE66WteeCutv8=";
})
];
postPatch = old.postPatch + ''
# copy the nice icon to it
cp ${spacemacsIcon} mac/Emacs.app/Contents/Resources/Emacs.icns
'';
});
emacsPkg = emacsSource.pkgs.emacsWithPackages (epkgs: with epkgs; [
treesit-grammars.with-all-grammars
(nerd-icons.overrideAttrs(old: {
postInstall = old.postInstall + ''
install -Dm644 $src/fonts/*.ttf -t $out/share/fonts/truetype
'';
}))
] ++ (with epkgs.melpaPackages; [
vterm
all-the-icons
emojify
]));
deps = [
(pkgs.aspellWithDicts (dicts: with dicts; [ en en-computers en-science ]))
(pkgs.hunspellWithDicts (with pkgs.hunspellDicts; [ en_GB-large ]))
(pkgs.nuspellWithDicts (with pkgs.hunspellDicts; [ en_GB-large ]))
pkgs.graphviz-nox
pkgs.imagemagick # for image-dired
pkgs.fd
pkgs.gnutls # for TLS connectivity
pkgs.coreutils # needed for gls for dired
pkgs.binutils # native-comp needs 'as', provided by this
(pkgs.ripgrep.override { withPCRE2 = true; })
pkgs.zstd
pkgs.git
# :tools editorconfig
pkgs.editorconfig-core-c
# :tools lookup & :lang org +roam
pkgs.sqlite
# other goodies
pkgs.alejandra # to format nix code
pkgs.shfmt
pkgs.jq
];
env = ''
(setq exec-path (append exec-path '( ${pkgs.lib.concatMapStringsSep " " (x: ''"${x}/bin"'') deps} )))
'';
in
(pkgs.symlinkJoin {
name = "my-doom-emacs";
paths = [ emacsPkg ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/emacs \
--prefix PATH : ${pkgs.lib.makeBinPath deps}:${config.home.homeDirectory}/.emacs.d/bin \
--set LSP_USE_PLISTS true
wrapProgram $out/bin/emacsclient \
--prefix PATH : ${pkgs.lib.makeBinPath deps}:${config.home.homeDirectory}/.emacs.d/bin \
--set LSP_USE_PLISTS true
''
+ (pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
wrapProgram $out/Applications/Emacs.app/Contents/MacOS/Emacs \
--prefix PATH : ${pkgs.lib.makeBinPath deps}:${config.home.homeDirectory}/.emacs.d/bin \
--set LSP_USE_PLISTS true
'');
inherit (pkgs.emacs29-macport) meta;
});
myFonts = with pkgs; [
emacs-all-the-icons-fonts
emacsPackages.nerd-icons
nerdfonts
fira-code
font-awesome
# (iosevka.override { privateBuildPlan = { family = "Iosevka Term"; design = [ "term" "ss08" ]; }; set = "term-ss08"; })
(iosevka-bin.override { variant = "SGr-IosevkaTermSS08"; })
(iosevka-bin.override { variant = "Etoile"; })
powerline-fonts
powerline-symbols
source-code-pro
];
in
rec {
# Allow non-free (as in beer) packages
nixpkgs = {
config = {
allowUnfree = true;
allowUnsupportedSystem = true;
};
};
# fix for https://github.com/nix-community/home-manager/issues/3344
manual.manpages.enable = false;
xdg = {
enable = true;
configHome = "${home.homeDirectory}/.config";
dataHome = "${home.homeDirectory}/.local/share";
cacheHome = "${home.homeDirectory}/.cache";
};
# Packages in alphabetical order, as I can't do categories
home.packages = with pkgs; [
alejandra
cachix
curl
devenv
dua
duf
entr
espanso_app
eza
fd
fortune
gitAndTools.delta
# gitAndTools.git-branchless
gitAndTools.gitSVN
gitAndTools.hub
gnused
gron
htop
hyperfine
imagemagick
jc
jless
jq
loc
lua
moreutils
mtr
netcat
niv.niv
nixpkgs-fmt
nmap
openssh # needed because macOS version is limited wrt yubikey
p7zip
paperkey
python3Custom
readline
ripgrep
rsync
sd
shellcheck
shfmt
tree
unar
# problems with fastparquet, hence the override
# problems with building skia-pathops (dep of fonttools, dep of visidata), hence comment out
# (visidata.overrideAttrs (old: rec {
# propagatedBuildInputs = old.propagatedBuildInputs ++ [ python3Packages.pyarrow python3Packages.fastparquet ];
# }))
xz
yq-go
yubico-piv-tool
yubikey-agent
yubikey-manager
yubikey-personalization
watch
wezterm_app
zstd
(pkgs.callPackage ./nix/pkgs/orgprotocolclient.nix { emacs = theEmacs; })
# Use my own bespoke wrapper for `emacsclient`.
(wrapEmacsclient { emacs = theEmacs; })
# need to include the Emacs itself, as I'm avoiding programs.emacs because it makes doom unusable
theEmacs
] ++ myFonts;
# TODO:
# Install the following apps (might need nix-darwin)
# hammerspoon
# karabiner
# istatmenus
# trello
# busycall
# programs.emacs = {
# enable = true;
# package = theEmacs;
# # extraPackages = (epkgs: [epkgs.pdf-tools] );
# };
programs.fzf.enable = true;
programs.direnv = {
enable = true;
enableZshIntegration = true;
nix-direnv.enable = true;
};
programs.bat = {
enable = true;
config = {
style = "header,changes";
theme = "Monokai Extended Light";
};
};
programs.carapace = {
enable = true;
enableZshIntegration = true;
};
programs.neovim = {
enable = true;
viAlias = true;
vimAlias = true;
vimdiffAlias = true;
withRuby = false;
extraConfig = ''
syntax on
syntax enable " Turn on syntax highlighting allowing local overrides
set hidden " hide buffers instead of removing them
set number " Show line numbers
set relativenumber " Show them relative to line
set ruler " Show line and column number
set termguicolors " Use full colors
set clipboard=unnamed " Allow for x-app pasting
'';
};
# home.file.".emacs.d" = {
# source = link sources.doomemacs;
# recursive = true;
# onChange = "${config.home.homeDirectory}/.emacs.d/bin/doom sync";
# };
# This creates a symlink to the file, so I can easily edit it
# Not for the faint of heart, though...
# TODO: maybe patch https://github.com/berbiche/dotfiles/blob/b5cb06db7764a963ab10b943d9269a51b12991e0/profiles/dev/home-manager/emacs/default.nix#L42
home.file.".doom.d".source = link ./configs/doom;
programs.jujutsu = {
enable = true;
};
programs.git = {
enable = true;
package = pkgs.gitAndTools.gitFull;
userEmail = "nikola@knezevic.ch";
userName = "Nikola Knezevic";
# aliases are defined in ~/.gitaliases
extraConfig = {
color = {
status = "auto";
diff = "auto";
branch = "auto";
ui = "auto";
};
credential.helper = "osxkeychain";
core.whitespace = "fix,-indent-with-non-tab,trailing-space,cr-at-eol";
repack.usedeltabaseoffset = "true";
diff = {
renames = "copies";
mnemonicprefix = "true";
algorithm = "histogram";
};
branch.autosetupmerge = "true";
push.default = "current";
merge.stat = "true";
pull.ff = "only";
rebase = {
autoSquash = true;
autoStash = true;
};
rerere = {
autoupdate = true;
enabled = true;
};
# Sort tags as version numbers whenever applicable, so 1.10.2 is AFTER 1.2.0.
tag.sort = "version:refname";
};
# Replaces ~/.gitignore
ignores = [
".cache/"
".DS_Store"
".idea/"
"*.swp"
"*.elc"
"auto-save-list"
".direnv/"
# exclude nix-build result
"result"
"result-*"
];
# see home.file.".gitaliases".source below
includes = [
{ path = "~/.gitaliases"; }
];
};
home.file.".gitaliases".source = ./configs/gitaliases;
programs.z-lua = {
enable = true;
options = [ "once" "fzf" ];
};
programs.zsh = rec {
enable = true;
# This way, my functions could be stored under
# .config/zsh/lib
dotDir = ".config/zsh";
autosuggestion.enable = true;
enableCompletion = true;
history = {
size = 50000;
save = 500000;
# Put the ZSH history into the same directory as the configuration.
# Also, the path must be absolute, relative paths just make new directories
# wherever you're working from.
path =
let
inherit (config.home) homeDirectory;
in
"${homeDirectory}/${dotDir}/history";
extended = true;
ignoreDups = true;
share = true;
};
sessionVariables = rec {
LANG = "en_US.UTF-8";
LC_ALL = "en_US.UTF-8";
NVIM_TUI_ENABLE_TRUE_COLOR = "1";
BROWSER = if pkgs.stdenv.isDarwin then "open" else "xdg-open";
# use the same nixpkgs for the rest of the system as we use here
NIX_PATH = "nixpkgs=${sources.nixpkgs}:home-manager=${sources."home-manager"}";
EDITOR = "vim";
VISUAL = EDITOR;
GIT_EDITOR = EDITOR;
XDG_CONFIG_HOME = xdg.configHome;
XDG_CACHE_HOME = xdg.cacheHome;
XDG_DATA_HOME = xdg.dataHome;
GOPATH = "$HOME/go";
PATH = "$HOME/bin:$GOPATH/bin:$HOME/.emacs.d/bin:$PATH";
TERM = "xterm-256color";
LESS = "-F -g -i -M -R -S -w -X -z-4";
# This is to make `z my-dir` work with z.lua
_ZL_HYPHEN = "1";
};
localVariables = {
# This way, C-w deletes words (path elements)
WORDCHARS = "*?_-.[]~&;!#$%^(){}<>";
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE = "fg=8";
};
shellAliases = {
l = "eza --color auto";
ls = "eza -G --color auto -a -s type";
ll = "eza -l --color always -a -s type";
"]" = "open";
dl = "\curl -O -L";
up = "\cd ..";
p = "pushd";
pd = "perldoc";
mkdir = "nocorrect mkdir";
cat = "bat";
x = "unar";
zb = "z -b";
zh = "z -I -t .";
# fd's default of not searching hidden files is annoying
f = "fd -H --no-ignore";
k = "kubectl";
hm = "home-manager";
d = "direnv";
df = "duf";
du = "dua";
# commonly used git aliases (lifted from prezto)
g = "git";
ga = "git add";
gai = "git add -i";
gap = "git add --patch";
gau = "git add --update";
gb = "git branch";
gbx = "git branch -d";
gbX = "git branch -D";
gba = "git branch -a";
gbm = "git branch -m";
gc = "git commit --verbose";
gcm = "git commit --message";
gcf = "git commit --amend --reuse-message HEAD";
gco = "git checkout";
gd = "git diff";
gl = "git pull";
gm = "git merge";
gma = "git merge --abort";
gcpa = "git cherry-pick --abort";
gp = "git push -u";
gpf = "git push -u --force-with-lease";
gpa = "git push --all && git push --tags";
gr = "git rebase";
gri = "git rebase --interactive";
gra = "git rebase --abort";
grc = "git rebase --continue";
grs = "git rebase --skip";
gst = "git status";
gt = "git tag";
gup = ''git fetch -p && git rebase --autostash "''${$(git symbolic-ref refs/remotes/origin/HEAD)#refs/remotes/}"'';
gfa = "git fetch --all -v";
stash = "git stash";
unstash = "git stash pop";
staged = "git diff --no-ext-diff --cached";
};
initExtraFirst = ''
DIRSTACKSIZE=10
setopt emacs
setopt notify globdots correct cdablevars autolist
setopt correctall autocd recexact longlistjobs
setopt autoresume
setopt rcquotes mailwarning
unsetopt bgnice
setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups
setopt COMPLETE_IN_WORD # Complete from both ends of a word.
setopt ALWAYS_TO_END # Move cursor to the end of a completed word.
setopt AUTO_MENU # Show completion menu on a successive tab press.
setopt AUTO_LIST # Automatically list choices on ambiguous completion.
setopt EXTENDED_GLOB # Needed for file modification glob modifiers with compinit
unsetopt AUTO_PARAM_SLASH # If completed parameter is a directory, do not add a trailing slash.
unsetopt MENU_COMPLETE # Do not autoselect the first completion entry.
unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor.
# compinit will be called after this block
'';
# Called whenever zsh is initialized
initExtra = ''
# Nix setup (environment variables, etc.)
if [ -e ~/.nix-profile/etc/profile.d/nix.sh ]; then
. ~/.nix-profile/etc/profile.d/nix.sh
fi
# expands .... to ../..
function expand-dot-to-parent-directory-path {
if [[ $LBUFFER = *.. ]]; then
LBUFFER+='/..'
else
LBUFFER+='.'
fi
}
zle -N expand-dot-to-parent-directory-path
bindkey -M emacs '\e[1;5D' backward-word
bindkey -M emacs '\e[1;5C' forward-word
bindkey -M emacs '\e[3~' delete-char
bindkey -M emacs "^P" history-substring-search-up
bindkey -M emacs "^N" history-substring-search-down
# also bind to keys up and down
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
# expand .... to ../..
bindkey -M emacs "." expand-dot-to-parent-directory-path
# but not during incremental search
bindkey -M isearch . self-insert 2> /dev/null
# more flexible push-line, C-q kills the line and restores after new line is executed
for key in "\C-Q" "\e"{q,Q}
bindkey -M emacs "$key" push-line-or-edit
# Expand history on space.
bindkey -M emacs ' ' magic-space
fpath=(${config.xdg.configHome}/zsh/functions(-/FN) $fpath)
# functions must be autoloaded, do it in a function to isolate
function {
local pfunction_glob='^([_.]*|prompt_*_setup|README*|*~)(-.N:t)'
local pfunction
# Extended globbing is needed for listing autoloadable function directories.
setopt LOCAL_OPTIONS EXTENDED_GLOB
for pfunction in ${config.xdg.configHome}/zsh/functions/$~pfunction_glob; do
autoload -Uz "$pfunction"
done
}
eval "$(lua ${sources.rh}/rh.lua --init zsh ~/work)"
# Theme (custom built on powerlevel10k)
# First load all variables
source ${config.xdg.configHome}/zsh/p10k.zsh
# Then source the theme
source ${sources.powerlevel10k}/powerlevel10k.zsh-theme
# zsh-histdb start
HISTDB_TABULATE_CMD=(sed -e $'s/\x1f/\t/g')
source ''${ZDOTDIR}/plugins/zsh-histdb/sqlite-history.zsh
_zsh_autosuggest_strategy_histdb_top() {
local query="
select commands.argv from history
left join commands on history.command_id = commands.rowid
left join places on history.place_id = places.rowid
where commands.argv LIKE '$(sql_escape $1)%'
group by commands.argv, places.dir
order by places.dir != '$(sql_escape $PWD)', count(*) desc
limit 1
"
suggestion=$(_histdb_query "$query")
}
ZSH_AUTOSUGGEST_STRATEGY=histdb_top
# need to rebind the key again, since plugins are sourced before sourcing fzf
bindkey '^R' histdb-fzf-widget
# zsh-histdb end
# wezterm shell integration
source "${config.home.profileDirectory}/etc/profile.d/wezterm.sh"
'';
loginExtra = ''
# Execute code only if STDERR is bound to a TTY.
if [[ -o INTERACTIVE && -t 2 ]]; then
# Print a random, hopefully interesting, adage.
if (( $+commands[fortune] )); then
fortune -s
print
fi
fi >&2
'';
plugins = [
{
name = "zsh-autosuggestions";
src = sources.zsh-autosuggestions;
}
{
name = "fast-syntax-highlighting";
src = sources.fast-syntax-highlighting;
}
{
name = "zsh-history-substring-search";
src = sources.zsh-history-substring-search;
}
{
name = "async";
src = sources.zsh-async;
}
{
# look at home.file.".p10k.zsh".source for config
name = "powerlevel10k";
src = sources.powerlevel10k;
}
{
name = "zsh-you-should-use";
src = sources.zsh-you-should-use;
}
{
name = "zsh-histdb";
src = sources.zsh-histdb;
}
{
name = "zsh-histdb-fzf";
src = sources.zsh-histdb-fzf;
}
];
};
xdg.configFile."zsh/p10k.zsh".source = ./zsh/p10k.zsh;
xdg.configFile."zsh/functions".source = ./zsh/functions;
xdg.configFile."wezterm".source = link ./configs/wezterm;
# Setting up aspell
home.file.".aspell.conf".text = ''
data-dir ${builtins.getEnv "HOME"}/.nix-profile/lib/aspell
master en_US
extra-dicts en-computers.rws
add-extra-dicts en_US-science.rws
'';
# It's Hammerspoon time
home.file.".hammerspoon/init.lua".source = ./configs/hammerspoon/init.lua;
home.file.".hammerspoon/colemak.lua".source = ./configs/hammerspoon/colemak.lua;
home.file.".hammerspoon/grille.lua".source = "${sources.hs-grille}/grille.lua";
home.file.".hammerspoon/winter.lua".source = "${sources.hs-winter}/winter.lua";
# Karabiner's config file
xdg.configFile."karabiner/karabiner.json".source = link ./configs/karabiner/karabiner.json;
# Use cachix to speed up some fetches (niv, specifically)
xdg.configFile."nix/nix.conf".text = ''
experimental-features = nix-command flakes
keep-outputs = true
keep-derivations = true
substituters = https://knl.cachix.org https://niv.cachix.org https://cache.nixos.org https://nix-community.cachix.org https://fzakaria.cachix.org https://devenv.cachix.org
trusted-public-keys = knl.cachix.org-1:/iqUbqBexzvcDn5ee7Q3Kj1MBh6P9RTwEVh6hh9SDE0= niv.cachix.org-1:X32PCg2e/zAm3/uD1ScqW2z/K0LtDyNV7RdaxIuLgQM= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= fzakaria.cachix.org-1:SpQviPuoJ3GnCVG40vwTp/r9y1/cbwP808SbMJ/XlGo= devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=
'';
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
targets.darwin.defaults = {
"com.apple.desktopservices" = {
# Avoid creating .DS_Store files on network volumes (default: false).
DSDontWriteNetworkStores = true;
DSDontWriteUSBStores = true;
};
"com.apple.dock" = {
# hide and put it on right
autohide = true;
orientation = "right";
# Don’t automatically rearrange Spaces based on most recent use
"mru-spaces" = 0;
# Don’t show Dashboard as a Space
"dashboard-in-overlay" = true;
# Make it small
tilesize = 42;
};
# Disable Dashboard
"com.apple.dashboard" = {
"mcx-disabled" = true;
};
"Apple Global Domain" = {
# Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs) (default: not set).
AppleKeyboardUIMode = 3;
# Always show scrollbars (default: WhenScrolling).
AppleShowScrollBars = "Always";
# Show all filename extensions in Finder (default: false).
AppleShowAllExtensions = true;
# Expand save panel (default: false).
NSNavPanelExpandedStateForSaveMode = true;
# Display ASCII control characters using caret notation in standard text views
# Try e.g. `cd /tmp; unidecode "\x{0000}" > cc.txt; open -e cc.txt`
NSTextShowsControlCharacters = true;
# Disable smart quotes as they’re annoying when typing code
NSAutomaticQuoteSubstitutionEnabled = false;
# Disable smart dashes as they’re annoying when typing code
NSAutomaticDashSubstitutionEnabled = false;
# Disable automatic capitalization as it’s annoying when typing code
NSAutomaticCapitalizationEnabled = false;
# Disable automatic period substitution as it’s annoying when typing code
NSAutomaticPeriodSubstitutionEnabled = false;
# Disable auto-correct
NSAutomaticSpellingCorrectionEnabled = false;
# Disable “natural” (Lion-style) scrolling
"com.apple.swipescrolldirection" = false;
# Trackpad: enable tap to click for this user
"com.apple.mouse.tapBehavior" = 1;
# Trackpad: map tap with two fingers to secondary click
"com.apple.trackpad.trackpadCornerClickBehavior" = 1;
"com.apple.trackpad.enableSecondaryClick" = true;
# Set language and text formats
AppleLanguages = [ "en" ];
AppleLocale = "en_CH";
AppleMeasurementUnits = "Centimeters";
AppleMetricUnits = true;
};
"com.apple.finder" = {
# Display full POSIX path as Finder window title (default: false).
_FXShowPosixPathInTitle = true;
# Disable the warning when changing a file extension (default: true).
FXEnableExtensionChangeWarning = false;
# Show hidden files by default
AppleShowAllFiles = true;
# Show status bar
ShowStatusBar = true;
# Show path bar
ShowPathbar = true;
# Allow text selection in Quick Look
QLEnableTextSelection = true;
};
"com.apple.driver.AppleBluetoothMultitouch.trackpad" = {
# Trackpad: enable tap to click for this user
Clicking = true;
# Trackpad: map tap with two fingers to secondary click
TrackpadCornerSecondaryClick = 1;
TrackpadRightClick = true;
};
"com.apple.HIToolbox" = {
AppleCurrentKeyboardLayoutInputSourceID = "com.apple.keylayout.ABC";
AppleEnabledInputSources = [
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 252;
"KeyboardLayout Name" = "ABC";
}
{
"Bundle ID" = "com.apple.inputmethod.EmojiFunctionRowItem";
InputSourceKind = "Non Keyboard Input Method";
}
{
"Bundle ID" = "com.apple.PressAndHold";
InputSourceKind = "Non Keyboard Input Method";
}
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 19;
"KeyboardLayout Name" = "Swiss German";
}
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 19521;
"KeyboardLayout Name" = "Serbian";
}
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = -19521;
"KeyboardLayout Name" = "Serbian-Latin";
}
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = -1;
"KeyboardLayout Name" = "Unicode Hex Input";
}
];
AppleSelectedInputSources = [
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 252;
"KeyboardLayout Name" = "ABC";
}
{
"Bundle ID" = "com.apple.inputmethod.EmojiFunctionRowItem";
InputSourceKind = "Non Keyboard Input Method";
}
{
"Bundle ID" = "com.apple.PressAndHold";
InputSourceKind = "Non Keyboard Input Method";
}
];
};
};
home = {
# Home Manager needs a bit of information about you and the
# paths it should manage.
username = builtins.getEnv "USER";
homeDirectory = builtins.getEnv "HOME";
# This value determines the Home Manager release that your
# configuration is compatible with. This helps avoid breakage
# when a new Home Manager release introduces backwards
# incompatible changes.
#
# You can update Home Manager without changing this value. See
# the Home Manager release notes for a list of state version
# changes in each release.
stateVersion = "23.05";
};
}