btw i use nix
1{
2 pkgs,
3 config,
4 lib,
5 ...
6}:
7
8let
9 tmux-sessionizer = pkgs.writeScriptBin "tmux-sessionizer" ''
10 #!/usr/bin/env bash
11
12 hist_file=~/.cache/sessionizer.hist
13
14 if [[ $# -eq 1 ]]; then
15 selected=$1
16 else
17 selected=$((tac "$hist_file"
18 find ~/ ~/projects -mindepth 1 -maxdepth 1 -type d -not -path '*/[.]*'
19 awk '{print "ssh " $1}' ~/.ssh/known_hosts 2>/dev/null | sort -u
20 echo /etc/nixos) | awk '!seen[$0]++' | fzf --print-query | tail -n 1)
21 fi
22
23 if [[ -z $selected ]]; then
24 exit 0
25 fi
26
27 echo "$selected" >> $hist_file
28
29 selected_name=$(basename "$selected" | tr . _)
30 tmux_running=$(pgrep tmux)
31
32 if [[ $selected == ssh\ * ]]; then
33 if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
34 tmux new-session -s "$selected_name" "$selected"
35 exit 0
36 fi
37
38 if ! tmux has-session -t="$selected_name" 2> /dev/null; then
39 tmux new-session -ds "$selected_name" "$selected"
40 fi
41 else
42 if [[ -z $TMUX ]] && [[ -z "$tmux_running" ]]; then
43 tmux new-session -s "$selected_name" -c "$selected"
44 exit 0
45 fi
46
47 if ! tmux has-session -t="$selected_name" 2> /dev/null; then
48 tmux new-session -ds "$selected_name" -c "$selected"
49 fi
50 fi
51
52
53 tmux switch-client -t "$selected_name"
54 '';
55in
56{
57 imports = [
58 ./mail.nix
59 ./calendar.nix
60 ./gui/default.nix
61 ./nvim/default.nix
62 ./emacs/default.nix
63 ./battery.nix
64 ];
65
66 options.custom.machineColour = lib.mkOption {
67 type = lib.types.str;
68 default = "cyan";
69 };
70
71 config = {
72 home.sessionVariables = {
73 EDITOR = "nvim";
74 NIX_AUTO_RUN = "y";
75 NIX_AUTO_RUN_INTERACTIVE = "y";
76 GOPATH = "$HOME/.go";
77 };
78 home.packages = with pkgs; [
79 htop
80 gnumake
81 inetutils
82 dig
83 fzf
84 jq
85 bc
86 openssh
87 # multicore rust command line utils
88 dua
89 fd
90 ripgrep
91 tmux-sessionizer
92 ];
93
94 home.shellAliases = {
95 ls = "ls -p --color=auto";
96 pls = "sudo $(fc -ln -1)";
97 o = "xdg-open";
98 se = "sudoedit";
99 su = "su -p";
100 ssh = "TERM=xterm ssh";
101 nix-shell = "nix-shell --command zsh";
102 inhibit-lid = "systemd-inhibit --what=handle-lid-switch sleep 1d";
103 tmux = "tmux -2";
104 feh = "feh --scale-down --auto-zoom";
105 nix-stray-roots = "nix-store --gc --print-roots | egrep -v '^(/nix/var|/run|/proc|{censored})'";
106 };
107
108 # https://github.com/nix-community/home-manager/issues/1439#issuecomment-1106208294
109 home.activation = {
110 linkDesktopApplications = {
111 after = [
112 "writeBoundary"
113 "createXdgUserDirectories"
114 ];
115 before = [ ];
116 data = ''
117 rm -rf ${config.xdg.dataHome}/"applications/home-manager"
118 mkdir -p ${config.xdg.dataHome}/"applications/home-manager"
119 cp -Lr ${config.home.homeDirectory}/.nix-profile/share/applications/* ${config.xdg.dataHome}/"applications/home-manager/"
120 '';
121 };
122 };
123
124 programs.zsh = {
125 enable = true;
126 history = {
127 size = 1000000;
128 path = "$HOME/.histfile";
129 share = false;
130 };
131 autosuggestion.enable = true;
132 syntaxHighlighting.enable = true;
133 enableCompletion = true;
134 initExtraFirst = ''
135 export ZSH_AUTOSUGGEST_STRATEGY=(match_prev_cmd completion history)
136 export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=5"
137 PROMPT='%(?..%F{red}%3?%f )%F{${config.custom.machineColour}}%n@%m%f:%~ %#'$'\n'
138 '';
139 initExtra = builtins.readFile ./zsh.cfg;
140 };
141
142 programs.bash.initExtra = ''
143 PS1='\[\e[36m\]\u@\h:\W\[\e[0m\] $ '
144 '';
145
146 programs.gpg = {
147 enable = true;
148 publicKeys = [
149 {
150 text = ''
151 -----BEGIN PGP PUBLIC KEY BLOCK-----
152
153 mDMEZZ1zrBYJKwYBBAHaRw8BAQdA8Zeb1OFbzEWx3tM7ylO0ILCnDCG2JoA/iay6
154 iWXmB7G0G1J5YW4gR2liYiA8cnlhbkBmcmV1bWgub3JnPoiUBBMWCgA8FiEE67lV
155 Y2amyVrqUoWjGfnbY35Mq3QFAmWdc6wCGwMFCQPCZwAECwkIBwQVCgkIBRYCAwEA
156 Ah4FAheAAAoJEBn522N+TKt0mwcA/AvuKD4dTPj4hJ/cezEWDOFELMaVYZqDS3V1
157 LmRJrdIHAQDYgST8awabyd2Y3PRTFf9ZcWRRompeg0v7c2hCc9/3A7g4BGWdc6wS
158 CisGAQQBl1UBBQEBB0AdJP8T3mGR7SUp9DBlIaVU1ESRC7sLWbm4QFCR1JTfSgMB
159 CAeIfgQYFgoAJhYhBOu5VWNmpsla6lKFoxn522N+TKt0BQJlnXOsAhsMBQkDwmcA
160 AAoJEBn522N+TKt07KwA/10R+ejRZeW0cYScowHAsnDZ09A43bZvdp1X7KeQHMl+
161 AQD+TbceHh393VFc4tkl5pYHfrmkCXMdN0faVWolkc7GCA==
162 =EfP/
163 -----END PGP PUBLIC KEY BLOCK-----
164 '';
165 trust = "ultimate";
166 }
167 ];
168 };
169 services.gpg-agent.pinentryPackage = pkgs.pinentry-qt;
170
171 programs.git = {
172 enable = true;
173 extraConfig = {
174 init = {
175 defaultBranch = "main";
176 };
177 user = {
178 email = "ryan@freumh.org";
179 name = "Ryan Gibb";
180 signingKey = "19F9DB637E4CAB74";
181 };
182 alias = {
183 s = "status";
184 c = "commit";
185 cm = "commit --message";
186 ca = "commit --amend";
187 cu = "commit --message update";
188 ci = "commit --message initial";
189 br = "branch";
190 co = "checkout";
191 df = "diff";
192 l = "log";
193 lg = "log -p";
194 lol = "log --graph --decorate --pretty=oneline --abbrev-commit";
195 lola = "log --graph --decorate --pretty=oneline --abbrev-commit --all";
196 ls = "ls-files";
197 a = "add";
198 aa = "add --all";
199 au = "add -u";
200 ap = "add --patch";
201 ai = "add -i";
202 ps = "push";
203 pf = "push --force";
204 pu = "push --set-upstream";
205 pl = "pull";
206 pr = "pull --rebase";
207 acp = "!git add --all && git commit --message update && git push";
208 d = "diff";
209 dc = "diff --cached";
210 };
211 };
212 };
213
214 programs.tmux = {
215 enable = true;
216 extraConfig =
217 let
218 toggle-status-bar = pkgs.writeScript "toggle-status-bar.sh" ''
219 #!/usr/bin/env bash
220 window_count=$(tmux list-windows | wc -l)
221 if [ "$window_count" -ge "2" ]; then
222 tmux set-option status on
223 else
224 tmux set-option status off
225 fi
226 '';
227 in
228 # https://github.com/ThePrimeagen/.dotfiles/blob/master/bin/.local/scripts/tmux-sessionizer
229 ''
230 # alternative modifier
231 unbind C-b
232 set-option -g prefix C-a
233 bind-key C-a send-prefix
234
235 set-window-option -g mode-keys vi
236 set-option -g mouse on
237 set-option -g set-titles on
238 set-option -g set-titles-string "#T"
239 bind-key t capture-pane -S -\; new-window '(tmux show-buffer; tmux delete-buffer) | nvim -c $'
240 bind-key u capture-pane\; new-window '(tmux show-buffer; tmux delete-buffer) | ${pkgs.urlscan}/bin/urlscan'
241 set-hook -g session-window-changed 'run-shell ${toggle-status-bar}'
242 set-hook -g session-created 'run-shell ${toggle-status-bar}'
243 # Fixes C-Up/Down in TUIs
244 set-option default-terminal tmux
245 # https://stackoverflow.com/questions/62182401/neovim-screen-lagging-when-switching-mode-from-insert-to-normal
246 # locking
247 set -s escape-time 0
248 set -g lock-command ${pkgs.vlock}/bin/vlock
249 set -g lock-after-time 0 # Seconds; 0 = never
250 bind L lock-session
251 # for .zprofile display environment starting https://github.com/tmux/tmux/issues/3483
252 set-option -g update-environment XDG_VTNR
253 # Allow clipboard with OSC-52 work
254 set -s set-clipboard on
255 # toggle
256 bind -r ^ last-window
257 # vim copy
258 bind -T copy-mode-vi v send-keys -X begin-selection
259 bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
260 # find
261 bind-key -r f run-shell "tmux neww tmux-sessionizer"
262 # reload
263 bind-key r source-file ~/.config/tmux/tmux.conf
264 # kill unattached
265 bind-key K run-shell 'tmux ls | grep -v attached | cut -d: -f1 | xargs -I {} tmux kill-window -t {}'
266 '';
267 };
268
269 programs.less = {
270 enable = true;
271 keys = ''
272 #line-edit
273 \e[1;5D word-left
274 \e[1;5C word-right
275 '';
276 };
277
278 programs.go.goPath = "~/.go";
279
280 home.stateVersion = "22.05";
281 };
282}