about summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
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;