1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.lighttpd.cgit;
7 configFile = pkgs.writeText "cgitrc"
8 ''
9 ${cfg.configText}
10 '';
11in
12{
13
14 options.services.lighttpd.cgit = {
15
16 enable = mkOption {
17 default = false;
18 type = types.bool;
19 description = ''
20 If true, enable cgit (fast web interface for git repositories) as a
21 sub-service in lighttpd. cgit will be accessible at
22 http://yourserver/cgit
23 '';
24 };
25
26 configText = mkOption {
27 default = "";
28 example = ''
29 cache-size=1000
30 scan-path=/srv/git
31 '';
32 type = types.lines;
33 description = ''
34 Verbatim contents of the cgit runtime configuration file. Documentation
35 (with cgitrc example file) is available in "man cgitrc". Or online:
36 http://git.zx2c4.com/cgit/tree/cgitrc.5.txt
37 '';
38 };
39
40 };
41
42 config = mkIf cfg.enable {
43
44 # make the cgitrc manpage available
45 environment.systemPackages = [ pkgs.cgit ];
46
47 # declare module dependencies
48 services.lighttpd.enableModules = [ "mod_cgi" "mod_alias" "mod_setenv" ];
49
50 services.lighttpd.extraConfig = ''
51 $HTTP["url"] =~ "^/cgit" {
52 cgi.assign = (
53 "cgit.cgi" => "${pkgs.cgit}/cgit/cgit.cgi"
54 )
55 alias.url = (
56 "/cgit.css" => "${pkgs.cgit}/cgit/cgit.css",
57 "/cgit.png" => "${pkgs.cgit}/cgit/cgit.png",
58 "/cgit" => "${pkgs.cgit}/cgit/cgit.cgi"
59 )
60 setenv.add-environment = (
61 "CGIT_CONFIG" => "${configFile}"
62 )
63 }
64 '';
65
66 systemd.services.lighttpd.preStart = ''
67 mkdir -p /var/cache/cgit
68 chown lighttpd:lighttpd /var/cache/cgit
69 '';
70
71 };
72
73}