blob: 61d3eb1f4708d3bf3dcb54059e993d3d7e79cfff [file] [log] [blame]
Samuel Shuert02ffd1e2024-02-13 21:37:15 -05001{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7{
8 options.chimera.git = {
9 gitReview.enable = lib.mkEnableOption "Enable git review";
10 delta.enable = lib.mkEnableOption "Enable delta, an alternative pager for git diffs that highlights syntax";
Skyler Greyec50d242024-02-15 23:09:46 +000011 stgit.enable = lib.mkEnableOption "Install StGit, a tool that makes working with stacked patches easier";
Skyler Grey3883b642024-06-30 23:01:42 +000012 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 -050013 auth = {
14 clicksUsername = lib.mkOption {
15 type = lib.types.str;
16 description = "Username for Clicks Gerrit";
17 };
18 };
Skyler Grey695fa632024-02-17 22:45:41 +000019 gpg = {
20 enable = lib.mkEnableOption "Enable signing with gpg";
21 commit = lib.mkOption {
22 type = lib.types.bool;
23 description = "Enable gpg signing for commits by default";
24 default = true;
25 };
26 push = lib.mkOption {
27 type = lib.types.bool;
28 description = "Enable gpg signing for pushes by when asked by the server";
29 default = true;
30 };
31 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050032 };
33
Skyler Greya9478182024-05-25 00:33:38 +000034 config = let
35 urlReplacements = {
36 aur = {
37 http = "https://aur.archlinux.org/";
38 ssh = "ssh://aur@aur.archlinux.org/";
39 };
40 aux = {
41 http = "https://github.com/auxolotl/";
42 ssh = "ssh://git@github.com/auxolotl/";
43 };
44 cb = {
45 http = "https://codeberg.org/";
46 ssh = "ssh://git@codeberg.org/";
47 };
48 clicks = {
49 http = "https://git.clicks.codes/";
50 ssh = "ssh://${config.chimera.git.auth.clicksUsername}@ssh.clicks.codes:29418/";
51 };
52 fdo = {
53 http = "https://gitlab.freedesktop.org/";
54 ssh = "ssh://git@gitlab.freedesktop.org/";
55 };
56 gh = {
57 http = "https://github.com/";
58 ssh = "ssh://git@github.com/";
59 };
60 gl = {
61 http = "https://gitlab.com/";
62 ssh = "ssh://git@gitlab.com/";
63 };
64 kde = {
65 http = "https://invent.kde.org/";
66 ssh = "ssh://git@invent.kde.org/";
67 };
68 lix = {
69 http = "https://git.lix.systems/";
70 ssh = "ssh://git@git.lix.systems/";
71 };
Skyler Greyc5fb2ea2024-05-31 23:07:42 +000072 srht = {
73 http = "https://git.sr.ht/";
74 ssh = "git@git.sr.ht:";
75 };
Skyler Greya9478182024-05-25 00:33:38 +000076 };
77
78 replacementToHTTPInsteadOf = name: urls: {
79 name = urls.http;
80 value.insteadOf = "${name}:";
81 };
82 replacementToSSHInsteadOf = name: urls: {
83 name = urls.ssh;
84 value = {
85 insteadOf = "p:${name}:";
86 pushInsteadOf = [ urls.http "${name}:" ];
87 };
88 };
89
90 replacementURLList =
91 (lib.mapAttrsToList replacementToHTTPInsteadOf urlReplacements)
92 ++ (lib.mapAttrsToList replacementToSSHInsteadOf urlReplacements);
93
94 replacementURLs = builtins.listToAttrs replacementURLList;
95 in {
Skyler Grey695fa632024-02-17 22:45:41 +000096 chimera.gpg.enable = lib.mkIf config.chimera.git.gpg.enable true;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050097
Skyler Greyd5457a22024-02-15 23:02:32 +000098 home.packages =
Skyler Greyec50d242024-02-15 23:09:46 +000099 (if config.chimera.git.gitReview.enable then [ pkgs.git-review ] else [ ])
Skyler Grey3883b642024-06-30 23:01:42 +0000100 ++ (if config.chimera.git.stgit.enable then [ pkgs.stgit ] else [ ])
101 ++ (if config.chimera.git.jj.enable then [ pkgs.jujutsu ] else [ ]);
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500102
103 programs.zsh.shellAliases =
104 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
105
106 programs.bash.shellAliases =
107 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
108
109 programs.git = {
110 enable = true;
111
Skyler Greybb7586a2024-02-15 19:15:04 +0000112 delta = {
Skyler Greyec50d242024-02-15 23:09:46 +0000113 enable = config.chimera.git.delta.enable;
114 options.light = lib.mkIf config.chimera.theme.catppuccin.enable (
115 config.chimera.theme.catppuccin.style == "Latte"
116 );
117 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500118
119 extraConfig = {
120 init.defaultBranch = "main";
121 advice.skippedcherrypicks = false;
Skyler Grey695fa632024-02-17 22:45:41 +0000122 commit.gpgsign = lib.mkIf config.chimera.git.gpg.enable config.chimera.git.gpg.commit;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500123 credential.helper = "cache";
124 core = {
125 repositoryformatversion = 0;
126 filemode = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000127 # 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 -0500128 };
129 push = {
130 autoSetupRemote = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000131 gpgSign = lib.mkIf config.chimera.git.gpg.enable (
132 if config.chimera.git.gpg.push then "if-asked" else false
133 );
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500134 };
Skyler Greyfde4a192024-05-24 23:24:22 +0000135 pull.rebase = "merges";
136 rebase.updateRefs = true;
Skyler Greya9478182024-05-25 00:33:38 +0000137 url = replacementURLs;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500138 merge.conflictstyle = "diff3";
139 trailer.ifexists = "addIfDifferent";
140 };
141 };
142 };
143}