-
Notifications
You must be signed in to change notification settings - Fork 1
/
dot_bashrc
2609 lines (2340 loc) · 75 KB
/
dot_bashrc
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
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## Copyright © 2018, 2019, 2020, 2021, 2022, 2023, 2024 Oleg Pykhalov <go.wigust@gmail.com>
## Released under the GNU GPLv3 or any later version.
if [ -f "/etc/skel/.bashrc" ]
then
# Load the skel profile's settings.
source "/etc/skel/.bashrc"
fi
if [ -f "$HOME/.bash_vterm" ] && [[ $INSIDE_EMACS == vterm ]]
then
source "$HOME/.bash_vterm"
fi
if [ -f "$HOME/.bash_aliases" ]
then
# Load the Bash aliases and functions.
source "$HOME/.bash_aliases"
fi
if [ -f "$HOME/.bash_guix" ]
then
source "$HOME/.bash_guix"
fi
function dmesg()
{
if [[ -z ${@:1} ]] && [[ -e "${HOME}/.guix-profile/bin/spacer" ]]
then
sudo /run/current-system/profile/bin/dmesg \
--reltime \
--human \
--nopager \
--decode \
--ctime \
--follow \
--color=always \
| "${HOME}/.guix-profile/bin/spacer"
else
sudo /run/current-system/profile/bin/dmesg
fi
}
alias ,h="${BROWSER} ~/.guix-profile/share/doc/concise-gnu-bash/concise-gnu-bash.pdf"
alias ,c='command'
# Count number of code lines
alias ,l='tokei'
# Show Git repository statics
alias ,g='onefetch'
alias rm="rm -i"
alias cp="cp -i"
alias mv="mv -i"
alias mtr="sudo mtr --show-ips --aslookup"
alias xclipp='xclip -selection secondary'
alias svg=xdot
alias hosts='hosts --auto-sudo'
alias log='sudo lnav /var/log'
alias lsns='lsns --notruncate --output-all'
alias goaccess='goaccess --log-format=COMBINED'
alias catj=gron
alias sqlite-visualize=sqleton
alias tree="tree --dirsfirst -C"
alias free="free -mht"
alias psc='ps xawf -eo pid,user,cgroup,args'
alias markdown-github=grip
alias iostat='iostat -xm 2'
alias dhall-to-yaml='dhall-to-yaml --omit-empty'
alias noise-brown="mpv --no-resume-playback --loop '/srv/video/metube/Smoothed Brown Noise.webm'"
mem()
{
cat <<EOF
The top 5 applications using most RAM:
$(ps -eo pid,%mem,cmd --sort=-%mem | head -n 6)
EOF
}
httping()
{
case "$1" in
majordomo*)
command httping -s --colors https://www.majordomo.ru
;;
*)
command httping -s --colors "$@"
;;
esac
}
emacs()
{
case "$1" in
signals)
"$BROWSER" https://emacs.stackexchange.com/a/44087
;;
tty)
emacs -nw -Q "${@:2}"
;;
*)
command emacs "$@"
esac
}
emc()
{
# Setting TERM is required to fix colors in tmux running inside Alacritty.
TERM=xterm-256color command emacsclient --create-frame --tty "$@"
}
guile()
{
(
if [ "$INSIDE_EMACS" == "vterm" ]
then
unset INSIDE_EMACS
fi
case "$1" in
wisp)
exec -a "$0" guile -x .w --language=wisp "${@:2}"
;;
*)
exec -a "$0" guile "$@"
;;
esac
)
}
cat()
{
if [[ "${*:-1}" == /proc/*/environ ]]
then
command cat "${@: -1}" | tr '\000' '\n'
elif [[ "${*:-1}" == *.md ]]
then
command glow "$@"
else
command cat "$@"
fi
}
benchmark()
{
hyperfine "$@"
}
lsd()
{
if [ "$INSIDE_EMACS" == "vterm" ]
then
exa --all --long "$@"
else
ls "$@"
fi
}
if [ -f "$HOME/.guix-profile/etc/profile.d/autojump.sh" ]
then
source "$HOME/.guix-profile/etc/profile.d/autojump.sh"
fi
# http://puzan.info/linux/2014-05-14-direnv.html
if [ -f "$HOME/.guix-profile/bin/direnv" ]
then
eval "$(direnv hook bash)"
fi
man_in_emacs()
{
emacsclient --eval "(man \"$1\")"
}
man_to_pdf()
{
man -t "$1" | ps2pdf - "$1.pdf"
}
stat_link()
{
stat --format=%N "$@"
}
# Origin <https://www.fsf.org/blogs/directory/the-free-software-directory-needs-you-irc-meetups-every-friday-1>.
#
# Every Friday at 12:00-15:00 EDT (16:00 to 19:00 UTC)
# meet on IRC in the #fsf channel on irc.freenode.org
date_fsf()
{
date --date='TZ="America/New_York" 12:00 this Fri'
}
cl()
{
echo "$(tput cols)x$(tput lines)"
}
alias bedtime='sudo loginctl suspend'
alias aria2c='aria2c --seed-time=0'
ihs()
{
GUILE_INSTALL_LOCALE=0 \
GUIX_BUILD_OPTIONS='' \
IHS_USER=pyhalov \
IHS_PASS="$(pass show majordomo/private/hms/pyhalov)" \
CVM_USER=cron \
CVM_PASS="$(pass show majordomo/private/cvm/cron)" \
command ihs "$@"
}
if [[ -e "${HOME}/.bash.d/nix.bash" ]]
then
source "${HOME}/.bash.d/nix.bash"
fi
rg()
{
case "$1" in
edit)
last_command="$(history -w /dev/stdout | tail --lines=2 | head --lines=1)";
if [[ "$last_command" =~ 'rg' ]] && [[ "$last_command" != *last_command* ]]
then last_output="$(eval "$last_command")"
emacsclient --no-wait +"$(echo "$last_output" | cut -d: -f 2)" "$(echo "$last_output" | cut -d: -f 1)"
else
emacsclient --no-wait "$@"
fi
stumpish emacsclient
;;
*)
command rg "$@"
esac
}
# TODO: readlink could fail to enter `guix environment`
# alias wi-pure-bash="env -i $(readlink $(which bash)) --noprofile --norc"
# TODO: Escape window names with asterisks.
# wi_x_resize_window ()
# {
# window_name=$(xwininfo | grep 'Window id' | awk '{ print $5 }')
# xdotool search --name "$window_name" windowsize $1 $2
# }
iptables()
{
case "$1" in
block)
sudo --login command iptables -I INPUT -s "$2" -j DROP
;;
--help)
command iptables --help
echo "\
Extra commands:
block block IP-ADDRESS on INPUT chain"
;;
*)
command sudo iptables "$@"
;;
esac
}
ansible_host()
{
ansible --inventory "$1", "$1" --become --ask-become-pass "${@:2}"
}
yq()
{
command yq --width "$(tput cols)" "$@"
}
jc()
{
if [[ $# -eq 0 ]]
then
glow "https://github.com/kellyjonbrazil/jc"
else
command jc "$@"
fi
}
jord_vm_ip()
{
gms vm ip "$1" | recsel -pip_address | awk '{ print $2 }'
}
jord_ansible_service_start()
{
vm="$(gms vm ip "$1" | recsel -pip_address | awk '{ print $2 }')"
ansible --user sup --private-key="$HOME/.ssh/id_rsa_sup" --inventory "$vm", \
"$vm" --module-name service --args "name=$2 state=started" \
--become --ask-become-pass
}
jord_web_loadavg()
{
watch --color "seq -f 'web%gs' 15 37 | xargs guix environment -l $HOME/src/guile-loadavg/guix.scm -- $HOME/src/guile-loadavg/pre-inst-env loadavg weather"
}
parallel_curl()
{
parallel --will-cite -k 'printf "domain: %s\n" {1}; curl --max-time 10 -L -s -o /dev/null -w "ip-address: %{remote_ip}\nstatus_code: %{http_code}" {1}; printf "\n\n"' ::: "$@"
}
jord_web_account_check()
{
parallel --will-cite -k 'printf "domain: %s\n" {1}; curl --max-time 10 -L -s -o /dev/null -w "ip-address: %{remote_ip}\nstatus_code: %{http_code}" {1}; printf "\n\n"' \
::: "$(gms account website "$1" | recsel -pname | awk '{ print $2 }')"
}
guix_export_archive()
{
path="$1"
destination="$2"
guix archive --export -r "$path" \
| ssh "$destination" guix archive --import
}
ssh_keygen_rsa()
{
file="$1"
ssh-keygen -b 4096 -m pem -f "$HOME/.ssh/id_rsa_$file"
}
ssh_keygen_show_host_key()
{
ssh-keygen -lf <(ssh-keyscan -p 1022 "$1" 2>/dev/null)
}
activity()
{
ps -ef | awk '{ print $1 }' | sort | uniq | wc -l;
}
alias t5='TMOUT=5'
alias close='TMOUT=5'
# https://www.gnu.org/software/emacs/manual/html_node/efaq/Disabling-backups.html
alias ls='ls -B -p --color=auto'
if [ -f "$HOME/.nix-profile/share/bash-completion/completions/docker" ]
then
source "$HOME/.nix-profile/share/bash-completion/completions/docker"
fi
if [ -f "$HOME/.bash_tmp" ]
then
source "$HOME/.bash_tmp"
fi
alias bridge='bridge -color=always'
alias ip='ip -color=always'
jenkins_log()
{
job="$1"
curl --silent --user "admin:$(pass show magnolia/jenkins/admin)" \
"https://jenkins.wugi.info/job/$job/lastBuild/consoleText"
}
jenkins_jobs_list()
{
curl --silent --user "admin:$(pass show magnolia/jenkins/admin)" \
https://jenkins.wugi.info/api/json/ \
| jq -r '.jobs[] | [.name, .color] | @tsv'
}
jenkins_active_jobs()
{
jenkins-jobs | grep --color=no red_anime
}
grub_list_entries()
{
awk -F\" '$1=="menuentry " {print i++ " : " $2}' /boot/grub/grub.cfg
}
# https://github.com/jarun/Buku/wiki/Third-party-integration
fb()
{
# save newline separated string into an array
mapfile -t website <<< "$(buku -p -f 4 | column -ts$'\t' | fzf --multi)"
# open each website
for i in "${website[@]}"; do
index="$(echo "$i" | awk '{print $1}')"
buku -p "$index"
buku -o "$index"
done
}
guix()
{
guix_modules="$HOME/.local/share/chezmoi/dotfiles/guixsd/modules"
guix_extra_modules=(
"${HOME}/src/cgit.duckdns.org/guix/guix-wigust/guix"
"${HOME}/src/gitlab.com/nonguix/nonguix"
"${HOME}/src/gitlab.com/wigust/prometheus-shepherd-exporter"
)
case "$1" in
manifest)
case "$2" in
apply)
command guix package \
-L "$HOME/.local/share/chezmoi/dotfiles/guixsd/modules" \
--fallback \
--manifest="$HOME/.local/share/chezmoi/dotfiles/manifests/$HOSTNAME.scm" "${@:3}"
;;
build)
command guix environment \
-L "$HOME/.local/share/chezmoi/dotfiles/guixsd/modules" \
--fallback \
--manifest="$HOME/.local/share/chezmoi/dotfiles/manifests/$HOSTNAME.scm" "${@:3}" \
-- sh -c 'exit 0'
;;
esac
;;
home)
case "$2" in
build)
(
cd "${HOME}/.local/share/chezmoi" || exit 1
command guix home build \
-L "$HOME/.local/share/chezmoi/dotfiles/guixsd/modules" \
--fallback \
"$HOME/.local/share/chezmoi/dotfiles/guixsd/home/${HOSTNAME}.scm" "${@:3}"
)
;;
switch)
(
cd "${HOME}/.local/share/chezmoi"
guix_command=()
if [[ "${PRE_INST_ENV:-FALSE}" == TRUE ]]
then
guix_command+=("${HOME}/src/git.savannah.gnu.org/git/guix/pre-inst-env")
else
guix_command+=("command")
fi
guix_command+=(
guix home reconfigure
)
for module in "${guix_extra_modules[@]}"
do
guix_command+=("--load-path=${module}")
done
guix_command+=(
--load-path="$guix_modules"
--fallback
)
if [[ -n $allow_downgrades ]]
then
guix_command+=("--allow-downgrades")
fi
if [[ -n $fallback ]]
then
guix_command+=("--fallback")
fi
guix_command+=(
"$HOME/.local/share/chezmoi/dotfiles/guixsd/home/${HOSTNAME}.scm"
"${@:3}"
)
"${guix_command[@]}"
)
;;
esac
;;
maintainer)
mapfile -t output < <(git log --grep="gnu: Add" --format=%s --author=go.wigust@gmail.com)
for line in "${output[@]}"
do
package="${line/gnu: Add /}"
package="${package::-1}"
case "$package" in
*Revert*|*service*|premake4|perl-strictures-2|perl-role-tiny-2|emacs-cl-generic|emacs-seq|emacs-emms-player-simple-mpv|php-with-bcmath|shlomif-cmake-modules|go-github-com-muesli-reflow|go-github-com-emirpasic-gods-trees-binaryheap|nginx-socket-cloexec)
printf ""
;;
*go-github-com*)
printf ""
;;
*zabbix-agentd*)
printf "zabbix-agentd\nzabbix-server\n"
;;
*)
echo "$package"
;;
esac
done
;;
menu)
{
exec 3>&1
mapfile -t options < <(
dialog --separate-output --title "Guix" --checklist "Guix Options" 22 72 3 \
-- --no-offload "--no-offload" off \
--commit "--commit" off \
--allow-downgrades "--allow-downgrades" off \
--fallback "--fallback" off \
--disable-authentication "--disable-authentication" off \
2>&1 2>&1 1>&3
)
declare -p options
for option in "${options[@]}"
do
if [[ "$option" == "--commit" ]]
then
exec 3>&1
options=("${options[@]/--commit}")
commit=$(dialog --backtitle "Guix commit" --inputbox "Enter Guix's Git commit" 8 60 2>&1 1>&3)
exec 3>&-
fi
if [[ "$option" == "--allow-downgrades" ]]
then
options=("${options[@]/--allow-downgrades}")
allow_downgrades=true
fi
if [[ "$option" == "--fallback" ]]
then
options=("${options[@]/--fallback}")
fallback=true
fi
if [[ "$option" == "--disable-authentication" ]]
then
options=("${options[@]/--disable-authentication}")
disable_authentication=true
fi
done
}
{
exec 3>&1
mapfile -t selection < <(
dialog --separate-output --title "Guix" --checklist "Guix Operations" 22 72 3 \
"pull channels" "Test build and update channel file" "${STATE:-off}" \
pull "Pull new changes" "${STATE:-on}" \
"system build" "Build system" "${STATE:-on}" \
"home build" "Build home" "${STATE:-on}" \
"home switch" "Reconfigure home" "${STATE:-on}" \
"manifest apply" "Apply package manifest" "${STATE:-on}" \
"system switch" "Reconfigure system" "${STATE:-on}" \
"distribute" "Pull on remote hosts" "${STATE:-off}" \
"system deploy" "Deploy to remote hosts" "${STATE:-off}" \
2>&1 2>&1 1>&3
)
declare -p selection
exec 3>&-
}
clear
(
set -ex
for operation in "${selection[@]}"
do
eval "guix $operation $options"
done
)
;;
pull)
case "$2" in
channels)
(
set -e
cd "${HOME}/.local/share/chezmoi" || exit 1
make dotfiles/channels-current.scm
if [[ $(git diff dotfiles/channels-current.scm) != "" ]]
then
if git commit -m "channels-current: Update." dotfiles/channels-current.scm
then
:
else
exit 1
fi
fi
)
;;
*)
guix_command=(
"command"
"guix" "pull"
)
if [[ -n $channels_file ]]
then
guix_command+=(
"--channels=${channels_file}"
)
else
guix_command+=(
"--channels=${HOME}/.local/share/chezmoi/dotfiles/channels-current.scm"
)
fi
if [[ -n $dry_run ]]
then
guix_command=(
echo
"${guix_command[@]}"
)
fi
if [[ -n $commit ]]
then
guix_command+=("--commit=$commit")
fi
if [[ -n $allow_downgrades ]]
then
guix_command+=("--allow-downgrades")
fi
if [[ -n $fallback ]]
then
guix_command+=("--fallback")
fi
if [[ -n $disable_authentication ]]
then
guix_command+=("--disable-authentication")
fi
(set -ex; "${guix_command[@]}" "${@:2}"; sudo --login "${guix_command[@]}" "${@:2}")
esac
;;
distribute)
"$(guix build --file="$HOME/.local/share/chezmoi/dotfiles/ansible/guix.scm" "${@:2}")"
;;
prebuild)
guix_command=(
echo
sudo --login
GUIX_PACKAGE_PATH="$guix_modules"
"${HOME}/src/git.savannah.gnu.org/git/guix/pre-inst-env"
guix
system
build
--fallback
--no-grafts
)
for module in "${guix_extra_modules[@]}"
do
guix_command+=("--load-path=${module}")
done
guix_command+=(
"$HOME/.local/share/chezmoi/dotfiles/guixsd/guixsd.scm"
)
sudo --login "${guix_command[@]}" "${@:2}"
;;
prereconfigure)
guix_command=(
"${HOME}/src/git.savannah.gnu.org/git/guix/pre-inst-env"
"guix"
)
for module in "${guix_extra_modules[@]}"
do
guix_command+=("--load-path=${module}")
done
guix_command+=(
system reconfigure
--load-path="$guix_modules"
--fallback "$HOME/.local/share/chezmoi/dotfiles/guixsd/guixsd.scm"
--no-grafts
"$HOME/.local/share/chezmoi/dotfiles/guixsd/guixsd.scm"
)
sudo --login "${guix_command[@]}" "${@:2}"
;;
# repl)
# GUILE_AUTO_COMPILE=0 command guix repl -L "$guix_modules" "${@:3}"
# ;;
remote)
case "$2" in
reboot)
ansible-playbook <(
cat <<'EOF'
- hosts: guix_vm
become: true
tasks:
- reboot: search_paths=/home/oleg/bin
EOF
)
;;
esac
;;
substituters)
cat <<'EOF'
The Guix project runs two official build farms that continuously build binary
substitutes, so users don't have to build everything at home. When installing
Guix or Guix System for the first time, you'll be asked whether to trust their
signatures and download their substitutes by default:
https://ci.guix.gnu.org (Germany)
https://bordeaux.guix.gnu.org (France)
For Guix users outside of Europe, connections to both of these can sometimes
be slow or censored. Don't fret just yet: volunteers maintain unofficial
mirrors of the official servers that may be closer by:
People's Republic of China
https://mirrors.sjtug.sjtu.edu.cn/guix (mirrors ci.guix.gnu.org)
Singapore
https://bordeaux-singapore-mirror.cbaines.net
United States of America
https://bordeaux-us-east-mirror.cbaines.net (mirrors bordeaux.guix.gnu.org)
Germany
https://hydra-guix-129.guix.gnu.org (official mirror of bordeaux.guix.gnu.org in Berlin)
EOF
;;
system)
case "$2" in
build)
sudo --login GUILE_LOAD_PATH="${HOME}/.local/share/chezmoi/dotfiles/guixsd/modules:${GUILE_LOAD_PATH}" command guix system build \
-L "$guix_modules" \
"${@:3}" \
"$HOME/.local/share/chezmoi/dotfiles/guixsd/$HOSTNAME.scm"
;;
deploy)
(
set -ex
guix deploy -L "$guix_modules" "${@:3}" \
"$HOME/.local/share/chezmoi/dotfiles/guixsd/deploy.scm"
)
;;
reconfigure)
sudo --login GUILE_LOAD_PATH="${HOME}/.local/share/chezmoi/dotfiles/guixsd/modules:${GUILE_LOAD_PATH}" command guix system reconfigure \
-L "$guix_modules" \
--no-bootloader "${@:3}" \
"$HOME/.local/share/chezmoi/dotfiles/guixsd/$HOSTNAME.scm"
;;
switch)
guix_command=(
sudo --login GUILE_LOAD_PATH="${HOME}/.local/share/chezmoi/dotfiles/guixsd/modules:${GUILE_LOAD_PATH}" command guix system reconfigure \
-L "$guix_modules" \
"${@:3}" \
"$HOME/.local/share/chezmoi/dotfiles/guixsd/$HOSTNAME.scm"
)
if [[ -n $allow_downgrades ]]
then
guix_command+=("--allow-downgrades")
fi
"${guix_command[@]}"
if [[ -n $fallback ]]
then
guix_command+=("--fallback")
fi
;;
*)
command guix system "${@:2}"
;;
esac
;;
update)
(
set -e
guix pull
guix system build
guix manifest
guix system switch
set +e
)
;;
master-staging)
git -C "${HOME}/src/git.savannah.gnu.org/git/guix" shortlog -n upstream/master..upstream/staging
;;
qemu)
# https://wiki.archlinux.org/index.php/QEMU#Creating_bridge_manually
printf -v macaddr "52:54:%02x:%02x:%02x:%02x" \
$(( RANDOM & 0xff)) $(( RANDOM & 0xff )) $(( RANDOM & 0xff)) $(( RANDOM & 0xff ))
sudo command qemu-system-x86_64 -daemonize -enable-kvm \
-smp cores=4,threads=1 -cpu host -m 4096 -vga virtio -full-screen \
-net nic,model=virtio,macaddr="$macaddr" -net bridge,br=br0 \
"$@"
;;
clean)
(
set -x
command guix package --delete-generations=1m
command guix pull --delete-generations=1m
command guix gc --list-failures | xargs guix gc --clear-failures
sudo --login command guix system delete-generations 1m
sudo --login command guix pull --delete-generations=1m
command guix home delete-generations 1m
)
;;
profiles)
echo "$(readlink --canonicalize $HOME/.guix-profile)" \
"$(readlink --canonicalize /run/current-system)" \
"$(readlink --canonicalize $HOME/.config/guix/current)"
;;
test-vm)
eval "$(sed 's,-nic user[^ ]* ,,' "$(./pre-inst-env guix system vm --no-offload "$2")" | tail -1 | sed 's/\sexec\s//') -m 4096 -smp 2 -nic user,model=virtio-net-pci,hostfwd=tcp::10022-:22"
;;
updatedb)
updatedb \
--localpaths=/gnu/store \
--findoptions='( -path /gnu/store/.links -o -name *.drv -o -name *.chroot ) -prune -o -type f -print' \
--output="$HOME/.config/guix/dbfile"
;;
locate)
locate -d "$HOME/.config/guix/dbfile" "${@:2}"
;;
xpanes)
guix_machines=(
vm1.wugi.info
vm2.wugi.info
vm3.wugi.info
vm4.wugi.info
vm5.wugi.info
ws1.wugi.info
localhost
)
xpanes -c 'ssh {}' "${guix_machines[@]}"
;;
depends)
for package in $(guix package --list-installed | cut --fields=1)
do
if guix graph "$package" | grep --quiet "$2"
then
echo "$package"
fi
done
;;
*)
command guix "$@"
;;
esac
}
maintenance()
{
case "$1" in
upgrade)
(
set -xe
cd "${HOME}/.local/share/chezmoi" || exit 1
make dotfiles/nix/flake.lock
if make dotfiles/nix/flake.nix
then
:
else
git restore dotfiles/nix/flake.lock
fi
)
;;
*)
command nix "$@"
;;
esac
}
listen_ports()
{
ss -tulpn | awk '{ print $5 }' | cut -d: -f 2 | sort -un | xargs echo
}
alias vnc-server-android="vncserver -AcceptSetDesktopSize=no -geometry 1280x720"
# jenkins_log()
# {
# for project in $(curl -s -k "https://admin:$(pass show majordomo/public/jenkins.intr/admin)@jenkins.intr/api/json?pretty=true" | jq -r '.jobs[] | .name'); do
# for job in $(curl -s -k "https://admin:$(pass show majordomo/public/jenkins.intr/admin)@jenkins.intr/job/$project/api/json" | jq -r '.jobs[] | .url'); do
# echo "@ $job" |
# curl -u "admin:$(pass show majordomo/public/jenkins.intr/admin)" -s -k "$job/job/master/lastBuild/consoleText"
# done
# done
# }
# https://markhneedham.com/blog/2015/11/14/jq-filtering-missing-keys/
alias get-todos='scp work:/home/user/src/jord/doc/todo.org ~/src/todo.org '
# nix-shell -E 'with import <nixpkgs> {}; callPackage ./default.nix {}' -A luaCrypto
# nix-build -E 'with import <nixpkgs> {}; callPackage ./default.nix {}';
# grep '^FAIL ' /tmp/6.txt | cut -d '/' -f 2- | cut -d ']' -f 1 | sed 's@^@ext/@'
nix_untar_docker()
{
# argument example: /nix/store/vqi100nf7x7z82pr4lkagasmzl9zj0zp-docker-image-apache2-php56.tar.gz
tar xv --wildcards '*/layer.tar' -f "$1" \
| tee /tmp/tempstore \
| xargs -n1 -I{} tar xvf {}
}
tmux_renumber_windows()
{
tmux movew -r
}
nix_user_uid()
{
nix-build -E 'with import <nixpkgs> {}; runCommand "foo" {} "id"'
}
nix_info()
{
nix-shell -p nix-info --run "nix-info -m"
}
guix_packages_json()
{
curl https://guix.gnu.org/packages.json
}
git_guix_pre_new_build()
{
number="$1"
git log --oneline \
| head -n "$number" \
| grep Add \
| awk '{ print $NF }' \
| cut -d'.' -f 1 \
| xargs ./pre-inst-env guix build --no-grafts
}
git_guix_pre_new_lint()
{
number="$1"
git log --oneline \
| head -n "$number" \
| grep Add \
| awk '{ print $NF }' \
| cut -d'.' -f 1 \
| xargs ./pre-inst-env guix lint
}
git_guix_pre_update()
{
number="$1"
git log --oneline \
| head -n "$number" \
| grep Update \
| awk '{ print $3 }' \
| cut -d: -f 1 \
| xargs ./pre-inst-env guix build --no-grafts
}
git_guix_home()
{
number="$1"
git show "$number" | grep home | cut -d'"' -f 2
}
# archive_dir()
# {
# for dir in $@; do
# mv -vi "$dir" "$HOME/archive/src/"
# done
# }
terraform_init_with_nix()
{
terraform init -plugin-dir ~/.nix-profile/bin "$@"
}
terraform_init()
{
terraform_init_with_nix -plugin-dir ~/go/src/gitlab.intr/majordomo/terraform-provider-majordomo
}
alias tsw='tmuxifier s web'
alias nn='notmuch new'
alias wtr='curl -H "Accept-Language: ru" wttr.in/Санкт-Петербург'
alias hylang='docker run --rm -it hylang'
nix_build()
{
nix_build="$(which nix-build)"
if [[ "$(readlink -f "$PWD")" =~ "majordomo" ]]
then
cmd="sshpass -Ppassphrase -p$(pass show majordomo/private/gitlab.intr/ssh/id_rsa_gitlab_intr) $nix_build --no-out-link"
if grep --quiet buildLayeredImage default.nix
then
cmd="docker load --input $($cmd)"
fi
else
cmd="$nix_build --no-out-link"
fi
case "$1" in
20.03)
$cmd "$HOME/src/nixpkgs-master" "${@:2}"
;;
19.09)
$cmd "$HOME/src/nixpkgs-master" "${@:2}"
;;
master)
$cmd "$HOME/src/nixpkgs-master" "${@:2}"
;;
unstable)
$cmd "$HOME/.nix-defexpr/channels/nixos-unstable" "${@:2}"
;;
*)
$cmd '<nixpkgs>' "$@"
esac
}