blob: 9b81f132c7ddef0c9c3e2e1a09b0141ca72b5105 [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";
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050012 auth = {
13 clicksUsername = lib.mkOption {
14 type = lib.types.str;
15 description = "Username for Clicks Gerrit";
16 };
17 };
Skyler Grey695fa632024-02-17 22:45:41 +000018 gpg = {
19 enable = lib.mkEnableOption "Enable signing with gpg";
20 commit = lib.mkOption {
21 type = lib.types.bool;
22 description = "Enable gpg signing for commits by default";
23 default = true;
24 };
25 push = lib.mkOption {
26 type = lib.types.bool;
27 description = "Enable gpg signing for pushes by when asked by the server";
28 default = true;
29 };
30 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050031 };
32
Skyler Greya9478182024-05-25 00:33:38 +000033 config = let
34 urlReplacements = {
35 aur = {
36 http = "https://aur.archlinux.org/";
37 ssh = "ssh://aur@aur.archlinux.org/";
38 };
39 aux = {
40 http = "https://github.com/auxolotl/";
41 ssh = "ssh://git@github.com/auxolotl/";
42 };
43 cb = {
44 http = "https://codeberg.org/";
45 ssh = "ssh://git@codeberg.org/";
46 };
47 clicks = {
48 http = "https://git.clicks.codes/";
49 ssh = "ssh://${config.chimera.git.auth.clicksUsername}@ssh.clicks.codes:29418/";
50 };
51 fdo = {
52 http = "https://gitlab.freedesktop.org/";
53 ssh = "ssh://git@gitlab.freedesktop.org/";
54 };
55 gh = {
56 http = "https://github.com/";
57 ssh = "ssh://git@github.com/";
58 };
59 gl = {
60 http = "https://gitlab.com/";
61 ssh = "ssh://git@gitlab.com/";
62 };
63 kde = {
64 http = "https://invent.kde.org/";
65 ssh = "ssh://git@invent.kde.org/";
66 };
67 lix = {
68 http = "https://git.lix.systems/";
69 ssh = "ssh://git@git.lix.systems/";
70 };
Skyler Greyc5fb2ea2024-05-31 23:07:42 +000071 srht = {
72 http = "https://git.sr.ht/";
73 ssh = "git@git.sr.ht:";
74 };
Skyler Greya9478182024-05-25 00:33:38 +000075 };
76
77 replacementToHTTPInsteadOf = name: urls: {
78 name = urls.http;
79 value.insteadOf = "${name}:";
80 };
81 replacementToSSHInsteadOf = name: urls: {
82 name = urls.ssh;
83 value = {
84 insteadOf = "p:${name}:";
85 pushInsteadOf = [ urls.http "${name}:" ];
86 };
87 };
88
89 replacementURLList =
90 (lib.mapAttrsToList replacementToHTTPInsteadOf urlReplacements)
91 ++ (lib.mapAttrsToList replacementToSSHInsteadOf urlReplacements);
92
93 replacementURLs = builtins.listToAttrs replacementURLList;
94 in {
Skyler Grey695fa632024-02-17 22:45:41 +000095 chimera.gpg.enable = lib.mkIf config.chimera.git.gpg.enable true;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050096
Skyler Greyd5457a22024-02-15 23:02:32 +000097 home.packages =
Skyler Greyec50d242024-02-15 23:09:46 +000098 (if config.chimera.git.gitReview.enable then [ pkgs.git-review ] else [ ])
Samuel Shuert849a93e2024-02-21 22:38:53 +000099 ++ (if config.chimera.git.stgit.enable then [ pkgs.stgit ] else [ ]);
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500100
101 programs.zsh.shellAliases =
102 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
103
104 programs.bash.shellAliases =
105 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
106
107 programs.git = {
108 enable = true;
109
Skyler Greybb7586a2024-02-15 19:15:04 +0000110 delta = {
Skyler Greyec50d242024-02-15 23:09:46 +0000111 enable = config.chimera.git.delta.enable;
112 options.light = lib.mkIf config.chimera.theme.catppuccin.enable (
113 config.chimera.theme.catppuccin.style == "Latte"
114 );
115 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500116
117 extraConfig = {
118 init.defaultBranch = "main";
119 advice.skippedcherrypicks = false;
Skyler Grey695fa632024-02-17 22:45:41 +0000120 commit.gpgsign = lib.mkIf config.chimera.git.gpg.enable config.chimera.git.gpg.commit;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500121 credential.helper = "cache";
122 core = {
123 repositoryformatversion = 0;
124 filemode = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000125 # 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 -0500126 };
127 push = {
128 autoSetupRemote = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000129 gpgSign = lib.mkIf config.chimera.git.gpg.enable (
130 if config.chimera.git.gpg.push then "if-asked" else false
131 );
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500132 };
Skyler Greyfde4a192024-05-24 23:24:22 +0000133 pull.rebase = "merges";
134 rebase.updateRefs = true;
Skyler Greya9478182024-05-25 00:33:38 +0000135 url = replacementURLs;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500136 merge.conflictstyle = "diff3";
137 trailer.ifexists = "addIfDifferent";
138 };
139 };
140 };
141}