summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/misc/gitweb.nix
blob: 65f923add2d5f6ae992350c5cfd1078cab302219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.services.gitweb;
  cfgNginx = config.services.gitweb.nginx;
  package = pkgs.gitweb.override (
    lib.optionalAttrs cfg.gitwebTheme {
      gitwebTheme = true;
    }
  );
in
{

  options.services.gitweb = {

    projectroot = lib.mkOption {
      default = "/srv/git";
      type = lib.types.path;
      description = ''
        Path to git projects (bare repositories) that should be served by
        gitweb. Must not end with a slash.
      '';
    };

    extraConfig = lib.mkOption {
      default = "";
      type = lib.types.lines;
      description = ''
        Verbatim configuration text appended to the generated gitweb.conf file.
      '';
      example = ''
        $feature{'highlight'}{'default'} = [1];
        $feature{'ctags'}{'default'} = [1];
        $feature{'avatar'}{'default'} = ['gravatar'];
      '';
    };

    gitwebTheme = lib.mkOption {
      default = false;
      type = lib.types.bool;
      description = ''
        Use an alternative theme for gitweb, strongly inspired by GitHub.
      '';
    };

    gitwebConfigFile = lib.mkOption {
      default = pkgs.writeText "gitweb.conf" ''
        # path to git projects (<project>.git)
        $projectroot = "${cfg.projectroot}";
        $highlight_bin = "${pkgs.highlight}/bin/highlight";
        ${cfg.extraConfig}
      '';
      defaultText = lib.literalMD "generated config file";
      type = lib.types.path;
      readOnly = true;
      internal = true;
    };

    nginx = {
      enable = lib.mkOption {
        default = false;
        type = lib.types.bool;
        description = ''
          If true, enable gitweb in nginx.
        '';
      };

      location = lib.mkOption {
        default = "/gitweb";
        type = lib.types.str;
        description = ''
          Location to serve gitweb on.
        '';
      };

      user = lib.mkOption {
        default = "nginx";
        type = lib.types.str;
        description = ''
          Existing user that the CGI process will belong to. (Default almost surely will do.)
        '';
      };

      group = lib.mkOption {
        default = "nginx";
        type = lib.types.str;
        description = ''
          Group that the CGI process will belong to. (Set to `config.services.gitolite.group` if you are using gitolite.)
        '';
      };

      virtualHost = lib.mkOption {
        default = "_";
        type = lib.types.str;
        description = ''
          VirtualHost to serve gitweb on. Default is catch-all.
        '';
      };
    };

  };

  imports = [
    (lib.mkRenamedOptionModule
      [ "services" "nginx" "gitweb" "enable" ]
      [ "services" "gitweb" "nginx" "enable" ]
    )
    (lib.mkRenamedOptionModule
      [ "services" "nginx" "gitweb" "location" ]
      [ "services" "gitweb" "nginx" "location" ]
    )
    (lib.mkRenamedOptionModule
      [ "services" "nginx" "gitweb" "user" ]
      [ "services" "gitweb" "nginx" "user" ]
    )
    (lib.mkRenamedOptionModule
      [ "services" "nginx" "gitweb" "group" ]
      [ "services" "gitweb" "nginx" "group" ]
    )
    (lib.mkRenamedOptionModule
      [ "services" "nginx" "gitweb" "virtualHost" ]
      [ "services" "gitweb" "nginx" "virtualHost" ]
    )
  ];

  config = lib.mkIf cfgNginx.enable {

    systemd.services.gitweb = {
      description = "GitWeb service";
      script = "${package}/gitweb.cgi --fastcgi --nproc=1";
      environment = {
        FCGI_SOCKET_PATH = "/run/gitweb/gitweb.sock";
      };
      serviceConfig = {
        User = cfgNginx.user;
        Group = cfgNginx.group;
        RuntimeDirectory = [ "gitweb" ];
      };
      wantedBy = [ "multi-user.target" ];
    };

    services.nginx = {
      virtualHosts.${cfgNginx.virtualHost} = {
        locations."${cfgNginx.location}/static/" = {
          alias = "${package}/static/";
        };
        locations."${cfgNginx.location}/" = {
          extraConfig = ''
            include ${config.services.nginx.package}/conf/fastcgi_params;
            fastcgi_param GITWEB_CONFIG ${cfg.gitwebConfigFile};
            fastcgi_pass unix:/run/gitweb/gitweb.sock;
          '';
        };
      };
    };

  };

  meta.maintainers = [ ];

}