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