citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

git-server.nix (1923B)


      1 { extra, config, pkgs }:
      2 let gitwebConf = pkgs.writeText "gitweb.conf" ''
      3       # path to git projects (<project>.git)
      4       $projectroot = "${extra.git.projectroot}";
      5     '';
      6     gitweb-wrapper = pkgs.writeScript "gitweb.cgi" ''
      7       #!${pkgs.bash}/bin/bash
      8       export PERL5LIB=$PERL5LIB:${with pkgs.perlPackages; makePerlPath [ CGI HTMLParser ]}
      9       ${pkgs.perl}/bin/perl ${pkgs.git}/share/gitweb/gitweb.cgi
     10     '';
     11     gitweb-theme = pkgs.fetchFromGitHub {
     12       owner  = "kogakure";
     13       repo   = "gitweb-theme";
     14       rev    = "4305b3551551c470339c24a6567b1ac9e642ae54";
     15       sha256 = "0gagy0jvqb3mc587b6yy8l9g5j5wqr2xlz128v6f01364cb7whmv";
     16     };
     17 in
     18 if config.services.fcgiwrap.enable then ''
     19   server {
     20       listen       80;
     21       server_name  ${extra.host};
     22 
     23       location = / {
     24         return 301 http://${extra.host}/repos/;
     25       }
     26 
     27       location = /repos {
     28         return 301 http://${extra.host}/repos/;
     29       }
     30 
     31       location / {
     32         # fcgiwrap is set up to listen on this host:port
     33         fastcgi_pass                  unix:${config.services.fcgiwrap.socketAddress};
     34         include                       ${pkgs.nginx}/conf/fastcgi_params;
     35         fastcgi_param SCRIPT_FILENAME ${pkgs.git}/bin/git-http-backend;
     36 
     37         client_max_body_size 0;
     38 
     39         # export all repositories under GIT_PROJECT_ROOT
     40 
     41         fastcgi_param GIT_HTTP_EXPORT_ALL "";
     42         fastcgi_param GIT_PROJECT_ROOT    ${extra.git.projectroot};
     43         fastcgi_param PATH_INFO           $uri;
     44       }
     45 
     46       location /repos/static {
     47         alias ${gitweb-theme};
     48       }
     49 
     50       location /repos {
     51         include ${pkgs.nginx}/conf/fastcgi_params;
     52         gzip off;
     53 
     54         fastcgi_param GITWEB_CONFIG   ${gitwebConf};
     55         fastcgi_param SCRIPT_FILENAME ${gitweb-wrapper};
     56         fastcgi_pass  unix:${config.services.fcgiwrap.socketAddress};
     57       }
     58 
     59   }
     60 '' else throw "fcgiwrap must be enabled to run git-server"