aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCollin Williams <96917990+bluedragon1221@users.noreply.github.com>2026-02-21 17:18:40 -0600
committerCollin Williams <96917990+bluedragon1221@users.noreply.github.com>2026-02-21 17:18:40 -0600
commitda80bdbe5f325e06b9d4f01274f8b30efe4facf1 (patch)
treec93d55e280061e3cfc773f7c816af595cacffcd7 /modules
parent75711117f4cae27f28bb2f04de495dacc6282960 (diff)
add cgit
Diffstat (limited to 'modules')
-rw-r--r--modules/services/nixos/cgit.nix78
-rw-r--r--modules/services/nixos/default.nix1
2 files changed, 79 insertions, 0 deletions
diff --git a/modules/services/nixos/cgit.nix b/modules/services/nixos/cgit.nix
new file mode 100644
index 0000000..235335f
--- /dev/null
+++ b/modules/services/nixos/cgit.nix
@@ -0,0 +1,78 @@
+{
+ pkgs,
+ config,
+ lib,
+ hosts,
+ ...
+}: let
+ cfg = config.collinux.services.cgit;
+
+ authorizedKeys =
+ hosts
+ |> builtins.mapAttrs (_: data: ''command="git-shell -c \"$SSH_ORIGINAL_COMMAND\"" ${data.user_pubkey or null}'')
+ |> builtins.attrValues
+ |> builtins.filter (x: x != null);
+in {
+ config = lib.mkIf cfg.enable {
+ users.groups."git" = {};
+ users.users."git" = {
+ isSystemUser = true;
+ group = "git";
+ home = "/var/lib/cgit";
+ homeMode = 755;
+ shell = "${pkgs.git}/libexec/git-core/git-shell";
+
+ openssh.authorizedKeys.keys = authorizedKeys;
+ };
+
+ services.openssh.extraConfig = lib.mkAfter ''
+ Match User git
+ AllowTcpForwarding no
+ X11Forwarding no
+ PermitTunnel no
+ ForceCommand git-shell
+ PubkeyAuthentication yes
+ AuthenticationMethods publickey
+ '';
+
+ environment.etc."cgitrc" = ''
+ scan-path=/var/lib/cgit
+ virtual-root=/
+ repo.sort=age
+
+ readme=:README.md
+ '';
+
+ services.fcgiwrap.instance."cgit" = {
+ enable = true;
+
+ process = {
+ user = "git";
+ group = "git";
+ };
+
+ socket = {
+ user = "caddy";
+ group = "caddy";
+ type = "unix";
+ address = "/run/fcgiwrap-cgit.sock";
+ };
+ };
+
+ services.caddy.virtualHosts."git.ganymede".extraConfig = ''
+ tls internal
+
+ @assets path /cgit.css /cgit.js /cgit.png /favicon.ico /robots.txt
+ handle @assets {
+ root * ${pkgs.cgit}/cgit
+ file_server
+ }
+
+ reverse_proxy unix//run/fcgiwrap-cgit.sock {
+ transport fastcgi {
+ env SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi
+ }
+ }
+ '';
+ };
+}
diff --git a/modules/services/nixos/default.nix b/modules/services/nixos/default.nix
index 48c14b6..738213f 100644
--- a/modules/services/nixos/default.nix
+++ b/modules/services/nixos/default.nix
@@ -2,6 +2,7 @@
imports = [
./mopidy.nix
./forgejo.nix
+ ./cgit.nix
./openssh.nix
# ./jellyfin.nix
./caddy.nix