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