@@ -0,0 +1,101 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.nginx.gitweb;
7+ gitwebConfigFile = pkgs.writeText "gitweb.conf" ''
8+ # path to git projects (<project>.git)
9+ $projectroot = "${cfg.projectroot}";
10+ $highlight_bin = "${pkgs.highlight}/bin/highlight";
11+ ${cfg.extraConfig}
12+ '';
13+ gitwebPerlLibs = with pkgs.perlPackages; [ CGIFast FCGI FCGIProcManager HTMLTagCloud ];
14+ git = pkgs.git.overrideAttrs (oldAttrs: rec {
15+ postInstall = ''
16+ ${oldAttrs.postInstall}
17+ for p in ${lib.concatStringsSep " " gitwebPerlLibs}; do
18+ sed -i -e "/use CGI /i use lib \"$p/lib/perl5/site_perl\";" \
19+ "$out/share/gitweb/gitweb.cgi"
20+ done
21+ '';
22+ });
23+
24+in
25+{
26+
27+ options.services.nginx.gitweb = {
28+
29+ enable = mkOption {
30+ default = false;
31+ type = types.bool;
32+ description = ''
33+ If true, enable gitweb in nginx. Access it at http://yourserver/gitweb
34+ '';
35+ };
36+
37+ projectroot = mkOption {
38+ default = "/srv/git";
39+ type = types.path;
40+ description = ''
41+ Path to git projects (bare repositories) that should be served by
42+ gitweb. Must not end with a slash.
43+ '';
44+ };
45+
46+ extraConfig = mkOption {
47+ default = "";
48+ type = types.lines;
49+ description = ''
50+ Verbatim configuration text appended to the generated gitweb.conf file.
51+ '';
52+ example = ''
53+ $feature{'highlight'}{'default'} = [1];
54+ $feature{'ctags'}{'default'} = [1];
55+ '';
56+ };
57+
58+ };
59+
60+ config = mkIf cfg.enable {
61+
62+ systemd.sockets.gitweb = {
63+ description = "GitWeb Listen Socket";
64+ listenStreams = [ "/run/gitweb.sock" ];
65+ socketConfig = {
66+ Accept = "false";
67+ SocketUser = "nginx";
68+ SocketGroup = "nginx";
69+ SocketMode = "0600";
70+ };
71+ wantedBy = [ "sockets.target" ];
72+ };
73+ systemd.services.gitweb = {
74+ description = "GitWeb service";
75+ script = "${git}/share/gitweb/gitweb.cgi --fcgi";
76+ serviceConfig = {
77+ Type = "simple";
78+ StandardInput = "socket";
79+ User = "nginx";
80+ Group = "nginx";
81+ };
82+ };
83+
84+ services.nginx = {
85+ virtualHosts.default = {
86+ locations."/gitweb" = {
87+ root = "${pkgs.git}/share/gitweb";
88+ extraConfig = ''
89+ include ${pkgs.nginx}/conf/fastcgi_params;
90+ fastcgi_param GITWEB_CONFIG ${gitwebConfigFile};
91+ fastcgi_pass unix:/run/gitweb.sock;
92+ '';
93+ };
94+ };
95+ };
96+
97+ };
98+
99+ meta.maintainers = with maintainers; [ gnidorah ];
100+
101+}