about summary refs log tree commit diff
path: root/ops/nixos/monorepo-gerrit.nix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-06-13T20·52+0100
committertazjin <mail@tazj.in>2020-06-13T23·52+0000
commit268729083eb80c93aa402883085c37e32c8a08cf (patch)
tree0916bace8073d30976ec752bb9de8c19a06027ae /ops/nixos/monorepo-gerrit.nix
parent9658e96a87178e972b656db0acf3219937013b88 (diff)
refactor(ops/nixos): Move my NixOS configurations to //users/tazjin r/941
NixOS modules move one level up because it's unlikely that //ops/nixos
will contain actual systems at this point (they're user-specific).

This is the first users folder, so it is also added to the root
readTree invocation for the repository.

Change-Id: I546c701145fa204b7ba7518a8a56a783588629e0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/244
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'ops/nixos/monorepo-gerrit.nix')
-rw-r--r--ops/nixos/monorepo-gerrit.nix105
1 files changed, 105 insertions, 0 deletions
diff --git a/ops/nixos/monorepo-gerrit.nix b/ops/nixos/monorepo-gerrit.nix
new file mode 100644
index 000000000000..58fbb8d206ac
--- /dev/null
+++ b/ops/nixos/monorepo-gerrit.nix
@@ -0,0 +1,105 @@
+# Gerrit configuration for the TVL monorepo
+{ pkgs, config, lib, ... }:
+
+let
+  cfg = config.services.gerrit;
+  gerritHooks = pkgs.runCommandNoCC "gerrit-hooks" {} ''
+    mkdir -p $out
+    ln -s ${config.depot.ops.besadii}/bin/besadii $out/ref-updated
+  '';
+in {
+  services.gerrit = {
+    enable = true;
+    listenAddress = "[::]:4778"; # 4778 - grrt
+    serverId = "4fdfa107-4df9-4596-8e0a-1d2bbdd96e36";
+    builtinPlugins = [
+      "download-commands"
+      "hooks"
+    ];
+
+    plugins = with config.depot.third_party.gerrit_plugins; [
+      owners
+      owners-autoassign
+    ];
+
+    settings = {
+      core.packedGitLimit = "100m";
+      log.jsonLogging = true;
+      log.textLogging = false;
+      sshd.advertisedAddress = "code.tvl.fyi:29418";
+      hooks.path = "${gerritHooks}";
+
+      # Configures gerrit for being reverse-proxied by nginx as per
+      # https://gerrit-review.googlesource.com/Documentation/config-reverseproxy.html
+      gerrit.canonicalWebUrl = "https://cl.tvl.fyi";
+      httpd.listenUrl = "proxy-https://${cfg.listenAddress}";
+
+      download.command = [
+        "checkout"
+        "cherry_pick"
+        "format_patch"
+        "pull"
+      ];
+
+      # Configure for cgit.
+      gitweb = {
+        type = "custom";
+        url = "https://code.tvl.fyi";
+        project = "/";
+        revision = "/commit/?id=\${commit}";
+        branch = "/log/?h=\${branch}";
+        tag = "/tag/?h=\${tag}";
+        roottree = "/tree/?h=\${commit}";
+        file = "/tree/\${file}?h=\${commit}";
+        filehistory = "/log/\${file}?h=\${branch}";
+        linkname = "cgit";
+      };
+
+      # Configures integration with the locally running OpenLDAP
+      auth.type = "LDAP";
+      ldap = {
+        server = "ldap://localhost";
+        accountBase = "ou=users,dc=tvl,dc=fyi";
+        accountPattern = "(&(objectClass=organizationalPerson)(cn=\${username}))";
+        accountFullName = "cn";
+        accountEmailAddress = "mail";
+        accountSshUserName = "cn";
+        groupBase = "ou=groups,dc=tvl,dc=fyi";
+
+        # TODO(tazjin): Assuming this is what we'll be doing ...
+        groupMemberPattern = "(&(objectClass=group)(member=\${dn}))";
+      };
+
+      # Email sending (emails are relayed via the tazj.in domain's
+      # GSuite currently).
+      #
+      # Note that sendemail.smtpPass is stored in
+      # $site_path/etc/secure.config and is *not* controlled by Nix.
+      #
+      # Receiving email is not currently supported.
+      sendemail = {
+        enable = true;
+        html = false;
+        connectTimeout = "10sec";
+        from = "TVL Code Review <tvlbot@tazj.in>";
+        includeDiff = true;
+        smtpEncryption = "none";
+        smtpServer = "localhost";
+        smtpServerPort = 2525;
+      };
+    };
+  };
+
+  systemd.services.gerrit = {
+    serviceConfig = {
+      # There seems to be no easy way to get `DynamicUser` to play
+      # well with other services (e.g. by using SupplementaryGroups,
+      # which seem to have no effect) so we force the DynamicUser
+      # setting for the Gerrit service to be disabled and reuse the
+      # existing 'git' user.
+      DynamicUser = lib.mkForce false;
+      User = "git";
+      Group = "git";
+    };
+  };
+}