]> Git — Sourcephile - sourcephile-nix.git/blob - install/logical/friot/nginx/gitweb.nix
shorewall: polish code.
[sourcephile-nix.git] / install / logical / friot / nginx / gitweb.nix
1 {pkgs, lib, config, ...}:
2 let inherit (config.services) gitweb gitolite nginx;
3 package = pkgs.gitweb.override (lib.optionalAttrs gitweb.gitwebTheme {
4 gitwebTheme = true;
5 });
6 RuntimeDirectory = "gitweb";
7 gitwebSocket = "/run/${RuntimeDirectory}/gitweb.sock";
8 in
9 {
10 config = {
11 services.nginx = {
12 virtualHosts."git" = {
13 serverName = "git.${config.networking.domain}";
14 #listen = [
15 # { addr = "0.0.0.0"; port = 80; ssl = false; }
16 #];
17 #default = true;
18 locations = {
19 "/" = {
20 extraConfig = ''
21 include ${pkgs.nginx}/conf/fastcgi_params;
22 fastcgi_param PATH_INFO $fastcgi_script_name;
23 # NOTE: used by gitweb's pathinfo feature.
24 fastcgi_param GITWEB_CONFIG ${gitweb.gitwebConfigFile};
25 fastcgi_pass unix:${gitwebSocket};
26 '';
27 };
28 "/static/" = {
29 alias = "${pkgs.gitweb}/static/";
30 };
31 };
32 };
33 };
34 systemd.services.gitweb = {
35 description = "GitWeb FastCGI service";
36 script = "${pkgs.gitweb}/gitweb.cgi --fastcgi --nproc=1";
37 environment = {
38 FCGI_SOCKET_PATH = gitwebSocket;
39 FCGI_SOCKET_PERM = "432"; # decimal of 660 in octal, since current CGI::Fast doesn't use perl's oct()
40 };
41 serviceConfig = {
42 User = gitolite.user;
43 Group = nginx.group;
44 RuntimeDirectory = [ RuntimeDirectory ];
45 Restart = "always";
46 RestartSec = 10;
47 };
48 wantedBy = [ "multi-user.target" ];
49 };
50 services.gitweb = {
51 gitwebTheme = false;
52 projectroot = "${gitolite.dataDir}/repositories";
53 extraConfig = ''
54 use utf8;
55 my $s = $cgi->https() ? "s" : "";
56 @extra_breadcrumbs = (["commonsoft" => "http''${s}://commonsoft.coop"]);
57 $home_link_str = "git";
58 $projects_list = "${gitolite.dataDir}/projects.list";
59 $projects_list_group_categories = 1;
60 $default_projects_order = "age";
61 $omit_owner = 1;
62 $export_ok = "git-daemon-export-ok";
63 $prevent_xss = 0;
64 @git_base_url_list =
65 ( "git://git.${config.networking.domain}"
66 , "git\@git.${config.networking.domain}:"
67 );
68 $feature{'pathinfo'}{'default'} = [1];
69 # NOTE: more readable URL.
70 @stylesheets = ("/static/gitweb.css");
71 $logo = "/static/git-logo.png";
72 $favicon = "/static/git-favicon.png";
73 $javascript = "/static/gitweb.js";
74 $feature{'highlight'}{'default'} = [1];
75 # FIX: gitweb bug: FCGI is not Unicode aware.
76 if ($first_request) {
77 my $enc = Encode::find_encoding('UTF-8');
78 my $org = \&FCGI::Stream::PRINT;
79 no warnings 'redefine';
80 *FCGI::Stream::PRINT = sub {
81 my @OUTPUT = @_;
82 for (my $i = 1; $i < @_; $i++) {
83 $OUTPUT[$i] = $enc->encode($_[$i], Encode::FB_CROAK|Encode::LEAVE_SRC);
84 }
85 @_ = @OUTPUT;
86 goto $org;
87 };
88 };
89 '';
90 };
91
92 };
93 }