Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 1 | { pkgs, config, lib, base, system, ... }: |
| 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 | bcb46d3 | 2023-11-10 20:48:38 +0000 | [diff] [blame] | 117 | (pkgs.fetchurl { |
| 118 | url = "https://gerrit-ci.gerritforge.com/job/plugin-oauth-bazel-master-master/55/artifact/bazel-bin/plugins/oauth/oauth.jar"; |
| 119 | hash = "sha256-Qil1CIh/+XC15rKfW0iYR9u370eF2TXnCNSmQfr+7/8="; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 120 | }) |
| 121 | ]; |
| 122 | builtinPlugins = [ |
| 123 | "codemirror-editor" |
| 124 | "commit-message-length-validator" |
| 125 | "delete-project" |
| 126 | "download-commands" |
| 127 | "gitiles" |
| 128 | "hooks" |
| 129 | "reviewnotes" |
| 130 | "singleusergroup" |
| 131 | "webhooks" |
| 132 | ]; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 133 | serverId = "45f277d0-fce7-43b7-9eb3-2e3234e0110f"; |
| 134 | |
Skyler Grey | 22428b0 | 2023-11-19 13:20:56 +0000 | [diff] [blame] | 135 | listenAddress = "127.0.0.255:1024"; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 138 | sops.secrets = { |
| 139 | gerrit_email_private_key = { |
| 140 | mode = "0400"; |
| 141 | owner = config.users.users.root.name; |
Skyler Grey | bcb46d3 | 2023-11-10 20:48:38 +0000 | [diff] [blame] | 142 | group = config.users.users.root.group; |
Samuel Shuert | f68685d | 2023-10-28 20:07:56 -0400 | [diff] [blame] | 143 | sopsFile = ../../secrets/gerrit.json; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 144 | format = "json"; |
| 145 | }; |
| 146 | gerrit_oauth_client_secret = { |
| 147 | mode = "0400"; |
| 148 | owner = config.users.users.root.name; |
Skyler Grey | bcb46d3 | 2023-11-10 20:48:38 +0000 | [diff] [blame] | 149 | group = config.users.users.root.group; |
Samuel Shuert | f68685d | 2023-10-28 20:07:56 -0400 | [diff] [blame] | 150 | sopsFile = ../../secrets/gerrit.json; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 151 | format = "json"; |
| 152 | }; |
Skyler Grey | 22428b0 | 2023-11-19 13:20:56 +0000 | [diff] [blame] | 153 | gerrit_email_password = { |
| 154 | mode = "0400"; |
| 155 | owner = config.users.users.root.name; |
| 156 | group = config.users.users.root.group; |
| 157 | sopsFile = ../../secrets/gerrit.json; |
| 158 | format = "json"; |
| 159 | }; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 160 | }; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 161 | } (let isDerived = base != null; |
| 162 | in if isDerived then |
| 163 | let |
| 164 | gerrit_cfgfile = |
| 165 | pkgs.writeText "gerrit.conf" (lib.generators.toGitINI cfg.settings); |
| 166 | in { |
| 167 | scalpel.trafos."gerrit.conf" = { |
| 168 | source = toString gerrit_cfgfile; |
| 169 | matchers."gerrit_email_private_key".secret = |
| 170 | config.sops.secrets.gerrit_email_private_key.path; |
| 171 | matchers."gerrit_oauth_client_secret".secret = |
| 172 | config.sops.secrets.gerrit_oauth_client_secret.path; |
Skyler Grey | 22428b0 | 2023-11-19 13:20:56 +0000 | [diff] [blame] | 173 | matchers."gerrit_email_password".secret = |
| 174 | config.sops.secrets.gerrit_email_password.path; |
Skyler Grey | bcb46d3 | 2023-11-10 20:48:38 +0000 | [diff] [blame] | 175 | owner = config.users.users.root.name; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 176 | group = "gerrit"; |
| 177 | mode = "0040"; |
| 178 | }; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 179 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 180 | systemd.services.gerrit.preStart = |
| 181 | base.config.systemd.services.gerrit.preStart + '' |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 182 | rm etc/gerrit.config |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 183 | ln -sfv ${ |
| 184 | config.scalpel.trafos."gerrit.conf".destination |
| 185 | } etc/gerrit.config |
| 186 | ''; |
| 187 | } |
| 188 | else |
| 189 | { }) |