summary refs log tree commit diff
diff options
context:
space:
mode:
authorgnidorah <gnidorah@users.noreply.github.com>2018-03-27 19:42:13 +0300
committergnidorah <gnidorah@users.noreply.github.com>2018-03-29 09:06:54 +0300
commit69a0c9721e4cd66739971d499a67988f8412e5d7 (patch)
treeec49f4feb00f6399e951dac1a6720801193fe7c0
parent9e6752075a9b456f37e637bdcaffa123038fbf0a (diff)
downloadnixpkgs-69a0c9721e4cd66739971d499a67988f8412e5d7.tar
nixpkgs-69a0c9721e4cd66739971d499a67988f8412e5d7.tar.gz
nixpkgs-69a0c9721e4cd66739971d499a67988f8412e5d7.tar.bz2
nixpkgs-69a0c9721e4cd66739971d499a67988f8412e5d7.tar.lz
nixpkgs-69a0c9721e4cd66739971d499a67988f8412e5d7.tar.xz
nixpkgs-69a0c9721e4cd66739971d499a67988f8412e5d7.tar.zst
nixpkgs-69a0c9721e4cd66739971d499a67988f8412e5d7.zip
nixos/nginx: add gitweb sub-service
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/web-servers/lighttpd/gitweb.nix5
-rw-r--r--nixos/modules/services/web-servers/nginx/gitweb.nix101
3 files changed, 107 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 9e232ce1f4e..b5bc8b6b9de 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -650,6 +650,7 @@
   ./services/web-servers/mighttpd2.nix
   ./services/web-servers/minio.nix
   ./services/web-servers/nginx/default.nix
+  ./services/web-servers/nginx/gitweb.nix
   ./services/web-servers/phpfpm/default.nix
   ./services/web-servers/shellinabox.nix
   ./services/web-servers/tomcat.nix
diff --git a/nixos/modules/services/web-servers/lighttpd/gitweb.nix b/nixos/modules/services/web-servers/lighttpd/gitweb.nix
index c8d9836b0b6..2f220c9ec53 100644
--- a/nixos/modules/services/web-servers/lighttpd/gitweb.nix
+++ b/nixos/modules/services/web-servers/lighttpd/gitweb.nix
@@ -7,6 +7,7 @@ let
   gitwebConfigFile = pkgs.writeText "gitweb.conf" ''
     # path to git projects (<project>.git)
     $projectroot = "${cfg.projectroot}";
+    $highlight_bin = "${pkgs.highlight}/bin/highlight";
     ${cfg.extraConfig}
   '';
 
@@ -38,6 +39,10 @@ in
       description = ''
         Verbatim configuration text appended to the generated gitweb.conf file.
       '';
+      example = ''
+        $feature{'highlight'}{'default'} = [1];
+        $feature{'ctags'}{'default'} = [1];
+      '';
     };
 
   };
diff --git a/nixos/modules/services/web-servers/nginx/gitweb.nix b/nixos/modules/services/web-servers/nginx/gitweb.nix
new file mode 100644
index 00000000000..315da66fab6
--- /dev/null
+++ b/nixos/modules/services/web-servers/nginx/gitweb.nix
@@ -0,0 +1,101 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.services.nginx.gitweb;
+  gitwebConfigFile = pkgs.writeText "gitweb.conf" ''
+    # path to git projects (<project>.git)
+    $projectroot = "${cfg.projectroot}";
+    $highlight_bin = "${pkgs.highlight}/bin/highlight";
+    ${cfg.extraConfig}
+  '';
+  gitwebPerlLibs = with pkgs.perlPackages; [ CGIFast FCGI FCGIProcManager HTMLTagCloud ];
+  git = pkgs.git.overrideAttrs (oldAttrs: rec {
+    postInstall = ''
+      ${oldAttrs.postInstall}
+      for p in ${lib.concatStringsSep " " gitwebPerlLibs}; do
+          sed -i -e "/use CGI /i use lib \"$p/lib/perl5/site_perl\";" \
+              "$out/share/gitweb/gitweb.cgi"
+      done
+    '';
+  });
+
+in
+{
+
+  options.services.nginx.gitweb = {
+
+    enable = mkOption {
+      default = false;
+      type = types.bool;
+      description = ''
+        If true, enable gitweb in nginx. Access it at http://yourserver/gitweb
+      '';
+    };
+
+    projectroot = mkOption {
+      default = "/srv/git";
+      type = types.path;
+      description = ''
+        Path to git projects (bare repositories) that should be served by
+        gitweb. Must not end with a slash.
+      '';
+    };
+
+    extraConfig = mkOption {
+      default = "";
+      type = types.lines;
+      description = ''
+        Verbatim configuration text appended to the generated gitweb.conf file.
+      '';
+      example = ''
+        $feature{'highlight'}{'default'} = [1];
+        $feature{'ctags'}{'default'} = [1];
+      '';
+    };
+
+  };
+
+  config = mkIf cfg.enable {
+
+    systemd.sockets.gitweb = {
+      description = "GitWeb Listen Socket";
+      listenStreams = [ "/run/gitweb.sock" ];
+      socketConfig = {
+        Accept = "false";
+        SocketUser = "nginx";
+        SocketGroup = "nginx";
+        SocketMode = "0600";
+      };
+      wantedBy = [ "sockets.target" ];
+    };
+    systemd.services.gitweb = {
+      description = "GitWeb service";
+      script = "${git}/share/gitweb/gitweb.cgi --fcgi";
+      serviceConfig = {
+        Type = "simple";
+        StandardInput = "socket";
+        User = "nginx";
+        Group = "nginx";
+      };
+    };
+
+    services.nginx = {
+      virtualHosts.default = {
+        locations."/gitweb" = {
+          root = "${pkgs.git}/share/gitweb";
+          extraConfig = ''
+            include ${pkgs.nginx}/conf/fastcgi_params;
+            fastcgi_param GITWEB_CONFIG ${gitwebConfigFile};
+            fastcgi_pass unix:/run/gitweb.sock;
+          '';
+        };
+      };
+    };
+
+  };
+
+  meta.maintainers = with maintainers; [ gnidorah ];
+
+}