diff options
-rw-r--r-- | modules/server/git-http-backend/default.nix | 84 | ||||
-rw-r--r-- | modules/server/spectrum/default.nix | 2 | ||||
-rw-r--r-- | modules/server/spectrum/git-http-backend/default.nix | 11 | ||||
-rw-r--r-- | sys/atuin.nix | 6 |
4 files changed, 102 insertions, 1 deletions
diff --git a/modules/server/git-http-backend/default.nix b/modules/server/git-http-backend/default.nix new file mode 100644 index 000000000000..d45eb0d3a27a --- /dev/null +++ b/modules/server/git-http-backend/default.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; + }; +} diff --git a/modules/server/spectrum/default.nix b/modules/server/spectrum/default.nix index 1c7eda3181a8..d1aa00b7c289 100644 --- a/modules/server/spectrum/default.nix +++ b/modules/server/spectrum/default.nix @@ -1,5 +1,5 @@ { ... }: { - imports = [ ./cgit ./nginx ./public-inbox ./tor ]; + imports = [ ./cgit ./git-http-backend ./nginx ./public-inbox ./tor ]; } diff --git a/modules/server/spectrum/git-http-backend/default.nix b/modules/server/spectrum/git-http-backend/default.nix new file mode 100644 index 000000000000..e7a3b003f190 --- /dev/null +++ b/modules/server/spectrum/git-http-backend/default.nix @@ -0,0 +1,11 @@ +{ ... }: + +{ + imports = [ ../../git-http-backend ]; + + services.git-http-backend.instances.spectrum = { + vhost = "spectrum-os.org"; + path = "/git"; + projectRoot = "/home/spectrum/git"; + }; +} diff --git a/sys/atuin.nix b/sys/atuin.nix index bc947e0223ff..2de03655af3c 100644 --- a/sys/atuin.nix +++ b/sys/atuin.nix @@ -7,6 +7,7 @@ ../modules/server/irc ../modules/server/cgit ../modules/server/ftp + ../modules/server/git-http-backend ../modules/server/nginx ../modules/server/tor ../modules/server/xmpp @@ -161,6 +162,11 @@ ''; }; + services.git-http-backend.instances.qyliss = { + vhost = "git.qyliss.net"; + projectRoot = "/home/qyliss/git"; + }; + services.nginx.virtualHosts = let vhosts = { |