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