1{ config, lib, pkgs, serverInfo, ... }: 2 3with lib; 4 5let 6 7 # Build a Subversion instance with Apache modules and Swig/Python bindings. 8 subversion = pkgs.subversion.override (origArgs: { 9 bdbSupport = true; 10 httpServer = true; 11 pythonBindings = true; 12 }); 13 14 pythonLib = p: "${p}/"; 15 16in 17 18{ 19 20 options = { 21 22 projectsLocation = mkOption { 23 description = "URL path in which Trac projects can be accessed"; 24 default = "/projects"; 25 }; 26 27 projects = mkOption { 28 description = "List of projects that should be provided by Trac. If they are not defined yet empty projects are created."; 29 default = []; 30 example = 31 [ { identifier = "myproject"; 32 name = "My Project"; 33 databaseURL="postgres://root:password@/tracdb"; 34 subversionRepository="/data/subversion/myproject"; 35 } 36 ]; 37 }; 38 39 user = mkOption { 40 default = "wwwrun"; 41 description = "User account under which Trac runs."; 42 }; 43 44 group = mkOption { 45 default = "wwwrun"; 46 description = "Group under which Trac runs."; 47 }; 48 49 ldapAuthentication = { 50 enable = mkOption { 51 default = false; 52 description = "Enable the ldap authentication in trac"; 53 }; 54 55 url = mkOption { 56 default = "ldap://127.0.0.1/dc=example,dc=co,dc=ke?uid?sub?(objectClass=inetOrgPerson)"; 57 description = "URL of the LDAP authentication"; 58 }; 59 60 name = mkOption { 61 default = "Trac server"; 62 description = "AuthName"; 63 }; 64 }; 65 66 }; 67 68 extraModules = singleton 69 { name = "python"; path = "${pkgs.mod_python}/modules/mod_python.so"; }; 70 71 extraConfig = '' 72 <Location ${config.projectsLocation}> 73 SetHandler mod_python 74 PythonHandler trac.web.modpython_frontend 75 PythonOption TracEnvParentDir /var/trac/projects 76 PythonOption TracUriRoot ${config.projectsLocation} 77 PythonOption PYTHON_EGG_CACHE /var/trac/egg-cache 78 </Location> 79 ${if config.ldapAuthentication.enable then '' 80 <LocationMatch "^${config.projectsLocation}[^/]+/login$"> 81 AuthType Basic 82 AuthName "${config.ldapAuthentication.name}" 83 AuthBasicProvider "ldap" 84 AuthLDAPURL "${config.ldapAuthentication.url}" 85 authzldapauthoritative Off 86 require valid-user 87 </LocationMatch> 88 '' else ""} 89 ''; 90 91 globalEnvVars = singleton 92 { name = "PYTHONPATH"; 93 value = 94 makeSearchPath "lib/${pkgs.python.libPrefix}/site-packages" 95 [ pkgs.mod_python 96 pkgs.pythonPackages.trac 97 pkgs.setuptools 98 pkgs.pythonPackages.genshi 99 pkgs.pythonPackages.psycopg2 100 pkgs.python.modules.sqlite3 101 subversion 102 ]; 103 }; 104 105 startupScript = pkgs.writeScript "activateTrac" '' 106 mkdir -p /var/trac 107 chown ${config.user}:${config.group} /var/trac 108 109 ${concatMapStrings (project: 110 '' 111 if [ ! -d /var/trac/${project.identifier} ] 112 then 113 export PYTHONPATH=${pkgs.pythonPackages.psycopg2}/lib/${pkgs.python.libPrefix}/site-packages 114 ${pkgs.pythonPackages.trac}/bin/trac-admin /var/trac/${project.identifier} initenv "${project.name}" "${project.databaseURL}" svn "${project.subversionRepository}" 115 fi 116 '' ) (config.projects)} 117 ''; 118 119}