1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8with lib;
9
10let
11 cfg = config.services.nginx.gitweb;
12 gitwebConfig = config.services.gitweb;
13 package = pkgs.gitweb.override (
14 optionalAttrs gitwebConfig.gitwebTheme {
15 gitwebTheme = true;
16 }
17 );
18
19in
20{
21
22 options.services.nginx.gitweb = {
23
24 enable = mkOption {
25 default = false;
26 type = types.bool;
27 description = ''
28 If true, enable gitweb in nginx.
29 '';
30 };
31
32 location = mkOption {
33 default = "/gitweb";
34 type = types.str;
35 description = ''
36 Location to serve gitweb on.
37 '';
38 };
39
40 user = mkOption {
41 default = "nginx";
42 type = types.str;
43 description = ''
44 Existing user that the CGI process will belong to. (Default almost surely will do.)
45 '';
46 };
47
48 group = mkOption {
49 default = "nginx";
50 type = types.str;
51 description = ''
52 Group that the CGI process will belong to. (Set to `config.services.gitolite.group` if you are using gitolite.)
53 '';
54 };
55
56 virtualHost = mkOption {
57 default = "_";
58 type = types.str;
59 description = ''
60 VirtualHost to serve gitweb on. Default is catch-all.
61 '';
62 };
63
64 };
65
66 config = mkIf cfg.enable {
67
68 systemd.services.gitweb = {
69 description = "GitWeb service";
70 script = "${package}/gitweb.cgi --fastcgi --nproc=1";
71 environment = {
72 FCGI_SOCKET_PATH = "/run/gitweb/gitweb.sock";
73 };
74 serviceConfig = {
75 User = cfg.user;
76 Group = cfg.group;
77 RuntimeDirectory = [ "gitweb" ];
78 };
79 wantedBy = [ "multi-user.target" ];
80 };
81
82 services.nginx = {
83 virtualHosts.${cfg.virtualHost} = {
84 locations."${cfg.location}/static/" = {
85 alias = "${package}/static/";
86 };
87 locations."${cfg.location}/" = {
88 extraConfig = ''
89 include ${config.services.nginx.package}/conf/fastcgi_params;
90 fastcgi_param GITWEB_CONFIG ${gitwebConfig.gitwebConfigFile};
91 fastcgi_pass unix:/run/gitweb/gitweb.sock;
92 '';
93 };
94 };
95 };
96
97 };
98
99 meta.maintainers = [ ];
100
101}