2022-06-22 18:24:35 +02:00
|
|
|
# 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, ... }:
|
2019-12-18 17:22:56 +01:00
|
|
|
|
|
|
|
let
|
2022-06-22 18:24:35 +02:00
|
|
|
cgitConfig = repo: pkgs.writeText "cgitrc" ''
|
2019-12-18 18:53:57 +01:00
|
|
|
# Global configuration
|
2019-12-20 17:24:15 +01:00
|
|
|
virtual-root=/
|
2021-09-16 18:20:18 +02:00
|
|
|
enable-http-clone=0
|
2019-12-20 19:31:34 +01:00
|
|
|
readme=:README.md
|
2022-02-03 19:39:18 +01:00
|
|
|
about-filter=${depot.tools.cheddar.about-filter}/bin/cheddar-about
|
2020-02-21 13:47:29 +01:00
|
|
|
source-filter=${depot.tools.cheddar}/bin/cheddar
|
2019-12-20 21:47:35 +01:00
|
|
|
enable-log-filecount=1
|
|
|
|
enable-log-linecount=1
|
|
|
|
enable-follow-links=1
|
|
|
|
enable-blame=1
|
2022-02-16 19:30:17 +01:00
|
|
|
mimetype-file=${pkgs.mime-types}/etc/mime.types
|
2021-10-01 18:57:43 +02:00
|
|
|
logo=https://static.tvl.fyi/${depot.web.static.drvHash}/logo-animated.svg
|
2019-12-18 17:22:56 +01:00
|
|
|
|
2019-12-18 18:53:57 +01:00
|
|
|
# Repository configuration
|
2019-12-18 17:22:56 +01:00
|
|
|
repo.url=depot
|
2022-06-22 18:24:35 +02:00
|
|
|
repo.path=${repo}
|
2021-03-31 21:16:56 +02:00
|
|
|
repo.desc=monorepo for the virus lounge
|
2021-09-16 18:20:18 +02:00
|
|
|
repo.owner=The Virus Lounge
|
2021-09-16 17:46:17 +02:00
|
|
|
repo.clone-url=https://code.tvl.fyi/depot.git
|
2019-12-18 17:22:56 +01:00
|
|
|
'';
|
2019-12-20 18:28:35 +01:00
|
|
|
|
2022-06-22 18:24:35 +02:00
|
|
|
thttpdConfig = port: pkgs.writeText "thttpd.conf" ''
|
|
|
|
port=${toString port}
|
2021-04-10 18:05:16 +02:00
|
|
|
dir=${depot.third_party.cgit}/cgit
|
2019-12-18 17:22:56 +01:00
|
|
|
nochroot
|
|
|
|
novhost
|
|
|
|
cgipat=**.cgi
|
|
|
|
'';
|
2019-12-18 18:53:57 +01:00
|
|
|
|
|
|
|
# Patched version of thttpd that serves cgit.cgi as the index and
|
|
|
|
# sets the environment variable for pointing cgit at the correct
|
|
|
|
# configuration.
|
|
|
|
#
|
|
|
|
# Things are done this way because recompilation of thttpd is much
|
2022-02-16 19:30:17 +01:00
|
|
|
# faster than cgit.
|
2022-06-22 18:24:35 +02:00
|
|
|
thttpdConfigPatch = repo: pkgs.writeText "thttpd_cgit_conf.patch" ''
|
2019-12-18 18:53:57 +01:00
|
|
|
diff --git a/libhttpd.c b/libhttpd.c
|
|
|
|
index c6b1622..eef4b73 100644
|
|
|
|
--- a/libhttpd.c
|
|
|
|
+++ b/libhttpd.c
|
|
|
|
@@ -3055,4 +3055,6 @@ make_envp( httpd_conn* hc )
|
|
|
|
|
|
|
|
envn = 0;
|
|
|
|
+ // force cgit to load the correct configuration
|
2022-06-22 18:24:35 +02:00
|
|
|
+ envp[envn++] = "CGIT_CONFIG=${cgitConfig repo}";
|
2019-12-18 18:53:57 +01:00
|
|
|
envp[envn++] = build_env( "PATH=%s", CGI_PATH );
|
|
|
|
#ifdef CGI_LD_LIBRARY_PATH
|
|
|
|
'';
|
2022-02-16 19:30:17 +01:00
|
|
|
|
2022-06-22 18:24:35 +02:00
|
|
|
thttpdCgit = repo: pkgs.thttpd.overrideAttrs (old: {
|
2019-12-22 00:36:02 +01:00
|
|
|
patches = [
|
|
|
|
./thttpd_cgi_idx.patch
|
2022-06-22 18:24:35 +02:00
|
|
|
(thttpdConfigPatch repo)
|
2019-12-22 00:36:02 +01:00
|
|
|
];
|
2019-12-18 17:22:56 +01:00
|
|
|
});
|
2022-02-16 19:30:17 +01:00
|
|
|
|
2022-06-22 18:24:35 +02:00
|
|
|
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}
|
|
|
|
'')
|
|
|
|
{ }
|