1 { config, lib, pkgs, ... }:
6 cfg = config.services.lighttpd.cgit;
7 pathPrefix = if stringLength cfg.subdir == 0 then "" else "/" + cfg.subdir;
8 configFile = pkgs.writeText "cgitrc"
10 # default paths to static assets
11 css=${pathPrefix}/cgit.css
12 logo=${pathPrefix}/cgit.png
13 favicon=${pathPrefix}/favicon.ico
21 options.services.lighttpd.cgit = {
26 description = lib.mdDoc ''
27 If true, enable cgit (fast web interface for git repositories) as a
28 sub-service in lighttpd.
36 description = lib.mdDoc ''
37 The subdirectory in which to serve cgit. The web application will be
38 accessible at http://yourserver/''${subdir}
42 configText = mkOption {
44 example = literalExpression ''
46 source-filter=''${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py
47 about-filter=''${pkgs.cgit}/lib/cgit/filters/about-formatting.sh
53 description = lib.mdDoc ''
54 Verbatim contents of the cgit runtime configuration file. Documentation
55 (with cgitrc example file) is available in "man cgitrc". Or online:
56 http://git.zx2c4.com/cgit/tree/cgitrc.5.txt
62 config = mkIf cfg.enable {
64 # make the cgitrc manpage available
65 environment.systemPackages = [ pkgs.cgit ];
67 # declare module dependencies
68 services.lighttpd.enableModules = [ "mod_cgi" "mod_alias" "mod_setenv" ];
70 services.lighttpd.extraConfig = ''
71 $HTTP["url"] =~ "^/${cfg.subdir}" {
73 "cgit.cgi" => "${pkgs.cgit}/cgit/cgit.cgi"
76 "${pathPrefix}/cgit.css" => "${pkgs.cgit}/cgit/cgit.css",
77 "${pathPrefix}/cgit.png" => "${pkgs.cgit}/cgit/cgit.png",
78 "${pathPrefix}" => "${pkgs.cgit}/cgit/cgit.cgi"
80 setenv.add-environment = (
81 "CGIT_CONFIG" => "${configFile}"
86 systemd.services.lighttpd.preStart = ''
87 mkdir -p /var/cache/cgit
88 chown lighttpd:lighttpd /var/cache/cgit