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 | 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 Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 16 | users.groups.gerrit = { }; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 17 | |
| 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 Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 26 | "-Djava.class.path=${pkgs.postgresql_jdbc}/share/java" |
| 27 | ]; |
| 28 | */ |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 29 | |
| 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 Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 63 | abandonMessage = |
| 64 | "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] | 65 | startTime = "00:00"; |
| 66 | interval = "1 day"; |
| 67 | }; |
| 68 | attentionSet = { |
| 69 | readdAfter = "1 week"; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 70 | 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 Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 72 | 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 Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 90 | reportBugUrl = |
| 91 | "https://discord.gg/bPaNnxe"; # TODO: kinda obnoxious, better to setup bugzilla/similar |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 92 | enablePeerIPInReflogRecord = true; |
| 93 | instanceId = "a1d1"; |
| 94 | instanceName = "a1d1.clicks"; |
| 95 | }; |
| 96 | mimetype = lib.pipe [ "image/*" "video/*" "application/pdf" ] [ |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 97 | (map (name: { |
| 98 | inherit name; |
| 99 | value.safe = true; |
| 100 | })) |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 101 | 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 Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 114 | plugins = [ |
| 115 | (derivation { |
| 116 | name = |
| 117 | "oauth.jar"; # HACK: wrapping a derivation in a derivation to rename it seems like a bad hack... but bazel would not build if I didn't (I think because it didn't like the .jar extension...) check why though? |
| 118 | src = (pkgs.buildBazelPackage { |
| 119 | __noChroot = true; # FIXME: terrible, horrible, no good, very bad |
| 120 | # name = "gerrit-oauth-provider.jar"; |
| 121 | pname = "gerrit-oauth-provider.jar"; |
| 122 | version = "unstable-2023-10-08"; |
| 123 | src = pkgs.fetchgit { |
| 124 | url = "https://gerrit.googlesource.com/plugins/oauth"; |
| 125 | rev = "1b3cc407cb2571d08601ab852e6e01f82d27160f"; |
| 126 | hash = "sha256-yC/8qnkDbfIujl+Cvamr+EQSwto1DcIUWXh5cwDEZHo="; |
| 127 | deepClone = |
| 128 | true; # FIXME: this bazel build uses some git stuff, maybe we should try replacing with fakegit? |
| 129 | }; |
| 130 | bazelTargets = [ "oauth" ]; |
| 131 | bazel = pkgs.bazel_4; |
| 132 | buildAttrs = { }; |
| 133 | fetchAttrs.sha256 = |
| 134 | "sha256-i5wOTn2NqqgJf4TCIqaCucpXu+5Vm5C84UPrGYFMSzc="; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 135 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 136 | postUnpack = '' |
| 137 | echo "4.2.2" > */.bazelversion # nixpkgs only has certain bazel versions, so let's upgrade the patch of this one |
| 138 | ''; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 139 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 140 | buildInputs = with pkgs; [ git curl jdk11 ]; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 141 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 142 | postInstall = '' |
| 143 | cp bazel-bin/oauth.jar $out |
| 144 | ''; |
| 145 | }); |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 146 | builder = "/bin/sh"; |
| 147 | args = [ "-c" "${pkgs.coreutils}/bin/cp $src $out" ]; |
| 148 | inherit system; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 149 | }) |
| 150 | ]; |
| 151 | builtinPlugins = [ |
| 152 | "codemirror-editor" |
| 153 | "commit-message-length-validator" |
| 154 | "delete-project" |
| 155 | "download-commands" |
| 156 | "gitiles" |
| 157 | "hooks" |
| 158 | "reviewnotes" |
| 159 | "singleusergroup" |
| 160 | "webhooks" |
| 161 | ]; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 162 | serverId = "45f277d0-fce7-43b7-9eb3-2e3234e0110f"; |
| 163 | |
| 164 | listenAddress = "127.0.0.255:1000"; |
| 165 | }; |
| 166 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 167 | nix.settings.sandbox = |
| 168 | "relaxed"; # FIXME: terrible, horrible, no good, very bad, here to support buildBazelPackage's use of cURL |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 169 | |
| 170 | sops.secrets = { |
| 171 | gerrit_email_private_key = { |
| 172 | mode = "0400"; |
| 173 | owner = config.users.users.root.name; |
| 174 | group = config.users.users.nobody.group; |
| 175 | sopsFile = ../secrets/gerrit.json; |
| 176 | format = "json"; |
| 177 | }; |
| 178 | gerrit_oauth_client_secret = { |
| 179 | mode = "0400"; |
| 180 | owner = config.users.users.root.name; |
| 181 | group = config.users.users.nobody.group; |
| 182 | sopsFile = ../secrets/gerrit.json; |
| 183 | format = "json"; |
| 184 | }; |
| 185 | }; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 186 | } (let isDerived = base != null; |
| 187 | in if isDerived then |
| 188 | let |
| 189 | gerrit_cfgfile = |
| 190 | pkgs.writeText "gerrit.conf" (lib.generators.toGitINI cfg.settings); |
| 191 | in { |
| 192 | scalpel.trafos."gerrit.conf" = { |
| 193 | source = toString gerrit_cfgfile; |
| 194 | matchers."gerrit_email_private_key".secret = |
| 195 | config.sops.secrets.gerrit_email_private_key.path; |
| 196 | matchers."gerrit_oauth_client_secret".secret = |
| 197 | config.sops.secrets.gerrit_oauth_client_secret.path; |
| 198 | owner = config.users.users.nobody.name; |
| 199 | group = "gerrit"; |
| 200 | mode = "0040"; |
| 201 | }; |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 202 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 203 | systemd.services.gerrit.preStart = |
| 204 | base.config.systemd.services.gerrit.preStart + '' |
Skyler Grey | 08758a6 | 2023-10-09 07:35:09 +0000 | [diff] [blame] | 205 | rm etc/gerrit.config |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 206 | ln -sfv ${ |
| 207 | config.scalpel.trafos."gerrit.conf".destination |
| 208 | } etc/gerrit.config |
| 209 | ''; |
| 210 | } |
| 211 | else |
| 212 | { }) |