From 1094306aa95476a16f28083d4e903bb3e5c2b3dc Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 22 Jun 2022 19:24:35 +0300 Subject: [PATCH] refactor(web/cgit-tvl): Move cgit config back out of module 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 --- ops/machines/whitby/default.nix | 2 +- ops/modules/cgit.nix | 39 ++++++++++++ .../modules/cgit => web/cgit-tvl}/default.nix | 63 +++++++------------ .../cgit-tvl}/thttpd_cgi_idx.patch | 0 4 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 ops/modules/cgit.nix rename {ops/modules/cgit => web/cgit-tvl}/default.nix (55%) rename {ops/modules/cgit => web/cgit-tvl}/thttpd_cgi_idx.patch (100%) diff --git a/ops/machines/whitby/default.nix b/ops/machines/whitby/default.nix index fc5badd9d..ea841e410 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 000000000..25318d1d7 --- /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 similarity index 55% rename from ops/modules/cgit/default.nix rename to web/cgit-tvl/default.nix index 580b8384b..d26de9a5e 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} - ''; - }; - }; - }; -} +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 similarity index 100% rename from ops/modules/cgit/thttpd_cgi_idx.patch rename to web/cgit-tvl/thttpd_cgi_idx.patch