blob: 8ee5e5fc52f0cd0e9389e3de4af7fc05b7cb51e1 [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";
Skyler Greycf0b8562024-10-02 22:14:37 +000016 radicle.unstable = lib.mkEnableOption "Install Radicle from their main branch";
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050017 auth = {
18 clicksUsername = lib.mkOption {
19 type = lib.types.str;
20 description = "Username for Clicks Gerrit";
21 };
22 };
Skyler Grey695fa632024-02-17 22:45:41 +000023 gpg = {
24 enable = lib.mkEnableOption "Enable signing with gpg";
25 commit = lib.mkOption {
26 type = lib.types.bool;
27 description = "Enable gpg signing for commits by default";
28 default = true;
29 };
30 push = lib.mkOption {
31 type = lib.types.bool;
32 description = "Enable gpg signing for pushes by when asked by the server";
Skyler Greyc1b28322024-09-17 21:07:18 +000033 default = !config.chimera.git.radicle.enable; # Radicle is not able to understand signed pushes, even with if-asked
Skyler Grey695fa632024-02-17 22:45:41 +000034 };
35 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -050036 };
37
Skyler Greya9478182024-05-25 00:33:38 +000038 config = let
39 urlReplacements = {
Skyler Grey4655e772024-07-02 22:01:22 +000040 af = {
41 http = "https://git.auxolotl.org/";
42 ssh = "ssh://forgejo@git.auxolotl.org/";
43 };
Skyler Greya9478182024-05-25 00:33:38 +000044 aur = {
45 http = "https://aur.archlinux.org/";
46 ssh = "ssh://aur@aur.archlinux.org/";
47 };
48 aux = {
Skyler Grey4655e772024-07-02 22:01:22 +000049 http = "https://git.auxolotl.org/auxolotl/";
50 ssh = "ssh://forgejo@git.auxolotl.org/auxolotl/";
Skyler Greya9478182024-05-25 00:33:38 +000051 };
52 cb = {
53 http = "https://codeberg.org/";
54 ssh = "ssh://git@codeberg.org/";
55 };
56 clicks = {
57 http = "https://git.clicks.codes/";
58 ssh = "ssh://${config.chimera.git.auth.clicksUsername}@ssh.clicks.codes:29418/";
59 };
60 fdo = {
61 http = "https://gitlab.freedesktop.org/";
62 ssh = "ssh://git@gitlab.freedesktop.org/";
63 };
64 gh = {
65 http = "https://github.com/";
66 ssh = "ssh://git@github.com/";
67 };
68 gl = {
69 http = "https://gitlab.com/";
70 ssh = "ssh://git@gitlab.com/";
71 };
72 kde = {
73 http = "https://invent.kde.org/";
74 ssh = "ssh://git@invent.kde.org/";
75 };
76 lix = {
77 http = "https://git.lix.systems/";
78 ssh = "ssh://git@git.lix.systems/";
79 };
Skyler Greyc5fb2ea2024-05-31 23:07:42 +000080 srht = {
81 http = "https://git.sr.ht/";
82 ssh = "git@git.sr.ht:";
83 };
Skyler Greya9478182024-05-25 00:33:38 +000084 };
85
86 replacementToHTTPInsteadOf = name: urls: {
87 name = urls.http;
88 value.insteadOf = "${name}:";
89 };
90 replacementToSSHInsteadOf = name: urls: {
91 name = urls.ssh;
92 value = {
93 insteadOf = "p:${name}:";
94 pushInsteadOf = [ urls.http "${name}:" ];
95 };
96 };
97
98 replacementURLList =
99 (lib.mapAttrsToList replacementToHTTPInsteadOf urlReplacements)
100 ++ (lib.mapAttrsToList replacementToSSHInsteadOf urlReplacements);
101
102 replacementURLs = builtins.listToAttrs replacementURLList;
103 in {
Skyler Grey695fa632024-02-17 22:45:41 +0000104 chimera.gpg.enable = lib.mkIf config.chimera.git.gpg.enable true;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500105
Skyler Greyd5457a22024-02-15 23:02:32 +0000106 home.packages =
Skyler Greyec50d242024-02-15 23:09:46 +0000107 (if config.chimera.git.gitReview.enable then [ pkgs.git-review ] else [ ])
Skyler Grey3883b642024-06-30 23:01:42 +0000108 ++ (if config.chimera.git.stgit.enable then [ pkgs.stgit ] else [ ])
Skyler Greybd08ef62024-07-21 12:27:18 +0000109 ++ (if config.chimera.git.jj.enable then [ inputs.jujutsu.packages.${system}.jujutsu ] else [ ])
Skyler Greycf0b8562024-10-02 22:14:37 +0000110 ++ (if !config.chimera.git.radicle.enable then [ ]
111 else if config.chimera.git.radicle.unstable then [ inputs.radicle.packages.${system}.default ]
112 else [ pkgs.radicle-node ]);
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500113
114 programs.zsh.shellAliases =
115 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
116
117 programs.bash.shellAliases =
118 if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
119
120 programs.git = {
121 enable = true;
122
Samuel Shuertfd4bc1d2024-09-04 17:03:38 -0400123 delta = {
124 enable = config.chimera.git.delta.enable;
125 options.light = lib.mkIf config.chimera.theme.catppuccin.enable (
126 config.chimera.theme.catppuccin.style == "Latte"
127 );
128 };
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500129
130 extraConfig = {
131 init.defaultBranch = "main";
132 advice.skippedcherrypicks = false;
Skyler Grey695fa632024-02-17 22:45:41 +0000133 commit.gpgsign = lib.mkIf config.chimera.git.gpg.enable config.chimera.git.gpg.commit;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500134 credential.helper = "cache";
135 core = {
136 repositoryformatversion = 0;
137 filemode = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000138 # 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 -0500139 };
140 push = {
141 autoSetupRemote = true;
Samuel Shuert659b5642024-02-23 20:47:43 +0000142 gpgSign = lib.mkIf config.chimera.git.gpg.enable (
143 if config.chimera.git.gpg.push then "if-asked" else false
144 );
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500145 };
Skyler Greyfde4a192024-05-24 23:24:22 +0000146 pull.rebase = "merges";
147 rebase.updateRefs = true;
Skyler Greya9478182024-05-25 00:33:38 +0000148 url = replacementURLs;
Samuel Shuert02ffd1e2024-02-13 21:37:15 -0500149 merge.conflictstyle = "diff3";
150 trailer.ifexists = "addIfDifferent";
151 };
152 };
153 };
154}