blob: 1e301665957e972637b75dc9fa64b2e39df48f86 [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";
Skyler Greybd08ef62024-07-21 12:27:18 +000015 radicle.enable = lib.mkEnableOption "Install Radicle, a peer-to-peer git forge";
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050016 auth = {
17 clicksUsername = lib.mkOption {
18 type = lib.types.str;
19 description = "Username for Clicks Gerrit";
20 };
21 };
Skyler Grey695fa632024-02-17 22:45:41 +000022 gpg = {
23 enable = lib.mkEnableOption "Enable signing with gpg";
24 commit = lib.mkOption {
25 type = lib.types.bool;
26 description = "Enable gpg signing for commits by default";
27 default = true;
28 };
29 push = lib.mkOption {
30 type = lib.types.bool;
31 description = "Enable gpg signing for pushes by when asked by the server";
32 default = true;
33 };
34 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050035 };
36
Skyler Greya9478182024-05-25 00:33:38 +000037 config = let
38 urlReplacements = {
Skyler Grey4655e772024-07-02 22:01:22 +000039 af = {
40 http = "https://git.auxolotl.org/";
41 ssh = "ssh://forgejo@git.auxolotl.org/";
42 };
Skyler Greya9478182024-05-25 00:33:38 +000043 aur = {
44 http = "https://aur.archlinux.org/";
45 ssh = "ssh://aur@aur.archlinux.org/";
46 };
47 aux = {
Skyler Grey4655e772024-07-02 22:01:22 +000048 http = "https://git.auxolotl.org/auxolotl/";
49 ssh = "ssh://forgejo@git.auxolotl.org/auxolotl/";
Skyler Greya9478182024-05-25 00:33:38 +000050 };
51 cb = {
52 http = "https://codeberg.org/";
53 ssh = "ssh://git@codeberg.org/";
54 };
55 clicks = {
56 http = "https://git.clicks.codes/";
57 ssh = "ssh://${config.chimera.git.auth.clicksUsername}@ssh.clicks.codes:29418/";
58 };
59 fdo = {
60 http = "https://gitlab.freedesktop.org/";
61 ssh = "ssh://git@gitlab.freedesktop.org/";
62 };
63 gh = {
64 http = "https://github.com/";
65 ssh = "ssh://git@github.com/";
66 };
67 gl = {
68 http = "https://gitlab.com/";
69 ssh = "ssh://git@gitlab.com/";
70 };
71 kde = {
72 http = "https://invent.kde.org/";
73 ssh = "ssh://git@invent.kde.org/";
74 };
75 lix = {
76 http = "https://git.lix.systems/";
77 ssh = "ssh://git@git.lix.systems/";
78 };
Skyler Greyc5fb2ea2024-05-31 23:07:42 +000079 srht = {
80 http = "https://git.sr.ht/";
81 ssh = "git@git.sr.ht:";
82 };
Skyler Greya9478182024-05-25 00:33:38 +000083 };
84
85 replacementToHTTPInsteadOf = name: urls: {
86 name = urls.http;
87 value.insteadOf = "${name}:";
88 };
89 replacementToSSHInsteadOf = name: urls: {
90 name = urls.ssh;
91 value = {
92 insteadOf = "p:${name}:";
93 pushInsteadOf = [ urls.http "${name}:" ];
94 };
95 };
96
97 replacementURLList =
98 (lib.mapAttrsToList replacementToHTTPInsteadOf urlReplacements)
99 ++ (lib.mapAttrsToList replacementToSSHInsteadOf urlReplacements);
100
101 replacementURLs = builtins.listToAttrs replacementURLList;
102 in {
Skyler Grey695fa632024-02-17 22:45:41 +0000103 chimera.gpg.enable = lib.mkIf config.chimera.git.gpg.enable true;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500104
Skyler Greyd5457a22024-02-15 23:02:32 +0000105 home.packages =
Skyler Greyec50d242024-02-15 23:09:46 +0000106 (if config.chimera.git.gitReview.enable then [ pkgs.git-review ] else [ ])
Skyler Grey3883b642024-06-30 23:01:42 +0000107 ++ (if config.chimera.git.stgit.enable then [ pkgs.stgit ] else [ ])
Skyler Greybd08ef62024-07-21 12:27:18 +0000108 ++ (if config.chimera.git.jj.enable then [ inputs.jujutsu.packages.${system}.jujutsu ] else [ ])
109 ++ (if config.chimera.git.radicle.enable then [ pkgs.radicle-node ] else [ ]);
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500110
111 programs.zsh.shellAliases =
112 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
113
114 programs.bash.shellAliases =
115 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
116
117 programs.git = {
118 enable = true;
119
Samuel Shuertfd4bc1d2024-09-04 17:03:38 -0400120 delta = {
121 enable = config.chimera.git.delta.enable;
122 options.light = lib.mkIf config.chimera.theme.catppuccin.enable (
123 config.chimera.theme.catppuccin.style == "Latte"
124 );
125 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500126
127 extraConfig = {
128 init.defaultBranch = "main";
129 advice.skippedcherrypicks = false;
Skyler Grey695fa632024-02-17 22:45:41 +0000130 commit.gpgsign = lib.mkIf config.chimera.git.gpg.enable config.chimera.git.gpg.commit;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500131 credential.helper = "cache";
132 core = {
133 repositoryformatversion = 0;
134 filemode = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000135 # 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 -0500136 };
137 push = {
138 autoSetupRemote = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000139 gpgSign = lib.mkIf config.chimera.git.gpg.enable (
140 if config.chimera.git.gpg.push then "if-asked" else false
141 );
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500142 };
Skyler Greyfde4a192024-05-24 23:24:22 +0000143 pull.rebase = "merges";
144 rebase.updateRefs = true;
Skyler Greya9478182024-05-25 00:33:38 +0000145 url = replacementURLs;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500146 merge.conflictstyle = "diff3";
147 trailer.ifexists = "addIfDifferent";
148 };
149 };
150 };
151}