summary refs log tree commit diff
path: root/hosts/vps/git.nix
blob: fcf8cfb237ce32163f3340503d618eb8c1098350 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{ pkgs, config, ... }:

{
  config = {
    users.groups.git = {};
    users.users.git = {
      isSystemUser = true;
      description = "tzlil";
      group = "git";
      home = "/home/git";
      packages = [pkgs.git];
      shell = "${pkgs.git}/bin/git-shell";
      openssh.authorizedKeys.keys = [
        "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMDyzrs9sbstv3KFK5FV8qYlSknnEy8Cn+qch4dJLmHA"
      ];
    };
    services = {
      fcgiwrap.enable = true;
      caddy = {
        virtualHosts."http://100.67.217.90".extraConfig = ''
          bind 100.67.217.90
          handle /cgit.png { 
            root * ${pkgs.cgit}/cgit
            file_server
          }
          handle /cgit.css { 
            root * ${pkgs.cgit}/cgit
            file_server
          }
          handle /favicon.ico { 
            root * ${pkgs.cgit}/cgit
            file_server
          }
          handle {
            reverse_proxy unix//run/fcgiwrap.sock { 
              transport fastcgi {
                env SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi
                env CGIT_CONFIG ${pkgs.writeText "cgitrc" (pkgs.lib.generators.toKeyValue { } {
                  css = "/cgit.css";
                  logo = "/cgit.png";
                  favicon = "/favicon.ico";
                  clone-url = (pkgs.lib.concatStringsSep " " [
                    "http://$HTTP_HOST$SCRIPT_NAME/$CGIT_REPO_URL"
                    "ssh://git@git.example.com:$CGIT_REPO_URL"
                  ]);
                  enable-log-filecount = 1;
                  enable-log-linecount = 1;
                  enable-git-config = 1;
                  root-title = "git.example.com";
                  root-desc = "Tzlil's Git Repositories";
                  scan-path = "/home/git";
                  about-filter = "${pkgs.cgit}/lib/cgit/filters/about-formatting.sh";
                  source-filter = "${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py";
                  logo-link = "/";
                })}
              } 
            }
          }
        '';
      };
    };
    environment.persistence."/nix/persist".directories = [ { directory = "/home/git"; user = "git"; group = "git"; } ];
  };
}