]> Git — Sourcephile - sourcephile-nix.git/blob - install/logical/friot/nginx/gitweb.nix
update
[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 systemd.services.gitweb = {
12 description = "GitWeb service";
13 script = "${pkgs.gitweb}/gitweb.cgi --fastcgi --nproc=1";
14 environment = {
15 FCGI_SOCKET_PATH = gitwebSocket;
16 FCGI_SOCKET_PERM = "432"; # decimal of 660 in octal, since current CGI::Fast doesn't use perl's oct()
17 };
18 serviceConfig = {
19 User = gitolite.user;
20 Group = nginx.group;
21 RuntimeDirectory = [ RuntimeDirectory ];
22 Restart = "always";
23 RestartSec = 10;
24 };
25 wantedBy = [ "multi-user.target" ];
26 };
27 services.gitweb = {
28 gitwebTheme = false;
29 projectroot = "${gitolite.dataDir}/repositories";
30 extraConfig = ''
31 # FIX: gitweb bug: FCGI is not Unicode aware.
32 if ($first_request) {
33 my $enc = Encode::find_encoding('UTF-8');
34 my $org = \&FCGI::Stream::PRINT;
35 no warnings 'redefine';
36 *FCGI::Stream::PRINT = sub {
37 my @OUTPUT = @_;
38 for (my $i = 1; $i < @_; $i++) {
39 $OUTPUT[$i] = $enc->encode($_[$i], Encode::FB_CROAK|Encode::LEAVE_SRC);
40 }
41 @_ = @OUTPUT;
42 goto $org;
43 };
44 };
45 '';
46 };
47 services.nginx = {
48 virtualHosts."git" = {
49 #listen = [
50 # { addr = "0.0.0.0"; port = 80; ssl = false; }
51 #];
52 #default = true;
53 locations = {
54 "/static/" = {
55 alias = "${pkgs.gitweb}/static/";
56 };
57 "/" = {
58 extraConfig = ''
59 include ${pkgs.nginx}/conf/fastcgi_params;
60 fastcgi_param GITWEB_CONFIG ${gitweb.gitwebConfigFile};
61 fastcgi_pass unix:${gitwebSocket};
62 '';
63 };
64 };
65 };
66 };
67
68 };
69 }