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 = lib.mdDoc '' 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 = lib.mdDoc '' 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 = literalExpression '' 45 ''' 46 source-filter=''${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py 47 about-filter=''${pkgs.cgit}/lib/cgit/filters/about-formatting.sh 48 cache-size=1000 49 scan-path=/srv/git 50 ''' 51 ''; 52 type = types.lines; 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 57 ''; 58 }; 59 60 }; 61 62 config = mkIf cfg.enable { 63 64 # make the cgitrc manpage available 65 environment.systemPackages = [ pkgs.cgit ]; 66 67 # declare module dependencies 68 services.lighttpd.enableModules = [ "mod_cgi" "mod_alias" "mod_setenv" ]; 69 70 services.lighttpd.extraConfig = '' 71 $HTTP["url"] =~ "^/${cfg.subdir}" { 72 cgi.assign = ( 73 "cgit.cgi" => "${pkgs.cgit}/cgit/cgit.cgi" 74 ) 75 alias.url = ( 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" 79 ) 80 setenv.add-environment = ( 81 "CGIT_CONFIG" => "${configFile}" 82 ) 83 } 84 ''; 85 86 systemd.services.lighttpd.preStart = '' 87 mkdir -p /var/cache/cgit 88 chown lighttpd:lighttpd /var/cache/cgit 89 ''; 90 91 }; 92 93}