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