about summary refs log tree commit diff
path: root/machines/srv3/services/cgit
diff options
context:
space:
mode:
authorPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2024-10-30 20:16:45 +0100
committerPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2024-10-30 20:16:45 +0100
commit009a43799c28eca77752de4268c0e74700d13527 (patch)
tree5eb771177ef9ccde32ecdaa11149549b5e9ea19e /machines/srv3/services/cgit
parent9c14b06fc484e4be8852c4f379cb1671ed367d6a (diff)
downloaddots-master.tar.gz
dots-master.zip
srv3: move services to folder HEAD master
Diffstat (limited to 'machines/srv3/services/cgit')
-rw-r--r--machines/srv3/services/cgit/baby-yoda.pngbin0 -> 957567 bytes
-rw-r--r--machines/srv3/services/cgit/baby-yoda.png.compbin0 -> 7710 bytes
-rw-r--r--machines/srv3/services/cgit/default.nix106
3 files changed, 106 insertions, 0 deletions
diff --git a/machines/srv3/services/cgit/baby-yoda.png b/machines/srv3/services/cgit/baby-yoda.png
new file mode 100644
index 0000000..42a200c
--- /dev/null
+++ b/machines/srv3/services/cgit/baby-yoda.png
Binary files differdiff --git a/machines/srv3/services/cgit/baby-yoda.png.comp b/machines/srv3/services/cgit/baby-yoda.png.comp
new file mode 100644
index 0000000..26eb247
--- /dev/null
+++ b/machines/srv3/services/cgit/baby-yoda.png.comp
Binary files differdiff --git a/machines/srv3/services/cgit/default.nix b/machines/srv3/services/cgit/default.nix
new file mode 100644
index 0000000..bcd63bb
--- /dev/null
+++ b/machines/srv3/services/cgit/default.nix
@@ -0,0 +1,106 @@
+{ pkgs, ...}:
+let
+  cgitHostname = "git.niedzwiedzinski.cyou";
+
+  mirror = pkgs.writeScriptBin "mirror" ''
+  #!/bin/sh
+
+  name=`echo "$1" | rev | cut -d'/' -f1 | rev`
+
+  cd /srv/git
+  sudo -u git ${pkgs.git}/bin/git clone --mirror $1 $name
+  sudo -u git /run/current-system/sw/bin/chmod -R g+w $name
+  '';
+
+  newrepo = pkgs.writeScriptBin "newrepo" ''
+  #!/bin/sh
+
+  [ -z $1 ] && echo "Pass repo name" && exit 1
+
+  sudo -u git git init --bare /srv/git/$1
+  sudo -u git /run/current-system/sw/bin/chmod -R g+w /srv/git/$1
+  '';
+
+in
+{
+  environment.systemPackages = [ newrepo mirror ];
+  systemd.services.git-fetch = {
+    script = ''
+      #!/bin/sh
+      cd /srv/git
+      for f in `find . -name HEAD`; do
+        cd ''${f%HEAD}
+        ${pkgs.git}/bin/git fetch
+        cd /srv/git
+      done
+    '';
+    serviceConfig = {
+      Type = "oneshot";
+      User = "git";
+    };
+  };
+  systemd.timers.git-fetch = {
+    partOf = [ "git-fetch.service" ];
+    wantedBy = ["timers.target" ];
+    timerConfig = {
+      OnCalendar = "hourly";
+      Unit = "git-fetch.service";
+    };
+  };
+  services.nginx.virtualHosts."${cgitHostname}" = {
+    locations."=/mylogo.png" = {
+      alias = "${./baby-yoda.png.comp}";
+    };
+    forceSSL = true;
+    enableACME = true;
+  };
+  services.cgit.gitN = {
+    enable = true;
+    user = "cgit";
+    package = pkgs.cgit-pink;
+    scanPath = "/srv/git";
+    nginx.virtualHost = cgitHostname;
+    settings = {
+      about-filter = let formatScript = pkgs.writeScriptBin "about-format.sh" ''
+          #!/bin/sh
+          ${pkgs.coreutils}/bin/cat << EOF
+          <style>
+          .md blockquote {
+            background: #eee;
+            font-style: italic;
+            padding: 0 1em;
+          }
+          </style>
+          <div class="md">
+          EOF
+          ${pkgs.coreutils}/bin/cat /dev/stdin | ${pkgs.lowdown}/bin/lowdown
+          echo '</div>'
+        '';
+      in "${formatScript}/bin/about-format.sh";
+      cache-size = "1000";
+      root-title = cgitHostname;
+      root-desc = "Personal git server, because I can";
+      readme = ":README.md";
+      snapshots = "tar.gz zip";
+      clone-prefix = "https://${cgitHostname}";
+      section-from-path = "1";
+      logo = "/mylogo.png";
+    };
+  };
+
+  users = {
+    groups = { git = {}; };
+    users = {
+      git = {
+        isSystemUser = true;
+        group = "git";
+        description = "git user";
+        home = "/srv/git";
+        shell = "${pkgs.git}/bin/git-shell";
+        openssh.authorizedKeys.keys = [
+          "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIqlCe4ovKa/Gwl5xmgu9nvVPmFXMgwdeLRYW7Gg7RWx pniedzwiedzinski19@gmail.com"
+        ];
+      };
+    };
+  };
+}