ctucx.git: nixfiles

ctucx' nixfiles

commit e302fbe3add88c69aed5dcbaef7072d353051118
parent 5f167c1a8cb9f430bb80de8335181d7db8ada43c
Author: Leah (ctucx) <git@ctu.cx>
Date: Tue, 16 May 2023 20:40:26 +0200

machines/trabbi/git: add command to rebuild webdir
1 file changed, 35 insertions(+), 27 deletions(-)
M
machines/trabbi/git.nix
|
62
+++++++++++++++++++++++++++++++++++---------------------------
diff --git a/machines/trabbi/git.nix b/machines/trabbi/git.nix
@@ -22,15 +22,17 @@ let
       return 1
     }
 
-    make_stagit_repo() {
+    build_stagit_repo() {
       reponame="$(basename "$1" ".git")"
       printf "[%s] Generate stagit HTML pages... " "$reponame"
 
+      mkdir -p "/var/lib/gitolite/stagit-cache"
       mkdir -p "/var/lib/stagit/$reponame"
+
       cd "/var/lib/stagit/$reponame" || return 1
 
-      # make pages
-      ${pkgs.stagit}/bin/stagit -c '.stagit-build-cache' -n 'ctucx.git' -h 'https://git.ctu.cx/' -s 'git@${config.networking.hostName}.ctu.cx:' "$1"
+      # build repo pages
+      ${pkgs.stagit}/bin/stagit -c "/var/lib/gitolite/stagit-cache/$reponame" -n 'ctucx.git' -h 'https://git.ctu.cx/' -s 'git@${config.networking.hostName}.ctu.cx:' "$1"
 
       # set correct permissions
       chown git:git -R /var/lib/stagit/$reponame;

@@ -39,7 +41,7 @@ let
       echo "done"
     }
 
-    make_stagit_index() {
+    build_stagit_index() {
       printf "Generating stagit index... "
 
       # set assets if not already there

@@ -58,7 +60,7 @@ let
         done
       done
 
-      # make index
+      # build index
       echo "$args" | xargs ${pkgs.stagit}/bin/stagit-index > /var/lib/stagit/index.html
 
       # set correct permissions

@@ -79,12 +81,33 @@ let
       # if forced update, remove directory and cache file
       is_forced_update && printf "[%s] Forced update, trigger complete regeneration of stagit-pages... \n" "$reponame" && rm -rf "/var/lib/stagit/$reponame"
 
-      make_stagit_repo "$repo"
-      make_stagit_index
+      build_stagit_repo "$repo"
+      build_stagit_index
     }
 
   '';
 
+  rebuildWebdir = ''
+    source ${stagitFunctions}
+
+    # clear webdir
+    rm -rf /var/lib/stagit/*
+
+    # clear cache
+    rm -rf /var/lib/gitolite/stagit-cache/*
+
+    # generate pages per repo
+    for repo in "$HOME/repositories/"*.git/; do
+      repo="''${repo%/}"
+      is_public_and_listed "$repo" || continue
+
+      build_stagit_repo "$repo"
+    done
+
+    # generate index page
+    build_stagit_index
+  '';
+
 in {
 
   dns.zones."ctu.cx".subdomains = {

@@ -113,29 +136,14 @@ in {
 
         push(@{$RC{ENABLE}}, 'cgit');
         push(@{$RC{ENABLE}}, 'symbolic-ref');
-        push(@{$RC{ENABLE}}, 'rebuild-stagit');
-
-        $RC{NON_CORE} = "rebuild-stagit POST_COMPILE rebuild-stagit";
-      '';
-
-      triggers.rebuild-stagit = ''
-        source ${stagitFunctions}
-
-        # clear webdir
-        rm -rf /var/lib/stagit/*
-
-        # generate pages per repo
-        for repo in "$HOME/repositories/"*.git/; do
-          repo="''${repo%/}"
-          is_public_and_listed "$repo" || continue
-
-          make_stagit_repo "$repo"
-        done
+        push(@{$RC{ENABLE}}, 'rebuild-webdir');
+        push(@{$RC{ENABLE}}, 'rebuild-webdir');
 
-        # generate index page
-        make_stagit_index
+        $RC{NON_CORE} = "rebuild-webdir-trigger POST_COMPILE rebuild-stagit";
       '';
 
+      triggers.rebuild-webdir = rebuildWebdir;
+      commands.rebuild-webdir = rebuildWebdir;
       commonHooks.post-receive = ''
         # update stagit pages
         source ${stagitFunctions}