1{ config, pkgs, serverInfo, lib, ... }: 2 3let 4 inherit (pkgs) mercurial; 5 inherit (lib) mkOption; 6 7 urlPrefix = config.urlPrefix; 8 9 cgi = pkgs.stdenv.mkDerivation { 10 name = "mercurial-cgi"; 11 buildCommand = '' 12 mkdir -p $out 13 cp -v ${mercurial}/share/cgi-bin/hgweb.cgi $out 14 sed -i "s|/path/to/repo/or/config|$out/hgweb.config|" $out/hgweb.cgi 15 echo " 16 [collections] 17 ${config.dataDir} = ${config.dataDir} 18 [web] 19 style = gitweb 20 allow_push = * 21 " > $out/hgweb.config 22 ''; 23 }; 24 25in { 26 27 extraConfig = '' 28 RewriteEngine on 29 RewriteRule /(.*) ${cgi}/hgweb.cgi/$1 30 31 <Location "${urlPrefix}"> 32 AuthType Basic 33 AuthName "Mercurial repositories" 34 AuthUserFile ${config.dataDir}/hgusers 35 <LimitExcept GET> 36 Require valid-user 37 </LimitExcept> 38 </Location> 39 <Directory "${cgi}"> 40 Order allow,deny 41 Allow from all 42 AllowOverride All 43 Options ExecCGI 44 AddHandler cgi-script .cgi 45 PassEnv PYTHONPATH 46 </Directory> 47 ''; 48 49 robotsEntries = '' 50 User-agent: * 51 Disallow: ${urlPrefix} 52 ''; 53 54 extraServerPath = [ pkgs.python ]; 55 56 globalEnvVars = [ { name = "PYTHONPATH"; value = "${mercurial}/lib/${pkgs.python.libPrefix}/site-packages"; } ]; 57 58 options = { 59 urlPrefix = mkOption { 60 default = "/hg"; 61 description = " 62 The URL prefix under which the Mercurial service appears. 63 Use the empty string to have it appear in the server root. 64 "; 65 }; 66 67 dataDir = mkOption { 68 example = "/data/mercurial"; 69 description = " 70 Path to the directory that holds the repositories. 71 "; 72 }; 73 }; 74 75}