From ac4ffaedd5fbdc593cc8a8f5a396538f9ca0cd7a Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sat, 28 May 2022 15:01:00 -0700 Subject: feat(cgit): generate the list of projects from gerrit Query the gerrit API to get the list of active projects, and generate the list of repositories from it. This run every 10 minutes as a systemd timer. Change-Id: I016a6d748597ff4d03af893e0a95b96830bdb3f7 Reviewed-on: https://cl.fcuny.net/c/world/+/87 Reviewed-by: Franck Cuny --- modules/services/cgit/default.nix | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'modules/services') diff --git a/modules/services/cgit/default.nix b/modules/services/cgit/default.nix index 919bcc4..87cc72c 100644 --- a/modules/services/cgit/default.nix +++ b/modules/services/cgit/default.nix @@ -4,22 +4,32 @@ let cgitrc = '' # Global configuration virtual-root=/ + + # clone will be handled by gerrit enable-http-clone=0 clone-url=https://cl.fcuny.net/$CGIT_REPO_URL + source-filter=${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py about-filter=${pkgs.cgit}/lib/cgit/filters/about-formatting.sh + readme=:README.md readme=:README.org readme=:readme.org + + # print the number of modified files enable-log-filecount=1 + # print the number of modified lines enable-log-linecount=1 enable-follow-links=1 enable-blame=1 - # Repository configuration - repo.url=world - repo.path=/var/lib/gerrit/git/world.git/ - repo.clone-url=https://git.fcuny.net/world.git + root-title="franck's personal repositories" + + # don't index or follow + robots="noindex, nofollow" + + scan-path=/var/lib/gerrit/git + project-list=/var/lib/cgit/cache/projects.list ''; in { options.my.services.cgit = with lib; { @@ -33,6 +43,27 @@ in { group = "git"; }; + systemd = { + timers.sync-cgit-repo = { + description = "synchronize the list of repositories from gerrit"; + wantedBy = [ "timers.target" ]; + partOf = [ "sync-cgit-repo.service" ]; + timerConfig.OnCalendar = "*:0/10"; + }; + services.sync-cgit-repo = { + description = "synchronize the list of repositories from gerrit"; + serviceConfig.Type = "oneshot"; + script = '' + mkdir -p /var/lib/cgit/cache + # as per https://gerrit-review.googlesource.com/Documentation/rest-api.html#output we need to remove `)]}' from the response + repos=$(${pkgs.curl}/bin/curl -s -H "Content-Type: application/json" "https://cl.fcuny.net/projects/?state=ACTIVE"|sed "s/^)]}'//"|${pkgs.jq}/bin/jq -r 'to_entries | .[] | .value | .id') + for repo in ''${repos}; do + grep "/var/lib/gerrit/git/''${repo}.git" /var/lib/cgit/cache/projects.list || echo "/var/lib/gerrit/git/''${repo}.git" >> /var/lib/cgit/cache/projects.list + done + ''; + }; + }; + services.nginx.virtualHosts."git.fcuny.net" = { forceSSL = true; enableACME = true; -- cgit 1.4.1