1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.lighttpd.gitweb;
7 gitwebConfigFile = pkgs.writeText "gitweb.conf" ''
8 # path to git projects (<project>.git)
9 $projectroot = "${cfg.projectroot}";
10 ${cfg.extraConfig}
11 '';
12
13in
14{
15
16 options.services.lighttpd.gitweb = {
17
18 enable = mkOption {
19 default = false;
20 type = types.bool;
21 description = ''
22 If true, enable gitweb in lighttpd. Access it at http://yourserver/gitweb
23 '';
24 };
25
26 projectroot = mkOption {
27 default = "/srv/git";
28 type = types.path;
29 description = ''
30 Path to git projects (bare repositories) that should be served by
31 gitweb. Must not end with a slash.
32 '';
33 };
34
35 extraConfig = mkOption {
36 default = "";
37 type = types.lines;
38 description = ''
39 Verbatim configuration text appended to the generated gitweb.conf file.
40 '';
41 };
42
43 };
44
45 config = mkIf cfg.enable {
46
47 # declare module dependencies
48 services.lighttpd.enableModules = [ "mod_cgi" "mod_redirect" "mod_alias" "mod_setenv" ];
49
50 services.lighttpd.extraConfig = ''
51 $HTTP["url"] =~ "^/gitweb" {
52 cgi.assign = (
53 ".cgi" => "${pkgs.perl}/bin/perl"
54 )
55 url.redirect = (
56 "^/gitweb$" => "/gitweb/"
57 )
58 alias.url = (
59 "/gitweb/static/" => "${pkgs.git}/share/gitweb/static/",
60 "/gitweb/" => "${pkgs.git}/share/gitweb/gitweb.cgi"
61 )
62 setenv.add-environment = (
63 "GITWEB_CONFIG" => "${gitwebConfigFile}"
64 )
65 }
66 '';
67
68 };
69
70}