git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/nginx: add gitweb sub-service
commit69a0c9721e4cd66739971d499a67988f8412e5d7 authorgnidorah <gnidorah@users.noreply.github.com> dateTue 27 Mar 2018, 19:42 (9 years ago) parent9e67520
3 files changed+107
nixos/modules/module-list.nix+1 nixos/modules/services/web-servers/lighttpd/gitweb.nix+5 nixos/modules/services/web-servers/nginx/gitweb.nix+101
nixos/modules/module-list.nix+1
@@ -650,6 +650,7 @@
650650 ./services/web-servers/mighttpd2.nix
651651 ./services/web-servers/minio.nix
652652 ./services/web-servers/nginx/default.nix
653+ ./services/web-servers/nginx/gitweb.nix
653654 ./services/web-servers/phpfpm/default.nix
654655 ./services/web-servers/shellinabox.nix
655656 ./services/web-servers/tomcat.nix
nixos/modules/services/web-servers/lighttpd/gitweb.nix+5
@@ -7,6 +7,7 @@ let
77 gitwebConfigFile = pkgs.writeText "gitweb.conf" ''
88 # path to git projects (<project>.git)
99 $projectroot = "${cfg.projectroot}";
10+ $highlight_bin = "${pkgs.highlight}/bin/highlight";
1011 ${cfg.extraConfig}
1112 '';
1213
@@ -38,6 +39,10 @@ in
3839 description = ''
3940 Verbatim configuration text appended to the generated gitweb.conf file.
4041 '';
42+ example = ''
43+ $feature{'highlight'}{'default'} = [1];
44+ $feature{'ctags'}{'default'} = [1];
45+ '';
4146 };
4247
4348 };
nixos/modules/services/web-servers/nginx/gitweb.nixnew file+101
@@ -0,0 +1,101 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.nginx.gitweb;
7+ gitwebConfigFile = pkgs.writeText "gitweb.conf" ''
8+ # path to git projects (<project>.git)
9+ $projectroot = "${cfg.projectroot}";
10+ $highlight_bin = "${pkgs.highlight}/bin/highlight";
11+ ${cfg.extraConfig}
12+ '';
13+ gitwebPerlLibs = with pkgs.perlPackages; [ CGIFast FCGI FCGIProcManager HTMLTagCloud ];
14+ git = pkgs.git.overrideAttrs (oldAttrs: rec {
15+ postInstall = ''
16+ ${oldAttrs.postInstall}
17+ for p in ${lib.concatStringsSep " " gitwebPerlLibs}; do
18+ sed -i -e "/use CGI /i use lib \"$p/lib/perl5/site_perl\";" \
19+ "$out/share/gitweb/gitweb.cgi"
20+ done
21+ '';
22+ });
23+
24+in
25+{
26+
27+ options.services.nginx.gitweb = {
28+
29+ enable = mkOption {
30+ default = false;
31+ type = types.bool;
32+ description = ''
33+ If true, enable gitweb in nginx. Access it at http://yourserver/gitweb
34+ '';
35+ };
36+
37+ projectroot = mkOption {
38+ default = "/srv/git";
39+ type = types.path;
40+ description = ''
41+ Path to git projects (bare repositories) that should be served by
42+ gitweb. Must not end with a slash.
43+ '';
44+ };
45+
46+ extraConfig = mkOption {
47+ default = "";
48+ type = types.lines;
49+ description = ''
50+ Verbatim configuration text appended to the generated gitweb.conf file.
51+ '';
52+ example = ''
53+ $feature{'highlight'}{'default'} = [1];
54+ $feature{'ctags'}{'default'} = [1];
55+ '';
56+ };
57+
58+ };
59+
60+ config = mkIf cfg.enable {
61+
62+ systemd.sockets.gitweb = {
63+ description = "GitWeb Listen Socket";
64+ listenStreams = [ "/run/gitweb.sock" ];
65+ socketConfig = {
66+ Accept = "false";
67+ SocketUser = "nginx";
68+ SocketGroup = "nginx";
69+ SocketMode = "0600";
70+ };
71+ wantedBy = [ "sockets.target" ];
72+ };
73+ systemd.services.gitweb = {
74+ description = "GitWeb service";
75+ script = "${git}/share/gitweb/gitweb.cgi --fcgi";
76+ serviceConfig = {
77+ Type = "simple";
78+ StandardInput = "socket";
79+ User = "nginx";
80+ Group = "nginx";
81+ };
82+ };
83+
84+ services.nginx = {
85+ virtualHosts.default = {
86+ locations."/gitweb" = {
87+ root = "${pkgs.git}/share/gitweb";
88+ extraConfig = ''
89+ include ${pkgs.nginx}/conf/fastcgi_params;
90+ fastcgi_param GITWEB_CONFIG ${gitwebConfigFile};
91+ fastcgi_pass unix:/run/gitweb.sock;
92+ '';
93+ };
94+ };
95+ };
96+
97+ };
98+
99+ meta.maintainers = with maintainers; [ gnidorah ];
100+
101+}