blob: 36bc1cd3864eb8d6fe975811ac288c57d6147aea [file] [log] [blame]
Skyler Greyfe1740c2023-10-21 01:24:18 +00001{ pkgs, config, lib, base, system, ... }:
2let cfg = config.services.gerrit;
3in lib.recursiveUpdate {
Skyler Grey08758a62023-10-09 07:35:09 +00004 sops.secrets.clicks_gerrit_db_password = {
5 mode = lib.mkForce "0440";
6 group = lib.mkForce "gerrit";
7 };
8
9 users.users.gerrit = {
10 isSystemUser = true;
11 createHome = true;
12 home = "/var/lib/gerrit";
13 group = config.users.groups.gerrit.name;
14 shell = pkgs.bashInteractive;
15 };
Skyler Greyfe1740c2023-10-21 01:24:18 +000016 users.groups.gerrit = { };
Skyler Grey08758a62023-10-09 07:35:09 +000017
18 systemd.services.gerrit.serviceConfig.User = "gerrit";
19 systemd.services.gerrit.serviceConfig.Group = "gerrit";
20 systemd.services.gerrit.serviceConfig.DynamicUser = lib.mkForce false;
21
22 services.gerrit = {
23 enable = true;
24
25 /* jvmOpts = [
Skyler Greyfe1740c2023-10-21 01:24:18 +000026 "-Djava.class.path=${pkgs.postgresql_jdbc}/share/java"
27 ];
28 */
Skyler Grey08758a62023-10-09 07:35:09 +000029
30 settings = {
31 # accountPatchReviewDb.url = "postgresql://localhost:${toString config.services.postgresql.port}/gerrit?user=gerrit&password=!!gerrit_database_password!!";
32 accounts = {
33 visibility = "SAME_GROUP";
34 defaultDisplayName = "USERNAME";
35 };
36 addReviewer = {
37 maxWithoutConfirmation = 3;
38 maxAllowed = 10;
39 };
40 auth = {
41 type = "OAUTH";
42 registerEmailPrivateKey = "!!gerrit_email_private_key!!";
43 userNameCaseInsensitive = true;
44 gitBasicAuthPolicy = "HTTP";
45 };
46 plugin."gerrit-oauth-provider-keycloak-oauth" = {
47 root-url = "https://login.clicks.codes";
48 realm = "clicks";
49 client-id = "git";
50 client-secret = "!!gerrit_oauth_client_secret!!";
51 use-preferred-username = true;
52 };
53 change = {
54 topicLimit = 0;
55 mergeabilityComputationBehavior = "API_REF_UPDATED_AND_CHANGE_REINDEX";
56 sendNewPatchsetEmails = false;
57 showAssigneeInChangesTable = true;
58 submitWholeTopic = true;
59 diff3ConflictView = true;
60 };
61 changeCleanup = {
62 abandonAfter = "3 weeks";
Skyler Greyfe1740c2023-10-21 01:24:18 +000063 abandonMessage =
64 "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 +000065 startTime = "00:00";
66 interval = "1 day";
67 };
68 attentionSet = {
69 readdAfter = "1 week";
Skyler Greyfe1740c2023-10-21 01:24:18 +000070 readdMessage =
71 "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 +000072 startTime = "00:00";
73 interval = "1 day";
74 };
75 commentlink.gerrit = {
76 match = "(I[0-9a-f]{8,40})";
77 link = "/q/$1";
78 };
79 gc = {
80 aggressive = true;
81 startTime = "Sun 00:00";
82 interval = "1 week";
83 };
84 gerrit = {
85 basePath = "/var/lib/gerrit/repos";
86 defaultBranch = "refs/heads/main";
87 canonicalWebUrl = "https://git.clicks.codes/";
88 canonicalGitUrl = "ssh://ssh.clicks.codes/";
89 gitHttpUrl = "https://git.clicks.codes/";
Skyler Greyfe1740c2023-10-21 01:24:18 +000090 reportBugUrl =
91 "https://discord.gg/bPaNnxe"; # TODO: kinda obnoxious, better to setup bugzilla/similar
Skyler Grey08758a62023-10-09 07:35:09 +000092 enablePeerIPInReflogRecord = true;
93 instanceId = "a1d1";
94 instanceName = "a1d1.clicks";
95 };
96 mimetype = lib.pipe [ "image/*" "video/*" "application/pdf" ] [
Skyler Greyfe1740c2023-10-21 01:24:18 +000097 (map (name: {
98 inherit name;
99 value.safe = true;
100 }))
Skyler Grey08758a62023-10-09 07:35:09 +0000101 builtins.listToAttrs
102 ];
103 receive.enableSignedPush = true;
104 sendemail.enable = false; # TODO: add credentials to git@clicks.codes
105 sshd.advertisedAddress = "ssh.clicks.codes:29418";
106 user = {
107 name = "Clicks Gerrit";
108 email = "git@clicks.codes";
109 anonymousCoward = "Anonymous";
110 };
111 httpd.listenUrl = "proxy-https://${cfg.listenAddress}";
112 };
113
Skyler Greyfe1740c2023-10-21 01:24:18 +0000114 plugins = [
Skyler Greybcb46d32023-11-10 20:48:38 +0000115 (pkgs.fetchurl {
116 url = "https://gerrit-ci.gerritforge.com/job/plugin-oauth-bazel-master-master/55/artifact/bazel-bin/plugins/oauth/oauth.jar";
117 hash = "sha256-Qil1CIh/+XC15rKfW0iYR9u370eF2TXnCNSmQfr+7/8=";
Skyler Greyfe1740c2023-10-21 01:24:18 +0000118 })
119 ];
120 builtinPlugins = [
121 "codemirror-editor"
122 "commit-message-length-validator"
123 "delete-project"
124 "download-commands"
125 "gitiles"
126 "hooks"
127 "reviewnotes"
128 "singleusergroup"
129 "webhooks"
130 ];
Skyler Grey08758a62023-10-09 07:35:09 +0000131 serverId = "45f277d0-fce7-43b7-9eb3-2e3234e0110f";
132
133 listenAddress = "127.0.0.255:1000";
134 };
135
Skyler Grey08758a62023-10-09 07:35:09 +0000136 sops.secrets = {
137 gerrit_email_private_key = {
138 mode = "0400";
139 owner = config.users.users.root.name;
Skyler Greybcb46d32023-11-10 20:48:38 +0000140 group = config.users.users.root.group;
Skyler Grey08758a62023-10-09 07:35:09 +0000141 sopsFile = ../secrets/gerrit.json;
142 format = "json";
143 };
144 gerrit_oauth_client_secret = {
145 mode = "0400";
146 owner = config.users.users.root.name;
Skyler Greybcb46d32023-11-10 20:48:38 +0000147 group = config.users.users.root.group;
Skyler Grey08758a62023-10-09 07:35:09 +0000148 sopsFile = ../secrets/gerrit.json;
149 format = "json";
150 };
151 };
Skyler Greyfe1740c2023-10-21 01:24:18 +0000152} (let isDerived = base != null;
153in if isDerived then
154 let
155 gerrit_cfgfile =
156 pkgs.writeText "gerrit.conf" (lib.generators.toGitINI cfg.settings);
157 in {
158 scalpel.trafos."gerrit.conf" = {
159 source = toString gerrit_cfgfile;
160 matchers."gerrit_email_private_key".secret =
161 config.sops.secrets.gerrit_email_private_key.path;
162 matchers."gerrit_oauth_client_secret".secret =
163 config.sops.secrets.gerrit_oauth_client_secret.path;
Skyler Greybcb46d32023-11-10 20:48:38 +0000164 owner = config.users.users.root.name;
Skyler Greyfe1740c2023-10-21 01:24:18 +0000165 group = "gerrit";
166 mode = "0040";
167 };
Skyler Grey08758a62023-10-09 07:35:09 +0000168
Skyler Greyfe1740c2023-10-21 01:24:18 +0000169 systemd.services.gerrit.preStart =
170 base.config.systemd.services.gerrit.preStart + ''
Skyler Grey08758a62023-10-09 07:35:09 +0000171 rm etc/gerrit.config
Skyler Greyfe1740c2023-10-21 01:24:18 +0000172 ln -sfv ${
173 config.scalpel.trafos."gerrit.conf".destination
174 } etc/gerrit.config
175 '';
176 }
177else
178 { })