summary refs log tree commit diff
path: root/nixos/modules/services/web-servers/apache-httpd/trac.nix
blob: c4aa6b6ad3a385d0a8b13946507616d9b0086b24 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
{ config, lib, pkgs, serverInfo, ... }:

with lib;

let

  # Build a Subversion instance with Apache modules and Swig/Python bindings.
  subversion = pkgs.subversion.override {
    bdbSupport = true;
    httpServer = true;
    pythonBindings = true;
    apacheHttpd = httpd;
  };

  pythonLib = p: "${p}/";

  httpd = serverInfo.serverConfig.package;

  versionPre24 = versionOlder httpd.version "2.4";

in

{

  options = {

    projectsLocation = mkOption {
      description = "URL path in which Trac projects can be accessed";
      default = "/projects";
    };

    projects = mkOption {
      description = "List of projects that should be provided by Trac. If they are not defined yet empty projects are created.";
      default = [];
      example =
        [ { identifier = "myproject";
            name = "My Project";
            databaseURL="postgres://root:password@/tracdb";
            subversionRepository="/data/subversion/myproject";
          }
        ];
    };

    user = mkOption {
      default = "wwwrun";
      description = "User account under which Trac runs.";
    };

    group = mkOption {
      default = "wwwrun";
      description = "Group under which Trac runs.";
    };

    ldapAuthentication = {
      enable = mkOption {
        default = false;
        description = "Enable the ldap authentication in trac";
      };

      url = mkOption {
        default = "ldap://127.0.0.1/dc=example,dc=co,dc=ke?uid?sub?(objectClass=inetOrgPerson)";
        description = "URL of the LDAP authentication";
      };

      name = mkOption {
        default = "Trac server";
        description = "AuthName";
      };
    };

  };

  extraModules = singleton
    { name = "python"; path = "${pkgs.mod_python}/modules/mod_python.so"; };

  extraConfig = ''
    <Location ${config.projectsLocation}>
      SetHandler mod_python
      PythonHandler trac.web.modpython_frontend
      PythonOption TracEnvParentDir /var/trac/projects
      PythonOption TracUriRoot ${config.projectsLocation}
      PythonOption PYTHON_EGG_CACHE /var/trac/egg-cache
    </Location>
    ${if config.ldapAuthentication.enable then ''
      <LocationMatch "^${config.projectsLocation}[^/]+/login$">
        AuthType Basic
        AuthName "${config.ldapAuthentication.name}"
        AuthBasicProvider "ldap"
        AuthLDAPURL "${config.ldapAuthentication.url}"
        ${if versionPre24 then "authzldapauthoritative Off" else ""}
        require valid-user
      </LocationMatch>
    '' else ""}
  '';

  globalEnvVars = singleton
    { name = "PYTHONPATH";
      value =
        makeSearchPathOutputs "lib/${pkgs.python.libPrefix}/site-packages" ["lib"]
          [ pkgs.mod_python
            pkgs.pythonPackages.trac
            pkgs.setuptools
            pkgs.pythonPackages.genshi
            pkgs.pythonPackages.psycopg2
            pkgs.python.modules.sqlite3
            subversion
          ];
    };

  startupScript = pkgs.writeScript "activateTrac" ''
    mkdir -p /var/trac
    chown ${config.user}:${config.group} /var/trac

    ${concatMapStrings (project:
      ''
        if [ ! -d /var/trac/${project.identifier} ]
        then
            export PYTHONPATH=${pkgs.pythonPackages.psycopg2}/lib/${pkgs.python.libPrefix}/site-packages
            ${pkgs.pythonPackages.trac}/bin/trac-admin /var/trac/${project.identifier} initenv "${project.name}" "${project.databaseURL}" svn "${project.subversionRepository}"
        fi
      '' ) (config.projects)}
  '';

}