diff options
-rw-r--r-- | ops/machines/whitby/default.nix | 2 | ||||
-rw-r--r-- | ops/modules/cgit.nix | 39 | ||||
-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 |