blob: 8c5be0abbf567cc550049c0881a6aa1f1e182dec [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 };
71 };
72
73 replacementToHTTPInsteadOf = name: urls: {
74 name = urls.http;
75 value.insteadOf = "${name}:";
76 };
77 replacementToSSHInsteadOf = name: urls: {
78 name = urls.ssh;
79 value = {
80 insteadOf = "p:${name}:";
81 pushInsteadOf = [ urls.http "${name}:" ];
82 };
83 };
84
85 replacementURLList =
86 (lib.mapAttrsToList replacementToHTTPInsteadOf urlReplacements)
87 ++ (lib.mapAttrsToList replacementToSSHInsteadOf urlReplacements);
88
89 replacementURLs = builtins.listToAttrs replacementURLList;
90 in {
Skyler Grey695fa632024-02-17 22:45:41 +000091 chimera.gpg.enable = lib.mkIf config.chimera.git.gpg.enable true;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050092
Skyler Greyd5457a22024-02-15 23:02:32 +000093 home.packages =
Skyler Greyec50d242024-02-15 23:09:46 +000094 (if config.chimera.git.gitReview.enable then [ pkgs.git-review ] else [ ])
Samuel Shuert849a93e2024-02-21 22:38:53 +000095 ++ (if config.chimera.git.stgit.enable then [ pkgs.stgit ] else [ ]);
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050096
97 programs.zsh.shellAliases =
98 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
99
100 programs.bash.shellAliases =
101 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
102
103 programs.git = {
104 enable = true;
105
Skyler Greybb7586a2024-02-15 19:15:04 +0000106 delta = {
Skyler Greyec50d242024-02-15 23:09:46 +0000107 enable = config.chimera.git.delta.enable;
108 options.light = lib.mkIf config.chimera.theme.catppuccin.enable (
109 config.chimera.theme.catppuccin.style == "Latte"
110 );
111 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500112
113 extraConfig = {
114 init.defaultBranch = "main";
115 advice.skippedcherrypicks = false;
Skyler Grey695fa632024-02-17 22:45:41 +0000116 commit.gpgsign = lib.mkIf config.chimera.git.gpg.enable config.chimera.git.gpg.commit;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500117 credential.helper = "cache";
118 core = {
119 repositoryformatversion = 0;
120 filemode = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000121 # 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 -0500122 };
123 push = {
124 autoSetupRemote = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000125 gpgSign = lib.mkIf config.chimera.git.gpg.enable (
126 if config.chimera.git.gpg.push then "if-asked" else false
127 );
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500128 };
Skyler Greyfde4a192024-05-24 23:24:22 +0000129 pull.rebase = "merges";
130 rebase.updateRefs = true;
Skyler Greya9478182024-05-25 00:33:38 +0000131 url = replacementURLs;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500132 merge.conflictstyle = "diff3";
133 trailer.ifexists = "addIfDifferent";
134 };
135 };
136 };
137}