aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/modules/server/cgit/smart-http.nix
diff options
context:
space:
mode:
Diffstat (limited to 'infra/libkookie/modules/server/cgit/smart-http.nix')
-rw-r--r--infra/libkookie/modules/server/cgit/smart-http.nix84
1 files changed, 84 insertions, 0 deletions
diff --git a/infra/libkookie/modules/server/cgit/smart-http.nix b/infra/libkookie/modules/server/cgit/smart-http.nix
new file mode 100644
index 000000000000..d45eb0d3a27a
--- /dev/null
+++ b/infra/libkookie/modules/server/cgit/smart-http.nix
@@ -0,0 +1,84 @@
+{ lib, pkgs, config, ... }:
+
+let
+ inherit (builtins) split;
+ inherit (lib) foldr groupBy head mapAttrs mapAttrsToList mkOption nameValuePair
+ optionalAttrs types;
+
+ cfg = config.services.git-http-backend;
+
+ instancesByVhost = groupBy ({ value, ... }: value.vhost)
+ (mapAttrsToList nameValuePair cfg.instances);
+
+ vhostConfigs = mapAttrs (vhost: instances:
+ foldr (l: r: l // r) {} (map ({ name, value }: let
+ path = head (split "/+$" value.path);
+ pathRegex =
+ "^${path}(/.*?)(\.git)?/(HEAD|info/refs|git-(upload|receive)-pack)$";
+ in {
+ locations = {
+ "~ ${pathRegex}" = {
+ fastcgiParams.SCRIPT_FILENAME = "${cfg.package}/bin/git-http-backend";
+ fastcgiParams.GIT_PROJECT_ROOT = value.projectRoot;
+ fastcgiParams.GIT_HTTP_EXPORT_ALL = "";
+ fastcgiParams.PATH_INFO = "$1$2/$3";
+
+ extraConfig = ''
+ client_max_body_size 0;
+ fastcgi_pass unix:/run/fcgiwrap.sock;
+ '';
+ };
+ };
+ }) instances)
+ ) instancesByVhost;
+in
+
+{
+ options.services.git-http-backend = {
+ package = mkOption {
+ type = types.package;
+ default = pkgs.gitMinimal;
+ description = "git package to use";
+ };
+
+ instances = mkOption {
+ type = types.attrsOf (types.submodule {
+ options = {
+ vhost = mkOption {
+ type = types.str;
+ example = "spectrum-os.org";
+ description = "Nginx vhost for the git server";
+ };
+
+ path = mkOption {
+ type = types.strMatching "/(.*[^/])?";
+ default = "/";
+ example = "/git";
+ description = ''
+ Path to be prepended to all clone URLs.
+
+ Leading slashes are mandatory; trailing slashes are forbidden.
+ '';
+ };
+
+ projectRoot = mkOption {
+ type = types.strMatching "/(.*[^/])?";
+ example = "/var/www/git";
+ description = ''
+ Directory in which to look for git repositories.
+
+ Leading slashes are mandatory; trailing slashes are forbidden.
+ '';
+ };
+ };
+ });
+ default = {};
+ description = "List of git-http-backend instances to run";
+ };
+ };
+
+ config = {
+ services.fcgiwrap = optionalAttrs (cfg.instances != {}) { enable = true; };
+ services.nginx.virtualHosts = vhostConfigs;
+ };
+}