summary refs log tree commit diff
path: root/modules/services/web-servers/apache-httpd/mercurial.nix
blob: 45cb81979179a56eca3ee5453c71b79726083be9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ config, pkgs, serverInfo, ... }:

let
  inherit (pkgs) mercurial;
  inherit (pkgs.lib) mkOption;

  urlPrefix = config.urlPrefix;
  
  cgi = pkgs.stdenv.mkDerivation {
    name = "mercurial-cgi";  
    buildCommand = ''
      ensureDir $out
      cp -v ${mercurial}/share/cgi-bin/hgweb.cgi $out
      sed -i "s|/path/to/repo/or/config|$out/hgweb.config|" $out/hgweb.cgi
      echo "
      [collections]
      ${config.dataDir} = ${config.dataDir}
      [web]
      style = gitweb
      allow_push = *
      " > $out/hgweb.config
    '';
  };
      
in {

  extraConfig = ''
    RewriteEngine on
    RewriteRule /(.*) ${cgi}/hgweb.cgi/$1

    <Location "${urlPrefix}">
        AuthType Basic
        AuthName "Mercurial repositories"
        AuthUserFile ${config.dataDir}/hgusers
        <LimitExcept GET>
            Require valid-user
        </LimitExcept>
    </Location>
    <Directory "${cgi}">
        Order allow,deny
        Allow from all
        AllowOverride All
        Options ExecCGI
        AddHandler cgi-script .cgi
        PassEnv PYTHONPATH
    </Directory>
  '';
  
  robotsEntries = ''
    User-agent: *
    Disallow: ${urlPrefix}
  '';
  
  extraServerPath = [
    (pkgs.python+"/bin")    
  ];
  
  globalEnvVars = [ { name = "PYTHONPATH"; value = "${mercurial}/lib/${pkgs.python.libPrefix}/site-packages"; } ];
  
  options = {
    urlPrefix = mkOption {
      default = "/hg";
      description = "
        The URL prefix under which the Mercurial service appears.
        Use the empty string to have it appear in the server root.
      ";
    };
    
    dataDir = mkOption {
      example = "/data/mercurial";
      description = "
        Path to the directory that holds the repositories.
      ";
    };
  };
  
}