]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/mermet/nginx/sourcephile.fr/git.nix
losurdo: disable tor
[sourcephile-nix.git] / hosts / mermet / nginx / sourcephile.fr / git.nix
1 { domain, ... }:
2 { pkgs, lib, config, ... }:
3 let
4 inherit (config) networking;
5 inherit (config.services) gitweb gitolite nginx;
6 srv = "git";
7 gitwebSocket = "/run/gitweb/gitweb.sock";
8 in
9 {
10 services.nginx = {
11 commonHttpConfig = ''
12 fastcgi_cache_path /var/cache/nginx/fastcgi_cache:${domain}:${srv}
13 keys_zone=${domain}/${srv}:2M
14 inactive=10m
15 levels=1:2
16 max_size=32M;
17 '';
18 virtualHosts."${srv}.${domain}" = {
19 serverAliases = [ "code.${domain}" ];
20 forceSSL = true;
21 useACMEHost = domain;
22 extraConfig = ''
23 access_log /var/log/nginx/${domain}/${srv}/access.log json buffer=32k;
24 error_log /var/log/nginx/${domain}/${srv}/error.log warn;
25 '';
26 locations = {
27 "/" = {
28 extraConfig = ''
29 include ${pkgs.nginx}/conf/fastcgi_params;
30 ${nginx.configs.https_add_headers}
31 add_header X-Cache $upstream_cache_status;
32 fastcgi_cache ${domain}/${srv};
33 fastcgi_cache_valid 200 1m;
34 fastcgi_cache_valid 404 3m;
35 fastcgi_max_temp_file_size 1M;
36 # Used by gitweb's pathinfo feature
37 fastcgi_param PATH_INFO $fastcgi_script_name;
38 fastcgi_param GITWEB_CONFIG ${gitweb.gitwebConfigFile};
39 fastcgi_pass unix:${gitwebSocket};
40 '';
41 };
42 "/static/" = {
43 alias = "${pkgs.gitweb}/static/";
44 extraConfig = ''
45 access_log off;
46 '';
47 };
48 "/static-custom/" = {
49 root = pkgs.writeTextDir "static-custom/style.css" ''
50 .project_list {
51 width:100%;
52 }
53 '';
54 extraConfig = ''
55 access_log off;
56 '';
57 };
58 "/robots.txt" = {
59 root = pkgs.writeTextDir "robots.txt" ''
60 User-agent: *
61 Disallow: /*/blame/*
62 Disallow: /*/blobdiff/*
63 Disallow: /*/commitdiff/*
64 Disallow: /*/commitdiff_plain/*
65 Disallow: /*/patch/*
66 Disallow: /*/search/*
67 Disallow: /*/snapshot/*
68 Disallow: /*a=blame*
69 Disallow: /*a=blobdiff*
70 Disallow: /*a=commitdiff*
71 Disallow: /*a=commitdiff_plain*
72 Disallow: /*a=patch*
73 Disallow: /*a=search*
74 Disallow: /*a=snapshot*
75 '';
76 extraConfig = ''
77 access_log off;
78 '';
79 };
80 };
81 };
82 };
83 systemd.services.nginx.serviceConfig.LogsDirectory = lib.mkForce ["nginx/${domain}/${srv}"];
84 systemd.services.gitweb = {
85 description = "GitWeb FastCGI service";
86 script = "${pkgs.gitweb}/gitweb.cgi --fastcgi --nproc=1";
87 environment = {
88 FCGI_SOCKET_PATH = gitwebSocket;
89 FCGI_SOCKET_PERM = "432"; # decimal of 660 in octal, since current CGI::Fast doesn't use perl's oct()
90 };
91 serviceConfig = {
92 User = gitolite.user;
93 Group = nginx.group;
94 RuntimeDirectory = [ "gitweb" ];
95 Restart = "always";
96 RestartSec = 10;
97 };
98 wantedBy = [ "multi-user.target" ];
99 };
100 services.gitweb = {
101 gitwebTheme = false;
102 projectroot = "${gitolite.dataDir}/repositories";
103 extraConfig = ''
104 use utf8;
105 my $s = $cgi->https() ? "s" : "";
106 @extra_breadcrumbs = (["sourcephile" => "http''${s}://${domain}"]);
107 $site_name = "Git — Sourcephile";
108 $home_link_str = "git";
109 $projects_list = "${gitolite.dataDir}/projects.list";
110 $projects_list_description_width = 50;
111 $projects_list_group_categories = 1;
112 $default_projects_order = "age";
113 $default_text_plain_charset = 'utf-8';
114 #$fallback_encoding = "utf-8";
115 $omit_owner = 1;
116 $export_ok = "git-daemon-export-ok";
117 $prevent_xss = 0;
118 @git_base_url_list =
119 ( "git://${srv}.${domain}"
120 , "git\@${srv}.${domain}:"
121 );
122 # NOTE: more readable URL.
123 $feature{'pathinfo'}{'default'} = [1];
124 @stylesheets = ( "/static/gitweb.css"
125 , "/static-custom/style.css"
126 );
127 $logo = "/static/git-logo.png";
128 $favicon = "/static/git-favicon.png";
129 $javascript = "/static/gitweb.js";
130 $feature{'highlight'}{'default'} = [1];
131 '';
132 };
133 }