blob: ecbb140be2db42b8f0a4cf7208dc5bbd2a3504ea [file] [log] [blame]
Samuel Shuert02ffd1e2024-02-13 21:37:15 -05001{
Skyler Greyb3d7b042024-07-01 00:48:13 +00002 inputs,
3 system,
Samuel Shuert02ffd1e2024-02-13 21:37:15 -05004 config,
5 lib,
6 pkgs,
7 ...
8}:
9{
10 options.chimera.git = {
11 gitReview.enable = lib.mkEnableOption "Enable git review";
12 delta.enable = lib.mkEnableOption "Enable delta, an alternative pager for git diffs that highlights syntax";
Skyler Greyec50d242024-02-15 23:09:46 +000013 stgit.enable = lib.mkEnableOption "Install StGit, a tool that makes working with stacked patches easier";
Skyler Grey3883b642024-06-30 23:01:42 +000014 jj.enable = lib.mkEnableOption "Install jj, a git-compatible VCS, allowing powerful features, performance and stability improvements ontop of git";
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050015 auth = {
16 clicksUsername = lib.mkOption {
17 type = lib.types.str;
18 description = "Username for Clicks Gerrit";
19 };
20 };
Skyler Grey695fa632024-02-17 22:45:41 +000021 gpg = {
22 enable = lib.mkEnableOption "Enable signing with gpg";
23 commit = lib.mkOption {
24 type = lib.types.bool;
25 description = "Enable gpg signing for commits by default";
26 default = true;
27 };
28 push = lib.mkOption {
29 type = lib.types.bool;
30 description = "Enable gpg signing for pushes by when asked by the server";
31 default = true;
32 };
33 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050034 };
35
Skyler Greya9478182024-05-25 00:33:38 +000036 config = let
37 urlReplacements = {
Skyler Grey4655e772024-07-02 22:01:22 +000038 af = {
39 http = "https://git.auxolotl.org/";
40 ssh = "ssh://forgejo@git.auxolotl.org/";
41 };
Skyler Greya9478182024-05-25 00:33:38 +000042 aur = {
43 http = "https://aur.archlinux.org/";
44 ssh = "ssh://aur@aur.archlinux.org/";
45 };
46 aux = {
Skyler Grey4655e772024-07-02 22:01:22 +000047 http = "https://git.auxolotl.org/auxolotl/";
48 ssh = "ssh://forgejo@git.auxolotl.org/auxolotl/";
Skyler Greya9478182024-05-25 00:33:38 +000049 };
50 cb = {
51 http = "https://codeberg.org/";
52 ssh = "ssh://git@codeberg.org/";
53 };
54 clicks = {
55 http = "https://git.clicks.codes/";
56 ssh = "ssh://${config.chimera.git.auth.clicksUsername}@ssh.clicks.codes:29418/";
57 };
58 fdo = {
59 http = "https://gitlab.freedesktop.org/";
60 ssh = "ssh://git@gitlab.freedesktop.org/";
61 };
62 gh = {
63 http = "https://github.com/";
64 ssh = "ssh://git@github.com/";
65 };
66 gl = {
67 http = "https://gitlab.com/";
68 ssh = "ssh://git@gitlab.com/";
69 };
70 kde = {
71 http = "https://invent.kde.org/";
72 ssh = "ssh://git@invent.kde.org/";
73 };
74 lix = {
75 http = "https://git.lix.systems/";
76 ssh = "ssh://git@git.lix.systems/";
77 };
Skyler Greyc5fb2ea2024-05-31 23:07:42 +000078 srht = {
79 http = "https://git.sr.ht/";
80 ssh = "git@git.sr.ht:";
81 };
Skyler Greya9478182024-05-25 00:33:38 +000082 };
83
84 replacementToHTTPInsteadOf = name: urls: {
85 name = urls.http;
86 value.insteadOf = "${name}:";
87 };
88 replacementToSSHInsteadOf = name: urls: {
89 name = urls.ssh;
90 value = {
91 insteadOf = "p:${name}:";
92 pushInsteadOf = [ urls.http "${name}:" ];
93 };
94 };
95
96 replacementURLList =
97 (lib.mapAttrsToList replacementToHTTPInsteadOf urlReplacements)
98 ++ (lib.mapAttrsToList replacementToSSHInsteadOf urlReplacements);
99
100 replacementURLs = builtins.listToAttrs replacementURLList;
101 in {
Skyler Grey695fa632024-02-17 22:45:41 +0000102 chimera.gpg.enable = lib.mkIf config.chimera.git.gpg.enable true;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500103
Skyler Greyd5457a22024-02-15 23:02:32 +0000104 home.packages =
Skyler Greyec50d242024-02-15 23:09:46 +0000105 (if config.chimera.git.gitReview.enable then [ pkgs.git-review ] else [ ])
Skyler Grey3883b642024-06-30 23:01:42 +0000106 ++ (if config.chimera.git.stgit.enable then [ pkgs.stgit ] else [ ])
Skyler Greyb3d7b042024-07-01 00:48:13 +0000107 ++ (if config.chimera.git.jj.enable then [ inputs.jujutsu.packages.${system}.jujutsu ] else [ ]);
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500108
109 programs.zsh.shellAliases =
110 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
111
112 programs.bash.shellAliases =
113 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
114
115 programs.git = {
116 enable = true;
117
Skyler Greybb7586a2024-02-15 19:15:04 +0000118 delta = {
Skyler Greyec50d242024-02-15 23:09:46 +0000119 enable = config.chimera.git.delta.enable;
120 options.light = lib.mkIf config.chimera.theme.catppuccin.enable (
121 config.chimera.theme.catppuccin.style == "Latte"
122 );
123 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500124
125 extraConfig = {
126 init.defaultBranch = "main";
127 advice.skippedcherrypicks = false;
Skyler Grey695fa632024-02-17 22:45:41 +0000128 commit.gpgsign = lib.mkIf config.chimera.git.gpg.enable config.chimera.git.gpg.commit;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500129 credential.helper = "cache";
130 core = {
131 repositoryformatversion = 0;
132 filemode = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000133 # TODO: from git docs, should we provide an option for this?: NOTE: this is a possibly dangerous operation; do not use it unless you understand the implications (see git-rebase[1] for details).
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500134 };
135 push = {
136 autoSetupRemote = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000137 gpgSign = lib.mkIf config.chimera.git.gpg.enable (
138 if config.chimera.git.gpg.push then "if-asked" else false
139 );
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500140 };
Skyler Greyfde4a192024-05-24 23:24:22 +0000141 pull.rebase = "merges";
142 rebase.updateRefs = true;
Skyler Greya9478182024-05-25 00:33:38 +0000143 url = replacementURLs;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500144 merge.conflictstyle = "diff3";
145 trailer.ifexists = "addIfDifferent";
146 };
147 };
148 };
149}