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