Skyler Grey | c5ed69c | 2023-12-23 02:25:41 +0000 | [diff] [blame^] | 1 | { pkgs, config, lib, base, system, gerrit-oauth, ... }: |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 2 | let cfg = config.services.gerrit; |
| 3 | in lib.recursiveUpdate { |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 4 | 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 Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 11 | users.groups.gerrit = { }; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 12 | |
| 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 Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 20 | settings = { |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 21 | accounts = { |
| 22 | visibility = "SAME_GROUP"; |
Skyler Grey | 66e61a8 | 2023-11-26 22:05:14 +0000 | [diff] [blame] | 23 | defaultDisplayName = "FULL_NAME"; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 24 | }; |
| 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 Grey | 22428b0 | 2023-11-19 13:20:56 +0000 | [diff] [blame] | 37 | realm = "master"; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 38 | 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 Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 52 | abandonMessage = |
| 53 | "This change was abandoned due to 3 weeks of inactivity. If you still want it, please restore it"; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 54 | startTime = "00:00"; |
| 55 | interval = "1 day"; |
| 56 | }; |
| 57 | attentionSet = { |
| 58 | readdAfter = "1 week"; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 59 | 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 Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 61 | 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 Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 79 | reportBugUrl = |
TheCodedProf | 8faa256 | 2023-10-25 14:26:19 -0400 | [diff] [blame] | 80 | "https://discord.gg/bPaNnxe"; # TODO: kinda obnoxious, better to setup openproject |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 81 | enablePeerIPInReflogRecord = true; |
Skyler Grey | 22428b0 | 2023-11-19 13:20:56 +0000 | [diff] [blame] | 82 | instanceId = "clicks"; |
| 83 | instanceName = "Clicks Gerrit"; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 84 | }; |
| 85 | mimetype = lib.pipe [ "image/*" "video/*" "application/pdf" ] [ |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 86 | (map (name: { |
| 87 | inherit name; |
| 88 | value.safe = true; |
| 89 | })) |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 90 | builtins.listToAttrs |
| 91 | ]; |
Skyler Grey | 22428b0 | 2023-11-19 13:20:56 +0000 | [diff] [blame] | 92 | 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 Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 107 | 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 Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 116 | plugins = [ |
Skyler Grey | c5ed69c | 2023-12-23 02:25:41 +0000 | [diff] [blame^] | 117 | (builtins.path { path = gerrit-oauth; name = "oauth.jar"; }) |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 118 | ]; |
| 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 Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 130 | serverId = "45f277d0-fce7-43b7-9eb3-2e3234e0110f"; |
| 131 | |
Skyler Grey | 22428b0 | 2023-11-19 13:20:56 +0000 | [diff] [blame] | 132 | listenAddress = "127.0.0.255:1024"; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 135 | sops.secrets = { |
| 136 | gerrit_email_private_key = { |
| 137 | mode = "0400"; |
| 138 | owner = config.users.users.root.name; |
Skyler Grey | bcb46d3 | 2023-11-10 20:48:38 +0000 | [diff] [blame] | 139 | group = config.users.users.root.group; |
Samuel Shuert | f68685d | 2023-10-28 20:07:56 -0400 | [diff] [blame] | 140 | sopsFile = ../../secrets/gerrit.json; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 141 | format = "json"; |
| 142 | }; |
| 143 | gerrit_oauth_client_secret = { |
| 144 | mode = "0400"; |
| 145 | owner = config.users.users.root.name; |
Skyler Grey | bcb46d3 | 2023-11-10 20:48:38 +0000 | [diff] [blame] | 146 | group = config.users.users.root.group; |
Samuel Shuert | f68685d | 2023-10-28 20:07:56 -0400 | [diff] [blame] | 147 | sopsFile = ../../secrets/gerrit.json; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 148 | format = "json"; |
| 149 | }; |
Skyler Grey | 22428b0 | 2023-11-19 13:20:56 +0000 | [diff] [blame] | 150 | 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 Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 157 | }; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 158 | } (let isDerived = base != null; |
| 159 | in 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 Grey | 22428b0 | 2023-11-19 13:20:56 +0000 | [diff] [blame] | 170 | matchers."gerrit_email_password".secret = |
| 171 | config.sops.secrets.gerrit_email_password.path; |
Skyler Grey | bcb46d3 | 2023-11-10 20:48:38 +0000 | [diff] [blame] | 172 | owner = config.users.users.root.name; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 173 | group = "gerrit"; |
| 174 | mode = "0040"; |
| 175 | }; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 176 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 177 | systemd.services.gerrit.preStart = |
| 178 | base.config.systemd.services.gerrit.preStart + '' |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 179 | rm etc/gerrit.config |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 180 | ln -sfv ${ |
| 181 | config.scalpel.trafos."gerrit.conf".destination |
| 182 | } etc/gerrit.config |
| 183 | ''; |
| 184 | } |
| 185 | else |
| 186 | { }) |