nixos configs
1{ pkgs, ... }:
2
3let
4 git-ssh-dispatch = pkgs.writeScriptBin "git-ssh-dispatch" ''
5 #!/usr/bin/env zsh
6 set -eu -o pipefail
7
8 # this script roughly acts like openssh
9 # at least in terms of how git uses it
10
11 if [[ $1 == '-G' && $# == 2 ]]; then
12 ssh $@
13 exit
14 fi
15
16 if [[ ! $2 =~ "git-(upload|receive)-pack '(.*)'" && $# == 2 ]]; then
17 echo 'unexpected form' $@ >&2
18 exit 1
19 fi
20
21 target=$1:$match[2]
22
23 case $target in
24
25 (git@github.com:dkuettel/*)
26 key=private
27 user="Yves Ineichen iff@yvesineichen.com"
28 ;;
29
30 (git@github.com:/dkuettel/*)
31 key=private
32 user="Yves Ineichen iff@yvesineichen.com"
33 ;;
34
35 (git@github.com:iff/*)
36 key=private
37 user="Yves Ineichen iff@yvesineichen.com"
38 ;;
39
40 (git@github.com:/iff/*)
41 key=private
42 user="Yves Ineichen iff@yvesineichen.com"
43 ;;
44
45 (git@codeberg.org:yff/*)
46 key=private
47 user="Yves Ineichen iff@yvesineichen.com"
48 ;;
49
50 (git@codeberg.org:/yff/*)
51 key=private
52 user="Yves Ineichen iff@yvesineichen.com"
53 ;;
54
55 (git@github.com:mbssacosta/*)
56 key=private
57 user="Yves Ineichen iff@yvesineichen.com"
58 ;;
59
60 (git@github.com:dakies/*)
61 key=private
62 user="Yves Ineichen iff@yvesineichen.com"
63 ;;
64
65 (git@tangled.org:iff.io/*)
66 key=private
67 user="Yves Ineichen iff@yvesineichen.com"
68 ;;
69
70 (git@github.com:verion-eda/*)
71 key=private
72 user="Yves Ineichen iff@yvesineichen.com"
73 ;;
74
75 (git@github.com:wereHamster/*)
76 key=private
77 user="Yves Ineichen iff@yvesineichen.com"
78 ;;
79
80 (git@github.com:pulp-platform/*)
81 key=private
82 user="Yves Ineichen iff@yvesineichen.com"
83 ;;
84
85 (git@github.com:grantae/*)
86 key=private
87 user="Yves Ineichen iff@yvesineichen.com"
88 ;;
89
90 (*)
91 echo 'no match for' $target >&2
92 exit 1
93 ;;
94
95 esac
96
97 if [[ -e .git && -v user ]]; then
98 if ! actual="$(git config --get user.name) $(git config --get user.email)"; then
99 echo 'no git user is set instead of' $user >&2
100 exit 1
101 fi
102 if [[ $actual != $user ]]; then
103 echo 'git user is' $actual 'but expected' $user >&2
104 exit 1
105 fi
106 fi
107
108 echo $target '->' $key >&2
109 ssh -i ~/.ssh/$key $@
110 '';
111
112 gpr = pkgs.writeScriptBin "gpr" ''
113 #!/usr/bin/env zsh
114 set -eu -o pipefail
115
116 gh pr create --editor --fill-verbose
117 '';
118
119 wt = pkgs.writeScriptBin "wt" ''
120 #!/usr/bin/env zsh
121 set -eu -o pipefail
122
123 name=''${1?-worktree name}
124 [[ ! -v 2 ]]
125
126 sha=$(git rev-parse HEAD)
127 git worktree add --detach $(realpath wt/$name) $sha
128 # maybe zsh subshell in this path and remove/purge when returning?
129 echo "new tree: $(realpath wt/$name)"
130 '';
131
132 add-gha = pkgs.writeScriptBin "add-gha" ''
133 #!/usr/bin/env zsh
134 set -eu -o pipefail
135
136 git subtree add --prefix=.github https://github.com/iff/ci-conf.git main --squash
137 '';
138in
139{
140 home.packages = [
141 pkgs.gh
142 pkgs.git
143 pkgs.jujutsu
144 pkgs.moreutils
145 #
146 add-gha
147 git-ssh-dispatch
148 gpr
149 wt
150 ];
151
152 xdg.configFile."git/config".source = ./git-config;
153 xdg.configFile."jj/config.toml".source = ./jujutsu-config.toml;
154}