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