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 cache-size=1000 46 scan-path=/srv/git 47 ''; 48 type = types.lines; 49 description = '' 50 Verbatim contents of the cgit runtime configuration file. Documentation 51 (with cgitrc example file) is available in "man cgitrc". Or online: 52 http://git.zx2c4.com/cgit/tree/cgitrc.5.txt 53 ''; 54 }; 55 56 }; 57 58 config = mkIf cfg.enable { 59 60 # make the cgitrc manpage available 61 environment.systemPackages = [ pkgs.cgit ]; 62 63 # declare module dependencies 64 services.lighttpd.enableModules = [ "mod_cgi" "mod_alias" "mod_setenv" ]; 65 66 services.lighttpd.extraConfig = '' 67 $HTTP["url"] =~ "^/${cfg.subdir}" { 68 cgi.assign = ( 69 "cgit.cgi" => "${pkgs.cgit}/cgit/cgit.cgi" 70 ) 71 alias.url = ( 72 "${pathPrefix}/cgit.css" => "${pkgs.cgit}/cgit/cgit.css", 73 "${pathPrefix}/cgit.png" => "${pkgs.cgit}/cgit/cgit.png", 74 "${pathPrefix}" => "${pkgs.cgit}/cgit/cgit.cgi" 75 ) 76 setenv.add-environment = ( 77 "CGIT_CONFIG" => "${configFile}" 78 ) 79 } 80 ''; 81 82 systemd.services.lighttpd.preStart = '' 83 mkdir -p /var/cache/cgit 84 chown lighttpd:lighttpd /var/cache/cgit 85 ''; 86 87 }; 88 89}