blob: 27588eb0d01f4e105722676f2dde46e70817fde5 [file] [log] [blame]
Skyler Greyc5ed69c2023-12-23 02:25:41 +00001{ pkgs, config, lib, base, system, gerrit-oauth, ... }:
Skyler Greyfe1740c2023-10-21 01:24:18 +00002let cfg = config.services.gerrit;
3in lib.recursiveUpdate {
Skyler Grey08758a62023-10-09 07:35:09 +00004 users.users.gerrit = {
5 isSystemUser = true;
6 createHome = true;
7 home = "/var/lib/gerrit";
8 group = config.users.groups.gerrit.name;
9 shell = pkgs.bashInteractive;
10 };
Skyler Greyfe1740c2023-10-21 01:24:18 +000011 users.groups.gerrit = { };
Skyler Grey08758a62023-10-09 07:35:09 +000012
13 systemd.services.gerrit.serviceConfig.User = "gerrit";
14 systemd.services.gerrit.serviceConfig.Group = "gerrit";
15 systemd.services.gerrit.serviceConfig.DynamicUser = lib.mkForce false;
16
17 services.gerrit = {
18 enable = true;
19
Skyler Grey08758a62023-10-09 07:35:09 +000020 settings = {
Skyler Grey08758a62023-10-09 07:35:09 +000021 accounts = {
22 visibility = "SAME_GROUP";
Skyler Grey66e61a82023-11-26 22:05:14 +000023 defaultDisplayName = "FULL_NAME";
Skyler Grey08758a62023-10-09 07:35:09 +000024 };
25 addReviewer = {
26 maxWithoutConfirmation = 3;
27 maxAllowed = 10;
28 };
29 auth = {
30 type = "OAUTH";
31 registerEmailPrivateKey = "!!gerrit_email_private_key!!";
32 userNameCaseInsensitive = true;
33 gitBasicAuthPolicy = "HTTP";
34 };
35 plugin."gerrit-oauth-provider-keycloak-oauth" = {
36 root-url = "https://login.clicks.codes";
Skyler Grey22428b02023-11-19 13:20:56 +000037 realm = "master";
Skyler Grey08758a62023-10-09 07:35:09 +000038 client-id = "git";
39 client-secret = "!!gerrit_oauth_client_secret!!";
40 use-preferred-username = true;
41 };
42 change = {
43 topicLimit = 0;
44 mergeabilityComputationBehavior = "API_REF_UPDATED_AND_CHANGE_REINDEX";
45 sendNewPatchsetEmails = false;
46 showAssigneeInChangesTable = true;
47 submitWholeTopic = true;
48 diff3ConflictView = true;
49 };
50 changeCleanup = {
51 abandonAfter = "3 weeks";
Skyler Greyfe1740c2023-10-21 01:24:18 +000052 abandonMessage =
53 "This change was abandoned due to 3 weeks of inactivity. If you still want it, please restore it";
Skyler Grey08758a62023-10-09 07:35:09 +000054 startTime = "00:00";
55 interval = "1 day";
56 };
57 attentionSet = {
58 readdAfter = "1 week";
Skyler Greyfe1740c2023-10-21 01:24:18 +000059 readdMessage =
60 "I've given the owner a *ping* as nothing has happened for a week. If in two weeks time the change is still inactive, I'll abandon it for you. If you still want it, please do something before then";
Skyler Grey08758a62023-10-09 07:35:09 +000061 startTime = "00:00";
62 interval = "1 day";
63 };
64 commentlink.gerrit = {
65 match = "(I[0-9a-f]{8,40})";
66 link = "/q/$1";
67 };
68 gc = {
69 aggressive = true;
70 startTime = "Sun 00:00";
71 interval = "1 week";
72 };
73 gerrit = {
74 basePath = "/var/lib/gerrit/repos";
75 defaultBranch = "refs/heads/main";
76 canonicalWebUrl = "https://git.clicks.codes/";
77 canonicalGitUrl = "ssh://ssh.clicks.codes/";
78 gitHttpUrl = "https://git.clicks.codes/";
Skyler Greyfe1740c2023-10-21 01:24:18 +000079 reportBugUrl =
TheCodedProf8faa2562023-10-25 14:26:19 -040080 "https://discord.gg/bPaNnxe"; # TODO: kinda obnoxious, better to setup openproject
Skyler Grey08758a62023-10-09 07:35:09 +000081 enablePeerIPInReflogRecord = true;
Skyler Grey22428b02023-11-19 13:20:56 +000082 instanceId = "clicks";
83 instanceName = "Clicks Gerrit";
Skyler Grey08758a62023-10-09 07:35:09 +000084 };
85 mimetype = lib.pipe [ "image/*" "video/*" "application/pdf" ] [
Skyler Greyfe1740c2023-10-21 01:24:18 +000086 (map (name: {
87 inherit name;
88 value.safe = true;
89 }))
Skyler Grey08758a62023-10-09 07:35:09 +000090 builtins.listToAttrs
91 ];
Skyler Grey22428b02023-11-19 13:20:56 +000092 sendemail = {
93 enable = true;
94 smtpServer = "mail.clicks.codes";
95 smtpUser = "git";
96 smtpPass = "!!gerrit_email_password!!";
97 };
98 receiveemail = {
99 enable = true;
100 protocol = "IMAP";
101 host = "mail.clicks.codes";
102 username = "git@clicks.codes";
103 password = "!!gerrit_email_password!!";
104 encryption = "SSL";
105 enableImapIdle = true;
106 };
Skyler Grey08758a62023-10-09 07:35:09 +0000107 sshd.advertisedAddress = "ssh.clicks.codes:29418";
108 user = {
109 name = "Clicks Gerrit";
110 email = "git@clicks.codes";
111 anonymousCoward = "Anonymous";
112 };
113 httpd.listenUrl = "proxy-https://${cfg.listenAddress}";
114 };
115
Skyler Greyfe1740c2023-10-21 01:24:18 +0000116 plugins = [
Skyler Greyc5ed69c2023-12-23 02:25:41 +0000117 (builtins.path { path = gerrit-oauth; name = "oauth.jar"; })
Skyler Greyfe1740c2023-10-21 01:24:18 +0000118 ];
119 builtinPlugins = [
120 "codemirror-editor"
121 "commit-message-length-validator"
122 "delete-project"
123 "download-commands"
124 "gitiles"
125 "hooks"
126 "reviewnotes"
127 "singleusergroup"
128 "webhooks"
129 ];
Skyler Grey08758a62023-10-09 07:35:09 +0000130 serverId = "45f277d0-fce7-43b7-9eb3-2e3234e0110f";
131
Skyler Grey22428b02023-11-19 13:20:56 +0000132 listenAddress = "127.0.0.255:1024";
Skyler Grey08758a62023-10-09 07:35:09 +0000133 };
134
Skyler Grey08758a62023-10-09 07:35:09 +0000135 sops.secrets = {
136 gerrit_email_private_key = {
137 mode = "0400";
138 owner = config.users.users.root.name;
Skyler Greybcb46d32023-11-10 20:48:38 +0000139 group = config.users.users.root.group;
Samuel Shuertf68685d2023-10-28 20:07:56 -0400140 sopsFile = ../../secrets/gerrit.json;
Skyler Grey08758a62023-10-09 07:35:09 +0000141 format = "json";
142 };
143 gerrit_oauth_client_secret = {
144 mode = "0400";
145 owner = config.users.users.root.name;
Skyler Greybcb46d32023-11-10 20:48:38 +0000146 group = config.users.users.root.group;
Samuel Shuertf68685d2023-10-28 20:07:56 -0400147 sopsFile = ../../secrets/gerrit.json;
Skyler Grey08758a62023-10-09 07:35:09 +0000148 format = "json";
149 };
Skyler Grey22428b02023-11-19 13:20:56 +0000150 gerrit_email_password = {
151 mode = "0400";
152 owner = config.users.users.root.name;
153 group = config.users.users.root.group;
154 sopsFile = ../../secrets/gerrit.json;
155 format = "json";
156 };
Skyler Grey08758a62023-10-09 07:35:09 +0000157 };
Skyler Greyfe1740c2023-10-21 01:24:18 +0000158} (let isDerived = base != null;
159in if isDerived then
160 let
161 gerrit_cfgfile =
162 pkgs.writeText "gerrit.conf" (lib.generators.toGitINI cfg.settings);
163 in {
164 scalpel.trafos."gerrit.conf" = {
165 source = toString gerrit_cfgfile;
166 matchers."gerrit_email_private_key".secret =
167 config.sops.secrets.gerrit_email_private_key.path;
168 matchers."gerrit_oauth_client_secret".secret =
169 config.sops.secrets.gerrit_oauth_client_secret.path;
Skyler Grey22428b02023-11-19 13:20:56 +0000170 matchers."gerrit_email_password".secret =
171 config.sops.secrets.gerrit_email_password.path;
Skyler Greybcb46d32023-11-10 20:48:38 +0000172 owner = config.users.users.root.name;
Skyler Greyfe1740c2023-10-21 01:24:18 +0000173 group = "gerrit";
174 mode = "0040";
175 };
Skyler Grey08758a62023-10-09 07:35:09 +0000176
Skyler Greyfe1740c2023-10-21 01:24:18 +0000177 systemd.services.gerrit.preStart =
178 base.config.systemd.services.gerrit.preStart + ''
Skyler Grey08758a62023-10-09 07:35:09 +0000179 rm etc/gerrit.config
Skyler Greyfe1740c2023-10-21 01:24:18 +0000180 ln -sfv ${
181 config.scalpel.trafos."gerrit.conf".destination
182 } etc/gerrit.config
183 '';
184 }
185else
186 { })