aboutsummaryrefslogtreecommitdiff
path: root/profiles/git-server.nix
blob: 0d02d8abbdcae27a7dae4ef38f50dbc0ac43693a (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
{ pkgs, lib, ... }:
let
  cgit-org2html = pkgs.writeShellScriptBin "org2html" ''
    ${pkgs.pandoc}/bin/pandoc \
      --from org \
      --to html5 \
      --sandbox=true \
      --html-q-tags \
      --ascii \
      --standalone \
      --wrap=auto \
      --embed-resources \
      -M document-css=false
  '';
  about-formatting = pkgs.writeShellScriptBin "about-formatting" ''
    cd "${pkgs.cgit}/lib/cgit/filters/html-converters"
    case "$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" in
    	*.markdown|*.mdown|*.md|*.mkd) exec ./md2html; ;;
    	*.rst) exec ./rst2html; ;;
    	*.[1-9]) exec ./man2html; ;;
    	*.htm|*.html) exec cat; ;;
    	*.txt) exec ./txt2html; ;;
      *.org) exec ${cgit-org2html}/bin/org2html; ;;
    esac
  '';
in
{
  services.gitolite = {
    enable = true;
    adminPubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINBkozy+X96u5ciX766bJ/AyQ3xm1tXZTIr5+4PVFZFi";
    user = "git";
    group = "git";
    extraGitoliteRc = ''
      # Make dirs/files group readable, needed for webserver/cgit. (Default
      # setting is 0077.)
      $RC{UMASK} = 0027;
      $RC{GIT_CONFIG_KEYS} = 'cgit.desc cgit.hide cgit.ignore cgit.owner cgit.section';
      $RC{LOCAL_CODE} = "$rc{GL_ADMIN_BASE}/local";
      push( @{$RC{ENABLE}}, 'symbolic-ref' );
    '';
  };

  # let's make sure the default branch is `main'.
  # NOTE: gitolite-admin.git default branch needs to be named master
  systemd.tmpfiles.rules = [
    "C /var/lib/gitolite/.gitconfig - git git 0644 ${pkgs.writeText "gitolite-gitconfig" ''
      [init]
      	defaultBranch = main
    ''}"
  ];

  services.cgit.main = {
    enable = true;
    package = pkgs.cgit;
    user = "git";
    group = "git";
    nginx.virtualHost = "code.fcuny.net";
    scanPath = "/var/lib/gitolite/repositories";
    settings = {
      css = "/cgit.css";
      logo = "/cgit.png";
      favicon = "/favicon.ico";
      robots = "noindex, nofollow";
      readme = [
        ":README.md"
        ":README.org"
      ];
      project-list = "/var/lib/gitolite/projects.list";
      about-filter = "${about-formatting}/bin/about-formatting";
      source-filter = "${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py";
      clone-url = (lib.concatStringsSep " " [ "https://code.fcuny.net/$CGIT_REPO_URL" ]);
      enable-log-filecount = 1;
      enable-log-linecount = 1;
      enable-git-config = 1;
      enable-blame = 1;
      enable-commit-graph = 1;
      enable-follow-links = 1;
      enable-index-owner = 0;
      enable-index-links = 1;
      enable-remote-branches = 1;
      enable-subject-links = 1;
      remove-suffix = 1;
      enable-tree-linenumbers = 1;
      max-atom-items = 108;
      max-commit-count = 250;
      max-repo-count = 500;
      repository-sort = "age";
      snapshots = "tar.gz";
      root-title = \\_(ツ)_/¯";
      root-desc = "source code of my various projects";
    };
  };
}