blob: 835a2857ee5e1915470a242c67872974586ca005 [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 = {
38 aur = {
39 http = "https://aur.archlinux.org/";
40 ssh = "ssh://aur@aur.archlinux.org/";
41 };
42 aux = {
43 http = "https://github.com/auxolotl/";
44 ssh = "ssh://git@github.com/auxolotl/";
45 };
46 cb = {
47 http = "https://codeberg.org/";
48 ssh = "ssh://git@codeberg.org/";
49 };
50 clicks = {
51 http = "https://git.clicks.codes/";
52 ssh = "ssh://${config.chimera.git.auth.clicksUsername}@ssh.clicks.codes:29418/";
53 };
54 fdo = {
55 http = "https://gitlab.freedesktop.org/";
56 ssh = "ssh://git@gitlab.freedesktop.org/";
57 };
58 gh = {
59 http = "https://github.com/";
60 ssh = "ssh://git@github.com/";
61 };
62 gl = {
63 http = "https://gitlab.com/";
64 ssh = "ssh://git@gitlab.com/";
65 };
66 kde = {
67 http = "https://invent.kde.org/";
68 ssh = "ssh://git@invent.kde.org/";
69 };
70 lix = {
71 http = "https://git.lix.systems/";
72 ssh = "ssh://git@git.lix.systems/";
73 };
Skyler Greyc5fb2ea2024-05-31 23:07:42 +000074 srht = {
75 http = "https://git.sr.ht/";
76 ssh = "git@git.sr.ht:";
77 };
Skyler Greya9478182024-05-25 00:33:38 +000078 };
79
80 replacementToHTTPInsteadOf = name: urls: {
81 name = urls.http;
82 value.insteadOf = "${name}:";
83 };
84 replacementToSSHInsteadOf = name: urls: {
85 name = urls.ssh;
86 value = {
87 insteadOf = "p:${name}:";
88 pushInsteadOf = [ urls.http "${name}:" ];
89 };
90 };
91
92 replacementURLList =
93 (lib.mapAttrsToList replacementToHTTPInsteadOf urlReplacements)
94 ++ (lib.mapAttrsToList replacementToSSHInsteadOf urlReplacements);
95
96 replacementURLs = builtins.listToAttrs replacementURLList;
97 in {
Skyler Grey695fa632024-02-17 22:45:41 +000098 chimera.gpg.enable = lib.mkIf config.chimera.git.gpg.enable true;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050099
Skyler Greyd5457a22024-02-15 23:02:32 +0000100 home.packages =
Skyler Greyec50d242024-02-15 23:09:46 +0000101 (if config.chimera.git.gitReview.enable then [ pkgs.git-review ] else [ ])
Skyler Grey3883b642024-06-30 23:01:42 +0000102 ++ (if config.chimera.git.stgit.enable then [ pkgs.stgit ] else [ ])
Skyler Greyb3d7b042024-07-01 00:48:13 +0000103 ++ (if config.chimera.git.jj.enable then [ inputs.jujutsu.packages.${system}.jujutsu ] else [ ]);
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500104
105 programs.zsh.shellAliases =
106 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
107
108 programs.bash.shellAliases =
109 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
110
111 programs.git = {
112 enable = true;
113
Skyler Greybb7586a2024-02-15 19:15:04 +0000114 delta = {
Skyler Greyec50d242024-02-15 23:09:46 +0000115 enable = config.chimera.git.delta.enable;
116 options.light = lib.mkIf config.chimera.theme.catppuccin.enable (
117 config.chimera.theme.catppuccin.style == "Latte"
118 );
119 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500120
121 extraConfig = {
122 init.defaultBranch = "main";
123 advice.skippedcherrypicks = false;
Skyler Grey695fa632024-02-17 22:45:41 +0000124 commit.gpgsign = lib.mkIf config.chimera.git.gpg.enable config.chimera.git.gpg.commit;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500125 credential.helper = "cache";
126 core = {
127 repositoryformatversion = 0;
128 filemode = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000129 # 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 -0500130 };
131 push = {
132 autoSetupRemote = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000133 gpgSign = lib.mkIf config.chimera.git.gpg.enable (
134 if config.chimera.git.gpg.push then "if-asked" else false
135 );
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500136 };
Skyler Greyfde4a192024-05-24 23:24:22 +0000137 pull.rebase = "merges";
138 rebase.updateRefs = true;
Skyler Greya9478182024-05-25 00:33:38 +0000139 url = replacementURLs;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500140 merge.conflictstyle = "diff3";
141 trailer.ifexists = "addIfDifferent";
142 };
143 };
144 };
145}