aboutsummaryrefslogtreecommitdiff
path: root/infra/modules/gitserver-ui.nix
blob: 9e1feb59347f8b5c6da8dacd467ff59bc38f8799 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
  flake.modules.nixos.gitserver-ui =
    { config, pkgs, ... }:
    let
      cgitrc = pkgs.writeText "cgitrc" ''
        cache-size=1000
        cache-static-ttl=60
        enable-commit-graph=1
        enable-http-clone=0
        enable-index-links=1
        enable-log-filecount=1
        enable-log-linecount=1
        enable-subject-links=1

        repo.name=monorepo
        repo.url=monorepo-public
        repo.path=/var/lib/git/monorepo-public
        repo.desc=an attempt at managing everything in a single repo
        repo.defbranch=main
        repo.readme=:README.md
      '';
    in
    {
      users = {
        groups.cgit = { };
        users.cgit = {
          group = "cgit";
          isSystemUser = true;
          extraGroups = [ "git" ];
        };
      };

      services.fcgiwrap.instances.cgit = {
        process = {
          user = "cgit";
          group = "cgit";
        };
        socket = {
          user = config.services.caddy.user;
          group = config.services.caddy.group;
        };
      };

      services.caddy.virtualHosts."code.vkcku.com" = {
        extraConfig = ''
          @static path /cgit.css /cgit.png /favicon.ico /robots.txt
          handle @static {
            root * ${pkgs.cgit}/cgit
            file_server
          }

          handle / {
            redir * /monorepo-public
          }

          handle {
            reverse_proxy unix/${config.services.fcgiwrap.instances.cgit.socket.address} {
              transport fastcgi {
                env SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi
                env CGIT_CONFIG ${cgitrc}
                env PATH_INFO {http.request.uri.path}
                env HTTP_HOST {http.request.host}
              }
            }
          }
        '';
      };

      assertions = [
        {
          assertion = config.services.caddy.enable;
          message = "Caddy must be enabled for gitserver-ui to work.";
        }
        {
          assertion = config.infra.gitserver.enablePublic;
          message = "public monorepo is not being served on this machine";
        }
      ];
    };
}