about summary refs log tree commit diff
path: root/modules/services
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-05-28 15:01:00 -0700
committerFranck Cuny <franck@fcuny.net>2022-05-28 17:42:35 -0700
commitac4ffaedd5fbdc593cc8a8f5a396538f9ca0cd7a (patch)
treefb75a1f56ab72b9a90dce882ec5d8acf62be530c /modules/services
parentfeat(cgit): set the clone URL to gerrit (diff)
downloadworld-ac4ffaedd5fbdc593cc8a8f5a396538f9ca0cd7a.tar.gz
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 <franck@fcuny.net>
Diffstat (limited to '')
-rw-r--r--modules/services/cgit/default.nix39
1 files changed, 35 insertions, 4 deletions
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;