1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.lighttpd.cgit;
7 pathPrefix = if stringLength cfg.subdir == 0 then "" else "/" + cfg.subdir;
8 configFile = pkgs.writeText "cgitrc"
9 ''
10 # default paths to static assets
11 css=${pathPrefix}/cgit.css
12 logo=${pathPrefix}/cgit.png
13 favicon=${pathPrefix}/favicon.ico
14
15 # user configuration
16 ${cfg.configText}
17 '';
18in
19{
20
21 options.services.lighttpd.cgit = {
22
23 enable = mkOption {
24 default = false;
25 type = types.bool;
26 description = ''
27 If true, enable cgit (fast web interface for git repositories) as a
28 sub-service in lighttpd.
29 '';
30 };
31
32 subdir = mkOption {
33 default = "cgit";
34 example = "";
35 type = types.str;
36 description = ''
37 The subdirectory in which to serve cgit. The web application will be
38 accessible at http://yourserver/''${subdir}
39 '';
40 };
41
42 configText = mkOption {
43 default = "";
44 example = ''
45 source-filter=''${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py
46 about-filter=''${pkgs.cgit}/lib/cgit/filters/about-formatting.sh
47 cache-size=1000
48 scan-path=/srv/git
49 '';
50 type = types.lines;
51 description = ''
52 Verbatim contents of the cgit runtime configuration file. Documentation
53 (with cgitrc example file) is available in "man cgitrc". Or online:
54 http://git.zx2c4.com/cgit/tree/cgitrc.5.txt
55 '';
56 };
57
58 };
59
60 config = mkIf cfg.enable {
61
62 # make the cgitrc manpage available
63 environment.systemPackages = [ pkgs.cgit ];
64
65 # declare module dependencies
66 services.lighttpd.enableModules = [ "mod_cgi" "mod_alias" "mod_setenv" ];
67
68 services.lighttpd.extraConfig = ''
69 $HTTP["url"] =~ "^/${cfg.subdir}" {
70 cgi.assign = (
71 "cgit.cgi" => "${pkgs.cgit}/cgit/cgit.cgi"
72 )
73 alias.url = (
74 "${pathPrefix}/cgit.css" => "${pkgs.cgit}/cgit/cgit.css",
75 "${pathPrefix}/cgit.png" => "${pkgs.cgit}/cgit/cgit.png",
76 "${pathPrefix}" => "${pkgs.cgit}/cgit/cgit.cgi"
77 )
78 setenv.add-environment = (
79 "CGIT_CONFIG" => "${configFile}"
80 )
81 }
82 '';
83
84 systemd.services.lighttpd.preStart = ''
85 mkdir -p /var/cache/cgit
86 chown lighttpd:lighttpd /var/cache/cgit
87 '';
88
89 };
90
91}