about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-06-22T16·24+0300
committertazjin <tazjin@tvl.su>2022-06-27T14·15+0000
commit1094306aa95476a16f28083d4e903bb3e5c2b3dc (patch)
tree17fbb2d8bbe028d28df686d22d3da6656a00a386
parent32b75c45c527ec4469e6f0848e3b097c2f7b1fd6 (diff)
refactor(web/cgit-tvl): Move cgit config back out of module r/4254
It occured to me yesterday that with the config inside of the module
it is kind of difficult to test cgit locally.

This moves it back to a separate location (//web/cgit-tvl) and makes
the most important things configurable via overrides.

Change-Id: I9b0f4c60b75c31441e1718e63b5b55aba3100aae
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5893
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
-rw-r--r--ops/machines/whitby/default.nix2
-rw-r--r--ops/modules/cgit.nix39
-rw-r--r--web/cgit-tvl/default.nix (renamed from ops/modules/cgit/default.nix)63
-rw-r--r--web/cgit-tvl/thttpd_cgi_idx.patch (renamed from ops/modules/cgit/thttpd_cgi_idx.patch)0
4 files changed, 62 insertions, 42 deletions
diff --git a/ops/machines/whitby/default.nix b/ops/machines/whitby/default.nix
index fc5badd9d8a5..ea841e410df7 100644
--- a/ops/machines/whitby/default.nix
+++ b/ops/machines/whitby/default.nix
@@ -10,7 +10,7 @@ in
 {
   imports = [
     (mod "atward.nix")
-    (mod "cgit/default.nix")
+    (mod "cgit.nix")
     (mod "clbot.nix")
     (mod "gerrit-queue.nix")
     (mod "irccat.nix")
diff --git a/ops/modules/cgit.nix b/ops/modules/cgit.nix
new file mode 100644
index 000000000000..25318d1d723e
--- /dev/null
+++ b/ops/modules/cgit.nix
@@ -0,0 +1,39 @@
+# Configuration for running the TVL cgit instance using thttpd.
+{ config, depot, lib, pkgs, ... }:
+
+let
+  cfg = config.services.depot.cgit;
+in
+{
+  options.services.depot.cgit = with lib; {
+    enable = mkEnableOption "Run cgit web interface for depot";
+
+    port = mkOption {
+      description = "Port on which cgit should listen";
+      type = types.int;
+      default = 2448;
+    };
+
+    repo = mkOption {
+      description = "Path to depot's .git folder on the machine";
+      type = types.str;
+      default = "/var/lib/gerrit/git/depot.git/";
+    };
+  };
+
+  config = lib.mkIf cfg.enable {
+    systemd.services.cgit = {
+      wantedBy = [ "multi-user.target" ];
+
+      serviceConfig = {
+        Restart = "on-failure";
+        User = "git";
+        Group = "git";
+
+        ExecStart = depot.web.cgit-tvl.override {
+          inherit (cfg) port repo;
+        };
+      };
+    };
+  };
+}
diff --git a/ops/modules/cgit/default.nix b/web/cgit-tvl/default.nix
index 580b8384bd90..d26de9a5ebe7 100644
--- a/ops/modules/cgit/default.nix
+++ b/web/cgit-tvl/default.nix
@@ -1,12 +1,12 @@
-# Configuration for running the TVL cgit instance using thttpd.
-{ config, depot, lib, pkgs, ... }:
+# Wrapper for running cgit through thttpd with TVL-specific
+# configuration.
+#
+# In practice this is only used for //ops/modules/cgit, but exposing
+# it here makes it easy to experiment with cgit locally.
+{ depot, lib, pkgs, ... }:
 
 let
-  inherit (pkgs) writeText;
-
-  cfg = config.services.depot.cgit;
-
-  cgitConfig = writeText "cgitrc" ''
+  cgitConfig = repo: pkgs.writeText "cgitrc" ''
     # Global configuration
     virtual-root=/
     enable-http-clone=0
@@ -22,14 +22,14 @@ let
 
     # Repository configuration
     repo.url=depot
-    repo.path=/var/lib/gerrit/git/depot.git/
+    repo.path=${repo}
     repo.desc=monorepo for the virus lounge
     repo.owner=The Virus Lounge
     repo.clone-url=https://code.tvl.fyi/depot.git
   '';
 
-  thttpdConfig = writeText "thttpd.conf" ''
-    port=${toString cfg.port}
+  thttpdConfig = port: pkgs.writeText "thttpd.conf" ''
+    port=${toString port}
     dir=${depot.third_party.cgit}/cgit
     nochroot
     novhost
@@ -42,7 +42,7 @@ let
   #
   # Things are done this way because recompilation of thttpd is much
   # faster than cgit.
-  thttpdConfigPatch = writeText "thttpd_cgit_conf.patch" ''
+  thttpdConfigPatch = repo: pkgs.writeText "thttpd_cgit_conf.patch" ''
     diff --git a/libhttpd.c b/libhttpd.c
     index c6b1622..eef4b73 100644
     --- a/libhttpd.c
@@ -51,42 +51,23 @@ let
 
          envn = 0;
     +    // force cgit to load the correct configuration
-    +    envp[envn++] = "CGIT_CONFIG=${cgitConfig}";
+    +    envp[envn++] = "CGIT_CONFIG=${cgitConfig repo}";
          envp[envn++] = build_env( "PATH=%s", CGI_PATH );
      #ifdef CGI_LD_LIBRARY_PATH
   '';
 
-  thttpdCgit = pkgs.thttpd.overrideAttrs (old: {
+  thttpdCgit = repo: pkgs.thttpd.overrideAttrs (old: {
     patches = [
       ./thttpd_cgi_idx.patch
-      thttpdConfigPatch
+      (thttpdConfigPatch repo)
     ];
   });
-in
-{
-  options.services.depot.cgit = with lib; {
-    enable = mkEnableOption "Run cgit web interface for depot";
-
-    port = mkOption {
-      description = "Port on which cgit should listen";
-      type = types.int;
-      default = 2448;
-    };
-  };
 
-  config = lib.mkIf cfg.enable {
-    systemd.services.cgit = {
-      wantedBy = [ "multi-user.target" ];
-
-      serviceConfig = {
-        Restart = "on-failure";
-        User = "git";
-        Group = "git";
-
-        ExecStart = pkgs.writeShellScript "cgit-launch" ''
-          exec ${thttpdCgit}/bin/thttpd -D -C ${thttpdConfig}
-        '';
-      };
-    };
-  };
-}
+in
+lib.makeOverridable
+  ({ port ? 2448
+   , repo ? "/var/lib/gerrit/git/depot.git/"
+   }: pkgs.writeShellScript "cgit-launch" ''
+    exec ${thttpdCgit repo}/bin/thttpd -D -C ${thttpdConfig port}
+  '')
+{ }
diff --git a/ops/modules/cgit/thttpd_cgi_idx.patch b/web/cgit-tvl/thttpd_cgi_idx.patch
index 67dbc0c7ab80..67dbc0c7ab80 100644
--- a/ops/modules/cgit/thttpd_cgi_idx.patch
+++ b/web/cgit-tvl/thttpd_cgi_idx.patch